perf hists: Changes on hists__{match,link} (v3)
Namhyung Kim
maintainercover perf hists: Changes on hists__{match,link} (v3)
Hi,
I rebased my series on Jiri's diff displacement removal patch. As the displacement logic is gone, no need to resort (by period) baseline since the output is only aligned to a newer data (i.e. "other" hists).
I also pushed the branch onto my tree at:
git://git.kernel.org/pub/scm/linux/kernel/git/namhyung/linux-perf.git perf/link-v3
Please take a look and give comments. Any comments are welcome.
Thanks,
Namhyung
Jiri Olsa (1):
perf diff: Removing displacement output option
Namhyung Kim (4):
perf hists: Exchange order of comparing items when collapsing hists perf hists: Link hist entries before inserting to an output tree perf diff: Use internal rb tree for compute resort
perf test: Add a test case for hists__{match,link}
tools/perf/Documentation/perf-diff.txt | 4 - tools/perf/Makefile | 1 + tools/perf/builtin-diff.c | 104 ++----- tools/perf/tests/builtin-test.c | 4 + tools/perf/tests/hists_link.c | 502 ++++++++++++++++++++++++++++++++ tools/perf/tests/tests.h | 1 + tools/perf/ui/hist.c | 25 -- tools/perf/util/hist.c | 51 +++- tools/perf/util/hist.h | 1 - tools/perf/util/machine.h | 1 + tools/perf/util/session.c | 2 +- 11 files changed, 580 insertions(+), 116 deletions(-) create mode 100644 tools/perf/tests/hists_link.c
Signature · 1 line
1.7.9.2
Namhyung Kim
maintainerPATCH 1/5 perf diff: Removing displacement output option
From: Jiri Olsa <[email protected]>
Removing displacement output option. It seems not very useful, because it's possible and event more convenient to lookup related symbol by name. Also the output value for both 'baseline' and 'new' data is quite apparent from diff output.
And above all it complicates hist code factoring ;)
Ditching out PERF_HPP__DISPL column with related output functions.
--- tools/perf/Documentation/perf-diff.txt | 4 ---- tools/perf/builtin-diff.c | 29 +++++++---------------------- tools/perf/ui/hist.c | 25 ------------------------- tools/perf/util/hist.h | 1 - 4 files changed, 7 insertions(+), 52 deletions(-)
tools/perf/Documentation/perf-diff.txt +0 -4
@@ -22,10 +22,6 @@ specified perf.data files. OPTIONS ------- --M:: ---displacement:: - Show position displacement relative to baseline. - -D:: --dump-raw-trace:: Dump raw trace in ASCII.
tools/perf/builtin-diff.c +7 -22
@@ -23,7 +23,6 @@ static char const *input_old = "perf.data.old", *input_new ="perf.data" ;static char diff__default_sort_order[] ="dso,symbol" ;static bool force; -static bool show_displacement;static bool show_period;static bool show_formula;static bool show_baseline_only;
@@ -296,9 +295,8 @@ static void insert_hist_entry_by_name(struct rb_root *root,rb_insert_color (&he->rb_node, root); } -static void hists__name_resort (struct hists *self,bool sort) +static void hists__name_resort (struct hists *self) { -unsigned long position =1 ;struct rb_root tmp =RB_ROOT ;struct rb_node *next =rb_first (&self->entries);
@@ -306,16 +304,12 @@ static void hists__name_resort(struct hists *self, bool sort) struct hist_entry *n = rb_entry(next, struct hist_entry, rb_node); next =rb_next (&n->rb_node); - n->position = position++; -if (sort) { -rb_erase (&n->rb_node, &self->entries); -insert_hist_entry_by_name (&tmp, n); - } +rb_erase (&n->rb_node, &self->entries); +insert_hist_entry_by_name (&tmp, n); } -if (sort) - self->entries = tmp; + self->entries = tmp; } static struct perf_evsel *evsel_match(struct perf_evsel *evsel,
@@ -339,12 +333,8 @@ static void perf_evlist__resort_hists(struct perf_evlist *evlist, bool name)hists__output_resort (hists); -/* -* The hists__name_resort only sets possition -* if name is false. -*/ -if (name || ((!name) && show_displacement)) -hists__name_resort (hists, name); +if (name) +hists__name_resort (hists); } }
@@ -549,8 +539,6 @@ static const char * const diff_usage[] = {static const struct option options[] = {OPT_INCR ('v' ,"verbose" , &verbose,"be more verbose (show symbol address, etc)" ), -OPT_BOOLEAN ('M' ,"displacement" , &show_displacement, -"Show position displacement relative to baseline" ),OPT_BOOLEAN ('b' ,"baseline-only" , &show_baseline_only,"Show only items with match in baseline" ), OPT_CALLBACK('c', "compute", &compute,
@@ -585,7 +573,7 @@ static const struct option options[] = {static void ui_init (void ) {/* -* Display baseline/delta/ratio/displacement/ +* Display baseline/delta/ratio * formula/periods columns. */ perf_hpp__column_enable (PERF_HPP__BASELINE );
@@ -604,9 +592,6 @@ static void ui_init(void)BUG_ON (1 ); }; -if (show_displacement) -perf_hpp__column_enable (PERF_HPP__DISPL ); -if (show_formula)perf_hpp__column_enable (PERF_HPP__FORMULA );
tools/perf/ui/hist.c +0 -25
@@ -351,30 +351,6 @@ static int hpp__entry_wdiff(struct perf_hpp *hpp, struct hist_entry *he)return scnprintf (hpp->buf, hpp->size, fmt, buf); } -static int hpp__header_displ (struct perf_hpp *hpp) -{ -return scnprintf (hpp->buf, hpp->size,"Displ." ); -} - -static int hpp__width_displ (struct perf_hpp *hpp__maybe_unused ) -{ -return 6 ; -} - -static int hpp__entry_displ (struct perf_hpp *hpp, -struct hist_entry *he) -{ -struct hist_entry *pair =hist_entry__next_pair (he); -long displacement = pair ? pair->position - he->position :0 ; -const char *fmt = symbol_conf.field_sep ?"%s" :"%6.6s" ; -char buf[32 ] =" " ; - -if (displacement) -scnprintf (buf,sizeof (buf),"%+4ld" , displacement); - -return scnprintf (hpp->buf, hpp->size, fmt, buf); -} -static int hpp__header_formula (struct perf_hpp *hpp) {const char *fmt = symbol_conf.field_sep ?"%s" :"%70s" ;
@@ -427,7 +403,6 @@ struct perf_hpp_fmt perf_hpp__format[] = {HPP__PRINT_FNS (delta),HPP__PRINT_FNS (ratio),HPP__PRINT_FNS (wdiff), -HPP__PRINT_FNS (displ), HPP__PRINT_FNS(formula) };
tools/perf/util/hist.h +0 -1
@@ -154,7 +154,6 @@ enum {PERF_HPP__DELTA ,PERF_HPP__RATIO ,PERF_HPP__WEIGHTED_DIFF , -PERF_HPP__DISPL ,PERF_HPP__FORMULA ,PERF_HPP__MAX_INDEX
Signature · 1 line
1.7.9.2
Namhyung Kim
maintainerPATCH 2/5 perf hists: Exchange order of comparing items when collapsing hists
In reply to Namhyung KimFrom: Namhyung Kim <[email protected]>
When comparing entries for collapsing put the given entry first, and then the iterated entry. This is not the case of hist_entry__cmp() when called if given sort keys don't require collapsing. So change the order for the sake of consistency. It will be required for matching and/or linking multiple hist entries.
--- tools/perf/util/hist.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tools/perf/util/hist.c +3 -3
@@ -285,7 +285,7 @@ static struct hist_entry *add_hist_entry(struct hists *hists, parent = *p; he = rb_entry(parent, struct hist_entry, rb_node_in); - cmp =hist_entry__cmp (entry, he); + cmp =hist_entry__cmp (he, entry);if (!cmp) {he_stat__add_period (&he->stat, period);
@@ -729,7 +729,7 @@ static struct hist_entry *hists__add_dummy_entry(struct hists *hists, parent = *p; he = rb_entry(parent, struct hist_entry, rb_node); - cmp =hist_entry__cmp (pair, he); + cmp =hist_entry__cmp (he, pair);if (!cmp) goto out;
@@ -759,7 +759,7 @@ static struct hist_entry *hists__find_entry(struct hists *hists,while (n) { struct hist_entry *iter = rb_entry(n, struct hist_entry, rb_node); -int64_t cmp =hist_entry__cmp (he, iter); +int64_t cmp =hist_entry__cmp (iter, he);if (cmp <0 ) n = n->rb_left;
Signature · 1 line
1.7.9.2
Re: [PATCH 2/5] perf hists: Exchange order of comparing items when collapsing hists
Quoted 7 lines · Namhyung Kim
From: Namhyung Kim <[email protected]>
When comparing entries for collapsing put the given entry first, and then the iterated entry. This is not the case of
hist_entry__cmp()when called if given sort keys don't require collapsing. So change the order for the sake of consistency. It will be required for matching and/or linking multiple hist entries.
As discussed with Arnadlo, this change seems like changing the sort order... could you ellaborate how it is usefull in future?
thanks,
jirka
Quoted 42 lines
Cc Jiri Olsa <[email protected]>Cc Stephane Eranian <[email protected]>Signed-off-by Namhyung Kim <[email protected]>--- tools/perf/util/hist.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)tools/perf/util/hist.c +3
-3@@ -285,7 +285,7 @@ static struct hist_entry *add_hist_entry(struct hists *hists, parent = *p; he = rb_entry(parent, struct hist_entry, rb_node_in); - cmp =hist_entry__cmp (entry, he); + cmp =hist_entry__cmp (he, entry);if (!cmp) {he_stat__add_period (&he->stat, period);@@ -729,7 +729,7 @@ static struct hist_entry *hists__add_dummy_entry(struct hists *hists, parent = *p; he = rb_entry(parent, struct hist_entry, rb_node); - cmp =hist_entry__cmp (pair, he); + cmp =hist_entry__cmp (he, pair);if (!cmp) goto out;@@ -759,7 +759,7 @@ static struct hist_entry *hists__find_entry(struct hists *hists,while (n) { struct hist_entry *iter = rb_entry(n, struct hist_entry, rb_node); -int64_t cmp =hist_entry__cmp (he, iter); +int64_t cmp =hist_entry__cmp (iter, he);if (cmp <0 ) n = n->rb_left;Signature · 1 line
1.7.9.2
Re: [PATCH 2/5] perf hists: Exchange order of comparing items when collapsing hists
Em Thu, Dec 06, 2012 at 05:53:25PM +0100, Jiri Olsa escreveu:
Quoted 11 lines · Namhyung Kim
Quoted 7 lines
From: Namhyung Kim <[email protected]>
When comparing entries for collapsing put the given entry first, and then the iterated entry. This is not the case of
hist_entry__cmp()when called if given sort keys don't require collapsing. So change the order for the sake of consistency. It will be required for matching and/or linking multiple hist entries.As discussed with Arnadlo, this change seems like changing the sort order... could you ellaborate how it is usefull in future?
In several places the order is (he, iter) then it became (iter, he), something like that, so he inverted it for consistency, but then he needs to invert in the cmp function too, unsure if this is worth the trouble now, perhaps some comment placed in the right spot clarifies things,
- Arnaldo
Quoted 45 lines
thanks,
jirkaQuoted 42 lines
Cc Jiri Olsa <[email protected]>Cc Stephane Eranian <[email protected]>Signed-off-by Namhyung Kim <[email protected]>--- tools/perf/util/hist.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)tools/perf/util/hist.c +3
-3@@ -285,7 +285,7 @@ static struct hist_entry *add_hist_entry(struct hists *hists, parent = *p; he = rb_entry(parent, struct hist_entry, rb_node_in); - cmp =hist_entry__cmp (entry, he); + cmp =hist_entry__cmp (he, entry);if (!cmp) {he_stat__add_period (&he->stat, period);@@ -729,7 +729,7 @@ static struct hist_entry *hists__add_dummy_entry(struct hists *hists, parent = *p; he = rb_entry(parent, struct hist_entry, rb_node); - cmp =hist_entry__cmp (pair, he); + cmp =hist_entry__cmp (he, pair);if (!cmp) goto out;@@ -759,7 +759,7 @@ static struct hist_entry *hists__find_entry(struct hists *hists,while (n) { struct hist_entry *iter = rb_entry(n, struct hist_entry, rb_node); -int64_t cmp =hist_entry__cmp (he, iter); +int64_t cmp =hist_entry__cmp (iter, he);if (cmp <0 ) n = n->rb_left;Signature · 1 line
1.7.9.2
Namhyung Kim
maintainerRe: [PATCH 2/5] perf hists: Exchange order of comparing items when collapsing hists
Hi Arnaldo,
Quoted 10 lines · Arnaldo Carvalho de Melo
Em Thu, Dec 06, 2012 at 05:53:25PM +0100, Jiri Olsa escreveu:
Quoted 9 lines · Namhyung Kim
Quoted 7 lines
From: Namhyung Kim <[email protected]>
When comparing entries for collapsing put the given entry first, and then the iterated entry. This is not the case of
hist_entry__cmp()when called if given sort keys don't require collapsing. So change the order for the sake of consistency. It will be required for matching and/or linking multiple hist entries.
Quoted 8 lines
Quoted 2 lines
As discussed with Arnadlo, this change seems like changing the sort order... could you ellaborate how it is usefull in future?
In several places the order is (he, iter) then it became (iter, he), something like that, so he inverted it for consistency, but then he needs to invert in the cmp function too, unsure if this is worth the trouble now, perhaps some comment placed in the right spot clarifies things,
The point is that it needs to have a same order when comparing two entries for both of inserting (add_hist_entry) and linking (hists__add_ dummy_entry and hists__find_entry). This was simple when we used output tree, because it's a single tree so that we can make sure that it use the same order as of insertion. But by using internal trees we should select one between inserting (entries_in) and collapsing (entries_collapsed) based on the sort keys given.
Unfortunately, inserting and collapsing used different order - (he, iter) vs. (iter, he) - so we need to use corresponding (different) order for match/link also. That means that without this patch, we have to call corresponding function with different order like following:
@@ -739,6 +739,10 @@ static struct hist_entry *hists__add_dummy_entry(struct hists *hists,
cmp = hist_entry__collapse(he, pair);
+ if (sort__need_collapse)
+ cmp = hist_entry__collapse(he, pair);
+ else
+ cmp = hist_entry__cmp(pair, he);
if (!cmp)
goto out;@@ -772,7 +776,12 @@ static struct hist_entry *hists__find_entry(struct hists *hists,
while (n) {
struct hist_entry *iter = rb_entry(n, struct hist_entry, rb_node_in);- int64_t cmp = hist_entry__collapse(iter, he);
+ int64_t cmp;
+
+ if (sort__need_collapse)
+ cmp = hist_entry__collapse(iter, he);
+ else
+ cmp = hist_entry__cmp(he, iter);
if (cmp < 0)
n = n->rb_left;It doesn't look good, especially hist_entry__collapse will be same as hist_entry__cmp if 'sort__need_collapse' is false. If we can make the order consistent, it'd be converted to a sigle _collapse() call without the conditional.
Thanks,
Namhyung
Re: [PATCH 2/5] perf hists: Exchange order of comparing items when collapsing hists
Quoted 2 lines · Namhyung Kim
Hi Arnaldo,
SNIP
Quoted 26 lines
(quoted diff) +10
-1@@ -739,6 +739,10 @@ static struct hist_entry *hists__add_dummy_entry(struct hists *hists, cmp = hist_entry__collapse(he, pair); + if (sort__need_collapse) + cmp = hist_entry__collapse(he, pair); + else + cmp = hist_entry__cmp(pair, he); if (!cmp) goto out;@@ -772,7 +776,12 @@ static struct hist_entry *hists__find_entry(struct hists *hists, while (n) { struct hist_entry *iter = rb_entry(n, struct hist_entry, rb_node_in); - int64_t cmp = hist_entry__collapse(iter, he); + int64_t cmp; + + if (sort__need_collapse) + cmp = hist_entry__collapse(iter, he); + else + cmp = hist_entry__cmp(he, iter); if (cmp < 0) n = n->rb_left;
Quoted 7 lines
It doesn't look good, especially
hist_entry__collapsewill be same ashist_entry__cmpif 'sort__need_collapse' is false. If we can make the order consistent, it'd be converted to a sigle_collapse()call without the conditional.Thanks,
Namhyung
I've got non matching entries in diff after applying just patch 2/5, and it's caused by missing he/iter swap in initial name resort in insert_hist_entry_by_name function.
I understand that function goes away in your next patch while add_hist_entry (swap ok) being the one doing initial name resort, but still.. took me some time to figure this out ;)
jirka
---
tools/perf/builtin-diff.c +1 -1
@@ -285,7 +285,7 @@ static void insert_hist_entry_by_name(struct rb_root *root,while (*p !=NULL ) { parent = *p; iter = rb_entry(parent, struct hist_entry, rb_node); -if (hist_entry__cmp (he, iter) <0 ) +if (hist_entry__cmp (iter, he) <0 ) p = &(*p)->rb_left;else p = &(*p)->rb_right;
Namhyung Kim
maintainerPATCH 3/5 perf hists: Link hist entries before inserting to an output tree
In reply to Namhyung KimFrom: Namhyung Kim <[email protected]>
For matching and/or linking hist entries, they need to be sorted by given sort keys. However current hists__match/link did this on the output trees, so that the entries in the output tree need to be resort before doing it.
This looks not so good since we have trees for collecting or collapsing entries before passing them to an output tree and they're already sorted by the given sort keys. Since we don't need to print anything at the time of matching/linking, we can use these internal trees directly instead of bothering with double resort on the output tree.
Its only user - at the time of this writing - perf diff can be easily converted to use the internal tree and can save some lines too by getting rid of unnecessary resorting codes.
--- tools/perf/builtin-diff.c | 65 ++++++++++++--------------------------------- tools/perf/util/hist.c | 49 +++++++++++++++++++++++++--------- 2 files changed, 54 insertions(+), 60 deletions(-)
tools/perf/builtin-diff.c +17 -48
@@ -275,43 +275,6 @@ static struct perf_tool tool = { .ordering_requires_timestamps = true, }; -static void insert_hist_entry_by_name (struct rb_root *root, -struct hist_entry *he) -{ -struct rb_node **p = &root->rb_node; -struct rb_node *parent =NULL ; -struct hist_entry *iter; - -while (*p !=NULL ) { - parent = *p; - iter = rb_entry(parent, struct hist_entry, rb_node); -if (hist_entry__cmp (he, iter) <0 ) - p = &(*p)->rb_left; -else - p = &(*p)->rb_right; - } - -rb_link_node (&he->rb_node, parent, p); -rb_insert_color (&he->rb_node, root); -} - -static void hists__name_resort (struct hists *self) -{ -struct rb_root tmp =RB_ROOT ; -struct rb_node *next =rb_first (&self->entries); - -while (next !=NULL ) { - struct hist_entry *n = rb_entry(next, struct hist_entry, rb_node); - - next =rb_next (&n->rb_node); - -rb_erase (&n->rb_node, &self->entries); -insert_hist_entry_by_name (&tmp, n); - } - - self->entries = tmp; -} -static struct perf_evsel *evsel_match (struct perf_evsel *evsel,struct perf_evlist *evlist) {
@@ -324,30 +287,34 @@ static struct perf_evsel *evsel_match(struct perf_evsel *evsel,return NULL ; } -static void perf_evlist__resort_hists (struct perf_evlist *evlist,bool name) +static void perf_evlist__resort_hists (struct perf_evlist *evlist) {struct perf_evsel *evsel;list_for_each_entry (evsel, &evlist->entries, node) {struct hists *hists = &evsel->hists; -hists__output_resort (hists); - -if (name) -hists__name_resort (hists); +hists__collapse_resort (hists); } }static void hists__baseline_only (struct hists *hists) { -struct rb_node *next =rb_first (&hists->entries); +struct rb_root *root; +struct rb_node *next; + +if (sort__need_collapse) + root = &hists->entries_collapsed; +else + root = hists->entries_in; + next =rb_first (root);while (next !=NULL ) { - struct hist_entry *he = rb_entry(next, struct hist_entry, rb_node); + struct hist_entry *he = rb_entry(next, struct hist_entry, rb_node_in); - next =rb_next (&he->rb_node); + next =rb_next (&he->rb_node_in);if (!hist_entry__next_pair (he)) { -rb_erase (&he->rb_node, &hists->entries); +rb_erase (&he->rb_node_in, root);hist_entry__free (he); } }
@@ -471,6 +438,8 @@ static void hists__process(struct hists *old, struct hists *new)else hists__link (new, old); +hists__output_resort (new); +if (sort_compute) {hists__precompute (new);hists__compute_resort (new);
@@ -505,8 +474,8 @@ static int __cmd_diff(void) evlist_old = older->evlist; evlist_new = newer->evlist; -perf_evlist__resort_hists (evlist_old, true); -perf_evlist__resort_hists (evlist_new, false); +perf_evlist__resort_hists (evlist_old); +perf_evlist__resort_hists (evlist_new);list_for_each_entry (evsel, &evlist_new->entries, node) {struct perf_evsel *evsel_old;
tools/perf/util/hist.c +37 -12
94 lines not on this page · raw message
Signature · 1 line
1.7.9.2
Re: [PATCH 3/5] perf hists: Link hist entries before inserting to an output tree
Quoted 7 lines · Namhyung Kim
From: Namhyung Kim <[email protected]>
For matching and/or linking hist entries, they need to be sorted by given sort keys. However current hists__match/link did this on the output trees, so that the entries in the output tree need to be resort before doing it.
Quoted 6 lines
This looks not so good since we have trees for collecting or collapsing entries before passing them to an output tree and they're already sorted by the given sort keys. Since we don't need to print anything at the time of matching/linking, we can use these internal trees directly instead of bothering with double resort on the output tree.
this patch also makes diff working over collapsed entries, which was not possible before.. nice ;)
outputs like:
[jolsa@krava perf]$ ./perf diff -s comm
# Event 'cycles:u'
#
# Baseline Delta Command
# ........ ....... ...............
#
5.24% +68.96% firefox
2.34% +5.66% X
48.51% -41.53% mocp
14.98% -11.53% skype
18.01% -15.35% plugin-containe
1.03% +1.48% xchat
5.54% -4.61% gkrellm
1.41% -0.93% xterm
+0.33% xmonad-x86_64-l
+0.23% vim
+0.07% xscreensaver
0.19% -0.14% swapper
1.00% -0.97% NetworkManager
0.28% -0.25% ssh
0.11% -0.09% sleep
0.84% -0.83% dbus-daemon
0.02% -0.01% perf
0.40% -0.40% wpa_supplicant
0.05% -0.05% gpm
0.04% -0.04% crondsmall nitpick below, otherwise
Quoted 19 lines
Its only user - at the time of this writing - perf diff can be easily converted to use the internal tree and can save some lines too by getting rid of unnecessary resorting codes.
Cc Jiri Olsa <[email protected]>Cc Stephane Eranian <[email protected]>Signed-off-by Namhyung Kim <[email protected]>--- tools/perf/builtin-diff.c | 65 ++++++++++++--------------------------------- tools/perf/util/hist.c | 49 +++++++++++++++++++++++++--------- 2 files changed, 54 insertions(+), 60 deletions(-)tools/perf/builtin-diff.c +0
-0@@ -275,43 +275,6 @@ static struct perf_tool tool = {return NULL ;A
SNIP
tools/perf/builtin-diff.c static struct perf_evsel *evsel_match(struct perf_evsel *evsel, · line 290
Quoted 4 lines
}
tools/perf/builtin-diff.c +1
-1-static void perf_evlist__resort_hists (struct perf_evlist *evlist,bool name) +static void perf_evlist__resort_hists (struct perf_evlist *evlist)
this could be called 'perf_evlist__collapse_resort' now
Quoted 13 lines
{
tools/perf/builtin-diff.c +1
-4struct perf_evsel *evsel;list_for_each_entry (evsel, &evlist->entries, node) {struct hists *hists = &evsel->hists; -hists__output_resort (hists); - -if (name) -hists__name_resort (hists); +hists__collapse_resort (hists); } }
SNIP
Namhyung Kim
maintainerRe: [PATCH 3/5] perf hists: Link hist entries before inserting to an output tree
Hi,
Quoted 48 lines · Jiri Olsa
Quoted 7 lines · Namhyung Kim
From: Namhyung Kim <[email protected]>
For matching and/or linking hist entries, they need to be sorted by given sort keys. However current hists__match/link did this on the output trees, so that the entries in the output tree need to be resort before doing it.
Quoted 6 lines
This looks not so good since we have trees for collecting or collapsing entries before passing them to an output tree and they're already sorted by the given sort keys. Since we don't need to print anything at the time of matching/linking, we can use these internal trees directly instead of bothering with double resort on the output tree.
this patch also makes diff working over collapsed entries, which was not possible before.. nice ;)
outputs like:
[jolsa@krava perf]$ ./perf diff -s comm
# Event 'cycles:u'
#
# Baseline Delta Command# ........ ....... ............... # 5.24% +68.96% firefox 2.34% +5.66% X 48.51% -41.53% mocp 14.98% -11.53% skype 18.01% -15.35% plugin-containe 1.03% +1.48% xchat 5.54% -4.61% gkrellm 1.41% -0.93% xterm +0.33% xmonad-x86_64-l +0.23% vim +0.07% xscreensaver 0.19% -0.14% swapper 1.00% -0.97% NetworkManager 0.28% -0.25% ssh 0.11% -0.09% sleep 0.84% -0.83% dbus-daemon 0.02% -0.01% perf 0.40% -0.40% wpa_supplicant 0.05% -0.05% gpm 0.04% -0.04% crond
Quoted 3 lines
small nitpick below, otherwise
Acked-by Jiri Olsa <[email protected]>
Thanks!
Quoted 24 lines
Quoted 21 lines
Its only user - at the time of this writing - perf diff can be easily converted to use the internal tree and can save some lines too by getting rid of unnecessary resorting codes.
Cc Jiri Olsa <[email protected]>Cc Stephane Eranian <[email protected]>Signed-off-by Namhyung Kim <[email protected]>--- tools/perf/builtin-diff.c | 65 ++++++++++++--------------------------------- tools/perf/util/hist.c | 49 +++++++++++++++++++++++++--------- 2 files changed, 54 insertions(+), 60 deletions(-)tools/perf/builtin-diff.c +0
-0@@ -275,43 +275,6 @@ static struct perf_tool tool = {return NULL ;A SNIP
Quoted 6 lines
tools/perf/builtin-diff.c static struct perf_evsel *evsel_match(struct perf_evsel *evsel, · line 290
Quoted 4 lines
}
tools/perf/builtin-diff.c +1
-1-static void perf_evlist__resort_hists (struct perf_evlist *evlist,bool name) +static void perf_evlist__resort_hists (struct perf_evlist *evlist)this could be called '
perf_evlist__collapse_resort' now
Will change in the next spin.
Thanks,
Namhyung
Namhyung Kim
maintainerPATCH 4/5 perf diff: Use internal rb tree for compute resort
In reply to Namhyung KimFrom: Namhyung Kim <[email protected]>
There's no reason to run hists_compute_resort() using output tree. Convert it to use internal tree so that it can remove unnecessary _output_resort.
--- tools/perf/builtin-diff.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-)
tools/perf/builtin-diff.c +16 -10
@@ -414,19 +414,25 @@ static void insert_hist_entry_by_compute(struct rb_root *root,static void hists__compute_resort (struct hists *hists) { -struct rb_root tmp =RB_ROOT ; -struct rb_node *next =rb_first (&hists->entries); +struct rb_root *root; +struct rb_node *next; + +if (sort__need_collapse) + root = &hists->entries_collapsed; +else + root = hists->entries_in; + + hists->entries =RB_ROOT ; + next =rb_first (root);while (next !=NULL ) { - struct hist_entry *he = rb_entry(next, struct hist_entry, rb_node); +struct hist_entry *he; - next =rb_next (&he->rb_node); + he = rb_entry(next, struct hist_entry, rb_node_in); + next =rb_next (&he->rb_node_in); -rb_erase (&he->rb_node, &hists->entries); -insert_hist_entry_by_compute (&tmp, he, compute); +insert_hist_entry_by_compute (&hists->entries, he, compute); } - - hists->entries = tmp; }static void hists__process (struct hists *old,struct hists *new)
@@ -438,11 +444,11 @@ static void hists__process(struct hists *old, struct hists *new)else hists__link (new, old); -hists__output_resort (new); -if (sort_compute) {hists__precompute (new);hists__compute_resort (new); + }else { +hists__output_resort (new); }hists__fprintf (new, true,0 ,0 , stdout);
Signature · 1 line
1.7.9.2
Re: [PATCH 4/5] perf diff: Use internal rb tree for compute resort
Quoted 5 lines · Namhyung Kim
From: Namhyung Kim <[email protected]>
There's no reason to run
hists_compute_resort()using output tree. Convert it to use internal tree so that it can remove unnecessary_output_resort.
I have another patch in queue ommiting dummy entries to display number in the compute column, so we don't have confusing 'sorted' outputs like:
[jolsa@krava perf]$ ./perf diff -c+delta
# Event 'cycles:u'
#
# Baseline Delta Shared Object Symbol
# ........ ....... ............. ..........................
#
17.92% -17.92% libc-2.15.so [.] _IO_link_in
+77.54% libc-2.15.so [.] __fprintf_chk
15.64% -15.64% libc-2.15.so [.] _dl_addr
0.08% +0.61% ld-2.15.so [.] _start
12.16% -12.16% ld-2.15.so [.] dl_main
15.39% -15.39% ld-2.15.so [.] _dl_check_map_versions
38.81% -17.04% [kernel.kallsyms] [k] page_fault just in case anyone actualy tries and wonders ;)
We need following change as well, because output resort does also col width recalc. Please add it if you respin, or I can send it later.
other than that:
thanks,
jirka
---
tools/perf/builtin-diff.c +3 -0
@@ -425,12 +425,15 @@ static void hists__compute_resort(struct hists *hists) hists->entries =RB_ROOT ; next =rb_first (root); +hists__reset_col_len (hists); +while (next !=NULL ) {struct hist_entry *he; he = rb_entry(next, struct hist_entry, rb_node_in); next =rb_next (&he->rb_node_in); +hists__calc_col_len (hists, he);insert_hist_entry_by_compute (&hists->entries, he, compute); } }
Namhyung Kim
maintainerRe: [PATCH 4/5] perf diff: Use internal rb tree for compute resort
Quoted 25 lines · Jiri Olsa
Quoted 5 lines · Namhyung Kim
From: Namhyung Kim <[email protected]>
There's no reason to run
hists_compute_resort()using output tree. Convert it to use internal tree so that it can remove unnecessary_output_resort.I have another patch in queue ommiting dummy entries to display number in the compute column, so we don't have confusing 'sorted' outputs like:
[jolsa@krava perf]$ ./perf diff -c+delta
# Event 'cycles:u'
#
# Baseline Delta Shared Object Symbol# ........ ....... ............. .......................... # 17.92% -17.92% libc-2.15.so [.] _IO_link_in +77.54% libc-2.15.so [.] __fprintf_chk 15.64% -15.64% libc-2.15.so [.] _dl_addr 0.08% +0.61% ld-2.15.so [.] _start 12.16% -12.16% ld-2.15.so [.] dl_main 15.39% -15.39% ld-2.15.so [.] _dl_check_map_versions 38.81% -17.04% [kernel.kallsyms] [k] page_fault
Quoted 1 line
just in case anyone actualy tries and wonders ;)
Sounds great!
Quoted 4 lines
We need following change as well, because output resort does also col width recalc. Please add it if you respin, or I can send it later.
Okay, I'll resend a new version after getting a reply on the patch 2/5 from Arnaldo. It'd be better if you send me a formal patch for this.
Quoted 4 lines
other than that:
Acked-by Jiri Olsa <[email protected]>
Thanks,
Namhyung
Quoted 22 lines
---
tools/perf/builtin-diff.c +3
-0@@ -425,12 +425,15 @@ static void hists__compute_resort(struct hists *hists) hists->entries =RB_ROOT ; next =rb_first (root); +hists__reset_col_len (hists); +while (next !=NULL ) {struct hist_entry *he; he = rb_entry(next, struct hist_entry, rb_node_in); next =rb_next (&he->rb_node_in); +hists__calc_col_len (hists, he);insert_hist_entry_by_compute (&hists->entries, he, compute); } }
Namhyung Kim
maintainerPATCH 5/5 perf test: Add a test case for hists__{match,link}
In reply to Namhyung KimFrom: Namhyung Kim <[email protected]>
As they are used from diff and event group report, add a test case to verify their behaviors.
In this test I made a fake machine and two evsel. Each evsel got 10 samples (so hist entries) - 5 are common and the rests are not. So after hists__match() both of them will have 5 entries with pair set.
And the second evsel has a collapsed entry so that the total number is 9 - I made it in order to simulate more realistic case. Thus after hists__link the first entry will have 14 entries - 5 are common (w/ pair), 5 are unmatch (w/o pair) and 4 are dummy (w/ pair). And the second entry will have 9 entries all have its pair.
--- tools/perf/Makefile | 1 + tools/perf/tests/builtin-test.c | 4 + tools/perf/tests/hists_link.c | 502 +++++++++++++++++++++++++++++++++++++++ tools/perf/tests/tests.h | 1 + tools/perf/util/machine.h | 1 + tools/perf/util/session.c | 2 +- 6 files changed, 510 insertions(+), 1 deletion(-) create mode 100644 tools/perf/tests/hists_link.c
tools/perf/Makefile +1 -0
@@ -460,6 +460,7 @@ LIB_OBJS += $(OUTPUT)tests/evsel-roundtrip-name.o LIB_OBJS += $(OUTPUT)tests/evsel-tp-sched.o LIB_OBJS += $(OUTPUT)tests/pmu.o LIB_OBJS += $(OUTPUT)tests/util.o +LIB_OBJS += $(OUTPUT)tests/hists_link.o BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o BUILTIN_OBJS += $(OUTPUT)builtin-bench.o
tools/perf/tests/builtin-test.c +4 -0
@@ -69,6 +69,10 @@ static struct test { .func = test__attr, }, { + .desc = "Test matching and linking mutliple hists", + .func = test__hists_link, + }, + { .func = NULL, }, };
tools/perf/tests/hists_link.c new file +502 -0
502 lines not on this page · raw message
tools/perf/tests/tests.h +1 -0
@@ -15,6 +15,7 @@ int test__pmu(void);int test__attr (void );int test__dso_data (void );int test__parse_events (void ); +int test__hists_link (void );/* Util */ int trace_event__id (const char *evname);
tools/perf/util/machine.h +1 -0
@@ -89,6 +89,7 @@ static inline bool machine__is_host(struct machine *machine)struct thread *machine__findnew_thread (struct machine *machine,pid_t pid);void machine__remove_thread (struct machine *machine,struct thread *th); +void machine__delete_threads (struct machine *machine);size_t machine__fprintf (struct machine *machine,FILE *fp);
tools/perf/util/session.c +1 -1
@@ -177,7 +177,7 @@ static void perf_session__delete_dead_threads(struct perf_session *session)machine__delete_dead_threads (&session->host_machine); } -static void machine__delete_threads (struct machine *self) +void machine__delete_threads (struct machine *self) {struct rb_node *nd =rb_first (&self->threads);
Signature · 1 line
1.7.9.2