Skip to content

Commit

Permalink
Merge #5
Browse files Browse the repository at this point in the history
5: Avoid potential division by zero r=charleskawczynski a=charleskawczynski

This PR:
 - Fixes a bug where we potentially divide by zero
 - Change output format to bytes, instead of KiB, to avoid rounding to zero
 - Adds a kwarg, `suppress_url`, to supress using urls in the output table (I suspect they're causing issues in the output when trying this on buildkite with other packages)
 - bumps the patch version

Co-authored-by: Charles Kawczynski <[email protected]>
  • Loading branch information
bors[bot] and charleskawczynski authored Jan 17, 2022
2 parents 2c6964b + 2202c45 commit 83bb887
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ReportMetrics"
uuid = "c1654acf-408b-4272-96ce-66c258df8a6c"
authors = ["Charles Kawczynski <[email protected]>"]
version = "0.2.0"
version = "0.2.1"

[deps]
Coverage = "a2441757-f6aa-5fb2-8edb-039e3f45d037"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ prints out:
[ Info: RA_example: Number of unique allocating sites: 2
┌───────────────────┬─────────────┬─────────────────────────────────────────┐
│ Allocations % │ Allocations │ <file>:<line number>
│ (alloc_i/∑allocs) │ (KiB) │ │
│ (alloc_i/∑allocs) │ (bytes) │ │
├───────────────────┼─────────────┼─────────────────────────────────────────┤
77 7809 │ ReportMetrics.jl/test/rep_workload.jl:7
23 2331 │ ReportMetrics.jl/test/rep_workload.jl:6
777996800 │ ReportMetrics.jl/test/rep_workload.jl:7
232387200 │ ReportMetrics.jl/test/rep_workload.jl:6
└───────────────────┴─────────────┴─────────────────────────────────────────┘
```
37 changes: 21 additions & 16 deletions src/ReportMetrics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Reports allocations
- `dirs_to_monitor` a `Vector` of directories to monitor
- `pkg_name` name of package being tested (for helping with string processing)
- `n_unique_allocs` limits number of unique allocation sites to report (to avoid large tables)
- `suppress_url` (` = true`) suppress trying to use URLs in the output table
## Notest
- `deps_to_monitor` and `dirs_to_monitor` are merged together.
Expand All @@ -36,6 +37,7 @@ function report_allocs(;
is_loading_pkg::Function = (fn, ln) -> false,
pkg_name::Union{Nothing, String} = nothing,
n_unique_allocs::Int = 10,
suppress_url::Bool = true,
)

##### Collect deps
Expand Down Expand Up @@ -93,8 +95,7 @@ function report_allocs(;
end
end
@info "$(job_name): Number of unique allocating sites: $(length(all_bytes))"
all_kbytes = map(b -> div(b, 1024), all_bytes) # convert from bytes to KiB
sum_bytes = sum(all_kbytes)
sum_bytes = sum(all_bytes)
xtick_name(filename, linenumber) = "$filename:$linenumber"
labels = xtick_name.(process_fn.(filenames), linenumbers)

Expand All @@ -111,29 +112,33 @@ function report_allocs(;

data = map(zip(filenames, linenumbers)) do (filename, linenumber)
label = xtick_name(process_fn(filename), linenumber)
# name = basename(pkg_dir_from_file(dirname(filename)))
url = ""
# TODO: incorporate URLS into table
# if haskey(pkg_urls, name)
# url = pkg_urls[name]
# else
# url = "https://www.google.com"
# end
PrettyTables.URLTextCell(label, url)
if suppress_url
label
else
url = ""
# name = basename(pkg_dir_from_file(dirname(filename)))
# TODO: incorporate URLS into table
# if haskey(pkg_urls, name)
# url = pkg_urls[name]
# else
# url = "https://www.google.com"
# end
PrettyTables.URLTextCell(label, url)
end
end

alloc_percent = map(all_kbytes) do bytes
alloc_percent = bytes / sum_bytes
Int(round(alloc_percent*100, digits = 0))
alloc_percent = map(all_bytes) do bytes
alloc_perc = bytes / sum_bytes
Int(round(alloc_perc*100, digits = 0))
end
header = (
["Allocations %", "Allocations", "<file>:<line number>"],
["(alloc_i/∑allocs)", "(KiB)", ""],
["(alloc_i/∑allocs)", "(bytes)", ""],
)

table_data = hcat(
alloc_percent,
all_kbytes,
all_bytes,
data,
)

Expand Down

2 comments on commit 83bb887

@charleskawczynski
Copy link
Member

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/52652

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.2.1 -m "<description of version>" 83bb88770bd5ad0ccb6e0bbea0ae0041a33267ab
git push origin v0.2.1

Please sign in to comment.