@@ -155,13 +155,24 @@ function Base.show(io::IO, e::EventType)
155
155
end
156
156
end
157
157
158
- const SYS_perf_event_open = 298
158
+ const SYS_perf_event_open = if Sys. ARCH === :x86_64
159
+ Clong (298 )
160
+ elseif Sys. ARCH === :i686
161
+ Clong (336 )
162
+ elseif Sys. ARCH === :aarch64
163
+ Clong (241 )
164
+ elseif Sys. ARCH === :arm
165
+ Clong (364 )
166
+ else
167
+ Clong (- 1 ) # sentinel for unknown syscall ID
168
+ end
159
169
160
170
"""
161
171
perf_event_open(attr::perf_event_attr, pid, cpu, fd, flags)
162
172
"""
163
173
function perf_event_open (attr:: perf_event_attr , pid, cpu, leader_fd, flags)
164
174
r_attr = Ref (attr)
175
+ SYS_perf_event_open == - 1 && error (" perf_event_open error : unknown architecture" )
165
176
GC. @preserve r_attr begin
166
177
# Have to do a manual conversion, since the ABI is a vararg call
167
178
ptr = Base. unsafe_convert (Ptr{Cvoid}, Base. cconvert (Ptr{Cvoid}, r_attr))
@@ -325,16 +336,28 @@ function Base.show(io::IO, g::EventGroup)
325
336
print (io, " \t " , g. event_types[end ], " )" )
326
337
end
327
338
328
- const SYS_prctl = Clong (157 )
339
+ const SYS_prctl = if Sys. ARCH === :x86_64
340
+ Clong (157 )
341
+ elseif Sys. ARCH === :i686
342
+ Clong (172 )
343
+ elseif Sys. ARCH === :aarch64
344
+ Clong (167 )
345
+ elseif Sys. ARCH === :arm
346
+ Clong (172 )
347
+ else
348
+ Clong (- 1 ) # sentinel for unknown syscall ID
349
+ end
329
350
const PR_TASK_PERF_EVENTS_DISABLE = Cint (31 )
330
351
const PR_TASK_PERF_EVENTS_ENABLE = Cint (32 )
331
352
332
353
# syscall is lower overhead than calling libc's prctl
333
354
function enable_all! ()
355
+ SYS_prctl == - 1 && error (" prctl error : unknown architecture" )
334
356
res = ccall (:syscall , Cint, (Clong, Clong... ), SYS_prctl, PR_TASK_PERF_EVENTS_ENABLE)
335
357
Base. systemerror (:prctl , res < 0 )
336
358
end
337
359
function disable_all! ()
360
+ SYS_prctl == - 1 && error (" prctl error : unknown architecture" )
338
361
res = ccall (:syscall , Cint, (Clong, Clong... ), SYS_prctl, PR_TASK_PERF_EVENTS_DISABLE)
339
362
Base. systemerror (:prctl , res < 0 )
340
363
end
@@ -470,8 +493,10 @@ Base.close(b::PerfBenchThreaded) = foreach(close, b.data)
470
493
471
494
function make_bench_threaded (groups; threads = true )
472
495
data = PerfBench[]
496
+ warn_unsupported = true
473
497
for tid in (threads ? alltids () : zero (getpid ()))
474
- push! (data, PerfBench (tid, [EventGroup (g, pid = tid, userspace_only = false ) for g in groups]))
498
+ push! (data, PerfBench (tid, [EventGroup (g; pid = tid, userspace_only = false , warn_unsupported) for g in groups]))
499
+ warn_unsupported = false # First tid's events will already have issued warnings
475
500
end
476
501
return PerfBenchThreaded (data)
477
502
end
0 commit comments