From: Milian Wolff <mail@milianw.de>
To: "elfutils-devel@sourceware.org" <elfutils-devel@sourceware.org>
Subject: Can dwarf_getscopes{,_die} performance be improved?
Date: Sat, 13 Jun 2020 19:40:06 +0200 [thread overview]
Message-ID: <2050295.fxRyV3M0rs@milian-workstation> (raw)
[-- Attachment #1: Type: text/plain, Size: 2529 bytes --]
Hey all!
In perfparser we are running into a performance issue with elfutils when we
try to resolve inline frames. We are following the procedure outlined by eu-
addr2line, i.e. for every IP we basically do:
```
Dwarf_Addr bias = 0;
Dwarf_Die *cudie = dwfl_module_addrdie(module, ip, &bias);
Dwarf_Die *subroutine = nullptr;
Dwarf_Die *scopes = nullptr;
int nscopes = dwarf_getscopes(cudie, ip - bias, &scopes);
for (int i = 0; i < nscopes; ++i) {
Dwarf_Die *scope = &scopes[i];
const int tag = dwarf_tag(scope);
if (tag == DW_TAG_subprogram || tag == DW_TAG_inlined_subroutine) {
subroutine = scope;
break;
}
}
Dwarf_Die *scopes_die = nullptr;
int nscopes_die = dwarf_getscopes_die(subroutine, &scopes_die);
for (int i = 0; i < nscopes_die; ++i) {
Dwarf_Die *scope = &scopes_die[i];
const int tag = dwarf_tag(scope);
if (tag == DW_TAG_subprogram || tag == DW_TAG_inlined_subroutine) {
// do stuff
}
}
free(scopes_die);
free(scopes);
```
Profiling shows that both, the calls to dwarf_getscopes and
dwarf_getscopes_die can take a really long time. I have seen cases (in
libclang.so.11) where a single call can take up to ~50ms on a fast desktop
machine (Ryzen 3900X CPU, fast SSD, 32GB of RAM).
Now while 50ms may not sound sound too problematic, we have to repeat these
calls for every IP we encounter in a perf.data file. We already apply heavy
caching, but even then we can easily encounter tens of thousands of individual
addresses, which can add up to minutes or even hours of time required to
process the data - only to get information on inlined frames.
I have learned that the DWARF format is mostly meant for efficient storage and
that one cannot assume that it is efficient for such mass post processing.
This is the reason why I'm writing this email:
Has anyone an idea on how to to post-process the DWARF data to optimize the
lookup of inlined frames?
Or is there some room for optimizations / caching within elfutils to amortize
the repeated DWARF hierarchy walking that happens when one calls
dwarf_getscopes{,_die}? From what I'm understanding, both calls will start a
top-down search within the CU DIE via __libdw_visit_scopes. Once a match is
found, the DIE scope chain is reported. I guess many times (parts of the) DIE
scope chain will be shared across different IPs, but I don't see any way to
leverage this to speed up the processing task.
Thanks, any input would be welcome
--
Milian Wolff
mail@milianw.de
http://milianw.de
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next reply other threads:[~2020-06-13 17:40 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-13 17:40 Milian Wolff [this message]
2020-06-15 16:54 ` Josh Stone
2020-06-19 23:45 ` Mark Wielaard
2020-06-22 8:29 ` Milian Wolff
2020-06-25 22:38 ` Mark Wielaard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2050295.fxRyV3M0rs@milian-workstation \
--to=mail@milianw.de \
--cc=elfutils-devel@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).