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
|
package guestmetric
import (
"testing"
)
func TestCollector(t *testing.T) {
c := Collector{
Client: nil,
}
funcs := []CollectFunc{
c.CollectDisk,
c.CollectMemory,
c.CollectMisc,
c.CollectNetworkAddr,
}
for _, f := range funcs {
metric, err := f()
if err != nil {
t.Errorf("%#v error: %#v\n", f, err)
}
t.Logf("%#v return %#v", f, metric)
}
}
func doBenchmark(b *testing.B, f CollectFunc) {
b.Logf("doBenchmark 1000 for %#v", f)
for i := 0; i < 1000; i++ {
if _, err := f(); err != nil {
b.Errorf("%#v error: %#v\n", f, err)
}
}
}
func BenchmarkCollectorDisk(b *testing.B) {
c := Collector{
Client: nil,
}
doBenchmark(b, c.CollectDisk)
}
func BenchmarkCollectMemory(b *testing.B) {
c := Collector{
Client: nil,
}
doBenchmark(b, c.CollectMemory)
}
func BenchmarkCollectMisc(b *testing.B) {
c := Collector{
Client: nil,
}
doBenchmark(b, c.CollectMisc)
}
func BenchmarkCollectNetwork(b *testing.B) {
c := Collector{
Client: nil,
}
doBenchmark(b, c.CollectNetworkAddr)
}
|