Skip to content

Commit c72c379

Browse files
authored
Add an example of the pstats macro to README (closes #21) (#25)
* make comments a bit shorter * add example of pstats macro to README * add example of specifying events
1 parent cbdf402 commit c72c379

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,42 @@ julia> data = zeros(10000); @measure g(data)
5252
└───────────────────────┴────────────┴─────────────┘
5353
```
5454

55+
The `@pstats' macro provides another (perhaps more concise) tool to measure
56+
performance events, which can be used in the same way as `@timed` of the
57+
standard library. The following example measures default events and reports its
58+
summary:
59+
```
60+
julia> using LinuxPerf, Random
61+
62+
julia> mt = MersenneTwister(1234);
63+
64+
julia> @pstats rand(mt, 1_000_000); # compile
65+
66+
julia> @pstats rand(mt, 1_000_000) # default events
67+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
68+
┌ cpu-cycles 2.88e+06 58.1% # 1.2 cycles per ns
69+
│ stalled-cycles-frontend 9.50e+03 58.1% # 0.3% of cycles
70+
└ stalled-cycles-backend 1.76e+06 58.1% # 61.2% of cycles
71+
┌ instructions 1.11e+07 41.9% # 3.9 insns per cycle
72+
│ branch-instructions 5.32e+05 41.9% # 4.8% of insns
73+
└ branch-misses 2.07e+03 41.9% # 0.4% of branch insns
74+
┌ task-clock 2.38e+06 100.0% # 2.4 ms
75+
│ context-switches 0.00e+00 100.0%
76+
│ cpu-migrations 0.00e+00 100.0%
77+
└ page-faults 1.95e+03 100.0%
78+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
79+
80+
julia> insn = "(instructions,branch-instructions,branch-misses)"
81+
82+
julia> @pstats insn rand(mt, 1_000_000) # specific events
83+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
84+
┌ instructions 1.05e+07 100.0%
85+
│ branch-instructions 5.03e+05 100.0% # 4.8% of insns
86+
└ branch-misses 2.01e+03 100.0% # 0.4% of branch insns
87+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
88+
```
89+
90+
See the documentation of `@pstats` for more details and available options.
91+
5592
For more fine tuned performance profile examples, please check out the `test`
5693
directory.

src/LinuxPerf.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -898,9 +898,9 @@ function printcounters(io::IO, groups::Vector{Vector{Counter}})
898898
for (num, den, label) in [
899899
("stalled-cycles-frontend", "cpu-cycles", "cycles"),
900900
("stalled-cycles-backend", "cpu-cycles", "cycles"),
901-
("branch-instructions", "instructions", "instructions"),
902-
("branch-misses", "branch-instructions", "branch instructions"),
903-
("cache-misses", "cache-references", "cache references"),
901+
("branch-instructions", "instructions", "insns"),
902+
("branch-misses", "branch-instructions", "branch insns"),
903+
("cache-misses", "cache-references", "cache refs"),
904904
("L1-dcache-load-misses", "L1-dcache-loads", "dcache loads"),
905905
("L1-icache-load-misses", "L1-icache-loads", "icache loads"),
906906
("dTLB-load-misses", "dTLB-loads", "dTLB loads"),
@@ -1017,8 +1017,8 @@ julia> @pstats sort(xs)
10171017
│ stalled-cycles-frontend 1.09e+07 49.7% # 4.2% of cycles
10181018
└ stalled-cycles-backend 7.07e+06 49.7% # 2.7% of cycles
10191019
┌ instructions 1.96e+08 50.3% # 0.8 insns per cycle
1020-
│ branch-instructions 4.02e+07 50.3% # 20.5% of instructions
1021-
└ branch-misses 8.15e+06 50.3% # 20.3% of branch instructions
1020+
│ branch-instructions 4.02e+07 50.3% # 20.5% of insns
1021+
└ branch-misses 8.15e+06 50.3% # 20.3% of branch insns
10221022
┌ task-clock 7.61e+07 100.0% # 76.1 ms
10231023
│ context-switches 7.00e+00 100.0%
10241024
│ cpu-migrations 0.00e+00 100.0%
@@ -1029,8 +1029,8 @@ julia> @pstats "(cpu-cycles,instructions,branch-instructions,branch-misses),page
10291029
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
10301030
┌ cpu-cycles 2.64e+08 100.0% # 3.5 cycles per ns
10311031
│ instructions 1.86e+08 100.0% # 0.7 insns per cycle
1032-
│ branch-instructions 3.74e+07 100.0% # 20.1% of instructions
1033-
└ branch-misses 8.21e+06 100.0% # 21.9% of branch instructions
1032+
│ branch-instructions 3.74e+07 100.0% # 20.1% of insns
1033+
└ branch-misses 8.21e+06 100.0% # 21.9% of branch insns
10341034
╶ page-faults 1.95e+03 100.0%
10351035
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
10361036
```

0 commit comments

Comments
 (0)