Skip to content

Commit f04fff2

Browse files
authored
Merge pull request #37 from nickrobinson251/npr-drop-formatting-jl
Drop Formatting.jl
2 parents 3c3375d + d064100 commit f04fff2

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

Project.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
name = "LinuxPerf"
22
uuid = "b4c46c6c-4fb0-484d-a11a-41bc3392d094"
3-
version = "0.3.7"
3+
version = "0.3.8"
44

55
[deps]
6-
Formatting = "59287772-0a20-5a39-b81b-1366585eb4c0"
76
PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
87
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
98

109
[compat]
11-
Formatting = "0.4"
1210
PrettyTables = "2"
1311
julia = "1"

src/LinuxPerf.jl

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ module LinuxPerf
22

33
using Printf
44
using PrettyTables
5-
using Formatting
65

76
export @measure, @measured, @pstats
87
export make_bench, enable!, disable!, reset!, reasonable_defaults, counters
@@ -360,12 +359,31 @@ struct Counters
360359
counters::Vector{Counter}
361360
end
362361

362+
_addcommas(i::Int64) = _addcommas(string(i))
363+
function _addcommas(s::String)
364+
len = length(s)
365+
t = ""
366+
for i in 1:3:len
367+
subs = s[max(1,len-i-1):len-i+1]
368+
if i == 1
369+
t = subs
370+
else
371+
if match(r"[0-9]", subs) != nothing
372+
t = subs * "," * t
373+
else
374+
t = subs * t
375+
end
376+
end
377+
end
378+
return t
379+
end
380+
363381
function Base.show(io::IO, c::Counters)
364382
events = map(x -> x.event, c.counters)
365383
stats = mapreduce(vcat, c.counters) do c
366384
c.enabled == 0 ? ["never enabled" "0 %"] :
367385
c.running == 0 ? ["did not run" "0 %"] :
368-
[format(Int64(c.value), commas=true) @sprintf("%.1f %%", 100*(c.running/c.enabled))]
386+
[_addcommas(Int64(c.value)) @sprintf("%.1f %%", 100*(c.running/c.enabled))]
369387
end
370388
return pretty_table(io, stats, header=["Events", "Active Time"], row_labels=events, alignment=:l, crop=:none, body_hlines=collect(axes(stats, 1)))
371389
end

test/runtests.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,13 @@ end
9797
@pstats "cpu-cycles,(instructions,branch-instructions,branch-misses),(task-clock,context-switches,cpu-migrations,page-faults),(L1-dcache-load-misses,L1-dcache-loads,L1-icache-load-misses),(dTLB-load-misses,dTLB-loads)" foo!(dest, a, b, c)
9898
end
9999

100+
@testset "_addcommas" begin
101+
@test LinuxPerf._addcommas(1) == "1"
102+
@test LinuxPerf._addcommas(12) == "12"
103+
@test LinuxPerf._addcommas(123) == "123"
104+
@test LinuxPerf._addcommas(1234) == "1,234"
105+
@test LinuxPerf._addcommas(12345) == "12,345"
106+
@test LinuxPerf._addcommas(typemin(Int64)) == "-9,223,372,036,854,775,808"
107+
end
100108

101-
end
109+
end

0 commit comments

Comments
 (0)