Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1763615AbcLTNdU (ORCPT ); Tue, 20 Dec 2016 08:33:20 -0500 Received: from mail.kdab.com ([176.9.126.58]:38784 "EHLO mail.kdab.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755158AbcLTNdS (ORCPT ); Tue, 20 Dec 2016 08:33:18 -0500 X-Greylist: delayed 363 seconds by postgrey-1.27 at vger.kernel.org; Tue, 20 Dec 2016 08:33:17 EST From: Milian Wolff To: Peter Zijlstra Cc: "Steinar H. Gunderson" , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo , Jiri Olsa Subject: Re: Inlined functions in perf report Date: Tue, 20 Dec 2016 14:27:10 +0100 Message-ID: <2027151.EnbG4A8ymx@milian-kdab2> Organization: KDAB In-Reply-To: <20161220121755.GL3124@twins.programming.kicks-ass.net> References: <20161220115954.GA35897@sesse.net> <20161220121755.GL3124@twins.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart8619909.WDQz9TpWy4"; micalg="sha1"; protocol="application/pkcs7-signature" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 13057 Lines: 255 --nextPart8619909.WDQz9TpWy4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="UTF-8" On Tuesday, December 20, 2016 1:17:55 PM CET Peter Zijlstra wrote: > On Tue, Dec 20, 2016 at 12:59:54PM +0100, Steinar H. Gunderson wrote: > > Hi Peter, > >=20 > > I can't find a good point of contact for perf, so I'm contacting you ba= sed > > on the MAINTAINERS file; feel free to redirect somewhere if you're not > > the right person. >=20 > Cc'ed linux-perf-users@vger.kernel.org >=20 > > I'm trying to figure out how to deal with perf report when there are > > inlined functions; they don't generally seem to show up in the call > > stack, which sometimes can make it very hard to figure out what is goin= g, > > especially in a code base one doesn't know too well. As an example, I > > threw together a>=20 > > minimal test program: > > #include > > =20 > > inline int foo() > > { > > =20 > > int k =3D rand(); > > int sum =3D 1; > > for (int i =3D 0; i < 10000000000; ++i) > > { > > =20 > > sum ^=3D k; > > sum +=3D k; > > =20 > > } > > return sum; > > =20 > > } > > =20 > > int main(void) > > { > > =20 > > return foo(); > > =20 > > } > >=20 > > Compiling with -O2 -g, and running perf record -g yields: > > # Samples: 6K of event 'cycles:ppp' > > # Event count (approx.): 5876825543 > > # > > # Children Self Command Shared Object Symbol > > # ........ ........ ....... ................. ...................= =2E.. > > # > > =20 > > 99.98% 99.98% inline inline [.] main > > =20 > > ---0x706258d4c544155 > > =20 > > main > > =20 > > 99.98% 0.00% inline [unknown] [.] 0x0706258d4c544= 155 > > =20 > > ---0x706258d4c544155 > > =20 > > main > >=20 > > Is there a way I can get it to show =E2=80=9Cfoo=E2=80=9D in the call g= raph? (I suppose > > also ideally, =E2=80=9Cfoo=E2=80=9D and not =E2=80=9Cmain=E2=80=9D shou= ld show up in a non-graph run.) Of > > course, this gets even more confusing if foo calls bar, since it now > > looks like the call chain is main -> bar directly. > >=20 > > I have debug information that should be sufficient in the binary, becau= se > > if>=20 > > I break in gdb, I definitely get the call stack: > > Program received signal SIGINT, Interrupt. > > 0x0000555555554589 in foo () at inline.c:5 > > 5 int k =3D rand(); > > (gdb) bt > > #0 0x0000555555554589 in foo () at inline.c:5 > > #1 main () at inline.c:17 > > (gdb) > >=20 > > FWIW, this is with perf from 4.10 (git as of a few days ago) and GCC > > 6.2.1. >=20 > OK, so it might be possible with: perf record -g --call-graph dwarf > but that's fairly heavy on the overhead, it will dump the top-of-stack > for each sample (8k default) and unwind using libunwind in userspace. It is not even possible with that, perf report is lacking the steps require= d=20 to add inline frames - it will only add "real" frames it gets from either o= f=20 the unwind libraries. I have a WIP patch available for this functionality though, it can be found= =20 here (depends on libbfd, i.e. bfd_find_inliner_info): https://github.com/milianw/linux/commit/ 71d031c9d679bfb4a4044226e8903dd80ea601b3 This is not yet upstreamable, but any early comments would be welcome. I ho= pe=20 to get some more time to drive this in the coming weeks. If you want to tes= t=20 it out, checkout my milian/perf branch of this repo, build it like you'd do= =20 the normal user-space perf, then run perf report -g srcline -s sym,srcline > The default mechanism used for call-graphs is frame-pointers which are > (relatively) simple and fast to traverse from kernel space. The down > side is of course that all your userspace needs to be compiled with > frame pointers enabled and inlined functions, as you noticed, are > 'lost'. >=20 > There has been talk to attempt to utilize the ELF EH frames which are > mandatory in the x86_64 ABI (even for C) to attempt a kernel based > 'DWARF' unwind, but nobody has put forward working code for this yet. > Also, even if the EH stuff is mapped at runtime, it doesn't mean the > pages will actually be loaded (due to demand paging) and available for > use, which also will limit usability. (perf sampling is using > interrupt/NMI context and we cannot page from that, so we're limited to > memory that's present.) While all of this would be nice to have, it is not directly related to=20 inlining from what I gathered. Bye =2D-=20 Milian Wolff | milian.wolff@kdab.com | Software Engineer KDAB (Deutschland) GmbH&Co KG, a KDAB Group company Tel: +49-30-521325470 KDAB - The Qt Experts --nextPart8619909.WDQz9TpWy4 Content-Type: application/pkcs7-signature; name="smime.p7s" Content-Disposition: attachment; filename="smime.p7s" Content-Transfer-Encoding: base64 MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEHAQAAoIIUdzCCBGYw ggNOoAMCAQICEFEmCpMc4n+cw6VfeeByroIwDQYJKoZIhvcNAQEFBQAwgZMxCzAJBgNVBAYTAlVT MQswCQYDVQQIEwJVVDEXMBUGA1UEBxMOU2FsdCBMYWtlIENpdHkxHjAcBgNVBAoTFVRoZSBVU0VS VFJVU1QgTmV0d29yazEhMB8GA1UECxMYaHR0cDovL3d3dy51c2VydHJ1c3QuY29tMRswGQYDVQQD ExJVVE4gLSBEQVRBQ29ycCBTR0MwHhcNMDUwNjA3MDgwOTEwWhcNMTkwNjI0MTkwNjMwWjBvMQsw CQYDVQQGEwJTRTEUMBIGA1UEChMLQWRkVHJ1c3QgQUIxJjAkBgNVBAsTHUFkZFRydXN0IEV4dGVy bmFsIFR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