flamegraph icon indicating copy to clipboard operation
flamegraph copied to clipboard

invalid xml from `xctrace`

Open jarjk opened this issue 3 months ago • 8 comments

I suppose it's not flamegraph's fault, but still...

I get (on macos)

Starting recording with the Time Profiler template. Launching process: .
Ctrl-C to stop the recording

test result: ok. 0 passed; 0 failed; 7 ignored; 1 measured; 0 filtered out; finished in 4.21s

Target app exited, ending recording...
Recording completed. Saving output file...
Output file saved as: cargo-flamegraph.trace
Error: unable to collapse generated profile data

Caused by:
    Invalid xml text from xctrace, which is not expected: UnterminatedEntity(72..77)

jarjk avatar Nov 28 '25 21:11 jarjk

I don't think this is actionable in the context of this project. The XML is generated by xctrace (I guess) and consumed by inferno.

djc avatar Dec 01 '25 08:12 djc

@djc symbols in the XML generated by xctrace are demangled by flamegraph without applying the necessary XML escaping, causing the generated XML to be invalid

friedrich avatar Dec 02 '25 22:12 friedrich

Pretty sure that part happens in inferno, though, not in flamegraph -- as I already explained.

djc avatar Dec 02 '25 22:12 djc

@friedrich you may want to ask the inferfno devs I understand

jarjk avatar Dec 02 '25 22:12 jarjk

The call to demangle_stream is clearly part of flamegraph: https://github.com/flamegraph-rs/flamegraph/blob/5c5129d8e1206b3be78b0a86cae12873d3587012/src/lib.rs#L533

Here is a fix that works for me: https://github.com/flamegraph-rs/flamegraph/commit/f82bc924e9e614d0b15203f01b9d2770ea74c373. I only tested it with xctrace, if other formats do not use XML it will break them.

friedrich avatar Dec 02 '25 23:12 friedrich

Ah, sorry, I forgot that demangling is done in this crate.

Pretty sure the other platforms do not use XML-based platforms, so your fix will need to be adapted. Additionally I'd prefer not to take on quick-xml as a dependency as it seems pretty heavyweight for what needs to be done here. Suggest using the xmlparser crate instead.

djc avatar Dec 03 '25 10:12 djc

quick-xml is already a dependency of flamegraph since it is used by inferno.

friedrich avatar Dec 03 '25 17:12 friedrich

Aahh, sorry, also didn't know about that. In that case, would be happy to review a PR.

djc avatar Dec 03 '25 20:12 djc