aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/builtin-diff.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/builtin-diff.c')
-rw-r--r--tools/perf/builtin-diff.c76
1 files changed, 34 insertions, 42 deletions
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index 1ea15d8aeed1..a6e2fdc7a04e 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -19,23 +19,15 @@
19static char const *input_old = "perf.data.old", 19static char const *input_old = "perf.data.old",
20 *input_new = "perf.data"; 20 *input_new = "perf.data";
21static char diff__default_sort_order[] = "dso,symbol"; 21static char diff__default_sort_order[] = "dso,symbol";
22static int force; 22static bool force;
23static bool show_displacement; 23static bool show_displacement;
24 24
25static int perf_session__add_hist_entry(struct perf_session *self, 25static int hists__add_entry(struct hists *self,
26 struct addr_location *al, u64 count) 26 struct addr_location *al, u64 period)
27{ 27{
28 bool hit; 28 if (__hists__add_entry(self, al, NULL, period) != NULL)
29 struct hist_entry *he = __perf_session__add_hist_entry(&self->hists, 29 return 0;
30 al, NULL, 30 return -ENOMEM;
31 count, &hit);
32 if (he == NULL)
33 return -ENOMEM;
34
35 if (hit)
36 he->count += count;
37
38 return 0;
39} 31}
40 32
41static int diff__process_sample_event(event_t *event, struct perf_session *session) 33static int diff__process_sample_event(event_t *event, struct perf_session *session)
@@ -57,12 +49,12 @@ static int diff__process_sample_event(event_t *event, struct perf_session *sessi
57 49
58 event__parse_sample(event, session->sample_type, &data); 50 event__parse_sample(event, session->sample_type, &data);
59 51
60 if (perf_session__add_hist_entry(session, &al, data.period)) { 52 if (hists__add_entry(&session->hists, &al, data.period)) {
61 pr_warning("problem incrementing symbol count, skipping event\n"); 53 pr_warning("problem incrementing symbol period, skipping event\n");
62 return -1; 54 return -1;
63 } 55 }
64 56
65 session->events_stats.total += data.period; 57 session->hists.stats.total_period += data.period;
66 return 0; 58 return 0;
67} 59}
68 60
@@ -95,35 +87,34 @@ static void perf_session__insert_hist_entry_by_name(struct rb_root *root,
95 rb_insert_color(&he->rb_node, root); 87 rb_insert_color(&he->rb_node, root);
96} 88}
97 89
98static void perf_session__resort_hist_entries(struct perf_session *self) 90static void hists__resort_entries(struct hists *self)
99{ 91{
100 unsigned long position = 1; 92 unsigned long position = 1;
101 struct rb_root tmp = RB_ROOT; 93 struct rb_root tmp = RB_ROOT;
102 struct rb_node *next = rb_first(&self->hists); 94 struct rb_node *next = rb_first(&self->entries);
103 95
104 while (next != NULL) { 96 while (next != NULL) {
105 struct hist_entry *n = rb_entry(next, struct hist_entry, rb_node); 97 struct hist_entry *n = rb_entry(next, struct hist_entry, rb_node);
106 98
107 next = rb_next(&n->rb_node); 99 next = rb_next(&n->rb_node);
108 rb_erase(&n->rb_node, &self->hists); 100 rb_erase(&n->rb_node, &self->entries);
109 n->position = position++; 101 n->position = position++;
110 perf_session__insert_hist_entry_by_name(&tmp, n); 102 perf_session__insert_hist_entry_by_name(&tmp, n);
111 } 103 }
112 104
113 self->hists = tmp; 105 self->entries = tmp;
114} 106}
115 107
116static void perf_session__set_hist_entries_positions(struct perf_session *self) 108static void hists__set_positions(struct hists *self)
117{ 109{
118 perf_session__output_resort(&self->hists, self->events_stats.total); 110 hists__output_resort(self);
119 perf_session__resort_hist_entries(self); 111 hists__resort_entries(self);
120} 112}
121 113
122static struct hist_entry * 114static struct hist_entry *hists__find_entry(struct hists *self,
123perf_session__find_hist_entry(struct perf_session *self, 115 struct hist_entry *he)
124 struct hist_entry *he)
125{ 116{
126 struct rb_node *n = self->hists.rb_node; 117 struct rb_node *n = self->entries.rb_node;
127 118
128 while (n) { 119 while (n) {
129 struct hist_entry *iter = rb_entry(n, struct hist_entry, rb_node); 120 struct hist_entry *iter = rb_entry(n, struct hist_entry, rb_node);
@@ -140,14 +131,13 @@ perf_session__find_hist_entry(struct perf_session *self,
140 return NULL; 131 return NULL;
141} 132}
142 133
143static void perf_session__match_hists(struct perf_session *old_session, 134static void hists__match(struct hists *older, struct hists *newer)
144 struct perf_session *new_session)
145{ 135{
146 struct rb_node *nd; 136 struct rb_node *nd;
147 137
148 for (nd = rb_first(&new_session->hists); nd; nd = rb_next(nd)) { 138 for (nd = rb_first(&newer->entries); nd; nd = rb_next(nd)) {
149 struct hist_entry *pos = rb_entry(nd, struct hist_entry, rb_node); 139 struct hist_entry *pos = rb_entry(nd, struct hist_entry, rb_node);
150 pos->pair = perf_session__find_hist_entry(old_session, pos); 140 pos->pair = hists__find_entry(older, pos);
151 } 141 }
152} 142}
153 143
@@ -156,8 +146,8 @@ static int __cmd_diff(void)
156 int ret, i; 146 int ret, i;
157 struct perf_session *session[2]; 147 struct perf_session *session[2];
158 148
159 session[0] = perf_session__new(input_old, O_RDONLY, force); 149 session[0] = perf_session__new(input_old, O_RDONLY, force, false);
160 session[1] = perf_session__new(input_new, O_RDONLY, force); 150 session[1] = perf_session__new(input_new, O_RDONLY, force, false);
161 if (session[0] == NULL || session[1] == NULL) 151 if (session[0] == NULL || session[1] == NULL)
162 return -ENOMEM; 152 return -ENOMEM;
163 153
@@ -167,15 +157,13 @@ static int __cmd_diff(void)
167 goto out_delete; 157 goto out_delete;
168 } 158 }
169 159
170 perf_session__output_resort(&session[1]->hists, 160 hists__output_resort(&session[1]->hists);
171 session[1]->events_stats.total);
172 if (show_displacement) 161 if (show_displacement)
173 perf_session__set_hist_entries_positions(session[0]); 162 hists__set_positions(&session[0]->hists);
174 163
175 perf_session__match_hists(session[0], session[1]); 164 hists__match(&session[0]->hists, &session[1]->hists);
176 perf_session__fprintf_hists(&session[1]->hists, session[0], 165 hists__fprintf(&session[1]->hists, &session[0]->hists,
177 show_displacement, stdout, 166 show_displacement, stdout);
178 session[1]->events_stats.total);
179out_delete: 167out_delete:
180 for (i = 0; i < 2; ++i) 168 for (i = 0; i < 2; ++i)
181 perf_session__delete(session[i]); 169 perf_session__delete(session[i]);
@@ -188,7 +176,7 @@ static const char * const diff_usage[] = {
188}; 176};
189 177
190static const struct option options[] = { 178static const struct option options[] = {
191 OPT_BOOLEAN('v', "verbose", &verbose, 179 OPT_INCR('v', "verbose", &verbose,
192 "be more verbose (show symbol address, etc)"), 180 "be more verbose (show symbol address, etc)"),
193 OPT_BOOLEAN('m', "displacement", &show_displacement, 181 OPT_BOOLEAN('m', "displacement", &show_displacement,
194 "Show position displacement relative to baseline"), 182 "Show position displacement relative to baseline"),
@@ -225,6 +213,10 @@ int cmd_diff(int argc, const char **argv, const char *prefix __used)
225 input_new = argv[1]; 213 input_new = argv[1];
226 } else 214 } else
227 input_new = argv[0]; 215 input_new = argv[0];
216 } else if (symbol_conf.default_guest_vmlinux_name ||
217 symbol_conf.default_guest_kallsyms) {
218 input_old = "perf.data.host";
219 input_new = "perf.data.guest";
228 } 220 }
229 221
230 symbol_conf.exclude_other = false; 222 symbol_conf.exclude_other = false;