diff options
Diffstat (limited to 'tools/perf/builtin-diff.c')
-rw-r--r-- | tools/perf/builtin-diff.c | 49 |
1 files changed, 32 insertions, 17 deletions
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c index 761f4197a9e2..5cb577a3c5b2 100644 --- a/tools/perf/builtin-diff.c +++ b/tools/perf/builtin-diff.c | |||
@@ -70,8 +70,8 @@ static struct perf_tool tool = { | |||
70 | .ordering_requires_timestamps = true, | 70 | .ordering_requires_timestamps = true, |
71 | }; | 71 | }; |
72 | 72 | ||
73 | static void perf_session__insert_hist_entry_by_name(struct rb_root *root, | 73 | static void insert_hist_entry_by_name(struct rb_root *root, |
74 | struct hist_entry *he) | 74 | struct hist_entry *he) |
75 | { | 75 | { |
76 | struct rb_node **p = &root->rb_node; | 76 | struct rb_node **p = &root->rb_node; |
77 | struct rb_node *parent = NULL; | 77 | struct rb_node *parent = NULL; |
@@ -90,7 +90,7 @@ static void perf_session__insert_hist_entry_by_name(struct rb_root *root, | |||
90 | rb_insert_color(&he->rb_node, root); | 90 | rb_insert_color(&he->rb_node, root); |
91 | } | 91 | } |
92 | 92 | ||
93 | static void hists__resort_entries(struct hists *self) | 93 | static void hists__name_resort(struct hists *self, bool sort) |
94 | { | 94 | { |
95 | unsigned long position = 1; | 95 | unsigned long position = 1; |
96 | struct rb_root tmp = RB_ROOT; | 96 | struct rb_root tmp = RB_ROOT; |
@@ -100,12 +100,16 @@ static void hists__resort_entries(struct hists *self) | |||
100 | struct hist_entry *n = rb_entry(next, struct hist_entry, rb_node); | 100 | struct hist_entry *n = rb_entry(next, struct hist_entry, rb_node); |
101 | 101 | ||
102 | next = rb_next(&n->rb_node); | 102 | next = rb_next(&n->rb_node); |
103 | rb_erase(&n->rb_node, &self->entries); | ||
104 | n->position = position++; | 103 | n->position = position++; |
105 | perf_session__insert_hist_entry_by_name(&tmp, n); | 104 | |
105 | if (sort) { | ||
106 | rb_erase(&n->rb_node, &self->entries); | ||
107 | insert_hist_entry_by_name(&tmp, n); | ||
108 | } | ||
106 | } | 109 | } |
107 | 110 | ||
108 | self->entries = tmp; | 111 | if (sort) |
112 | self->entries = tmp; | ||
109 | } | 113 | } |
110 | 114 | ||
111 | static struct hist_entry *hists__find_entry(struct hists *self, | 115 | static struct hist_entry *hists__find_entry(struct hists *self, |
@@ -121,7 +125,7 @@ static struct hist_entry *hists__find_entry(struct hists *self, | |||
121 | n = n->rb_left; | 125 | n = n->rb_left; |
122 | else if (cmp > 0) | 126 | else if (cmp > 0) |
123 | n = n->rb_right; | 127 | n = n->rb_right; |
124 | else | 128 | else |
125 | return iter; | 129 | return iter; |
126 | } | 130 | } |
127 | 131 | ||
@@ -150,6 +154,24 @@ static struct perf_evsel *evsel_match(struct perf_evsel *evsel, | |||
150 | return NULL; | 154 | return NULL; |
151 | } | 155 | } |
152 | 156 | ||
157 | static void perf_evlist__resort_hists(struct perf_evlist *evlist, bool name) | ||
158 | { | ||
159 | struct perf_evsel *evsel; | ||
160 | |||
161 | list_for_each_entry(evsel, &evlist->entries, node) { | ||
162 | struct hists *hists = &evsel->hists; | ||
163 | |||
164 | hists__output_resort(hists); | ||
165 | |||
166 | /* | ||
167 | * The hists__name_resort only sets possition | ||
168 | * if name is false. | ||
169 | */ | ||
170 | if (name || ((!name) && show_displacement)) | ||
171 | hists__name_resort(hists, name); | ||
172 | } | ||
173 | } | ||
174 | |||
153 | static int __cmd_diff(void) | 175 | static int __cmd_diff(void) |
154 | { | 176 | { |
155 | int ret, i; | 177 | int ret, i; |
@@ -176,15 +198,8 @@ static int __cmd_diff(void) | |||
176 | evlist_old = older->evlist; | 198 | evlist_old = older->evlist; |
177 | evlist_new = newer->evlist; | 199 | evlist_new = newer->evlist; |
178 | 200 | ||
179 | list_for_each_entry(evsel, &evlist_new->entries, node) | 201 | perf_evlist__resort_hists(evlist_old, true); |
180 | hists__output_resort(&evsel->hists); | 202 | perf_evlist__resort_hists(evlist_new, false); |
181 | |||
182 | list_for_each_entry(evsel, &evlist_old->entries, node) { | ||
183 | hists__output_resort(&evsel->hists); | ||
184 | |||
185 | if (show_displacement) | ||
186 | hists__resort_entries(&evsel->hists); | ||
187 | } | ||
188 | 203 | ||
189 | list_for_each_entry(evsel, &evlist_new->entries, node) { | 204 | list_for_each_entry(evsel, &evlist_new->entries, node) { |
190 | struct perf_evsel *evsel_old; | 205 | struct perf_evsel *evsel_old; |
@@ -200,7 +215,7 @@ static int __cmd_diff(void) | |||
200 | 215 | ||
201 | hists__match(&evsel_old->hists, &evsel->hists); | 216 | hists__match(&evsel_old->hists, &evsel->hists); |
202 | hists__fprintf(&evsel->hists, &evsel_old->hists, | 217 | hists__fprintf(&evsel->hists, &evsel_old->hists, |
203 | show_displacement, true, 0, 0, stdout); | 218 | true, 0, 0, stdout); |
204 | } | 219 | } |
205 | 220 | ||
206 | out_delete: | 221 | out_delete: |