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

Callgrind parser: Fixed associating file names with symbols and detection of root nodes #466

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

glatosinski
Copy link

This PR introduces several small improvements to updating the current file name for the Callgrind parser:

  • First of all, when called function (cfn) is within an inlined code block, it should use file names provided by fi or fe keys.
  • Secondly, when fn key is present, the parser should set the current file name to the value provided in the previous fl key (such reset is also applied in KCacheGrind: link to code.
  • Thirdly, the file associated with fn should be stored separately so that it is not overwritten later by new fl calls.

Those small modifications improve detection of root nodes. Before the PR, the same function could have several files associated with it - when fi/fe are not taken into account, the file name for the current callee is taken from the last fl or cfi call, which is later added to childMap in this.childrenTotalWeights instead of the actual function with its file name. After this, only one of the two representations of the same symbol get deleted from rootNodes.

Without the improvement, we can observe detached call stacks for such "orphaned" functions. With the improvement, the functions have properly provided names, which leads to better generation of the call graph.

Some examples before and after applying the commit from the PR (the marked calls are for the same function):

  • Example 1 (callgrind file)

    • Before:
      first-before-fix
    • After:
      first-after-fix
  • Example 2

    • Before:
      second-before-fix

    • After:
      second-after-fix

  • Example 3

    • Before:
      third-before-fix
    • After:
      third-after-fix

This fixes #465

…th functions

When called function is within an inlined code block, it should use file names
provided by 'fi' or 'fe' commands.

Also, when 'fn' command is called, it sets the current file name to the value
provided in the previous 'fl' call.

Also, the file associated with 'fn' should be stored separately so that
it is not overwritten by new 'fl' calls (Callgrind does not tell whether
there can be multiple 'fl' calls without following 'fn' calls, and this
should guard the parser from associating the wrong new file name with the
previous 'fn' function).

This modification fixes detached call stacks, which were created when one
function has been called from inline block without the file source update,
which led to duplicated entries, which were later not removed when
determining root functions.

Signed-off-by: Grzegorz Latosinski <[email protected]>
@glatosinski glatosinski force-pushed the glat/callgrind-filename-parsing-fix branch from 20072c5 to 20bc6ce Compare March 1, 2024 05:52
@coveralls
Copy link

Coverage Status

coverage: 43.652% (+0.03%) from 43.619%
when pulling 20bc6ce on antmicro:glat/callgrind-filename-parsing-fix
into 0121cf9 on jlfwong:main.

@jlfwong
Copy link
Owner

jlfwong commented Apr 15, 2024

Hi @glatosinski!

Thanks for contributing this, and sorry for the long response time. Can you please add a minimal test that demonstrates the failure mode this PR fixes?

Thanks!

@glatosinski
Copy link
Author

Hi, ok, I will prepare a minimal test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants