@@ -366,13 +366,13 @@ const reasonable_defaults =
366
366
[EventType(:cache, :L1_data, :write, :access),
367
367
EventType(:cache, :L1_data, :write, :miss)]=# ]
368
368
369
- function make_bench (x)
369
+ function make_bench (x; kwargs ... )
370
370
groups = EventGroup[]
371
371
for y in x
372
372
if isa (y, EventType)
373
- push! (groups, EventGroup ([y]))
373
+ push! (groups, EventGroup ([y]; kwargs ... ))
374
374
else
375
- push! (groups, EventGroup (y))
375
+ push! (groups, EventGroup (y; kwargs ... ))
376
376
end
377
377
end
378
378
PerfBench (groups)
@@ -464,17 +464,22 @@ function parse_pstats_options(opts)
464
464
(instructions, branch-instructions, branch-misses),
465
465
(task-clock, context-switches, cpu-migrations, page-faults)
466
466
" )
467
+ exclude_kernel = false
467
468
for opt in opts
468
469
if opt isa AbstractString
469
470
events = parse_groups (opt)
470
471
elseif opt isa Expr && opt. head == :(= )
471
472
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
473
478
else
474
479
error (" unknown option: $(opt) " )
475
480
end
476
481
end
477
- return (events = events,)
482
+ return (events = events, exclude_kernel = exclude_kernel, )
478
483
end
479
484
480
485
# syntax: groups = (group ',')* group
@@ -682,7 +687,8 @@ may follow these columns after a hash (#) character.
682
687
683
688
The macro can take some options. If a string object is passed, it is a
684
689
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).
686
692
687
693
# Examples
688
694
@@ -722,7 +728,7 @@ macro pstats(args...)
722
728
opts, expr = parse_pstats_options (args[1 : end - 1 ]), args[end ]
723
729
quote
724
730
(function ()
725
- bench = make_bench ($ (opts. events))
731
+ bench = make_bench ($ (opts. events), userspace_only = $ (opts . exclude_kernel) )
726
732
enable! (bench)
727
733
val = $ (esc (expr))
728
734
disable! (bench)
0 commit comments