Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a skip_zeros keyarg to analyze_malloc_fils. #73

Merged
merged 7 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/memalloc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ end
sortbybytes(a::MallocInfo, b::MallocInfo) = a.bytes < b.bytes

"""
analyze_malloc_files(files) -> Vector{MallocInfo}
analyze_malloc_files(files; skip_zeros::Bool = false) -> Vector{MallocInfo}

Iterates through the given list of filenames and return a `Vector` of
`MallocInfo`s with allocation information.
`MallocInfo`s with allocation information. If `skip_zeros` is `true`, then
allocations of zero bytes are skipped.
"""
function analyze_malloc_files(files)
function analyze_malloc_files(files; skip_zeros::Bool = false)
bc = MallocInfo[]
for filename in files
open(filename) do file
Expand All @@ -23,6 +24,7 @@ function analyze_malloc_files(files)
if !isempty(tln) && isdigit(tln[1])
s = split(tln)
b = parse(Int, s[1])
skip_zeros && b == 0 && continue
Azzaare marked this conversation as resolved.
Show resolved Hide resolved
push!(bc, MallocInfo(b, filename, i))
end
end
Expand Down
9 changes: 9 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ end # testset
malloc_results = analyze_malloc(datadir)
filename = joinpath(datadir, "testparser.jl.9172.mem")
@test malloc_results == [CoverageTools.MallocInfo(96669, filename, 2)]
# ... and memory data with zeros skipped
no_zeros = CoverageTools.analyze_malloc_files([filename]; skip_zeros = true)
@test length(no_zeros) == 1

lcov = IOBuffer()
# we only have a single file, but we want to test on the Vector of file results
Expand Down Expand Up @@ -194,6 +197,12 @@ end # testset
msg = "parsing error in $bustedfile:7: space before \"[\" not allowed in \"i [\""
elseif VERSION.major == 1 && VERSION.minor == 5
msg = "parsing error in $bustedfile:7: space before \"[\" not allowed in \"i [\" at none:4"
elseif VERSION.major == 1 && VERSION.minor > 9
msg = if Sys.iswindows()
"""parsing error in $bustedfile:8: Base.Meta.ParseError(\"ParseError:\\n# Error @ none:3:10\\n s = 0\\r\\n for i [1,2,3] # this line has a parsing error\\r\\n# β””β”€β”˜ ── invalid iteration spec: expected one of `=` `in` or `∈`\", Base.JuliaSyntax.ParseError(Base.JuliaSyntax.SourceFile(\"function parseerr()\\r\\n s = 0\\r\\n for i [1,2,3] # this line has a parsing error\\r\\n \", 46, \"none\", 1, [1, 22, 33, 86, 94]), Base.JuliaSyntax.Diagnostic[Base.JuliaSyntax.Diagnostic(88, 90, :error, \"invalid iteration spec: expected one of `=` `in` or `∈`\"), Base.JuliaSyntax.Diagnostic(93, 92, :error, \"invalid iteration spec: expected one of `=` `in` or `∈`\"), Base.JuliaSyntax.Diagnostic(95, 94, :error, \"invalid iteration spec: expected one of `=` `in` or `∈`\"), Base.JuliaSyntax.Diagnostic(95, 95, :error, \"unexpected `]`\"), Base.JuliaSyntax.Diagnostic(95, 94, :error, \"Expected `end`\"), Base.JuliaSyntax.Diagnostic(95, 94, :error, \"Expected `end`\"), Base.JuliaSyntax.Diagnostic(95, 95, :error, \"extra tokens after end of expression\")], :none))"""
else
"""parsing error in $bustedfile:8: Base.Meta.ParseError(\"ParseError:\\n# Error @ none:3:10\\n s = 0\\n for i [1,2,3] # this line has a parsing error\\n# β””β”€β”˜ ── invalid iteration spec: expected one of `=` `in` or `∈`\", Base.JuliaSyntax.ParseError(Base.JuliaSyntax.SourceFile(\"function parseerr()\\n s = 0\\n for i [1,2,3] # this line has a parsing error\\n \", 42, \"none\", 1, [1, 21, 31, 83, 91]), Base.JuliaSyntax.Diagnostic[Base.JuliaSyntax.Diagnostic(82, 84, :error, \"invalid iteration spec: expected one of `=` `in` or `∈`\"), Base.JuliaSyntax.Diagnostic(87, 86, :error, \"invalid iteration spec: expected one of `=` `in` or `∈`\"), Base.JuliaSyntax.Diagnostic(89, 88, :error, \"invalid iteration spec: expected one of `=` `in` or `∈`\"), Base.JuliaSyntax.Diagnostic(89, 89, :error, \"unexpected `]`\"), Base.JuliaSyntax.Diagnostic(89, 88, :error, \"Expected `end`\"), Base.JuliaSyntax.Diagnostic(89, 88, :error, \"Expected `end`\"), Base.JuliaSyntax.Diagnostic(89, 89, :error, \"extra tokens after end of expression\")], :none))"""
end
else
msg = "parsing error in $bustedfile:7: invalid iteration specification"
end
Expand Down
Loading