[PATCH 02/14] perf diff: Refactor diff displacement possition info
Moving the position calculation into the diff command, so the position is prepared inside struct hist_entry data and there's no need to compute in the output display path. Removing 'displacement' from struct perf_hpp as it is no longer needed. Cc: Arnaldo Carvalho de Melo Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Paul Mackerras Cc: Corey Ashford Cc: Frederic Weisbecker Cc: Namhyung Kim Signed-off-by: Jiri Olsa --- tools/perf/builtin-diff.c | 49 + tools/perf/builtin-report.c | 2 +- tools/perf/builtin-top.c| 2 +- tools/perf/ui/hist.c| 8 +--- tools/perf/ui/stdio/hist.c | 17 +++- tools/perf/util/hist.h | 4 +--- tools/perf/util/sort.h | 2 +- 7 files changed, 44 insertions(+), 40 deletions(-) diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c index 761f419..5cb577a 100644 --- a/tools/perf/builtin-diff.c +++ b/tools/perf/builtin-diff.c @@ -70,8 +70,8 @@ static struct perf_tool tool = { .ordering_requires_timestamps = true, }; -static void perf_session__insert_hist_entry_by_name(struct rb_root *root, - struct hist_entry *he) +static void insert_hist_entry_by_name(struct rb_root *root, + struct hist_entry *he) { struct rb_node **p = >rb_node; struct rb_node *parent = NULL; @@ -90,7 +90,7 @@ static void perf_session__insert_hist_entry_by_name(struct rb_root *root, rb_insert_color(>rb_node, root); } -static void hists__resort_entries(struct hists *self) +static void hists__name_resort(struct hists *self, bool sort) { unsigned long position = 1; struct rb_root tmp = RB_ROOT; @@ -100,12 +100,16 @@ static void hists__resort_entries(struct hists *self) struct hist_entry *n = rb_entry(next, struct hist_entry, rb_node); next = rb_next(>rb_node); - rb_erase(>rb_node, >entries); n->position = position++; - perf_session__insert_hist_entry_by_name(, n); + + if (sort) { + rb_erase(>rb_node, >entries); + insert_hist_entry_by_name(, n); + } } - self->entries = tmp; + if (sort) + self->entries = tmp; } static struct hist_entry *hists__find_entry(struct hists *self, @@ -121,7 +125,7 @@ static struct hist_entry *hists__find_entry(struct hists *self, n = n->rb_left; else if (cmp > 0) n = n->rb_right; - else + else return iter; } @@ -150,6 +154,24 @@ static struct perf_evsel *evsel_match(struct perf_evsel *evsel, return NULL; } +static void perf_evlist__resort_hists(struct perf_evlist *evlist, bool name) +{ + struct perf_evsel *evsel; + + list_for_each_entry(evsel, >entries, node) { + struct hists *hists = >hists; + + 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); + } +} + static int __cmd_diff(void) { int ret, i; @@ -176,15 +198,8 @@ static int __cmd_diff(void) evlist_old = older->evlist; evlist_new = newer->evlist; - list_for_each_entry(evsel, _new->entries, node) - hists__output_resort(>hists); - - list_for_each_entry(evsel, _old->entries, node) { - hists__output_resort(>hists); - - if (show_displacement) - hists__resort_entries(>hists); - } + perf_evlist__resort_hists(evlist_old, true); + perf_evlist__resort_hists(evlist_new, false); list_for_each_entry(evsel, _new->entries, node) { struct perf_evsel *evsel_old; @@ -200,7 +215,7 @@ static int __cmd_diff(void) hists__match(_old->hists, >hists); hists__fprintf(>hists, _old->hists, - show_displacement, true, 0, 0, stdout); + true, 0, 0, stdout); } out_delete: diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 1da243d..6748cac 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -320,7 +320,7 @@ static int perf_evlist__tty_browse_hists(struct perf_evlist *evlist, const char *evname = perf_evsel__name(pos); hists__fprintf_nr_sample_events(hists, evname, stdout); - hists__fprintf(hists, NULL, false, true, 0, 0, stdout); + hists__fprintf(hists, NULL, true, 0, 0, stdout); fprintf(stdout, "\n\n"); } diff --git a/tools/perf/builtin-top.c
[PATCH 02/14] perf diff: Refactor diff displacement possition info
Moving the position calculation into the diff command, so the position is prepared inside struct hist_entry data and there's no need to compute in the output display path. Removing 'displacement' from struct perf_hpp as it is no longer needed. Cc: Arnaldo Carvalho de Melo a...@ghostprotocols.net Cc: Peter Zijlstra a.p.zijls...@chello.nl Cc: Ingo Molnar mi...@elte.hu Cc: Paul Mackerras pau...@samba.org Cc: Corey Ashford cjash...@linux.vnet.ibm.com Cc: Frederic Weisbecker fweis...@gmail.com Cc: Namhyung Kim namhy...@kernel.org Signed-off-by: Jiri Olsa jo...@redhat.com --- tools/perf/builtin-diff.c | 49 + tools/perf/builtin-report.c | 2 +- tools/perf/builtin-top.c| 2 +- tools/perf/ui/hist.c| 8 +--- tools/perf/ui/stdio/hist.c | 17 +++- tools/perf/util/hist.h | 4 +--- tools/perf/util/sort.h | 2 +- 7 files changed, 44 insertions(+), 40 deletions(-) diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c index 761f419..5cb577a 100644 --- a/tools/perf/builtin-diff.c +++ b/tools/perf/builtin-diff.c @@ -70,8 +70,8 @@ static struct perf_tool tool = { .ordering_requires_timestamps = true, }; -static void perf_session__insert_hist_entry_by_name(struct rb_root *root, - struct hist_entry *he) +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; @@ -90,7 +90,7 @@ static void perf_session__insert_hist_entry_by_name(struct rb_root *root, rb_insert_color(he-rb_node, root); } -static void hists__resort_entries(struct hists *self) +static void hists__name_resort(struct hists *self, bool sort) { unsigned long position = 1; struct rb_root tmp = RB_ROOT; @@ -100,12 +100,16 @@ static void hists__resort_entries(struct hists *self) 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); n-position = position++; - perf_session__insert_hist_entry_by_name(tmp, n); + + if (sort) { + rb_erase(n-rb_node, self-entries); + insert_hist_entry_by_name(tmp, n); + } } - self-entries = tmp; + if (sort) + self-entries = tmp; } static struct hist_entry *hists__find_entry(struct hists *self, @@ -121,7 +125,7 @@ static struct hist_entry *hists__find_entry(struct hists *self, n = n-rb_left; else if (cmp 0) n = n-rb_right; - else + else return iter; } @@ -150,6 +154,24 @@ static struct perf_evsel *evsel_match(struct perf_evsel *evsel, return NULL; } +static void perf_evlist__resort_hists(struct perf_evlist *evlist, bool name) +{ + struct perf_evsel *evsel; + + list_for_each_entry(evsel, evlist-entries, node) { + struct hists *hists = evsel-hists; + + 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); + } +} + static int __cmd_diff(void) { int ret, i; @@ -176,15 +198,8 @@ static int __cmd_diff(void) evlist_old = older-evlist; evlist_new = newer-evlist; - list_for_each_entry(evsel, evlist_new-entries, node) - hists__output_resort(evsel-hists); - - list_for_each_entry(evsel, evlist_old-entries, node) { - hists__output_resort(evsel-hists); - - if (show_displacement) - hists__resort_entries(evsel-hists); - } + perf_evlist__resort_hists(evlist_old, true); + perf_evlist__resort_hists(evlist_new, false); list_for_each_entry(evsel, evlist_new-entries, node) { struct perf_evsel *evsel_old; @@ -200,7 +215,7 @@ static int __cmd_diff(void) hists__match(evsel_old-hists, evsel-hists); hists__fprintf(evsel-hists, evsel_old-hists, - show_displacement, true, 0, 0, stdout); + true, 0, 0, stdout); } out_delete: diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 1da243d..6748cac 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -320,7 +320,7 @@ static int perf_evlist__tty_browse_hists(struct perf_evlist *evlist, const char *evname = perf_evsel__name(pos); hists__fprintf_nr_sample_events(hists, evname, stdout); -