Skip to content

Commit c4077ed

Browse files
committed
Add exclude_kernel option
1 parent b6a85c5 commit c4077ed

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/LinuxPerf.jl

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -366,13 +366,13 @@ const reasonable_defaults =
366366
[EventType(:cache, :L1_data, :write, :access),
367367
EventType(:cache, :L1_data, :write, :miss)]=#]
368368

369-
function make_bench(x)
369+
function make_bench(x; kwargs...)
370370
groups = EventGroup[]
371371
for y in x
372372
if isa(y, EventType)
373-
push!(groups, EventGroup([y]))
373+
push!(groups, EventGroup([y]; kwargs...))
374374
else
375-
push!(groups, EventGroup(y))
375+
push!(groups, EventGroup(y; kwargs...))
376376
end
377377
end
378378
PerfBench(groups)
@@ -464,17 +464,22 @@ function parse_pstats_options(opts)
464464
(instructions, branch-instructions, branch-misses),
465465
(task-clock, context-switches, cpu-migrations, page-faults)
466466
")
467+
exclude_kernel = false
467468
for opt in opts
468469
if opt isa AbstractString
469470
events = parse_groups(opt)
470471
elseif opt isa Expr && opt.head == :(=)
471472
key, val = opt.args
472-
error("unknown key: $(key)")
473+
if key === :exclude_kernel
474+
exclude_kernel = esc(val)
475+
else
476+
error("unknown key: $(key)")
477+
end
473478
else
474479
error("unknown option: $(opt)")
475480
end
476481
end
477-
return (events = events,)
482+
return (events = events, exclude_kernel = exclude_kernel,)
478483
end
479484

480485
# syntax: groups = (group ',')* group
@@ -682,7 +687,8 @@ may follow these columns after a hash (#) character.
682687
683688
The macro can take some options. If a string object is passed, it is a
684689
comma-separated list of event names to measure. An event group can be
685-
indicated by a pair of parentheses.
690+
indicated by a pair of parentheses. If `exclude_kernel = true` is passed, the
691+
count excludes events that happen in kernel space (`false` by default).
686692
687693
# Examples
688694
@@ -722,7 +728,7 @@ macro pstats(args...)
722728
opts, expr = parse_pstats_options(args[1:end-1]), args[end]
723729
quote
724730
(function ()
725-
bench = make_bench($(opts.events))
731+
bench = make_bench($(opts.events), userspace_only = $(opts.exclude_kernel))
726732
enable!(bench)
727733
val = $(esc(expr))
728734
disable!(bench)

0 commit comments

Comments
 (0)