hotspot icon indicating copy to clipboard operation
hotspot copied to clipboard

Disassembler inlining

Open lievenhey opened this issue 2 years ago • 12 comments
trafficstars

this adds a simple detection for inlined code to elide it from the assembly view.

grafik

I am not sure if this works correctly so it would be nice if someone has a minimal example to test this. This currently brakes syntax highlighting and code navigation

lievenhey avatar Jun 30 '23 09:06 lievenhey

~~TODO: detect inline same file~~

lievenhey avatar Jul 04 '23 09:07 lievenhey

The inline detection is now working.

Output: grafik

example.c:

#include <stdio.h>

inline int square(int i) {
        return i * i;
}

int main() {
        for (int i = 0; i < 10000; i++) {
                int sum = 0;
                for (int j = 0; j < i; j++) {
                        sum += square(j);
                }
                printf("Sum: %d\n", sum);
        }
}

lievenhey avatar Jul 04 '23 13:07 lievenhey

If it does what I think it does then: yay. Can you please share what the previous build outputs to be able to compare the results?

GitMensch avatar Jul 04 '23 14:07 GitMensch

before: image after: image (click to expand an entry)

lievenhey avatar Jul 05 '23 13:07 lievenhey

Any idea why this fails on ArchLinux with clang?

GitMensch avatar Jul 26 '23 21:07 GitMensch

no, seems to only happen on the ci even if I ran the ci container locally, it fails to reproduce the issue

lievenhey avatar Jul 28 '23 08:07 lievenhey

found it objdump ... on non clazy target:

00000000000012a0 <main>:
main():
/home/lieven/KDAB/hotspot/tests/test-clients/cpp-recursion/main.cpp:19

objdump ... on clazy target:

00000000000012f0 <main>:
std::basic_ios<char, std::char_traits<char> >::widen(char) const:
/opt/hotspot/tests/test-clients/cpp-recursion/main.cpp:19

I used the the first instance of something(): as function name. Since on clazy it is std::basic_ios<char, std::char_traits<char> >::widen(char) const it thinks main is an inlined function

time to rewrite it using libdwarf

lievenhey avatar Jul 28 '23 09:07 lievenhey

related to #495

GitMensch avatar Jul 28 '23 10:07 GitMensch

Would that need a doc update (screenshots, maybe)? Is libdwarf a new dependency to be added?

GitMensch avatar Aug 16 '23 05:08 GitMensch

I'd like to give this a test - can you rebase that, please?

Apart from the actual inline view it will be interesting to see how the parsing with libdwarf effects the necessary time to open the disassembly view (while the time currently needed seems to be related to (the use of) Qt #505)

GitMensch avatar Oct 03 '23 16:10 GitMensch

This will still take some time. We want to move the logic to the perfparser since it has all the logic for finding binaries etc.

Originally posted by @lievenhey in https://github.com/KDAB/hotspot/issues/518#issuecomment-1759596746

That sounds very reasonable. If I understand that correctly, this means that perfparser may use libdwarf to do this and more, and then perfparser will be used both for handling the actual "perf.data" (as now) and additionally do "something special" for the disassembly, but not replacing objdump, right?

GitMensch avatar Oct 12 '23 13:10 GitMensch

Disassembling will still be handled by objdump. We just use libdwarf for additional information.

lievenhey avatar Oct 12 '23 13:10 lievenhey