Linux Perf Users
 help / color / mirror / Atom feed
From: Milian Wolff <milian.wolff@kdab.com>
To: Perf Users <linux-perf-users@vger.kernel.org>
Cc: "Jin, Yao" <yao.jin@linux.intel.com>
Subject: perf report --inline usability issues when sorting by function
Date: Thu, 27 Apr 2017 23:09:10 +0200	[thread overview]
Message-ID: <13103005.TJTgFMaJPi@agathebauer> (raw)

[-- Attachment #1: Type: text/plain, Size: 4381 bytes --]

Hey Jin, others

I observe a usability issue with the following example code:

~~~~~~~~~~~~~~~~~~~~
#include <cmath>
#include <random>
#include <iostream>

using namespace std;

int main()
{
    uniform_real_distribution<double> uniform(-1E5, 1E5);
    default_random_engine engine;
    double s = 0;
    for (int i = 0; i < 10000000; ++i) {
        s += uniform(engine);
    }
    cout << "random sum: " << s << '\n';
    return 0;
}
~~~~~~~~~~~~~~~~~~~~

Compile it with `g++ -O2 -g` then record it with `perf record --call-graph 
dwarf` and inspect the data with inliners enabled. Here are some excerpts that 
show the issues:

~~~~~~~~~~~~~~~~~~~~
$ perf report --stdio --inline --no-children
Failed to open [ext4], continuing without symbols
# To display the perf.data header info, please use --header/--header-only 
options.
#
#
# Total Lost Samples: 0
#
# Samples: 499  of event 'cycles'
# Event count (approx.): 329354953
#
# Overhead  Command    Shared Object      Symbol                          
# ........  .........  .................  ................................
#
    96.70%  ex_random  ex_random          [.] main
            |
            ---main
               __libc_start_main
               _start

     0.96%  ex_random  ld-2.25.so         [.] do_lookup_x
            |
            ---do_lookup_x
               _dl_lookup_symbol_x
               _dl_relocate_object
               dl_main
               _dl_sysdep_start
               _dl_start
               _dl_start_user

     0.30%  ex_random  ld-2.25.so         [.] _dl_lookup_symbol_x
...
~~~~~~~~~~~~~~~~~~~~~~

Note how no inlined frames are actually shown. I think the issue here is that 
when we group by function name (the default), then multiple samples with 
different IPs will get merged. Once we display the data then in e.g. ui/stdio/
hist.c, we will only have one node left for this function, with an arbitrary 
IP (of the first sample, I guess).

This is problematic, because depending on the IP, different inlined call 
stacks may have been used. This is observable for the above use-case by 
changing the grouping algorithm, e.g.:

~~~~~~~~~~~~~~~~~~~~~~~
$ perf report --stdio --inline --no-children -g srcline
Invalid callchain mode: srcline
Invalid callchain order: srcline
Failed to open [ext4], continuing without symbols
# To display the perf.data header info, please use --header/--header-only 
options.
#
#
# Total Lost Samples: 0
#
# Samples: 499  of event 'cycles'
# Event count (approx.): 329354953
#
# Overhead  Command    Shared Object      Symbol                          
# ........  .........  .................  ................................
#
    96.70%  ex_random  ex_random          [.] main
            |          
            |--28.97%--main random.tcc:3326
            |          /usr/include/c++/6.3.1/bits/random.h:185 (inline)
            |          /usr/include/c++/6.3.1/bits/random.h:1818 (inline)
            |          /usr/include/c++/6.3.1/bits/random.h:1809 (inline)
            |          /home/milian/projects/kdab/training-material/addon/
profiling/build/ex_random/../../ex_random/main.cpp:13 (inline)
            |          __libc_start_main
            |          _start
            |          
            |--28.14%--main random.h:143
            |          /usr/include/c++/6.3.1/bits/random.h:151 (inline)
            |          /usr/include/c++/6.3.1/bits/random.h:332 (inline)
            |          /usr/include/c++/6.3.1/bits/random.tcc:3332 (inline)
            |          /usr/include/c++/6.3.1/bits/random.h:185 (inline)
            |          /usr/include/c++/6.3.1/bits/random.h:1818 (inline)
            |          /usr/include/c++/6.3.1/bits/random.h:1809 (inline)
            |          /home/milian/projects/kdab/training-material/addon/
profiling/build/ex_random/../../ex_random/main.cpp:13 (inline)
            |          __libc_start_main
            |          _start
            |
...
~~~~~~~~~~~~~~~~~~~~~~~

Has anyone any suggestion on how to fix this? Some ideas:

- adapt the function aggregation to also take the inlined function into 
account
- always add inlined frames to the graph
- keep all IPs and their cost even when aggregating functions

Cheers

-- 
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

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5903 bytes --]

             reply	other threads:[~2017-04-27 21:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-27 21:09 Milian Wolff [this message]
2017-04-27 22:03 ` perf report --inline usability issues when sorting by function Milian Wolff

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=13103005.TJTgFMaJPi@agathebauer \
    --to=milian.wolff@kdab.com \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=yao.jin@linux.intel.com \
    /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