This repository has been archived by the owner on Nov 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix various style-related linters (#170)
* style: apply gofmt (darwin) * style: add copyright in each go file * style: add comments for packages, exported functions, exported types (mostly darwin) * style: fix receiver naming lint warning * style: fix unused argument lint warning (darwin) * style: fix unnecessary conversion lint warning * style: fix miscellaneous linter warnings, eg. error format specifier, invalid argument for function, typo * style: fix capitalized error message lint warning * style: fix typo warn lint * style: add missing comments on exported fields, const and packages (windows) * style: fix naming lint warnings (windows) * style: fix unused types / functions / fields and unnecessary cast lint warnings (windows) * style: add missing comments on exported fields, const and packages (windows continued) * style: fix naming lint warnings (windows, continued) * style: fix unused types / functions / fields and unnecessary cast lint warnings (windows continued) * style: fix naming lint warnings (windows, continued) * style: fix unnecessary cast lint warnings (windows continued) * style: fix naming lint warnings (windows, continued) * Update filesystem/filesystem.go Co-authored-by: Srdjan Grubor <[email protected]> * style: fix var-naming lint warning about Ip,Cpu,Json,Id capitalization * style: fix indent --------- Co-authored-by: Srdjan Grubor <[email protected]>
- Loading branch information
Showing
44 changed files
with
615 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
// This file is licensed under the MIT License. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright © 2015 Kentaro Kuribayashi <[email protected]> | ||
// Copyright 2014-present Datadog, Inc. | ||
|
||
// Package cpu regroups collecting information about the CPU | ||
package cpu | ||
|
||
import ( | ||
|
@@ -9,6 +15,8 @@ import ( | |
) | ||
|
||
// Cpu holds metadata about the host CPU | ||
// | ||
//nolint:revive | ||
type Cpu struct { | ||
// VendorId the CPU vendor ID | ||
VendorId string | ||
|
@@ -43,20 +51,24 @@ type Cpu struct { | |
|
||
const name = "cpu" | ||
|
||
func (self *Cpu) Name() string { | ||
// Name returns the name of the package | ||
func (cpu *Cpu) Name() string { | ||
return name | ||
} | ||
|
||
func (self *Cpu) Collect() (result interface{}, err error) { | ||
result, err = getCpuInfo() | ||
// Collect collects the CPU information. | ||
// Returns an object which can be converted to a JSON or an error if nothing could be collected. | ||
// Tries to collect as much information as possible. | ||
func (cpu *Cpu) Collect() (result interface{}, err error) { | ||
result, err = getCPUInfo() | ||
return | ||
} | ||
|
||
// Get returns a Cpu struct already initialized, a list of warnings and an error. The method will try to collect as much | ||
// Get returns a CPU struct already initialized, a list of warnings and an error. The method will try to collect as much | ||
// metadata as possible, an error is returned if nothing could be collected. The list of warnings contains errors if | ||
// some metadata could not be collected. | ||
func Get() (*Cpu, []string, error) { | ||
cpuInfo, err := getCpuInfo() | ||
cpuInfo, err := getCPUInfo() | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
// This file is licensed under the MIT License. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright © 2015 Kentaro Kuribayashi <[email protected]> | ||
// Copyright 2014-present Datadog, Inc. | ||
|
||
package cpu | ||
|
||
import ( | ||
|
@@ -17,8 +22,7 @@ var cpuMap = map[string]string{ | |
"machdep.cpu.stepping": "stepping", | ||
} | ||
|
||
func getCpuInfo() (cpuInfo map[string]string, err error) { | ||
|
||
func getCPUInfo() (cpuInfo map[string]string, err error) { | ||
cpuInfo = make(map[string]string) | ||
|
||
for option, key := range cpuMap { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
// +build linux | ||
// +build arm64 | ||
// This file is licensed under the MIT License. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright © 2015 Kentaro Kuribayashi <[email protected]> | ||
// Copyright 2014-present Datadog, Inc. | ||
|
||
//go:build linux && arm64 | ||
// +build linux,arm64 | ||
|
||
package cpu | ||
|
||
|
@@ -18,7 +23,7 @@ import ( | |
// nodeNRegex recognizes directories named `nodeNN` | ||
var nodeNRegex = regexp.MustCompile("^node[0-9]+$") | ||
|
||
func getCpuInfo() (cpuInfo map[string]string, err error) { | ||
func getCPUInfo() (cpuInfo map[string]string, err error) { | ||
cpuInfo = make(map[string]string) | ||
|
||
procCpu, err := readProcCpuInfo() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
// +build linux | ||
// +build !arm64 | ||
// This file is licensed under the MIT License. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright © 2015 Kentaro Kuribayashi <[email protected]> | ||
// Copyright 2014-present Datadog, Inc. | ||
|
||
//go:build linux && !arm64 | ||
// +build linux,!arm64 | ||
|
||
package cpu | ||
|
||
|
@@ -28,7 +33,7 @@ var perPhysicalProcValues = []string{ | |
"cpu_logical_processors", | ||
} | ||
|
||
func getCpuInfo() (cpuInfo map[string]string, err error) { | ||
func getCPUInfo() (cpuInfo map[string]string, err error) { | ||
lines, err := readProcFile() | ||
if err != nil { | ||
return | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
// This file is licensed under the MIT License. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright © 2015 Kentaro Kuribayashi <[email protected]> | ||
// Copyright 2014-present Datadog, Inc. | ||
|
||
package cpu | ||
|
||
import ( | ||
|
@@ -11,24 +16,33 @@ import ( | |
"golang.org/x/sys/windows/registry" | ||
) | ||
|
||
var getCpuInfo = GetCpuInfo | ||
|
||
// Values that need to be multiplied by the number of physical processors | ||
var perPhysicalProcValues = []string{ | ||
"cpu_cores", | ||
"cpu_logical_processors", | ||
} | ||
var getCPUInfo = GetCpuInfo | ||
|
||
// ERROR_INSUFFICIENT_BUFFER is the error number associated with the | ||
// "insufficient buffer size" error | ||
// | ||
//nolint:revive | ||
const ERROR_INSUFFICIENT_BUFFER syscall.Errno = 122 | ||
|
||
const registryHive = "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0" | ||
|
||
// CACHE_DESCRIPTOR contains cache related information | ||
// see https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-cache_descriptor | ||
// | ||
//nolint:unused,revive | ||
type CACHE_DESCRIPTOR struct { | ||
Level uint8 | ||
Associativity uint8 | ||
LineSize uint16 | ||
Size uint32 | ||
cacheType uint32 | ||
} | ||
|
||
// SYSTEM_LOGICAL_PROCESSOR_INFORMATION describes the relationship | ||
// between the specified processor set. | ||
// see https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-system_logical_processor_information | ||
// | ||
//nolint:unused,revive | ||
type SYSTEM_LOGICAL_PROCESSOR_INFORMATION struct { | ||
ProcessorMask uintptr | ||
Relationship int // enum (int) | ||
|
@@ -39,16 +53,32 @@ type SYSTEM_LOGICAL_PROCESSOR_INFORMATION struct { | |
|
||
//.const SYSTEM_LOGICAL_PROCESSOR_INFORMATION_SIZE = 32 | ||
|
||
// GROUP_AFFINITY represents a processor group-specific affinity, | ||
// such as the affinity of a thread. | ||
// see https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-group_affinity | ||
// | ||
//nolint:revive | ||
type GROUP_AFFINITY struct { | ||
Mask uintptr | ||
Group uint16 | ||
Reserved [3]uint16 | ||
} | ||
|
||
// NUMA_NODE_RELATIONSHIP represents information about a NUMA node | ||
// in a processor group. | ||
// see https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-numa_node_relationship | ||
// | ||
//nolint:revive | ||
type NUMA_NODE_RELATIONSHIP struct { | ||
NodeNumber uint32 | ||
Reserved [20]uint8 | ||
GroupMask GROUP_AFFINITY | ||
} | ||
|
||
// CACHE_RELATIONSHIP describes cache attributes. | ||
// see https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-cache_relationship | ||
// | ||
//nolint:revive | ||
type CACHE_RELATIONSHIP struct { | ||
Level uint8 | ||
Associativity uint8 | ||
|
@@ -59,18 +89,34 @@ type CACHE_RELATIONSHIP struct { | |
GroupMask GROUP_AFFINITY | ||
} | ||
|
||
// PROCESSOR_GROUP_INFO represents the number and affinity of processors | ||
// in a processor group. | ||
// see https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-processor_group_info | ||
// | ||
//nolint:revive | ||
type PROCESSOR_GROUP_INFO struct { | ||
MaximumProcessorCount uint8 | ||
ActiveProcessorCount uint8 | ||
Reserved [38]uint8 | ||
ActiveProcessorMask uintptr | ||
} | ||
|
||
// GROUP_RELATIONSHIP represents information about processor groups. | ||
// see https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-group_relationship | ||
// | ||
//nolint:revive | ||
type GROUP_RELATIONSHIP struct { | ||
MaximumGroupCount uint16 | ||
ActiveGroupCount uint16 | ||
Reserved [20]uint8 | ||
// variable size array of PROCESSOR_GROUP_INFO | ||
} | ||
|
||
// PROCESSOR_RELATIONSHIP represents information about affinity | ||
// within a processor group. | ||
// see https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-processor_relationship | ||
// | ||
//nolint:unused,revive | ||
type PROCESSOR_RELATIONSHIP struct { | ||
Flags uint8 | ||
EfficiencyClass uint8 | ||
|
@@ -79,6 +125,11 @@ type PROCESSOR_RELATIONSHIP struct { | |
// what follows is an array of zero or more GROUP_AFFINITY structures | ||
} | ||
|
||
// SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX contains information about | ||
// the relationships of logical processors and related hardware. | ||
// https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-system_logical_processor_information_ex | ||
// | ||
//nolint:revive | ||
type SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX struct { | ||
Relationship int | ||
Size uint32 | ||
|
@@ -89,12 +140,31 @@ type SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX struct { | |
// GROUP_RELATIONSHIP | ||
} | ||
|
||
const RelationProcessorCore = 0 | ||
const RelationNumaNode = 1 | ||
const RelationCache = 2 | ||
const RelationProcessorPackage = 3 | ||
const RelationGroup = 4 | ||
// see https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getlogicalprocessorinformationex | ||
const ( | ||
// RelationProcessorCore retrieves information about logical processors | ||
// that share a single processor core. | ||
RelationProcessorCore = 0 | ||
// RelationNumaNode retrieves information about logical processors | ||
// that are part of the same NUMA node. | ||
RelationNumaNode = 1 | ||
// RelationCache retrieves information about logical processors | ||
// that share a cache. | ||
RelationCache = 2 | ||
// RelationProcessorPackage retrieves information about logical processors | ||
// that share a physical package. | ||
RelationProcessorPackage = 3 | ||
// RelationGroup retrieves information about logical processors | ||
// that share a processor group. | ||
RelationGroup = 4 | ||
) | ||
|
||
// SYSTEM_INFO contains information about the current computer system. | ||
// This includes the architecture and type of the processor, the number | ||
// of processors in the system, the page size, and other such information. | ||
// see https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/ns-sysinfoapi-system_info | ||
// | ||
//nolint:revive | ||
type SYSTEM_INFO struct { | ||
wProcessorArchitecture uint16 | ||
wReserved uint16 | ||
|
@@ -109,6 +179,9 @@ type SYSTEM_INFO struct { | |
wProcessorRevision uint16 | ||
} | ||
|
||
// CPU_INFO contains information about cpu, eg. number of cores, cache size | ||
// | ||
//nolint:revive | ||
type CPU_INFO struct { | ||
numaNodeCount int // number of NUMA nodes | ||
pkgcount int // number of packages (physical CPUS) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
// This file is licensed under the MIT License. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright © 2015 Kentaro Kuribayashi <[email protected]> | ||
// Copyright 2014-present Datadog, Inc. | ||
|
||
package cpu | ||
|
||
import ( | ||
|
@@ -6,11 +11,16 @@ import ( | |
"unsafe" | ||
) | ||
|
||
// SYSTEM_LOGICAL_PROCESSOR_INFORMATION_SIZE is the size of | ||
// SYSTEM_LOGICAL_PROCESSOR_INFORMATION struct | ||
// | ||
//nolint:revive | ||
const SYSTEM_LOGICAL_PROCESSOR_INFORMATION_SIZE = 24 | ||
|
||
func getSystemLogicalProcessorInformationSize() int { | ||
return SYSTEM_LOGICAL_PROCESSOR_INFORMATION_SIZE | ||
} | ||
|
||
func byteArrayToProcessorStruct(data []byte) (info SYSTEM_LOGICAL_PROCESSOR_INFORMATION) { | ||
info.ProcessorMask = uintptr(binary.LittleEndian.Uint32(data)) | ||
info.Relationship = int(binary.LittleEndian.Uint32(data[4:])) | ||
|
Oops, something went wrong.