-
Notifications
You must be signed in to change notification settings - Fork 10
/
process_profile_test.go
69 lines (60 loc) · 1.04 KB
/
process_profile_test.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
package perf
import (
"os"
"testing"
"golang.org/x/sys/unix"
)
func TestProfiler(t *testing.T) {
profiler, err := NewProfiler(
unix.PERF_TYPE_HARDWARE,
unix.PERF_COUNT_HW_INSTRUCTIONS,
os.Getpid(),
-1,
)
if err != nil {
t.Fatal(err)
}
defer func() {
if err := profiler.Close(); err != nil {
t.Fatal(err)
}
}()
if err := profiler.Start(); err != nil {
t.Fatal(err)
}
profile := &ProfileValue{}
err = profiler.Profile(profile)
if err != nil {
t.Fatal(err)
}
if err := profiler.Stop(); err != nil {
t.Fatal(err)
}
}
func BenchmarkProfiler(b *testing.B) {
profiler, err := NewProfiler(
unix.PERF_TYPE_HARDWARE,
unix.PERF_COUNT_HW_INSTRUCTIONS,
os.Getpid(),
-1,
)
if err != nil {
b.Fatal(err)
}
defer func() {
if err := profiler.Close(); err != nil {
b.Fatal(err)
}
}()
profile := &ProfileValue{}
b.ResetTimer()
b.ReportAllocs()
if err := profiler.Start(); err != nil {
b.Fatal(err)
}
for n := 0; n < b.N; n++ {
if err := profiler.Profile(profile); err != nil {
b.Fatal(err)
}
}
}