Skip to content

Commit da8de67

Browse files
committed
Refactor show
1 parent 033e29e commit da8de67

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
@@ -634,18 +634,25 @@ function Base.show(io::IO, stats::Stats)
634634
# show a comment
635635
if name == "cpu-cycles"
636636
@printf(io, " # %4.1f cycles per ns", counter.value / counter.running)
637-
elseif (name == "stalled-cycles-frontend" || name == "stalled-cycles-backend") && haskey(stats, "cpu-cycles")
638-
@printf(io, " # %4.1f%% of cycles", scaledcount(counter) / scaledcount(stats["cpu-cycles"]) * 100)
639637
elseif name == "instructions" && haskey(stats, "cpu-cycles")
640638
@printf(io, " # %4.1f insns per cycle", scaledcount(counter) / scaledcount(stats["cpu-cycles"]))
641-
elseif name == "branch-instructions" && haskey(stats, "instructions")
642-
@printf(io, " # %4.1f%% of instructions", scaledcount(counter) / scaledcount(stats["instructions"]) * 100)
643-
elseif name == "branch-misses" && haskey(stats, "branch-instructions")
644-
@printf(io, " # %4.1f%% of branch instructions", scaledcount(counter)/ scaledcount(stats["branch-instructions"]) * 100)
645-
elseif name == "cache-misses" && haskey(stats, "cache-references")
646-
@printf(io, " # %4.1f%% of cache references", scaledcount(counter) / scaledcount(stats["cache-references"]) * 100)
647-
elseif name == "L1-dcache-load-misses" && haskey(stats, "L1-dcache-loads")
648-
@printf(io, " # %4.1f%% of loads", scaledcount(counter) / scaledcount(stats["L1-dcache-loads"]) * 100)
639+
else
640+
for (num, den, label) in [
641+
("stalled-cycles-frontend", "cpu-cycles", "cycles"),
642+
("stalled-cycles-backend", "cpu-cycles", "cycles"),
643+
("branch-instructions", "instructions", "instructions"),
644+
("branch-misses", "branch-instructions", "branch instructions"),
645+
("cache-misses", "cache-references", "cache references"),
646+
("L1-dcache-load-misses", "L1-dcache-loads", "dcache loads"),
647+
("L1-icache-load-misses", "L1-icache-loads", "icache loads"),
648+
("dTLB-load-misses", "dTLB-loads", "dTLB loads"),
649+
("iTLB-load-misses", "iTLB-loads", "iTLB loads"),
650+
]
651+
if name == num && haskey(stats, den)
652+
@printf(io, " # %4.1f%% of %s", scaledcount(counter) / scaledcount(stats[den]) * 100, label)
653+
break
654+
end
655+
end
649656
end
650657
end
651658
println(io)

0 commit comments

Comments
 (0)