-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdoc.go
82 lines (61 loc) · 1.75 KB
/
doc.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
// Copyright 2019 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
/*
Package perf provides access to the Linux perf API.
Counting events
A Group represents a set of perf events measured together.
var g perf.Group
g.Add(perf.Instructions, perf.CPUCycles)
hw, err := g.Open(targetpid, perf.AnyCPU)
// ...
gc, err := hw.MeasureGroup(func() { ... })
Attr configures an individual event.
fa := &perf.Attr{
CountFormat: perf.CountFormat{
Running: true,
ID: true,
},
}
perf.PageFaults.Configure(fa)
faults, err := perf.Open(fa, perf.CallingThread, perf.AnyCPU, nil)
// ...
c, err := faults.Measure(func() { ... })
Sampling events
Overflow records are available once the MapRing method on Event is called:
var ev perf.Event // initialized previously
ev.MapRing()
ev.Enable()
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
for {
rec, err := ev.ReadRecord(ctx)
// process rec
}
Tracepoints are also supported:
wa := &perf.Attr{
SampleFormat: perf.SampleFormat{
Pid: true,
Tid: true,
IP: true,
},
}
wa.SetSamplePeriod(1)
wa.SetWakeupEvents(1)
wtp := perf.Tracepoint("syscalls", "sys_enter_write")
wtp.Configure(wa)
writes, err := perf.Open(wa, targetpid, perf.AnyCPU, nil)
// ...
c, err := writes.Measure(func() { ... })
// ...
fmt.Printf("saw %d writes\n", c.Value)
rec, err := writes.ReadRecord(ctx)
// ...
sr, ok := rec.(*perf.SampleRecord)
// ...
fmt.Printf("pid = %d, tid = %d\n", sr.Pid, sr.Tid)
For more detailed information, see the examples, and man 2 perf_event_open.
NOTE: this package is experimental and does not yet offer compatibility
guarantees.
*/
package perf