JuliaPerf / PProf.jl

Export Julia profiles to the pprof format
MIT License
155 stars 17 forks source link

PProf fails to build `dot` graph if name contains `"` #30

Open NHDaly opened 3 years ago

NHDaly commented 3 years ago

For example:

julia> function var"#fo\"o#"()
           peakflops()
       end
#fo"o# (generic function with 1 method)

julia> var"#fo\"o#"()
1.8314014985396976e11

julia> Profile.clear()

julia> @profile var"#fo\"o#"()
1.7486120937946786e11

julia> pprof(out="var", webport=2232)
[ Info: Writing output to var.pb.gz
"var.pb.gz"

julia> Main binary filename not available.
Serving web UI on http://localhost:2232
Error: <stdin>: syntax error in line 39 near 'N37'
Failed to execute dot. Is Graphviz installed?
exit status 1
Error: <stdin>: syntax error in line 39 near 'N37'
Failed to execute dot. Is Graphviz installed?
exit status 1

By dumping the dot file, you can see the mistake: pprof itself is not escaping the name correctly:

julia> PProf.pprof_jll.pprof() do _
           io = IOBuffer()
           run(pipeline(`pprof -dot var.pb.gz`, stdout=io))
           write("profile.dot", String(take!(io)))
       end
N35 [label="LinearAlgebra\npeakflops##kw\n0 of 47 (47.00%)" id="node35" fontsize=8 shape=box tooltip="LinearAlgebra.peakflops##kw (47)" color="#b22400" fillcolor="#eddad5"]
N36 [label="Main\n#fo"o#\n0 of 47 (47.00%)" id="node36" fontsize=8 shape=box tooltip="Main.#fo"o# (47)" color="#b22400" fillcolor="#eddad5"]
N37 [label="REPL\n#run_repl#41\n0 of 47 (47.00%)" id="node37" fontsize=8 shape=box tooltip="REPL.#run_repl#41 (47)" color="#b22400" fillcolor="#eddad5"]

I'm going to open a PR against pprof to fix this. But if it stalls, we may want to escape the names we provide to the proto, but it's annoying because then they print ugly (and incorrectly) in the flamegraph