-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
capabilities.go
102 lines (85 loc) · 1.94 KB
/
capabilities.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package api
import (
"encoding/xml"
"fmt"
)
type yesnobool bool
type Capabilities struct {
XMLName xml.Name `xml:"capabilities"`
Host Host `xml:"host"`
}
type Host struct {
UUID string `xml:"uuid"`
CPU HostCPU `xml:"cpu"`
Topology Topology `xml:"topology"`
}
type HostCPU struct {
Arch string `xml:"arch"`
Model string `xml:"model"`
Vendor string `xml:"vendor"`
Counter []Counter `xml:"counter"`
}
type Counter struct {
Name string `xml:"name,attr"`
Frequency int64 `xml:"frequency,attr"`
Scaling yesnobool `xml:"scaling,attr"`
}
type CPU struct {
ID uint32 `xml:"id,attr"`
SocketID uint32 `xml:"socket_id,attr"`
DieID uint32 `xml:"die_id,attr"`
CoreID uint32 `xml:"core_id,attr"`
Siblings string `xml:"siblings,attr"`
}
type CPUs struct {
Num int `xml:"num,attr"`
CPU []CPU `xml:"cpu"`
}
type Distances struct {
Sibling []Sibling `xml:"sibling"`
}
type Sibling struct {
ID uint32 `xml:"id,attr"`
Value uint64 `xml:"value,attr"`
}
type Pages struct {
Count uint64 `xml:",chardata"`
Unit string `xml:"unit,attr"`
Size uint32 `xml:"size,attr"`
}
type Memory struct {
Amount uint64 `xml:",chardata"`
Unit string `xml:"unit,attr"`
}
type Cell struct {
ID uint32 `xml:"id,attr"`
Memory Memory `xml:"memory"`
Pages []Pages `xml:"pages"`
Distances Distances `xml:"distances"`
Cpus CPUs `xml:"cpus"`
}
type Cells struct {
Num uint32 `xml:"num,attr"`
Cell []Cell `xml:"cell"`
}
type Topology struct {
Cells Cells `xml:"cells"`
}
func (c *Capabilities) GetTSCCounter() (*Counter, error) {
for _, c := range c.Host.CPU.Counter {
if c.Name == "tsc" {
return &c, nil
}
}
return nil, nil
}
func (b *yesnobool) UnmarshalXMLAttr(attr xml.Attr) error {
if attr.Value == "yes" {
*b = true
return nil
} else if attr.Value == "no" {
*b = false
return nil
}
return fmt.Errorf("value %v of %v is not (yes|no)", attr.Value, attr.Name)
}