55
55
56
56
perf_event_attr () = perf_event_attr (ntuple (x-> 0 , fieldcount (perf_event_attr))... )
57
57
58
+ const PERF_TYPE_HARDWARE = 0
59
+ const PERF_TYPE_SOFTWARE = 1
60
+ const PERF_TYPE_TRACEPOINT = 2
61
+ const PERF_TYPE_HW_CACHE = 3
62
+ const PERF_TYPE_RAW = 4
63
+ const PERF_TYPE_BREAKPOINT = 3
64
+
58
65
const EVENT_TYPES =
59
66
[
60
- (:hw , 0 , # PERF_TYPE_HARDWARE
67
+ (:hw , PERF_TYPE_HARDWARE , # PERF_TYPE_HARDWARE
61
68
[(:cycles , 0 ), # PERF_COUNT_HW_CPU_CYCLES
62
69
(:instructions , 1 ), # PERF_COUNT_HW_INSTRUCTIONS
63
70
(:cache_access , 2 ), # PERF_COUNT_HW_CACHE_REFERENCES
@@ -78,15 +85,16 @@ const EVENT_TYPES =
78
85
])
79
86
]
80
87
81
- # cache events have special encoding
82
- const PERF_TYPE_HW_CACHE = 3
88
+
89
+ # cache events have special encoding, PERF_TYPE_HW_CACHE
83
90
const CACHE_TYPES =
84
91
[(:L1_data , 0 ),
85
92
(:L1_insn , 1 ),
86
93
(:LLC , 2 ),
87
94
(:TLB_data , 3 ),
88
95
(:TLB_insn , 4 ),
89
- (:BPU , 5 )]
96
+ (:BPU , 5 ),
97
+ (:NODE , 6 )]
90
98
const CACHE_OPS =
91
99
[(:read , 0 ),
92
100
(:write , 1 ),
@@ -194,7 +202,9 @@ mutable struct EventGroup
194
202
195
203
function EventGroup (types:: Vector{EventType} ;
196
204
warn_unsupported = true ,
197
- userspace_only = true
205
+ userspace_only = true ,
206
+ pinned = false ,
207
+ exclusive = false ,
198
208
)
199
209
my_types = EventType[]
200
210
group = new (- 1 , Cint[], EventType[])
@@ -205,12 +215,24 @@ mutable struct EventGroup
205
215
attr. size = sizeof (perf_event_attr)
206
216
attr. config = evt_type. event
207
217
attr. sample_period_or_freq = 0
208
- if userspace_only
209
- attr. flags = (1 << 5 ) # exclude kernel
210
- end
218
+ attr. flags = 0
219
+ # first attribute becomes group leader
211
220
if group. leader_fd == - 1
212
221
attr. flags |= (1 << 0 ) # start disabled
213
222
end
223
+ if pinned
224
+ attr. flags |= (1 << 2 )
225
+ end
226
+ if exclusive
227
+ attr. flags |= (1 << 3 )
228
+ end
229
+ # (1 << 4) exclude_user
230
+ if userspace_only
231
+ attr. flags |= (1 << 5 ) # exclude kernel
232
+ end
233
+ # (1 << 6) exclude hypervisor
234
+ # (1 << 7) exclude idle
235
+
214
236
attr. read_format =
215
237
PERF_FORMAT_GROUP |
216
238
PERF_FORMAT_TOTAL_TIME_ENABLED |
@@ -269,8 +291,10 @@ reset!(g::EventGroup) = ioctl(g, PERF_EVENT_IOC_RESET)
269
291
270
292
function Base. close (g:: EventGroup )
271
293
for fd in g. fds
294
+ fd == g. leader_fd && continue # close leader_fd last
272
295
ccall (:close , Cint, (Cint,), fd)
273
296
end
297
+ ccall (:close , Cint, (Cint,), g. leader_fd)
274
298
end
275
299
276
300
mutable struct PerfBench
0 commit comments