Skip to content

Commit fe015f0

Browse files
authored
Merge pull request #7 from JuliaPerf/vc/cleanup
Cherry-pick improvements
2 parents 57b84ac + d2326ef commit fe015f0

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

LICENSE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
The LinuxPerf.jl package is licensed under the MIT "Expat" License:
22

33
> Copyright (c) 2016: Oscar Blumberg.
4+
> Copyright (c) 2020: Nathan Daly, Valentin Churavy, and other contributors.
45
>
56
> Permission is hereby granted, free of charge, to any person obtaining a copy
67
> of this software and associated documentation files (the "Software"), to deal

src/LinuxPerf.jl

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,16 @@ end
5555

5656
perf_event_attr() = perf_event_attr(ntuple(x->0, fieldcount(perf_event_attr))...)
5757

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+
5865
const EVENT_TYPES =
5966
[
60-
(:hw, 0, # PERF_TYPE_HARDWARE
67+
(:hw, PERF_TYPE_HARDWARE, # PERF_TYPE_HARDWARE
6168
[(:cycles, 0), # PERF_COUNT_HW_CPU_CYCLES
6269
(:instructions, 1), # PERF_COUNT_HW_INSTRUCTIONS
6370
(:cache_access, 2), # PERF_COUNT_HW_CACHE_REFERENCES
@@ -78,15 +85,16 @@ const EVENT_TYPES =
7885
])
7986
]
8087

81-
# cache events have special encoding
82-
const PERF_TYPE_HW_CACHE = 3
88+
89+
# cache events have special encoding, PERF_TYPE_HW_CACHE
8390
const CACHE_TYPES =
8491
[(:L1_data, 0),
8592
(:L1_insn, 1),
8693
(:LLC, 2),
8794
(:TLB_data, 3),
8895
(:TLB_insn, 4),
89-
(:BPU, 5)]
96+
(:BPU, 5),
97+
(:NODE, 6)]
9098
const CACHE_OPS =
9199
[(:read, 0),
92100
(:write, 1),
@@ -194,7 +202,9 @@ mutable struct EventGroup
194202

195203
function EventGroup(types::Vector{EventType};
196204
warn_unsupported = true,
197-
userspace_only = true
205+
userspace_only = true,
206+
pinned = false,
207+
exclusive = false,
198208
)
199209
my_types = EventType[]
200210
group = new(-1, Cint[], EventType[])
@@ -205,12 +215,24 @@ mutable struct EventGroup
205215
attr.size = sizeof(perf_event_attr)
206216
attr.config = evt_type.event
207217
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
211220
if group.leader_fd == -1
212221
attr.flags |= (1 << 0) # start disabled
213222
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+
214236
attr.read_format =
215237
PERF_FORMAT_GROUP |
216238
PERF_FORMAT_TOTAL_TIME_ENABLED |
@@ -269,8 +291,10 @@ reset!(g::EventGroup) = ioctl(g, PERF_EVENT_IOC_RESET)
269291

270292
function Base.close(g::EventGroup)
271293
for fd in g.fds
294+
fd == g.leader_fd && continue # close leader_fd last
272295
ccall(:close, Cint, (Cint,), fd)
273296
end
297+
ccall(:close, Cint, (Cint,), g.leader_fd)
274298
end
275299

276300
mutable struct PerfBench

0 commit comments

Comments
 (0)