forked from jaypipes/ghw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
topology_linux.go
72 lines (66 loc) · 1.69 KB
/
topology_linux.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Use and distribution licensed under the Apache license version 2.
//
// See the COPYING file in the root project directory for full text.
//
package ghw
import (
"io/ioutil"
"strconv"
"strings"
)
func (ctx *context) topologyFillInfo(info *TopologyInfo) error {
info.Nodes = ctx.topologyNodes()
if len(info.Nodes) == 1 {
info.Architecture = ARCHITECTURE_SMP
} else {
info.Architecture = ARCHITECTURE_NUMA
}
return nil
}
// TopologyNodes has been deprecated in 0.2. Please use the TopologyInfo.Nodes
// attribute.
// TODO(jaypipes): Remove in 1.0.
func TopologyNodes() ([]*TopologyNode, error) {
msg := `
The TopologyNodes() function has been DEPRECATED and will be removed in the 1.0
release of ghw. Please use the TopologyInfo.Nodes attribute.
`
warn(msg)
ctx := contextFromEnv()
return ctx.topologyNodes(), nil
}
func (ctx *context) topologyNodes() []*TopologyNode {
nodes := make([]*TopologyNode, 0)
files, err := ioutil.ReadDir(ctx.pathSysDevicesSystemNode())
if err != nil {
warn("failed to determine nodes: %s\n", err)
return nodes
}
for _, file := range files {
filename := file.Name()
if !strings.HasPrefix(filename, "node") {
continue
}
node := &TopologyNode{}
nodeID, err := strconv.Atoi(filename[4:])
if err != nil {
warn("failed to determine node ID: %s\n", err)
return nodes
}
node.ID = nodeID
cores, err := ctx.coresForNode(nodeID)
if err != nil {
warn("failed to determine cores for node: %s\n", err)
return nodes
}
node.Cores = cores
caches, err := ctx.cachesForNode(nodeID)
if err != nil {
warn("failed to determine caches for node: %s\n", err)
return nodes
}
node.Caches = caches
nodes = append(nodes, node)
}
return nodes
}