@@ -345,13 +345,13 @@ const reasonable_defaults =
345345 [EventType(:cache, :L1_data, :write, :access),
346346 EventType(:cache, :L1_data, :write, :miss)]=# ]
347347
348- function make_bench (x)
348+ function make_bench (x; kwargs ... )
349349 groups = EventGroup[]
350350 for y in x
351351 if isa (y, EventType)
352- push! (groups, EventGroup ([y]))
352+ push! (groups, EventGroup ([y]; kwargs ... ))
353353 else
354- push! (groups, EventGroup (y))
354+ push! (groups, EventGroup (y; kwargs ... ))
355355 end
356356 end
357357 PerfBench (groups)
@@ -443,17 +443,22 @@ function parse_pstats_options(opts)
443443 (instructions, branch-instructions, branch-misses),
444444 (task-clock, context-switches, cpu-migrations, page-faults)
445445 " )
446+ exclude_kernel = false
446447 for opt in opts
447448 if opt isa AbstractString
448449 events = parse_groups (opt)
449450 elseif opt isa Expr && opt. head == :(= )
450451 key, val = opt. args
451- error (" unknown key: $(key) " )
452+ if key === :exclude_kernel
453+ exclude_kernel = esc (val)
454+ else
455+ error (" unknown key: $(key) " )
456+ end
452457 else
453458 error (" unknown option: $(opt) " )
454459 end
455460 end
456- return (events = events,)
461+ return (events = events, exclude_kernel = exclude_kernel, )
457462end
458463
459464# syntax: groups = (group ',')* group
@@ -661,7 +666,8 @@ may follow these columns after a hash (#) character.
661666
662667The macro can take some options. If a string object is passed, it is a
663668comma-separated list of event names to measure. An event group can be
664- indicated by a pair of parentheses.
669+ indicated by a pair of parentheses. If `exclude_kernel = true` is passed, the
670+ count excludes events that happen in kernel space (`false` by default).
665671
666672# Examples
667673
@@ -701,7 +707,7 @@ macro pstats(args...)
701707 opts, expr = parse_pstats_options (args[1 : end - 1 ]), args[end ]
702708 quote
703709 (function ()
704- bench = make_bench ($ (opts. events))
710+ bench = make_bench ($ (opts. events), userspace_only = $ (opts . exclude_kernel) )
705711 enable! (bench)
706712 val = $ (esc (expr))
707713 disable! (bench)
0 commit comments