perf: add sort by inclusive time functionality (v2)
cover perf: add sort by inclusive time functionality (v2)
This patch series refactors existing code a bit and adds sort by inclusive time (time spent in the function + callees).
Sample command lines:
# perf record -ag -- sleep 1 # perf report -g graph,0.5,callee -n -s inclusive
Known bugs:
total_period computation is broken for order=callee
PATCH 1/2 perf: refactor add_hist_entry() code paths
This makes perf__evsel_add_hist_entry() less busy in preparation for support for sorting by inclusive times.
--- builtin-report.c | 12 ++++-------- util/hist.c | 20 ++++++++++++++++++++ util/hist.h | 5 +++++ 3 files changed, 29 insertions(+), 8 deletions(-)
tools/perf/builtin-report.c +4 -8
@@ -61,6 +61,7 @@ static int perf_evsel__add_hist_entry(struct perf_evsel *evsel,struct symbol *parent =NULL ;int err =0 ;struct hist_entry *he; +struct callchain_cursor *cursor;if ((sort__has_parent || symbol_conf.use_callchain) && sample->callchain) { err = machine__resolve_callchain(machine, evsel, al->thread,
@@ -69,17 +70,12 @@ static int perf_evsel__add_hist_entry(struct perf_evsel *evsel,return err; } - he =__hists__add_entry (&evsel->hists, al, parent, sample->period); + cursor = &evsel->hists.callchain_cursor; + he =__hists__add_entry_single (&evsel->hists, al, parent, + cursor, sample->period);if (he ==NULL )return -ENOMEM ; -if (symbol_conf.use_callchain) { - err =callchain_append (he->callchain, - &evsel->hists.callchain_cursor, - sample->period); -if (err) -return err; - }/* * Only in the newt browser we are doing integrated annotation, * so we don't allocated the extra space needed because the stdio
tools/perf/util/hist.c +20 -0
@@ -252,6 +252,26 @@ out_unlock:return he; } +struct hist_entry *__hists__add_entry_single (struct hists *hists, +struct addr_location *al, +struct symbol *sym_parent, +struct callchain_cursor *cursor, +u64 period) +{ +struct hist_entry *he; +int err; + + he =__hists__add_entry (hists, al, sym_parent, period); +if (he ==NULL ) +return NULL ; +if (symbol_conf.use_callchain) { + err =callchain_append (he->callchain, cursor, period); +if (err) +return NULL ; + } +return he; +} +int64_t hist_entry__cmp (struct hist_entry *left,struct hist_entry *right) {
tools/perf/util/hist.h +5 -0
@@ -68,6 +68,11 @@ struct hists {struct hist_entry *__hists__add_entry (struct hists *self,struct addr_location *al,struct symbol *parent,u64 period); +struct hist_entry *__hists__add_entry_single (struct hists *self, +struct addr_location *al, +struct symbol *parent, +struct callchain_cursor *cursor, +u64 period);int64_t hist_entry__cmp (struct hist_entry *left,struct hist_entry *right);int64_t hist_entry__collapse (struct hist_entry *left,struct hist_entry *right); int hist_entry__snprintf(struct hist_entry *self, char *bf, size_t size,
Signature · 1 line
1.7.8.rc1
PATCH 2/2 perf: Add a new sort order: SORT_INCLUSIVE
In reply to Arun SharmaEach entry that used to get added once to the histogram, now is added chain->nr times, each time with one less entry in the callchain.
This will result in a non-leaf function that appears in a lot of samples to get a histogram entry with lots of hits.
The user can then drill down into the callchains of functions that have high inclusive times.
--- builtin-report.c | 9 +++++++-- util/callchain.c | 14 ++++++++++++++ util/callchain.h | 4 ++++ util/hist.c | 44 +++++++++++++++++++++++++++++++++++++++++++- util/hist.h | 5 +++++ util/sort.c | 3 +++ util/sort.h | 2 ++ 7 files changed, 78 insertions(+), 3 deletions(-)
tools/perf/builtin-report.c +7 -2
@@ -71,8 +71,12 @@ static int perf_evsel__add_hist_entry(struct perf_evsel *evsel, } cursor = &evsel->hists.callchain_cursor; - he =__hists__add_entry_single (&evsel->hists, al, parent, - cursor, sample->period); +if (sort__first_dimension ==SORT_INCLUSIVE ) + he =__hists__add_entry_inclusive (&evsel->hists, al, parent, + cursor, sample->period); +else + he =__hists__add_entry_single (&evsel->hists, al, parent, + cursor, sample->period);if (he ==NULL )return -ENOMEM ;
@@ -591,6 +595,7 @@ int cmd_report(int argc, const char **argv, const char *prefix __used)sort_entry__setup_elide (&sort_dso, symbol_conf.dso_list,"dso" , stdout);sort_entry__setup_elide (&sort_comm, symbol_conf.comm_list,"comm" , stdout);sort_entry__setup_elide (&sort_sym, symbol_conf.sym_list,"symbol" , stdout); +sort_entry__setup_elide (&sort_sym, symbol_conf.sym_list,"inclusive" , stdout);return __cmd_report (&report); }
tools/perf/util/callchain.c +14 -0
@@ -459,3 +459,17 @@ int callchain_cursor_append(struct callchain_cursor *cursor,return 0 ; } + +int callchain_get (struct callchain_cursor *cursor, +struct addr_location *al) +{ +struct callchain_cursor_node *node = cursor->curr; + +if (node ==NULL )return -1 ; + + al->map = node->map; + al->sym = node->sym; + al->addr = node->ip; + +return 0 ; +}
tools/perf/util/callchain.h +4 -0
@@ -103,9 +103,13 @@ int callchain_merge(struct callchain_cursor *cursor,struct ip_callchain ;union perf_event ; +struct addr_location ;bool ip_callchain__valid (struct ip_callchain *chain,const union perf_event *event); + +int callchain_get (struct callchain_cursor *cursor,struct addr_location *al); +/* * Initialize a cursor before adding entries inside, but keep * the previously allocated entries as a cache.
tools/perf/util/hist.c +43 -1
62 lines not on this page · raw message
tools/perf/util/hist.h +5 -0
@@ -73,6 +73,11 @@ struct hist_entry *__hists__add_entry_single(struct hists *self,struct symbol *parent, struct callchain_cursor *cursor, u64 period); +struct hist_entry *__hists__add_entry_inclusive (struct hists *self, +struct addr_location *al, +struct symbol *parent, +struct callchain_cursor *cursor, +u64 period);int64_t hist_entry__cmp (struct hist_entry *left,struct hist_entry *right);int64_t hist_entry__collapse (struct hist_entry *left,struct hist_entry *right); int hist_entry__snprintf(struct hist_entry *self, char *bf, size_t size,
tools/perf/util/sort.c +3 -0
@@ -259,6 +259,7 @@ static struct sort_dimension sort_dimensions[] = { { .name = "symbol", .entry = &sort_sym, }, { .name = "parent", .entry = &sort_parent, }, { .name = "cpu", .entry = &sort_cpu, }, + { .name = "inclusive", .entry = &sort_sym, }, }; int sort_dimension__add(const char *tok)
@@ -298,6 +299,8 @@ int sort_dimension__add(const char *tok) sort__first_dimension =SORT_DSO ; else if (!strcmp(sd->name, "symbol")) sort__first_dimension =SORT_SYM ; + else if (!strcmp(sd->name, "inclusive")) + sort__first_dimension =SORT_INCLUSIVE ; else if (!strcmp(sd->name, "parent")) sort__first_dimension =SORT_PARENT ; else if (!strcmp(sd->name, "cpu"))
tools/perf/util/sort.h +2 -0
@@ -65,6 +65,7 @@ struct hist_entry {bool init_have_children;char level;bool used; +bool inclusive;u8 filtered;struct symbol *parent;union {
@@ -82,6 +83,7 @@ enum sort_type {SORT_SYM ,SORT_PARENT ,SORT_CPU , + SORT_INCLUSIVE, };/*
Signature · 1 line
1.7.8.rc1
Re: [PATCH 2/2] perf: Add a new sort order: SORT_INCLUSIVE
Further testing showed one more bad memory reference when using sort inclusive. Fixed by the patch below.
commit 799f80b6e8168d4813de094f2327367d6d226a8c
Author: Arun Sharma <[email protected]> Date: Wed Mar 7 15:05:00 2012 -0800
perf: fix some bad memory references in tui
Check for he->ms.sym since that's what we're dereferencing
tools/perf/builtin-report.c +1 -1
@@ -86,7 +86,7 @@ static int perf_evsel__add_hist_entry(struct perf_evsel *evsel,* so we don't allocated the extra space needed because the stdio * code will not use it. */ -if (al->sym !=NULL && use_browser >0 ) { +if (he->ms.sym !=NULL && use_browser >0 ) {struct annotation *notes =symbol__annotation (he->ms.sym);assert (evsel !=NULL );
Re: [PATCH 2/2] perf: Add a new sort order: SORT_INCLUSIVE
In reply to Arun Sharmatools/perf/builtin-report.c static int perf_evsel__add_hist_entry(struct perf_evsel *evsel, · line 79
Quoted 12 lines · Arun Sharma
tools/perf/builtin-report.c +6
-2@@ -71,8 +71,12 @@ static int perf_evsel__add_hist_entry(struct perf_evsel *evsel, } cursor = &evsel->hists.callchain_cursor; - he =__hists__add_entry_single (&evsel->hists, al, parent, - cursor, sample->period); +if (sort__first_dimension ==SORT_INCLUSIVE ) + he =__hists__add_entry_inclusive (&evsel->hists, al, parent, + cursor, sample->period); +else + he =__hists__add_entry_single (&evsel->hists, al, parent, + cursor, sample->period);
If sort__first_dimension is available to hist.c then I think there should still be a simple __hists__add_entry() function in hist.c, which perf_evsel__add_hist_entry() calls - which then calls the static inline __hists__add_entry_inclusive() and __hists__add_entry_single() functions within hist.c.
I.e. this refactoring and splitup of the function into two parts is not a detail that should matter to builtin-report.c's perf_evsel__add_hist_entry().
Thanks,
Ingo
Quoted 7 lines · Arun Sharma
This patch series refactors existing code a bit and adds sort by inclusive time (time spent in the function + callees).
Sample command lines:
# perf record -ag -- sleep 1 # perf report -g graph,0.5,callee -n -s inclusive
So I tried this out with:
$ taskset 1 perf record -g git gc
and got entries above 100% (in the TUI):
$ perf report -g graph,0.5,callee -n -s inclusive
+ 321.11% 5628 [.] 0x392b609269 + 142.27% 3774 [.] create_delta + 78.86% 1248 [.] lookup_object + 40.54% 1348 [k] system_call_fastpath
[...]
Is that expected?
Thanks,
Ingo
Quoted 19 lines · Ingo Molnar
Quoted 7 lines · Arun Sharma
This patch series refactors existing code a bit and adds sort by inclusive time (time spent in the function + callees).
Sample command lines:
# perf record -ag -- sleep 1 # perf report -g graph,0.5,callee -n -s inclusiveSo I tried this out with:
$ taskset 1 perf record -g git gcand got entries above 100% (in the TUI):
$ perf report -g graph,0.5,callee -n -s inclusive
Quoted 7 lines
+ 321.11% 5628 [.] 0x392b609269 + 142.27% 3774 [.] create_delta + 78.86% 1248 [.] lookup_object + 40.54% 1348 [k] system_call_fastpath[...]
Is that expected?
I think this happens because of this:
- hists->stats.total_period += h->period;
+ if (!h->inclusive)
+ hists->stats.total_period += h->period;
Which I'm not sure why it is needed btw.
Re: [PATCH 2/2] perf: Add a new sort order: SORT_INCLUSIVE
In reply to Arun SharmaQuoted 9 lines · Arun Sharma
Each entry that used to get added once to the histogram, now is added
chain->nrtimes, each time with one less entry in the callchain.This will result in a non-leaf function that appears in a lot of samples to get a histogram entry with lots of hits.
The user can then drill down into the callchains of functions that have high inclusive times.
I don't yet understand the point of this.
Imagine those three hists:
a -> b -> c
a -> b -> d
a-> e -> f
The fractal inverted mode (-G) will report this:
a--
|
----- b
| |
| -----c
| |
| -----d
|
----- e
|
-----fThe branch sorting is recursive so outstanding callers appear in the first branches already.
So if your goal is to find important callers, I don't see why the existing functionalities aren't enough.
Re: [PATCH 2/2] perf: Add a new sort order: SORT_INCLUSIVE
Quoted 14 lines · Frederic Weisbecker
I don't yet understand the point of this.
Imagine those three hists:
a -> b -> c
a -> b -> d
a-> e -> fThe fractal inverted mode (-G) will report this:
a--
|
----- b
Quoted 9 lines
| |
| -----c
| |
| -----d
|
----- e
|
-----fPlease see the test program attached. It has only two paths from main() to c(). But for this discussion, imagine a callgraph with 10 different paths.
With -G, c() appears 10 times in the callgraph and the user is required to manually sum up the samples to realize that the callgraph under c() is very expensive.
With -s inclusive, c() will show up at the very top after main().
-Arun
#include <stdio.h>
int sum = 0;
#define LOOP(n) \
{ \
int j; \
for (j = 0; j < 10000; j++) { \
sum += j; \
} \
}int f()
{
LOOP(100);
}int d()
{
LOOP(100);
f();
}int e()
{
LOOP(100);
f();
}int c()
{
LOOP(100);
d();
LOOP(100);
e();
}int b()
{
LOOP(70);
c();
}int a()
{
LOOP(30);
c();
}int main()
{
int i;
for (i = 0; i < 10000; i++) {
a();
b();
}
}Quoted 20 lines · Frederic Weisbecker
Quoted 19 lines · Ingo Molnar
Quoted 7 lines · Arun Sharma
This patch series refactors existing code a bit and adds sort by inclusive time (time spent in the function + callees).
Sample command lines:
# perf record -ag -- sleep 1 # perf report -g graph,0.5,callee -n -s inclusiveSo I tried this out with:
$ taskset 1 perf record -g git gcand got entries above 100% (in the TUI):
$ perf report -g graph,0.5,callee -n -s inclusive
Quoted 7 lines
Quoted 7 lines
+ 321.11% 5628 [.] 0x392b609269 + 142.27% 3774 [.] create_delta + 78.86% 1248 [.] lookup_object + 40.54% 1348 [k] system_call_fastpath[...]
Is that expected?
Yes - this is the "known bug" I noted in the cover letter
The second column (samples) is still accurate and could be used for the analysis.
Quoted 8 lines
I think this happens because of this:
(quoted diff) +2
-1- hists->stats.total_period += h->period; + if (!h->inclusive) + hists->stats.total_period += h->period;Which I'm not sure why it is needed btw.
Suppose the perf.data file had 1000 samples each with a period of 1e6 events. total_period would be 1e9 without -s inclusive. Further, let's say the callchains had an average length of 10.
Now, after adding extra entries to the histogram, total_period would be 1e10, which screws up the percentages. I'd like to differentiate between the hist entries that were in the event stream vs the ones added for inclusive time computation. Desired end result: the total_period remains unchanged at 1e9.
This is done via:
+ if (i != 0)
+ he->inclusive = 1;
+ else
+ orig_he = he;
Either (i != 0) is not a good enough test, or the inclusive bit is not getting propagated properly after histogram collapsing/resorting. This is the part I need to better understand and debug.
I tried to explain this problem in my first RFC message as well:
http://thread.gmane.org/gmane.linux.kernel/1262289
The problem Ingo is running into (and I've reproduced it on my end as well) is that total_period is smaller than without -s inclusive i.e. h->inclusive is 1 when it shouldn't be.
-Arun
Hi,
Quoted 62 lines · Arun Sharma
Quoted 20 lines · Frederic Weisbecker
Quoted 19 lines · Ingo Molnar
Quoted 7 lines · Arun Sharma
This patch series refactors existing code a bit and adds sort by inclusive time (time spent in the function + callees).
Sample command lines:
# perf record -ag -- sleep 1 # perf report -g graph,0.5,callee -n -s inclusiveSo I tried this out with:
$ taskset 1 perf record -g git gcand got entries above 100% (in the TUI):
$ perf report -g graph,0.5,callee -n -s inclusiveQuoted 7 lines
Quoted 7 lines
+ 321.11% 5628 [.]
0x392b609269
+ 142.27% 3774 [.]create_delta
+ 78.86% 1248 [.]lookup_object
+ 40.54% 1348 [k]system_call_fastpath
[...]Is that expected?
Yes - this is the "known bug" I noted in the cover letter
The second column (samples) is still accurate and could be used for the analysis.
Quoted 8 lines
I think this happens because of this:
-
hists->stats.total_period+=h->period;
+ if (!h->inclusive)
+hists->stats.total_period+=h->period;Which I'm not sure why it is needed btw.
Suppose the perf.data file had 1000 samples each with a period of 1e6 events.
total_periodwould be 1e9 without -s inclusive. Further, let's say the callchains had an average length of 10.Now, after adding extra entries to the histogram,
total_periodwould be 1e10, which screws up the percentages. I'd like to differentiate between the hist entries that were in the event stream vs the ones added for inclusive time computation. Desired end result: thetotal_periodremains unchanged at 1e9.This is done via:
+ if (i != 0)
+he->inclusive= 1;
+ else
+orig_he= he;Either (i != 0) is not a good enough test, or the inclusive bit is not getting propagated properly after histogram collapsing/resorting. This is the part I need to better understand and debug.
Quoted 8 lines
I tried to explain this problem in my first RFC message as well:
http://thread.gmane.org/gmane.linux.kernel/1262289
The problem Ingo is running into (and I've reproduced it on my end as well) is that
total_periodis smaller than without -s inclusive i.e.h->inclusiveis 1 when it shouldn't be.
I think it's because of the shared hist_entry. If a callchain is a subset of another, it will be marked as inclusive so that it cannot be contributed to total period. Say, there're two chains - X (a -> b -> c) and Y (a -> b), once __hists__add_entry_inclusive() was called on X, we have:
a -> b -> c
a -> b (inclusive)
a (inclusive)
And then, calling the function on Y should make:
a -> b
a (inclusive)
However, since both callchains are in tree already they'll be shared and marked *inclusive*. Thus the total period will not increased at all for Y. Also I guess the reverse case - add Y first, and then X - will have the same result.
Thanks,
Namhyung
Hi,
Quoted 12 lines · Arun Sharma
This patch series refactors existing code a bit and adds sort by inclusive time (time spent in the function + callees).
Sample command lines:
# perf record -ag -- sleep 1 # perf report -g graph,0.5,callee -n -s inclusiveKnown bugs:
total_periodcomputation is broken for order=callee
I'd like to add two more :).
* If perf record misses callchain info, perf report will get stuck.
* If it's used with "symbol" sort order, it'll get stuck too.
BTW, I don't like the name 'inclusive' as a sort key. If it cares about time, IMHO, the name should contain 'time' - something like 'itime' or 'inctime'?
Furthermore, I don't think it is a sort key. As it doesn't sort anything, and only affects the way calculating symbol's period value, wouldn't it be better making it a separate switch rather than a sort key? Plus, checking whether it has callchain data and symbol sort key might be added also.
Thanks,
Namhyung
Quoted 13 lines · Namhyung Kim
I think it's because of the shared
hist_entry. If a callchain is a subset of another, it will be marked as inclusive so that it cannot be contributed to total period. Say, there're two chains - X (a -> b -> c) and Y (a -> b), once__hists__add_entry_inclusive()was called on X, we have:a -> b -> c
a -> b (inclusive)
a (inclusive)And then, calling the function on Y should make:
Quoted 7 lines
a -> b
a (inclusive)However, since both callchains are in tree already they'll be shared and marked *inclusive*. Thus the total period will not increased at all for Y. Also I guess the reverse case - add Y first, and then X - will have the same result.
Thanks for figuring this out. Looks like using a single bit (he->inclusive) is insufficient. How about:
struct hist_entry {
u64 period;
u64 period_self;
..
};Normal mode: period_self == period.
Inclusive mode: period_self will be zero for inclusive hist_entries. Shared entries: we sum up both period and period_self.
We can then compute total_period by summing up period_self.
-Arun
Quoted 10 lines · Namhyung Kim
Quoted 4 lines
Known bugs:
total_periodcomputation is broken for order=calleeI'd like to add two more :).
* If perf record misses callchain info, perf report will get stuck.
* If it's used with "symbol" sort order, it'll get stuck too.
Can you post the command lines you used to reproduce this? A backtrace on where perf report is getting stuck would be useful as well.
Since I didn't make any changes to the perf record or perf report code paths that don't involve "-s inclusive", I wonder if you see the same issues without my patch.
For missing callchain info cases, I'd expect cursor->nr to be zero. So loops such as:
+ for (i = 0; i < cursor->nr; i++) {
should terminate immediately.
Quoted 4 lines
BTW, I don't like the name 'inclusive' as a sort key. If it cares about time, IMHO, the name should contain 'time' - something like 'itime' or 'inctime'?
The existing sort orders: pid, comm, dso, symbol, parent -- all care about time, but none of them have time in their name?
Quoted 6 lines
Furthermore, I don't think it is a sort key. As it doesn't sort anything, and only affects the way calculating symbol's period value, wouldn't it be better making it a separate switch rather than a sort key? Plus, checking whether it has callchain data and symbol sort key might be added also.
Yes, we're still sorting by period, but a redefined meaning of period (please see my other mail about period vs period_self). Previous iterations of this code did use a top level flag, but that namespace is getting a bit crowded.
-Arun
Re: [PATCH 2/2] perf: Add a new sort order: SORT_INCLUSIVE
In reply to Ingo MolnarQuoted 5 lines · Ingo Molnar
I.e. this refactoring and splitup of the function into two parts is not a detail that should matter to builtin-report.c's
perf_evsel__add_hist_entry().
Agreed. I'll fold this into the next rev.
-Arun
Quoted 7 lines · Arun Sharma
Quoted 4 lines
BTW, I don't like the name 'inclusive' as a sort key. If it cares about time, IMHO, the name should contain 'time' - something like 'itime' or 'inctime'?
The existing sort orders: pid, comm, dso, symbol, parent -- all care about time, but none of them have time in their name?
I'll take that back. What they sort on depends on the event.
perf record -ge cache-misses
perf report -s inclusive
will sort by the number of cache-misses and not time.
-Arun
Quoted 30 lines · Arun Sharma
Quoted 12 lines · Namhyung Kim
I think it's because of the shared
hist_entry. If a callchain is a subset of another, it will be marked as inclusive so that it cannot be contributed to total period. Say, there're two chains - X (a -> b -> c) and Y (a -> b), once__hists__add_entry_inclusive()was called on X, we have:a -> b -> c
a -> b (inclusive)
a (inclusive)And then, calling the function on Y should make:
Quoted 7 lines
a -> b
a (inclusive)However, since both callchains are in tree already they'll be shared and marked *inclusive*. Thus the total period will not increased at all for Y. Also I guess the reverse case - add Y first, and then X - will have the same result.
Thanks for figuring this out. Looks like using a single bit (
he->inclusive) is insufficient. How about:struct hist_entry { u64 period; u64 period_self; .. };
Quoted 6 lines
Normal mode:
period_self== period.
Inclusive mode:period_selfwill be zero for inclusivehist_entries. Shared entries: we sum up both period andperiod_self.We can then compute
total_periodby summing upperiod_self.
Yeah, I agree that we need that kind of code to handle total_period properly. Looking forward to your v3 :).
Thanks,
Namhyung
Quoted 7 lines · Arun Sharma
Quoted 5 lines · Namhyung Kim
Quoted 4 lines
Known bugs:
total_periodcomputation is broken for order=callee
Quoted 9 lines
Quoted 5 lines
I'd like to add two more :).
* If perf record misses callchain info, perf report will get stuck.
* If it's used with "symbol" sort order, it'll get stuck too.Can you post the command lines you used to reproduce this? A backtrace on where perf report is getting stuck would be useful as well.
$ perf record sleep 1 $ perf report -s inclusive
and
$ perf record -g sleep 1 $ perf report -s inclusive,symbol
Thanks,
Namhyung
Hi,
Quoted 8 lines · Arun Sharma
Quoted 6 lines · Arun Sharma
Quoted 3 lines
BTW, I don't like the name 'inclusive' as a sort key. If it cares about time, IMHO, the name should contain 'time' - something like 'itime' or 'inctime'?
The existing sort orders: pid, comm, dso, symbol, parent -- all care about time, but none of them have time in their name?
Quoted 8 lines
I'll take that back. What they sort on depends on the event.
perf record -ge cache-misses
perf report -s inclusivewill sort by the number of cache-misses and not time.
-Arun
AFAIK, "sort" here means how perf identifies a sample event from others: "comm" will collect samples have same pid/comm, then "dso" will group samples belong to same library, and "symbol" will group again samples have same symbol name. This is what default sort order (comm,dso,symbol) does.
In case of "inclusive" it does same thing with "symbol" as you use sort_sym for the inclusive sort_dimension. Sorting by period for output is done at final stage and it won't be affected by any sort orders. It maybe sound confusing but that's how it works.
Thanks,
Namhyung
Re: [PATCH 2/2] perf: Add a new sort order: SORT_INCLUSIVE
In reply to Arun SharmaQuoted 25 lines · Arun Sharma
Quoted 14 lines · Frederic Weisbecker
I don't yet understand the point of this.
Imagine those three hists:
a -> b -> c
a -> b -> d
a-> e -> fThe fractal inverted mode (-G) will report this:
a--
|
----- bQuoted 9 lines
| | | -----c | | | -----d | ----- e | -----f
Quoted 3 lines
Please see the test program attached. It has only two paths from
main()toc(). But for this discussion, imagine a callgraph with 10 different paths.
Ok that makes sense.
Thanks.
Quoted 67 lines
With -G,
c()appears 10 times in the callgraph and the user is required to manually sum up the samples to realize that the callgraph underc()is very expensive.With -s inclusive,
c()will show up at the very top aftermain().-Arun
#include <
stdio.h>int sum = 0;
#define LOOP(n) \ { \ int j; \ for (j = 0; j < 10000; j++) { \ sum += j; \ } \ }int
f(){ LOOP(100); }int
d(){ LOOP(100); f(); }int
e(){ LOOP(100); f(); }int
c(){ LOOP(100); d(); LOOP(100); e(); }int
b(){ LOOP(70); c(); }int
a(){ LOOP(30); c(); }int
main(){ int i; for (i = 0; i < 10000; i++) { a(); b(); } }
Quoted 2 lines · Namhyung Kim
$ perf record -g sleep 1 $ perf report -s inclusive,symbol
Thanks. I was able to reproduce the hangs and they went away after I added sort_sym_inclusive (a copy of sort_sym, except for the se_header).
The output of perf report now better describes how the symbols are sorted. The text reads: "Symbol (Inclusive)".
v3 is coming via my next mail.
-Arun
Quoted 18 lines · Namhyung Kim
Hi,
Quoted 15 lines · Arun Sharma
Quoted 6 lines · Arun Sharma
Quoted 3 lines
BTW, I don't like the name 'inclusive' as a sort key. If it cares about time, IMHO, the name should contain 'time' - something like 'itime' or 'inctime'?
The existing sort orders: pid, comm, dso, symbol, parent -- all care about time, but none of them have time in their name?
I'll take that back. What they sort on depends on the event.
perf record -ge cache-misses
perf report -s inclusivewill sort by the number of cache-misses and not time.
Quoted 7 lines
Quoted 1 line
-Arun
AFAIK, "sort" here means how perf identifies a sample event from
others: "comm" will collect samples have same pid/comm, then "dso" will group samples belong to same library, and "symbol" will group again samples have same symbol name. This is what default sort order (comm,dso,symbol) does.
Right this is about how we group the events into histograms. If you sort by dso, you'll have one histogram per dso and events will be added to the histogram matching their dso.
Multiple sorting does the same with an "AND" between sort entries. If you sort by dso,pid, you'll have one histogram per possible couple of (dso,pid).
Say you have dso1, dso2 and pid1 and pid2, then you get 4 possible histograms:
(dso1,pid1), (dso1,pid2), (dso2,pid1), (dso2,pid2)
...assuming that over your events you have all these combinations.
So this is how we group samples into histograms.
Quoted 14 lines · Frederic Weisbecker
Quoted 5 lines
AFAIK, "sort" here means how perf identifies a sample event from
others: "comm" will collect samples have same pid/comm, then "dso" will group samples belong to same library, and "symbol" will group again samples have same symbol name. This is what default sort order (comm,dso,symbol) does.Right this is about how we group the events into histograms. If you sort by dso, you'll have one histogram per dso and events will be added to the histogram matching their dso.
Multiple sorting does the same with an "AND" between sort entries. If you sort by dso,pid, you'll have one histogram per possible couple of (dso,pid).
Quoted 5 lines
Say you have dso1, dso2 and pid1 and pid2, then you get 4 possible histograms:
(dso1,pid1), (dso1,pid2), (dso2,pid1), (dso2,pid2)
...assuming that over your events you have all these combinations.So this is how we group samples into histograms.
Agreed. It's a different sort order, but not necessarily a different sort dimension. I'm thinking "group by" vs "order by" in SQL here.
Re: adding a new top level flag, struct option options[] in builtin-report.c looks busy (especially for short options. Eg: -i is already taken).
I can see parallels between this and sort__branch_mode. Stephane: what do you think about putting this in a different namespace?
--sort-mode branch (sort__branch_mode)
--sort-mode inclusive (sort__inclusive_mode)
-Arun