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

Disassembly: per-instruction cost is not shown for inlined code #671

Closed
arvidfm opened this issue Aug 28, 2024 · 0 comments · Fixed by #672
Closed

Disassembly: per-instruction cost is not shown for inlined code #671

arvidfm opened this issue Aug 28, 2024 · 0 comments · Fixed by #672
Labels

Comments

@arvidfm
Copy link

arvidfm commented Aug 28, 2024

Describe the bug
When disassembling functions containing inlined code, the disassembly view does not show per-line/instruction costs for code inlined from other functions.

To Reproduce
Steps to reproduce the behavior:

Compile this program with gcc -g -O2 -o fib main.c :

#include <stdio.h>

unsigned long fib(unsigned long n) {
  unsigned long a = 0, b = 1;
  for (unsigned long i = 0; i < n; i++) {
    unsigned long tmp = a;
    a = a + b;
    b = tmp;
  }
  return a;
}

int main() {
  printf("%d\n", fib(10000000000));
}

Then profile the binary using Hotspot and open the disassembly view for main.

Expected behavior
The disassembly view should show per-line/instruction costs even for inlined code.

Screenshots
The profile in perf report:
image

The same profile in Hotspot's disassembly view:

image

If I compile with -fno-inline and disassemble fib instead, the costs show as expected:

image

Version Info (please complete the following information):

  • Linux Kernel version: 6.9.10
  • perf version: 6.9
  • hotspot version: 1.5.1 (tested both AppImage and compiled from AUR)

Additional context
Originally found while profiling Go code, but it seems Go and C binaries behave the same here.

@arvidfm arvidfm added the bug label Aug 28, 2024
milianw added a commit that referenced this issue Sep 2, 2024
Previously, we put the cost of an inline frame into a container
indexed by the inline symbol. But during disassembly, we never get
to query that data again, since we cannot disassemble an inline frame.
Instead, we need to be able to query the cost for arbitrary binary
offsets, independent of their originating symbol.

The patch here achieves this by lifting the OffsetLocationCostMap out
of the CallerCalleeEntryMap into CallerCalleeResults, but mapped by
the binary name. This way we can efficiently store and lookup the data
of a given offset within a specific binary during disassembly, which
allows us to show the cost for inlined code in the disassembly view.

Fixes: #671
milianw added a commit that referenced this issue Sep 2, 2024
Previously, we put the cost of an inline frame into a container
indexed by the inline symbol. But during disassembly, we never get
to query that data again, since we cannot disassemble an inline frame.
Instead, we need to be able to query the cost for arbitrary binary
offsets, independent of their originating symbol.

The patch here achieves this by lifting the OffsetLocationCostMap out
of the CallerCalleeEntryMap into CallerCalleeResults, but mapped by
the binary name. This way we can efficiently store and lookup the data
of a given offset within a specific binary during disassembly, which
allows us to show the cost for inlined code in the disassembly view.

Fixes: #671
milianw added a commit that referenced this issue Sep 5, 2024
Previously, we put the cost of an inline frame into a container
indexed by the inline symbol. But during disassembly, we never get
to query that data again, since we cannot disassemble an inline frame.
Instead, we need to be able to query the cost for arbitrary binary
offsets, independent of their originating symbol.

The patch here achieves this by lifting the OffsetLocationCostMap out
of the CallerCalleeEntryMap into CallerCalleeResults, but mapped by
the binary name. This way we can efficiently store and lookup the data
of a given offset within a specific binary during disassembly, which
allows us to show the cost for inlined code in the disassembly view.

Fixes: #671
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant