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