jonhoo / inferno

A Rust port of FlameGraph

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Templated C++ functions cut off after opening parenthesis in template arguments.

SoftwareApe opened this issue · comments

Same issue as brendangregg/FlameGraph#215 on the original tool.

Ah, yes, good catch! The Rust version of that code lives here:

fn tidy_generic(mut func: String) -> String {

It doesn't use regular expressions, but instead just walks the string in an equivalent way. Want to try putting up a PR that makes a similar change to the one you linked?

Thank you for the pointer. I can take a look. I was actually grepping for regex, since I assumed it was regex, but couldn't find it 😅 .

So it's kind of obvious what's happening. In the C++ stacks you have std::function<bool (...

Then it finds this parenthesis, and because the preceding char isn't "." it assumes this isn't Go (so far so good), but then it truncates the string after the parenthesis.

Ergo, we'd have to detect C++ stacks. However the preceding char (in this case, maybe compiler dependent? Is a space.

I think the easiest would be, we count the template/angle brackets ("<" and ">") to see if we're inside a template parameter (either they're balanced or unbalanced).

Do you think this is feasible?

Alternatively, it seems you try to get rid of function parameters. Maybe we should just remove parameters up to the closing parenthesis, since something may follow. Although personally I find the function parameters are part of the function signature, so potentially interesting.

Hmm, yeah, it's a tricky situation, and it's unfortunate we don't have more context. I think my inclination here is to only strip "arguments" (in parentheses) when they appear at the tail end of an expression. So I think your plan to not strip if we're inside <> will work well!

I suggested a fix now. I added some tests for C++ stack collapse with std::function templates.

I'm not sure what's up with the tests, but 4 of them were failing before I changed anything.