Skip to content

Commit

Permalink
Merge pull request #37 from nickrobinson251/npr-drop-formatting-jl
Browse files Browse the repository at this point in the history
Drop Formatting.jl
  • Loading branch information
carstenbauer authored Mar 7, 2024
2 parents 3c3375d + d064100 commit f04fff2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
4 changes: 1 addition & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
name = "LinuxPerf"
uuid = "b4c46c6c-4fb0-484d-a11a-41bc3392d094"
version = "0.3.7"
version = "0.3.8"

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

[compat]
Formatting = "0.4"
PrettyTables = "2"
julia = "1"
22 changes: 20 additions & 2 deletions src/LinuxPerf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ module LinuxPerf

using Printf
using PrettyTables
using Formatting

export @measure, @measured, @pstats
export make_bench, enable!, disable!, reset!, reasonable_defaults, counters
Expand Down Expand Up @@ -360,12 +359,31 @@ struct Counters
counters::Vector{Counter}
end

_addcommas(i::Int64) = _addcommas(string(i))
function _addcommas(s::String)
len = length(s)
t = ""
for i in 1:3:len
subs = s[max(1,len-i-1):len-i+1]
if i == 1
t = subs
else
if match(r"[0-9]", subs) != nothing
t = subs * "," * t
else
t = subs * t
end
end
end
return t
end

function Base.show(io::IO, c::Counters)
events = map(x -> x.event, c.counters)
stats = mapreduce(vcat, c.counters) do c
c.enabled == 0 ? ["never enabled" "0 %"] :
c.running == 0 ? ["did not run" "0 %"] :
[format(Int64(c.value), commas=true) @sprintf("%.1f %%", 100*(c.running/c.enabled))]
[_addcommas(Int64(c.value)) @sprintf("%.1f %%", 100*(c.running/c.enabled))]
end
return pretty_table(io, stats, header=["Events", "Active Time"], row_labels=events, alignment=:l, crop=:none, body_hlines=collect(axes(stats, 1)))
end
Expand Down
10 changes: 9 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,13 @@ end
@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)
end

@testset "_addcommas" begin
@test LinuxPerf._addcommas(1) == "1"
@test LinuxPerf._addcommas(12) == "12"
@test LinuxPerf._addcommas(123) == "123"
@test LinuxPerf._addcommas(1234) == "1,234"
@test LinuxPerf._addcommas(12345) == "12,345"
@test LinuxPerf._addcommas(typemin(Int64)) == "-9,223,372,036,854,775,808"
end

end
end

3 comments on commit f04fff2

@carstenbauer
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/102461

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.8 -m "<description of version>" f04fff2c4d0f19cd337b738050a6c3f936dd739c
git push origin v0.3.8

@nickrobinson251
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, @carstenbauer !

Please sign in to comment.