@@ -635,6 +635,62 @@ scaledcount(counter::Counter) = counter.value * (counter.enabled / counter.runni
635
635
@pstats [options] expr
636
636
637
637
Run `expr` and gather its performance statistics.
638
+
639
+ This macro basically measures the number of occurrences of events such as CPU
640
+ cycles, branch prediction misses, page faults, and so on. The list of
641
+ supported events can be shown by calling the `LinuxPerf.list` function.
642
+
643
+ Due to the resource limitation of performance measuring units (PMUs)
644
+ installed in a CPU core, all events may not be measured simultaneously,
645
+ resulting in multiplexing several groups of events in a single measurement.
646
+ If the running time is extremely short, some event groups may not be measured
647
+ at all.
648
+
649
+ The result is shown in a table. Each row consists of four columns: an event
650
+ group indicator, an event name, a scaled count and a running rate. A comment
651
+ may follow these columns after a hash (#) character.
652
+ 1. The event group indicated by a bracket is a set of events that are
653
+ measured simultaneously so that their count statistics can be meaningfully
654
+ compared.
655
+ 2. The event name is a conventional name of the measured event.
656
+ 3. The scaled count is the number of occurrences of the event, scaled by the
657
+ reciprocal of the running rate.
658
+ 4. The running rate is the ratio of the time of running and enabled.
659
+
660
+ The macro can take some options. If a string object is passed, it is a
661
+ comma-separated list of event names to measure. An event group can be
662
+ indicated by a pair of parentheses.
663
+
664
+ # Examples
665
+
666
+ ```
667
+ julia> xs = randn(1_000_000);
668
+
669
+ julia> sort(xs[1:9]); # compile
670
+
671
+ julia> @pstats sort(xs)
672
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
673
+ ┌ cpu-cycles 2.57e+08 48.6% # 3.8 cycles per ns
674
+ │ stalled-cycles-frontend 1.10e+07 48.6% # 4.3% of cycles
675
+ └ stalled-cycles-backend 2.48e+06 48.6% # 1.0% of cycles
676
+ ┌ instructions 1.84e+08 51.4% # 0.7 insns per cycle
677
+ │ branch-instructions 3.73e+07 51.4% # 20.2% of instructions
678
+ └ branch-misses 7.92e+06 51.4% # 21.2% of branch instructions
679
+ ┌ task-clock 6.75e+07 100.0%
680
+ │ context-switches 0.00e+00 100.0%
681
+ │ cpu-migrations 0.00e+00 100.0%
682
+ └ page-faults 1.95e+03 100.0%
683
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
684
+
685
+ julia> @pstats "(cpu-cycles,instructions,branch-instructions,branch-misses),page-faults" sort(xs)
686
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
687
+ ┌ cpu-cycles 2.61e+08 100.0% # 3.9 cycles per ns
688
+ │ instructions 1.80e+08 100.0% # 0.7 insns per cycle
689
+ │ branch-instructions 3.64e+07 100.0% # 20.2% of instructions
690
+ └ branch-misses 8.32e+06 100.0% # 22.8% of branch instructions
691
+ ╶ page-faults 0.00e+00 100.0%
692
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
693
+ ```
638
694
"""
639
695
macro pstats (args... )
640
696
if isempty (args)
0 commit comments