本文整理汇总了Golang中github.com/google/cadvisor/info/v1.Node类的典型用法代码示例。如果您正苦于以下问题:Golang Node类的具体用法?Golang Node怎么用?Golang Node使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Node类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestTopologyWithSimpleCpuinfo
func TestTopologyWithSimpleCpuinfo(t *testing.T) {
sysFs := &fakesysfs.FakeSysFs{}
c := sysfs.CacheInfo{
Size: 32 * 1024,
Type: "unified",
Level: 1,
Cpus: 1,
}
sysFs.SetCacheInfo(c)
topology, numCores, err := getTopology(sysFs, "processor\t: 0\n")
if err != nil {
t.Errorf("Expected cpuinfo with no topology data to succeed.")
}
node := info.Node{Id: 0}
core := info.Core{Id: 0}
core.Threads = append(core.Threads, 0)
cache := info.Cache{
Size: 32 * 1024,
Type: "unified",
Level: 1,
}
core.Caches = append(core.Caches, cache)
node.Cores = append(node.Cores, core)
// Copy over Memory from result. TODO(rjnagal): Use memory from fake.
node.Memory = topology[0].Memory
expected := []info.Node{node}
if !reflect.DeepEqual(topology, expected) {
t.Errorf("Expected topology %+v, got %+v", expected, topology)
}
if numCores != 1 {
t.Errorf("Expected 1 core, found %d", numCores)
}
}
开发者ID:chenzhen411,项目名称:kubernetes,代码行数:33,代码来源:topology_test.go
示例2: addNode
func addNode(nodes *[]info.Node, id int) (int, error) {
var idx int
if id == -1 {
// Some VMs don't fill topology data. Export single package.
id = 0
}
ok, idx := findNode(*nodes, id)
if !ok {
// New node
node := info.Node{Id: id}
// Add per-node memory information.
meminfo := fmt.Sprintf("/sys/devices/system/node/node%d/meminfo", id)
out, err := ioutil.ReadFile(meminfo)
// Ignore if per-node info is not available.
if err == nil {
m, err := parseCapacity(out, memoryCapacityRegexp)
if err != nil {
return -1, err
}
node.Memory = uint64(m)
}
*nodes = append(*nodes, node)
idx = len(*nodes) - 1
}
return idx, nil
}
开发者ID:Clarifai,项目名称:kubernetes,代码行数:27,代码来源:machine.go
示例3: TestTopology
func TestTopology(t *testing.T) {
testfile := "./testdata/cpuinfo"
testcpuinfo, err := ioutil.ReadFile(testfile)
if err != nil {
t.Fatalf("unable to read input test file %s", testfile)
}
sysFs := &fakesysfs.FakeSysFs{}
c := sysfs.CacheInfo{
Size: 32 * 1024,
Type: "unified",
Level: 1,
Cpus: 2,
}
sysFs.SetCacheInfo(c)
topology, numCores, err := getTopology(sysFs, string(testcpuinfo))
if err != nil {
t.Errorf("failed to get topology for sample cpuinfo %s", string(testcpuinfo))
}
if numCores != 12 {
t.Errorf("Expected 12 cores, found %d", numCores)
}
expected_topology := []info.Node{}
numNodes := 2
numCoresPerNode := 3
numThreads := 2
cache := info.Cache{
Size: 32 * 1024,
Type: "unified",
Level: 1,
}
for i := 0; i < numNodes; i++ {
node := info.Node{Id: i}
// Copy over Memory from result. TODO(rjnagal): Use memory from fake.
node.Memory = topology[i].Memory
for j := 0; j < numCoresPerNode; j++ {
core := info.Core{Id: i*numCoresPerNode + j}
core.Caches = append(core.Caches, cache)
for k := 0; k < numThreads; k++ {
core.Threads = append(core.Threads, k*numCoresPerNode*numNodes+core.Id)
}
node.Cores = append(node.Cores, core)
}
expected_topology = append(expected_topology, node)
}
if !reflect.DeepEqual(topology, expected_topology) {
t.Errorf("Expected topology %+v, got %+v", expected_topology, topology)
}
}
开发者ID:chenzhen411,项目名称:kubernetes,代码行数:50,代码来源:topology_test.go
注:本文中的github.com/google/cadvisor/info/v1.Node类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论