aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/hist.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/util/hist.c')
-rw-r--r--tools/perf/util/hist.c66
1 files changed, 42 insertions, 24 deletions
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index 236bc9d98ff2..277947a669b2 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -135,31 +135,47 @@ static void hist_entry__add_cpumode_period(struct hist_entry *he,
135{ 135{
136 switch (cpumode) { 136 switch (cpumode) {
137 case PERF_RECORD_MISC_KERNEL: 137 case PERF_RECORD_MISC_KERNEL:
138 he->period_sys += period; 138 he->stat.period_sys += period;
139 break; 139 break;
140 case PERF_RECORD_MISC_USER: 140 case PERF_RECORD_MISC_USER:
141 he->period_us += period; 141 he->stat.period_us += period;
142 break; 142 break;
143 case PERF_RECORD_MISC_GUEST_KERNEL: 143 case PERF_RECORD_MISC_GUEST_KERNEL:
144 he->period_guest_sys += period; 144 he->stat.period_guest_sys += period;
145 break; 145 break;
146 case PERF_RECORD_MISC_GUEST_USER: 146 case PERF_RECORD_MISC_GUEST_USER:
147 he->period_guest_us += period; 147 he->stat.period_guest_us += period;
148 break; 148 break;
149 default: 149 default:
150 break; 150 break;
151 } 151 }
152} 152}
153 153
154static void he_stat__add_period(struct he_stat *he_stat, u64 period)
155{
156 he_stat->period += period;
157 he_stat->nr_events += 1;
158}
159
160static void he_stat__add_stat(struct he_stat *dest, struct he_stat *src)
161{
162 dest->period += src->period;
163 dest->period_sys += src->period_sys;
164 dest->period_us += src->period_us;
165 dest->period_guest_sys += src->period_guest_sys;
166 dest->period_guest_us += src->period_guest_us;
167 dest->nr_events += src->nr_events;
168}
169
154static void hist_entry__decay(struct hist_entry *he) 170static void hist_entry__decay(struct hist_entry *he)
155{ 171{
156 he->period = (he->period * 7) / 8; 172 he->stat.period = (he->stat.period * 7) / 8;
157 he->nr_events = (he->nr_events * 7) / 8; 173 he->stat.nr_events = (he->stat.nr_events * 7) / 8;
158} 174}
159 175
160static bool hists__decay_entry(struct hists *hists, struct hist_entry *he) 176static bool hists__decay_entry(struct hists *hists, struct hist_entry *he)
161{ 177{
162 u64 prev_period = he->period; 178 u64 prev_period = he->stat.period;
163 179
164 if (prev_period == 0) 180 if (prev_period == 0)
165 return true; 181 return true;
@@ -167,9 +183,9 @@ static bool hists__decay_entry(struct hists *hists, struct hist_entry *he)
167 hist_entry__decay(he); 183 hist_entry__decay(he);
168 184
169 if (!he->filtered) 185 if (!he->filtered)
170 hists->stats.total_period -= prev_period - he->period; 186 hists->stats.total_period -= prev_period - he->stat.period;
171 187
172 return he->period == 0; 188 return he->stat.period == 0;
173} 189}
174 190
175static void __hists__decay_entries(struct hists *hists, bool zap_user, 191static void __hists__decay_entries(struct hists *hists, bool zap_user,
@@ -223,7 +239,7 @@ static struct hist_entry *hist_entry__new(struct hist_entry *template)
223 239
224 if (he != NULL) { 240 if (he != NULL) {
225 *he = *template; 241 *he = *template;
226 he->nr_events = 1; 242
227 if (he->ms.map) 243 if (he->ms.map)
228 he->ms.map->referenced = true; 244 he->ms.map->referenced = true;
229 if (symbol_conf.use_callchain) 245 if (symbol_conf.use_callchain)
@@ -238,7 +254,7 @@ static void hists__inc_nr_entries(struct hists *hists, struct hist_entry *h)
238 if (!h->filtered) { 254 if (!h->filtered) {
239 hists__calc_col_len(hists, h); 255 hists__calc_col_len(hists, h);
240 ++hists->nr_entries; 256 ++hists->nr_entries;
241 hists->stats.total_period += h->period; 257 hists->stats.total_period += h->stat.period;
242 } 258 }
243} 259}
244 260
@@ -270,8 +286,7 @@ static struct hist_entry *add_hist_entry(struct hists *hists,
270 cmp = hist_entry__cmp(entry, he); 286 cmp = hist_entry__cmp(entry, he);
271 287
272 if (!cmp) { 288 if (!cmp) {
273 he->period += period; 289 he_stat__add_period(&he->stat, period);
274 ++he->nr_events;
275 290
276 /* If the map of an existing hist_entry has 291 /* If the map of an existing hist_entry has
277 * become out-of-date due to an exec() or 292 * become out-of-date due to an exec() or
@@ -321,10 +336,14 @@ struct hist_entry *__hists__add_branch_entry(struct hists *self,
321 .cpu = al->cpu, 336 .cpu = al->cpu,
322 .ip = bi->to.addr, 337 .ip = bi->to.addr,
323 .level = al->level, 338 .level = al->level,
324 .period = period, 339 .stat = {
340 .period = period,
341 .nr_events = 1,
342 },
325 .parent = sym_parent, 343 .parent = sym_parent,
326 .filtered = symbol__parent_filter(sym_parent), 344 .filtered = symbol__parent_filter(sym_parent),
327 .branch_info = bi, 345 .branch_info = bi,
346 .hists = self,
328 }; 347 };
329 348
330 return add_hist_entry(self, &entry, al, period); 349 return add_hist_entry(self, &entry, al, period);
@@ -343,9 +362,13 @@ struct hist_entry *__hists__add_entry(struct hists *self,
343 .cpu = al->cpu, 362 .cpu = al->cpu,
344 .ip = al->addr, 363 .ip = al->addr,
345 .level = al->level, 364 .level = al->level,
346 .period = period, 365 .stat = {
366 .period = period,
367 .nr_events = 1,
368 },
347 .parent = sym_parent, 369 .parent = sym_parent,
348 .filtered = symbol__parent_filter(sym_parent), 370 .filtered = symbol__parent_filter(sym_parent),
371 .hists = self,
349 }; 372 };
350 373
351 return add_hist_entry(self, &entry, al, period); 374 return add_hist_entry(self, &entry, al, period);
@@ -410,12 +433,7 @@ static bool hists__collapse_insert_entry(struct hists *hists __maybe_unused,
410 cmp = hist_entry__collapse(iter, he); 433 cmp = hist_entry__collapse(iter, he);
411 434
412 if (!cmp) { 435 if (!cmp) {
413 iter->period += he->period; 436 he_stat__add_stat(&iter->stat, &he->stat);
414 iter->period_sys += he->period_sys;
415 iter->period_us += he->period_us;
416 iter->period_guest_sys += he->period_guest_sys;
417 iter->period_guest_us += he->period_guest_us;
418 iter->nr_events += he->nr_events;
419 437
420 if (symbol_conf.use_callchain) { 438 if (symbol_conf.use_callchain) {
421 callchain_cursor_reset(&callchain_cursor); 439 callchain_cursor_reset(&callchain_cursor);
@@ -518,7 +536,7 @@ static void __hists__insert_output_entry(struct rb_root *entries,
518 parent = *p; 536 parent = *p;
519 iter = rb_entry(parent, struct hist_entry, rb_node); 537 iter = rb_entry(parent, struct hist_entry, rb_node);
520 538
521 if (he->period > iter->period) 539 if (he->stat.period > iter->stat.period)
522 p = &(*p)->rb_left; 540 p = &(*p)->rb_left;
523 else 541 else
524 p = &(*p)->rb_right; 542 p = &(*p)->rb_right;
@@ -579,8 +597,8 @@ static void hists__remove_entry_filter(struct hists *hists, struct hist_entry *h
579 if (h->ms.unfolded) 597 if (h->ms.unfolded)
580 hists->nr_entries += h->nr_rows; 598 hists->nr_entries += h->nr_rows;
581 h->row_offset = 0; 599 h->row_offset = 0;
582 hists->stats.total_period += h->period; 600 hists->stats.total_period += h->stat.period;
583 hists->stats.nr_events[PERF_RECORD_SAMPLE] += h->nr_events; 601 hists->stats.nr_events[PERF_RECORD_SAMPLE] += h->stat.nr_events;
584 602
585 hists__calc_col_len(hists, h); 603 hists__calc_col_len(hists, h);
586} 604}