Skip to content

Commit 312a868

Browse files
committed
Refactor show
1 parent 96f508a commit 312a868

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/LinuxPerf.jl

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -613,18 +613,25 @@ function Base.show(io::IO, stats::Stats)
613613
# show a comment
614614
if name == "cpu-cycles"
615615
@printf(io, " # %4.1f cycles per ns", counter.value / counter.running)
616-
elseif (name == "stalled-cycles-frontend" || name == "stalled-cycles-backend") && haskey(stats, "cpu-cycles")
617-
@printf(io, " # %4.1f%% of cycles", scaledcount(counter) / scaledcount(stats["cpu-cycles"]) * 100)
618616
elseif name == "instructions" && haskey(stats, "cpu-cycles")
619617
@printf(io, " # %4.1f insns per cycle", scaledcount(counter) / scaledcount(stats["cpu-cycles"]))
620-
elseif name == "branch-instructions" && haskey(stats, "instructions")
621-
@printf(io, " # %4.1f%% of instructions", scaledcount(counter) / scaledcount(stats["instructions"]) * 100)
622-
elseif name == "branch-misses" && haskey(stats, "branch-instructions")
623-
@printf(io, " # %4.1f%% of branch instructions", scaledcount(counter)/ scaledcount(stats["branch-instructions"]) * 100)
624-
elseif name == "cache-misses" && haskey(stats, "cache-references")
625-
@printf(io, " # %4.1f%% of cache references", scaledcount(counter) / scaledcount(stats["cache-references"]) * 100)
626-
elseif name == "L1-dcache-load-misses" && haskey(stats, "L1-dcache-loads")
627-
@printf(io, " # %4.1f%% of loads", scaledcount(counter) / scaledcount(stats["L1-dcache-loads"]) * 100)
618+
else
619+
for (num, den, label) in [
620+
("stalled-cycles-frontend", "cpu-cycles", "cycles"),
621+
("stalled-cycles-backend", "cpu-cycles", "cycles"),
622+
("branch-instructions", "instructions", "instructions"),
623+
("branch-misses", "branch-instructions", "branch instructions"),
624+
("cache-misses", "cache-references", "cache references"),
625+
("L1-dcache-load-misses", "L1-dcache-loads", "dcache loads"),
626+
("L1-icache-load-misses", "L1-icache-loads", "icache loads"),
627+
("dTLB-load-misses", "dTLB-loads", "dTLB loads"),
628+
("iTLB-load-misses", "iTLB-loads", "iTLB loads"),
629+
]
630+
if name == num && haskey(stats, den)
631+
@printf(io, " # %4.1f%% of %s", scaledcount(counter) / scaledcount(stats[den]) * 100, label)
632+
break
633+
end
634+
end
628635
end
629636
end
630637
println(io)

0 commit comments

Comments
 (0)