Frederic Weisbecker | 8a0ecfb | 2010-05-13 19:47:16 +0200 | [diff] [blame] | 1 | #include "util.h" |
Frederic Weisbecker | 598357e | 2010-05-21 12:48:39 +0200 | [diff] [blame] | 2 | #include "build-id.h" |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 3 | #include "hist.h" |
Arnaldo Carvalho de Melo | 4e4f06e | 2009-12-14 13:10:39 -0200 | [diff] [blame] | 4 | #include "session.h" |
| 5 | #include "sort.h" |
Namhyung Kim | 29d720e | 2013-01-22 18:09:33 +0900 | [diff] [blame] | 6 | #include "evsel.h" |
Arnaldo Carvalho de Melo | 9b33827 | 2009-12-16 14:31:49 -0200 | [diff] [blame] | 7 | #include <math.h> |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 8 | |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 9 | static bool hists__filter_entry_by_dso(struct hists *hists, |
| 10 | struct hist_entry *he); |
| 11 | static bool hists__filter_entry_by_thread(struct hists *hists, |
| 12 | struct hist_entry *he); |
Namhyung Kim | e94d53e | 2012-03-16 17:50:51 +0900 | [diff] [blame] | 13 | static bool hists__filter_entry_by_symbol(struct hists *hists, |
| 14 | struct hist_entry *he); |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 15 | |
Arnaldo Carvalho de Melo | 7a007ca | 2010-07-21 09:19:41 -0300 | [diff] [blame] | 16 | enum hist_filter { |
| 17 | HIST_FILTER__DSO, |
| 18 | HIST_FILTER__THREAD, |
| 19 | HIST_FILTER__PARENT, |
Namhyung Kim | e94d53e | 2012-03-16 17:50:51 +0900 | [diff] [blame] | 20 | HIST_FILTER__SYMBOL, |
Arnaldo Carvalho de Melo | 7a007ca | 2010-07-21 09:19:41 -0300 | [diff] [blame] | 21 | }; |
| 22 | |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 23 | struct callchain_param callchain_param = { |
| 24 | .mode = CHAIN_GRAPH_REL, |
Sam Liao | d797fdc | 2011-06-07 23:49:46 +0800 | [diff] [blame] | 25 | .min_percent = 0.5, |
Andi Kleen | 99571ab | 2013-07-18 15:33:57 -0700 | [diff] [blame] | 26 | .order = ORDER_CALLEE, |
| 27 | .key = CCKEY_FUNCTION |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 28 | }; |
| 29 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 30 | u16 hists__col_len(struct hists *hists, enum hist_column col) |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 31 | { |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 32 | return hists->col_len[col]; |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 33 | } |
| 34 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 35 | void hists__set_col_len(struct hists *hists, enum hist_column col, u16 len) |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 36 | { |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 37 | hists->col_len[col] = len; |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 38 | } |
| 39 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 40 | bool hists__new_col_len(struct hists *hists, enum hist_column col, u16 len) |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 41 | { |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 42 | if (len > hists__col_len(hists, col)) { |
| 43 | hists__set_col_len(hists, col, len); |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 44 | return true; |
| 45 | } |
| 46 | return false; |
| 47 | } |
| 48 | |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 49 | void hists__reset_col_len(struct hists *hists) |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 50 | { |
| 51 | enum hist_column col; |
| 52 | |
| 53 | for (col = 0; col < HISTC_NR_COLS; ++col) |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 54 | hists__set_col_len(hists, col, 0); |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 55 | } |
| 56 | |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 57 | static void hists__set_unres_dso_col_len(struct hists *hists, int dso) |
| 58 | { |
| 59 | const unsigned int unresolved_col_width = BITS_PER_LONG / 4; |
| 60 | |
| 61 | if (hists__col_len(hists, dso) < unresolved_col_width && |
| 62 | !symbol_conf.col_width_list_str && !symbol_conf.field_sep && |
| 63 | !symbol_conf.dso_list) |
| 64 | hists__set_col_len(hists, dso, unresolved_col_width); |
| 65 | } |
| 66 | |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 67 | void hists__calc_col_len(struct hists *hists, struct hist_entry *h) |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 68 | { |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 69 | const unsigned int unresolved_col_width = BITS_PER_LONG / 4; |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 70 | int symlen; |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 71 | u16 len; |
| 72 | |
Namhyung Kim | ded19d5 | 2013-04-01 20:35:19 +0900 | [diff] [blame] | 73 | /* |
| 74 | * +4 accounts for '[x] ' priv level info |
| 75 | * +2 accounts for 0x prefix on raw addresses |
| 76 | * +3 accounts for ' y ' symtab origin info |
| 77 | */ |
| 78 | if (h->ms.sym) { |
| 79 | symlen = h->ms.sym->namelen + 4; |
| 80 | if (verbose) |
| 81 | symlen += BITS_PER_LONG / 4 + 2 + 3; |
| 82 | hists__new_col_len(hists, HISTC_SYMBOL, symlen); |
| 83 | } else { |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 84 | symlen = unresolved_col_width + 4 + 2; |
| 85 | hists__new_col_len(hists, HISTC_SYMBOL, symlen); |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 86 | hists__set_unres_dso_col_len(hists, HISTC_DSO); |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 87 | } |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 88 | |
| 89 | len = thread__comm_len(h->thread); |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 90 | if (hists__new_col_len(hists, HISTC_COMM, len)) |
| 91 | hists__set_col_len(hists, HISTC_THREAD, len + 6); |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 92 | |
| 93 | if (h->ms.map) { |
| 94 | len = dso__name_len(h->ms.map->dso); |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 95 | hists__new_col_len(hists, HISTC_DSO, len); |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 96 | } |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 97 | |
Namhyung Kim | cb99374 | 2012-12-27 18:11:42 +0900 | [diff] [blame] | 98 | if (h->parent) |
| 99 | hists__new_col_len(hists, HISTC_PARENT, h->parent->namelen); |
| 100 | |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 101 | if (h->branch_info) { |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 102 | if (h->branch_info->from.sym) { |
| 103 | symlen = (int)h->branch_info->from.sym->namelen + 4; |
Namhyung Kim | ded19d5 | 2013-04-01 20:35:19 +0900 | [diff] [blame] | 104 | if (verbose) |
| 105 | symlen += BITS_PER_LONG / 4 + 2 + 3; |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 106 | hists__new_col_len(hists, HISTC_SYMBOL_FROM, symlen); |
| 107 | |
| 108 | symlen = dso__name_len(h->branch_info->from.map->dso); |
| 109 | hists__new_col_len(hists, HISTC_DSO_FROM, symlen); |
| 110 | } else { |
| 111 | symlen = unresolved_col_width + 4 + 2; |
| 112 | hists__new_col_len(hists, HISTC_SYMBOL_FROM, symlen); |
| 113 | hists__set_unres_dso_col_len(hists, HISTC_DSO_FROM); |
| 114 | } |
| 115 | |
| 116 | if (h->branch_info->to.sym) { |
| 117 | symlen = (int)h->branch_info->to.sym->namelen + 4; |
Namhyung Kim | ded19d5 | 2013-04-01 20:35:19 +0900 | [diff] [blame] | 118 | if (verbose) |
| 119 | symlen += BITS_PER_LONG / 4 + 2 + 3; |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 120 | hists__new_col_len(hists, HISTC_SYMBOL_TO, symlen); |
| 121 | |
| 122 | symlen = dso__name_len(h->branch_info->to.map->dso); |
| 123 | hists__new_col_len(hists, HISTC_DSO_TO, symlen); |
| 124 | } else { |
| 125 | symlen = unresolved_col_width + 4 + 2; |
| 126 | hists__new_col_len(hists, HISTC_SYMBOL_TO, symlen); |
| 127 | hists__set_unres_dso_col_len(hists, HISTC_DSO_TO); |
| 128 | } |
| 129 | } |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 130 | |
| 131 | if (h->mem_info) { |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 132 | if (h->mem_info->daddr.sym) { |
| 133 | symlen = (int)h->mem_info->daddr.sym->namelen + 4 |
| 134 | + unresolved_col_width + 2; |
| 135 | hists__new_col_len(hists, HISTC_MEM_DADDR_SYMBOL, |
| 136 | symlen); |
| 137 | } else { |
| 138 | symlen = unresolved_col_width + 4 + 2; |
| 139 | hists__new_col_len(hists, HISTC_MEM_DADDR_SYMBOL, |
| 140 | symlen); |
| 141 | } |
| 142 | if (h->mem_info->daddr.map) { |
| 143 | symlen = dso__name_len(h->mem_info->daddr.map->dso); |
| 144 | hists__new_col_len(hists, HISTC_MEM_DADDR_DSO, |
| 145 | symlen); |
| 146 | } else { |
| 147 | symlen = unresolved_col_width + 4 + 2; |
| 148 | hists__set_unres_dso_col_len(hists, HISTC_MEM_DADDR_DSO); |
| 149 | } |
| 150 | } else { |
| 151 | symlen = unresolved_col_width + 4 + 2; |
| 152 | hists__new_col_len(hists, HISTC_MEM_DADDR_SYMBOL, symlen); |
| 153 | hists__set_unres_dso_col_len(hists, HISTC_MEM_DADDR_DSO); |
| 154 | } |
| 155 | |
| 156 | hists__new_col_len(hists, HISTC_MEM_LOCKED, 6); |
| 157 | hists__new_col_len(hists, HISTC_MEM_TLB, 22); |
| 158 | hists__new_col_len(hists, HISTC_MEM_SNOOP, 12); |
| 159 | hists__new_col_len(hists, HISTC_MEM_LVL, 21 + 3); |
| 160 | hists__new_col_len(hists, HISTC_LOCAL_WEIGHT, 12); |
| 161 | hists__new_col_len(hists, HISTC_GLOBAL_WEIGHT, 12); |
Andi Kleen | 475eeab | 2013-09-20 07:40:43 -0700 | [diff] [blame] | 162 | |
| 163 | if (h->transaction) |
| 164 | hists__new_col_len(hists, HISTC_TRANSACTION, |
| 165 | hist_entry__transaction_len()); |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 166 | } |
| 167 | |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 168 | void hists__output_recalc_col_len(struct hists *hists, int max_rows) |
| 169 | { |
| 170 | struct rb_node *next = rb_first(&hists->entries); |
| 171 | struct hist_entry *n; |
| 172 | int row = 0; |
| 173 | |
| 174 | hists__reset_col_len(hists); |
| 175 | |
| 176 | while (next && row++ < max_rows) { |
| 177 | n = rb_entry(next, struct hist_entry, rb_node); |
| 178 | if (!n->filtered) |
| 179 | hists__calc_col_len(hists, n); |
| 180 | next = rb_next(&n->rb_node); |
| 181 | } |
| 182 | } |
| 183 | |
Namhyung Kim | f39056f | 2014-01-14 14:25:37 +0900 | [diff] [blame] | 184 | static void he_stat__add_cpumode_period(struct he_stat *he_stat, |
| 185 | unsigned int cpumode, u64 period) |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 186 | { |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 187 | switch (cpumode) { |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 188 | case PERF_RECORD_MISC_KERNEL: |
Namhyung Kim | f39056f | 2014-01-14 14:25:37 +0900 | [diff] [blame] | 189 | he_stat->period_sys += period; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 190 | break; |
| 191 | case PERF_RECORD_MISC_USER: |
Namhyung Kim | f39056f | 2014-01-14 14:25:37 +0900 | [diff] [blame] | 192 | he_stat->period_us += period; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 193 | break; |
| 194 | case PERF_RECORD_MISC_GUEST_KERNEL: |
Namhyung Kim | f39056f | 2014-01-14 14:25:37 +0900 | [diff] [blame] | 195 | he_stat->period_guest_sys += period; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 196 | break; |
| 197 | case PERF_RECORD_MISC_GUEST_USER: |
Namhyung Kim | f39056f | 2014-01-14 14:25:37 +0900 | [diff] [blame] | 198 | he_stat->period_guest_us += period; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 199 | break; |
| 200 | default: |
| 201 | break; |
| 202 | } |
| 203 | } |
| 204 | |
Andi Kleen | 0548429 | 2013-01-24 16:10:29 +0100 | [diff] [blame] | 205 | static void he_stat__add_period(struct he_stat *he_stat, u64 period, |
| 206 | u64 weight) |
Namhyung Kim | 139c081 | 2012-10-04 21:49:43 +0900 | [diff] [blame] | 207 | { |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 208 | |
Namhyung Kim | 139c081 | 2012-10-04 21:49:43 +0900 | [diff] [blame] | 209 | he_stat->period += period; |
Andi Kleen | 0548429 | 2013-01-24 16:10:29 +0100 | [diff] [blame] | 210 | he_stat->weight += weight; |
Namhyung Kim | 139c081 | 2012-10-04 21:49:43 +0900 | [diff] [blame] | 211 | he_stat->nr_events += 1; |
| 212 | } |
| 213 | |
| 214 | static void he_stat__add_stat(struct he_stat *dest, struct he_stat *src) |
| 215 | { |
| 216 | dest->period += src->period; |
| 217 | dest->period_sys += src->period_sys; |
| 218 | dest->period_us += src->period_us; |
| 219 | dest->period_guest_sys += src->period_guest_sys; |
| 220 | dest->period_guest_us += src->period_guest_us; |
| 221 | dest->nr_events += src->nr_events; |
Andi Kleen | 0548429 | 2013-01-24 16:10:29 +0100 | [diff] [blame] | 222 | dest->weight += src->weight; |
Namhyung Kim | 139c081 | 2012-10-04 21:49:43 +0900 | [diff] [blame] | 223 | } |
| 224 | |
Namhyung Kim | f39056f | 2014-01-14 14:25:37 +0900 | [diff] [blame] | 225 | static void he_stat__decay(struct he_stat *he_stat) |
Arnaldo Carvalho de Melo | ab81f3f | 2011-10-05 19:16:15 -0300 | [diff] [blame] | 226 | { |
Namhyung Kim | f39056f | 2014-01-14 14:25:37 +0900 | [diff] [blame] | 227 | he_stat->period = (he_stat->period * 7) / 8; |
| 228 | he_stat->nr_events = (he_stat->nr_events * 7) / 8; |
Andi Kleen | 0548429 | 2013-01-24 16:10:29 +0100 | [diff] [blame] | 229 | /* XXX need decay for weight too? */ |
Arnaldo Carvalho de Melo | ab81f3f | 2011-10-05 19:16:15 -0300 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | static bool hists__decay_entry(struct hists *hists, struct hist_entry *he) |
| 233 | { |
Namhyung Kim | b24c28f | 2012-10-04 21:49:41 +0900 | [diff] [blame] | 234 | u64 prev_period = he->stat.period; |
Arnaldo Carvalho de Melo | c64550c | 2011-10-20 06:45:44 -0200 | [diff] [blame] | 235 | |
| 236 | if (prev_period == 0) |
Arnaldo Carvalho de Melo | df71d95 | 2011-10-13 08:01:33 -0300 | [diff] [blame] | 237 | return true; |
Arnaldo Carvalho de Melo | c64550c | 2011-10-20 06:45:44 -0200 | [diff] [blame] | 238 | |
Namhyung Kim | f39056f | 2014-01-14 14:25:37 +0900 | [diff] [blame] | 239 | he_stat__decay(&he->stat); |
Arnaldo Carvalho de Melo | c64550c | 2011-10-20 06:45:44 -0200 | [diff] [blame] | 240 | |
| 241 | if (!he->filtered) |
Namhyung Kim | b24c28f | 2012-10-04 21:49:41 +0900 | [diff] [blame] | 242 | hists->stats.total_period -= prev_period - he->stat.period; |
Arnaldo Carvalho de Melo | c64550c | 2011-10-20 06:45:44 -0200 | [diff] [blame] | 243 | |
Namhyung Kim | b24c28f | 2012-10-04 21:49:41 +0900 | [diff] [blame] | 244 | return he->stat.period == 0; |
Arnaldo Carvalho de Melo | ab81f3f | 2011-10-05 19:16:15 -0300 | [diff] [blame] | 245 | } |
| 246 | |
Namhyung Kim | 3a5714f | 2013-05-14 11:09:01 +0900 | [diff] [blame] | 247 | void hists__decay_entries(struct hists *hists, bool zap_user, bool zap_kernel) |
Arnaldo Carvalho de Melo | ab81f3f | 2011-10-05 19:16:15 -0300 | [diff] [blame] | 248 | { |
| 249 | struct rb_node *next = rb_first(&hists->entries); |
| 250 | struct hist_entry *n; |
| 251 | |
| 252 | while (next) { |
| 253 | n = rb_entry(next, struct hist_entry, rb_node); |
| 254 | next = rb_next(&n->rb_node); |
Arnaldo Carvalho de Melo | df71d95 | 2011-10-13 08:01:33 -0300 | [diff] [blame] | 255 | /* |
| 256 | * We may be annotating this, for instance, so keep it here in |
| 257 | * case some it gets new samples, we'll eventually free it when |
| 258 | * the user stops browsing and it agains gets fully decayed. |
| 259 | */ |
Arnaldo Carvalho de Melo | b079d4e | 2011-10-17 09:05:04 -0200 | [diff] [blame] | 260 | if (((zap_user && n->level == '.') || |
| 261 | (zap_kernel && n->level != '.') || |
| 262 | hists__decay_entry(hists, n)) && |
| 263 | !n->used) { |
Arnaldo Carvalho de Melo | ab81f3f | 2011-10-05 19:16:15 -0300 | [diff] [blame] | 264 | rb_erase(&n->rb_node, &hists->entries); |
| 265 | |
Namhyung Kim | 3a5714f | 2013-05-14 11:09:01 +0900 | [diff] [blame] | 266 | if (sort__need_collapse) |
Arnaldo Carvalho de Melo | ab81f3f | 2011-10-05 19:16:15 -0300 | [diff] [blame] | 267 | rb_erase(&n->rb_node_in, &hists->entries_collapsed); |
| 268 | |
| 269 | hist_entry__free(n); |
| 270 | --hists->nr_entries; |
| 271 | } |
| 272 | } |
| 273 | } |
| 274 | |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 275 | /* |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 276 | * histogram, sorted on item, collects periods |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 277 | */ |
| 278 | |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 279 | static struct hist_entry *hist_entry__new(struct hist_entry *template) |
| 280 | { |
Frederic Weisbecker | d2009c5 | 2010-08-22 20:05:22 +0200 | [diff] [blame] | 281 | size_t callchain_size = symbol_conf.use_callchain ? sizeof(struct callchain_root) : 0; |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 282 | struct hist_entry *he = zalloc(sizeof(*he) + callchain_size); |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 283 | |
Arnaldo Carvalho de Melo | 12c1427 | 2012-01-04 12:27:03 -0200 | [diff] [blame] | 284 | if (he != NULL) { |
| 285 | *he = *template; |
Namhyung Kim | c4b3535 | 2012-10-04 21:49:42 +0900 | [diff] [blame] | 286 | |
Arnaldo Carvalho de Melo | 12c1427 | 2012-01-04 12:27:03 -0200 | [diff] [blame] | 287 | if (he->ms.map) |
| 288 | he->ms.map->referenced = true; |
Stephane Eranian | 3cf0cb1 | 2013-01-14 15:02:45 +0100 | [diff] [blame] | 289 | |
| 290 | if (he->branch_info) { |
Namhyung Kim | 26353a6 | 2013-04-01 20:35:17 +0900 | [diff] [blame] | 291 | /* |
| 292 | * This branch info is (a part of) allocated from |
| 293 | * machine__resolve_bstack() and will be freed after |
| 294 | * adding new entries. So we need to save a copy. |
| 295 | */ |
| 296 | he->branch_info = malloc(sizeof(*he->branch_info)); |
| 297 | if (he->branch_info == NULL) { |
| 298 | free(he); |
| 299 | return NULL; |
| 300 | } |
| 301 | |
| 302 | memcpy(he->branch_info, template->branch_info, |
| 303 | sizeof(*he->branch_info)); |
| 304 | |
Stephane Eranian | 3cf0cb1 | 2013-01-14 15:02:45 +0100 | [diff] [blame] | 305 | if (he->branch_info->from.map) |
| 306 | he->branch_info->from.map->referenced = true; |
| 307 | if (he->branch_info->to.map) |
| 308 | he->branch_info->to.map->referenced = true; |
| 309 | } |
| 310 | |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 311 | if (he->mem_info) { |
| 312 | if (he->mem_info->iaddr.map) |
| 313 | he->mem_info->iaddr.map->referenced = true; |
| 314 | if (he->mem_info->daddr.map) |
| 315 | he->mem_info->daddr.map->referenced = true; |
| 316 | } |
| 317 | |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 318 | if (symbol_conf.use_callchain) |
Arnaldo Carvalho de Melo | 12c1427 | 2012-01-04 12:27:03 -0200 | [diff] [blame] | 319 | callchain_init(he->callchain); |
Arnaldo Carvalho de Melo | b821c73 | 2012-10-25 14:42:45 -0200 | [diff] [blame] | 320 | |
| 321 | INIT_LIST_HEAD(&he->pairs.node); |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 322 | } |
| 323 | |
Arnaldo Carvalho de Melo | 12c1427 | 2012-01-04 12:27:03 -0200 | [diff] [blame] | 324 | return he; |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 325 | } |
| 326 | |
Namhyung Kim | 66f97ed | 2012-12-10 17:29:56 +0900 | [diff] [blame] | 327 | void hists__inc_nr_entries(struct hists *hists, struct hist_entry *h) |
Arnaldo Carvalho de Melo | fefb0b9 | 2010-05-10 13:57:51 -0300 | [diff] [blame] | 328 | { |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 329 | if (!h->filtered) { |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 330 | hists__calc_col_len(hists, h); |
| 331 | ++hists->nr_entries; |
Namhyung Kim | b24c28f | 2012-10-04 21:49:41 +0900 | [diff] [blame] | 332 | hists->stats.total_period += h->stat.period; |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 333 | } |
Arnaldo Carvalho de Melo | fefb0b9 | 2010-05-10 13:57:51 -0300 | [diff] [blame] | 334 | } |
| 335 | |
Arnaldo Carvalho de Melo | 7a007ca | 2010-07-21 09:19:41 -0300 | [diff] [blame] | 336 | static u8 symbol__parent_filter(const struct symbol *parent) |
| 337 | { |
| 338 | if (symbol_conf.exclude_other && parent == NULL) |
| 339 | return 1 << HIST_FILTER__PARENT; |
| 340 | return 0; |
| 341 | } |
| 342 | |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 343 | static struct hist_entry *add_hist_entry(struct hists *hists, |
Namhyung Kim | f1cbf78 | 2013-12-18 14:21:11 +0900 | [diff] [blame] | 344 | struct hist_entry *entry, |
| 345 | struct addr_location *al) |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 346 | { |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 347 | struct rb_node **p; |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 348 | struct rb_node *parent = NULL; |
| 349 | struct hist_entry *he; |
Andi Kleen | 354cc40 | 2013-10-01 07:22:15 -0700 | [diff] [blame] | 350 | int64_t cmp; |
Namhyung Kim | f1cbf78 | 2013-12-18 14:21:11 +0900 | [diff] [blame] | 351 | u64 period = entry->stat.period; |
| 352 | u64 weight = entry->stat.weight; |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 353 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 354 | p = &hists->entries_in->rb_node; |
| 355 | |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 356 | while (*p != NULL) { |
| 357 | parent = *p; |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 358 | he = rb_entry(parent, struct hist_entry, rb_node_in); |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 359 | |
Namhyung Kim | 9afcf93 | 2012-12-10 17:29:54 +0900 | [diff] [blame] | 360 | /* |
| 361 | * Make sure that it receives arguments in a same order as |
| 362 | * hist_entry__collapse() so that we can use an appropriate |
| 363 | * function when searching an entry regardless which sort |
| 364 | * keys were used. |
| 365 | */ |
| 366 | cmp = hist_entry__cmp(he, entry); |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 367 | |
| 368 | if (!cmp) { |
Andi Kleen | 0548429 | 2013-01-24 16:10:29 +0100 | [diff] [blame] | 369 | he_stat__add_period(&he->stat, period, weight); |
David Miller | 63fa471 | 2012-03-27 03:14:18 -0400 | [diff] [blame] | 370 | |
Namhyung Kim | ceb2acb | 2013-04-01 20:35:18 +0900 | [diff] [blame] | 371 | /* |
| 372 | * This mem info was allocated from machine__resolve_mem |
| 373 | * and will not be used anymore. |
| 374 | */ |
Arnaldo Carvalho de Melo | 74cf249 | 2013-12-27 16:55:14 -0300 | [diff] [blame] | 375 | zfree(&entry->mem_info); |
Namhyung Kim | ceb2acb | 2013-04-01 20:35:18 +0900 | [diff] [blame] | 376 | |
David Miller | 63fa471 | 2012-03-27 03:14:18 -0400 | [diff] [blame] | 377 | /* If the map of an existing hist_entry has |
| 378 | * become out-of-date due to an exec() or |
| 379 | * similar, update it. Otherwise we will |
| 380 | * mis-adjust symbol addresses when computing |
| 381 | * the history counter to increment. |
| 382 | */ |
| 383 | if (he->ms.map != entry->ms.map) { |
| 384 | he->ms.map = entry->ms.map; |
| 385 | if (he->ms.map) |
| 386 | he->ms.map->referenced = true; |
| 387 | } |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 388 | goto out; |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | if (cmp < 0) |
| 392 | p = &(*p)->rb_left; |
| 393 | else |
| 394 | p = &(*p)->rb_right; |
| 395 | } |
| 396 | |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 397 | he = hist_entry__new(entry); |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 398 | if (!he) |
Namhyung Kim | 27a0dcb | 2013-05-14 11:09:02 +0900 | [diff] [blame] | 399 | return NULL; |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 400 | |
Namhyung Kim | c1fb565 | 2013-10-11 14:15:38 +0900 | [diff] [blame] | 401 | hists->nr_entries++; |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 402 | rb_link_node(&he->rb_node_in, parent, p); |
| 403 | rb_insert_color(&he->rb_node_in, hists->entries_in); |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 404 | out: |
Namhyung Kim | f39056f | 2014-01-14 14:25:37 +0900 | [diff] [blame] | 405 | he_stat__add_cpumode_period(&he->stat, al->cpumode, period); |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 406 | return he; |
| 407 | } |
| 408 | |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 409 | struct hist_entry *__hists__add_entry(struct hists *hists, |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 410 | struct addr_location *al, |
Namhyung Kim | 41a4e6e | 2013-10-31 15:56:03 +0900 | [diff] [blame] | 411 | struct symbol *sym_parent, |
| 412 | struct branch_info *bi, |
| 413 | struct mem_info *mi, |
| 414 | u64 period, u64 weight, u64 transaction) |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 415 | { |
| 416 | struct hist_entry entry = { |
| 417 | .thread = al->thread, |
Namhyung Kim | 4dfced3 | 2013-09-13 16:28:57 +0900 | [diff] [blame] | 418 | .comm = thread__comm(al->thread), |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 419 | .ms = { |
| 420 | .map = al->map, |
| 421 | .sym = al->sym, |
| 422 | }, |
| 423 | .cpu = al->cpu, |
| 424 | .ip = al->addr, |
| 425 | .level = al->level, |
Namhyung Kim | b24c28f | 2012-10-04 21:49:41 +0900 | [diff] [blame] | 426 | .stat = { |
Namhyung Kim | c4b3535 | 2012-10-04 21:49:42 +0900 | [diff] [blame] | 427 | .nr_events = 1, |
Namhyung Kim | 41a4e6e | 2013-10-31 15:56:03 +0900 | [diff] [blame] | 428 | .period = period, |
Andi Kleen | 0548429 | 2013-01-24 16:10:29 +0100 | [diff] [blame] | 429 | .weight = weight, |
Namhyung Kim | b24c28f | 2012-10-04 21:49:41 +0900 | [diff] [blame] | 430 | }, |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 431 | .parent = sym_parent, |
| 432 | .filtered = symbol__parent_filter(sym_parent), |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 433 | .hists = hists, |
Namhyung Kim | 41a4e6e | 2013-10-31 15:56:03 +0900 | [diff] [blame] | 434 | .branch_info = bi, |
| 435 | .mem_info = mi, |
Andi Kleen | 475eeab | 2013-09-20 07:40:43 -0700 | [diff] [blame] | 436 | .transaction = transaction, |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 437 | }; |
| 438 | |
Namhyung Kim | f1cbf78 | 2013-12-18 14:21:11 +0900 | [diff] [blame] | 439 | return add_hist_entry(hists, &entry, al); |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 440 | } |
| 441 | |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 442 | int64_t |
| 443 | hist_entry__cmp(struct hist_entry *left, struct hist_entry *right) |
| 444 | { |
| 445 | struct sort_entry *se; |
| 446 | int64_t cmp = 0; |
| 447 | |
| 448 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
Frederic Weisbecker | fcd1498 | 2010-04-14 19:11:29 +0200 | [diff] [blame] | 449 | cmp = se->se_cmp(left, right); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 450 | if (cmp) |
| 451 | break; |
| 452 | } |
| 453 | |
| 454 | return cmp; |
| 455 | } |
| 456 | |
| 457 | int64_t |
| 458 | hist_entry__collapse(struct hist_entry *left, struct hist_entry *right) |
| 459 | { |
| 460 | struct sort_entry *se; |
| 461 | int64_t cmp = 0; |
| 462 | |
| 463 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
| 464 | int64_t (*f)(struct hist_entry *, struct hist_entry *); |
| 465 | |
Frederic Weisbecker | fcd1498 | 2010-04-14 19:11:29 +0200 | [diff] [blame] | 466 | f = se->se_collapse ?: se->se_cmp; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 467 | |
| 468 | cmp = f(left, right); |
| 469 | if (cmp) |
| 470 | break; |
| 471 | } |
| 472 | |
| 473 | return cmp; |
| 474 | } |
| 475 | |
| 476 | void hist_entry__free(struct hist_entry *he) |
| 477 | { |
Arnaldo Carvalho de Melo | 74cf249 | 2013-12-27 16:55:14 -0300 | [diff] [blame] | 478 | zfree(&he->branch_info); |
| 479 | zfree(&he->mem_info); |
Namhyung Kim | f048d54 | 2013-09-11 14:09:28 +0900 | [diff] [blame] | 480 | free_srcline(he->srcline); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 481 | free(he); |
| 482 | } |
| 483 | |
| 484 | /* |
| 485 | * collapse the histogram |
| 486 | */ |
| 487 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 488 | static bool hists__collapse_insert_entry(struct hists *hists __maybe_unused, |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 489 | struct rb_root *root, |
| 490 | struct hist_entry *he) |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 491 | { |
Arnaldo Carvalho de Melo | b9bf089 | 2009-12-14 11:37:11 -0200 | [diff] [blame] | 492 | struct rb_node **p = &root->rb_node; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 493 | struct rb_node *parent = NULL; |
| 494 | struct hist_entry *iter; |
| 495 | int64_t cmp; |
| 496 | |
| 497 | while (*p != NULL) { |
| 498 | parent = *p; |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 499 | iter = rb_entry(parent, struct hist_entry, rb_node_in); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 500 | |
| 501 | cmp = hist_entry__collapse(iter, he); |
| 502 | |
| 503 | if (!cmp) { |
Namhyung Kim | 139c081 | 2012-10-04 21:49:43 +0900 | [diff] [blame] | 504 | he_stat__add_stat(&iter->stat, &he->stat); |
Namhyung Kim | 9ec6097 | 2012-09-26 16:47:28 +0900 | [diff] [blame] | 505 | |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 506 | if (symbol_conf.use_callchain) { |
Namhyung Kim | 4726064 | 2012-05-31 14:43:26 +0900 | [diff] [blame] | 507 | callchain_cursor_reset(&callchain_cursor); |
| 508 | callchain_merge(&callchain_cursor, |
| 509 | iter->callchain, |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 510 | he->callchain); |
| 511 | } |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 512 | hist_entry__free(he); |
Arnaldo Carvalho de Melo | fefb0b9 | 2010-05-10 13:57:51 -0300 | [diff] [blame] | 513 | return false; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | if (cmp < 0) |
| 517 | p = &(*p)->rb_left; |
| 518 | else |
| 519 | p = &(*p)->rb_right; |
| 520 | } |
| 521 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 522 | rb_link_node(&he->rb_node_in, parent, p); |
| 523 | rb_insert_color(&he->rb_node_in, root); |
Arnaldo Carvalho de Melo | fefb0b9 | 2010-05-10 13:57:51 -0300 | [diff] [blame] | 524 | return true; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 525 | } |
| 526 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 527 | static struct rb_root *hists__get_rotate_entries_in(struct hists *hists) |
| 528 | { |
| 529 | struct rb_root *root; |
| 530 | |
| 531 | pthread_mutex_lock(&hists->lock); |
| 532 | |
| 533 | root = hists->entries_in; |
| 534 | if (++hists->entries_in > &hists->entries_in_array[1]) |
| 535 | hists->entries_in = &hists->entries_in_array[0]; |
| 536 | |
| 537 | pthread_mutex_unlock(&hists->lock); |
| 538 | |
| 539 | return root; |
| 540 | } |
| 541 | |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 542 | static void hists__apply_filters(struct hists *hists, struct hist_entry *he) |
| 543 | { |
| 544 | hists__filter_entry_by_dso(hists, he); |
| 545 | hists__filter_entry_by_thread(hists, he); |
Namhyung Kim | e94d53e | 2012-03-16 17:50:51 +0900 | [diff] [blame] | 546 | hists__filter_entry_by_symbol(hists, he); |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 547 | } |
| 548 | |
Namhyung Kim | c1fb565 | 2013-10-11 14:15:38 +0900 | [diff] [blame] | 549 | void hists__collapse_resort(struct hists *hists, struct ui_progress *prog) |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 550 | { |
| 551 | struct rb_root *root; |
| 552 | struct rb_node *next; |
| 553 | struct hist_entry *n; |
| 554 | |
Namhyung Kim | 3a5714f | 2013-05-14 11:09:01 +0900 | [diff] [blame] | 555 | if (!sort__need_collapse) |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 556 | return; |
| 557 | |
| 558 | root = hists__get_rotate_entries_in(hists); |
| 559 | next = rb_first(root); |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 560 | |
| 561 | while (next) { |
Arnaldo Carvalho de Melo | 33e940a | 2013-09-17 16:34:28 -0300 | [diff] [blame] | 562 | if (session_done()) |
| 563 | break; |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 564 | n = rb_entry(next, struct hist_entry, rb_node_in); |
| 565 | next = rb_next(&n->rb_node_in); |
| 566 | |
| 567 | rb_erase(&n->rb_node_in, root); |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 568 | if (hists__collapse_insert_entry(hists, &hists->entries_collapsed, n)) { |
| 569 | /* |
| 570 | * If it wasn't combined with one of the entries already |
| 571 | * collapsed, we need to apply the filters that may have |
| 572 | * been set by, say, the hist_browser. |
| 573 | */ |
| 574 | hists__apply_filters(hists, n); |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 575 | } |
Namhyung Kim | c1fb565 | 2013-10-11 14:15:38 +0900 | [diff] [blame] | 576 | if (prog) |
| 577 | ui_progress__update(prog, 1); |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 578 | } |
| 579 | } |
| 580 | |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 581 | /* |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 582 | * reverse the map, sort on period. |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 583 | */ |
| 584 | |
Namhyung Kim | 29d720e | 2013-01-22 18:09:33 +0900 | [diff] [blame] | 585 | static int period_cmp(u64 period_a, u64 period_b) |
| 586 | { |
| 587 | if (period_a > period_b) |
| 588 | return 1; |
| 589 | if (period_a < period_b) |
| 590 | return -1; |
| 591 | return 0; |
| 592 | } |
| 593 | |
| 594 | static int hist_entry__sort_on_period(struct hist_entry *a, |
| 595 | struct hist_entry *b) |
| 596 | { |
| 597 | int ret; |
| 598 | int i, nr_members; |
| 599 | struct perf_evsel *evsel; |
| 600 | struct hist_entry *pair; |
| 601 | u64 *periods_a, *periods_b; |
| 602 | |
| 603 | ret = period_cmp(a->stat.period, b->stat.period); |
| 604 | if (ret || !symbol_conf.event_group) |
| 605 | return ret; |
| 606 | |
| 607 | evsel = hists_to_evsel(a->hists); |
| 608 | nr_members = evsel->nr_members; |
| 609 | if (nr_members <= 1) |
| 610 | return ret; |
| 611 | |
| 612 | periods_a = zalloc(sizeof(periods_a) * nr_members); |
| 613 | periods_b = zalloc(sizeof(periods_b) * nr_members); |
| 614 | |
| 615 | if (!periods_a || !periods_b) |
| 616 | goto out; |
| 617 | |
| 618 | list_for_each_entry(pair, &a->pairs.head, pairs.node) { |
| 619 | evsel = hists_to_evsel(pair->hists); |
| 620 | periods_a[perf_evsel__group_idx(evsel)] = pair->stat.period; |
| 621 | } |
| 622 | |
| 623 | list_for_each_entry(pair, &b->pairs.head, pairs.node) { |
| 624 | evsel = hists_to_evsel(pair->hists); |
| 625 | periods_b[perf_evsel__group_idx(evsel)] = pair->stat.period; |
| 626 | } |
| 627 | |
| 628 | for (i = 1; i < nr_members; i++) { |
| 629 | ret = period_cmp(periods_a[i], periods_b[i]); |
| 630 | if (ret) |
| 631 | break; |
| 632 | } |
| 633 | |
| 634 | out: |
| 635 | free(periods_a); |
| 636 | free(periods_b); |
| 637 | |
| 638 | return ret; |
| 639 | } |
| 640 | |
Arnaldo Carvalho de Melo | 1c02c4d | 2010-05-10 13:04:11 -0300 | [diff] [blame] | 641 | static void __hists__insert_output_entry(struct rb_root *entries, |
| 642 | struct hist_entry *he, |
| 643 | u64 min_callchain_hits) |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 644 | { |
Arnaldo Carvalho de Melo | 1c02c4d | 2010-05-10 13:04:11 -0300 | [diff] [blame] | 645 | struct rb_node **p = &entries->rb_node; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 646 | struct rb_node *parent = NULL; |
| 647 | struct hist_entry *iter; |
| 648 | |
Arnaldo Carvalho de Melo | d599db3 | 2009-12-15 20:04:42 -0200 | [diff] [blame] | 649 | if (symbol_conf.use_callchain) |
Arnaldo Carvalho de Melo | b9fb930 | 2010-04-02 09:50:42 -0300 | [diff] [blame] | 650 | callchain_param.sort(&he->sorted_chain, he->callchain, |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 651 | min_callchain_hits, &callchain_param); |
| 652 | |
| 653 | while (*p != NULL) { |
| 654 | parent = *p; |
| 655 | iter = rb_entry(parent, struct hist_entry, rb_node); |
| 656 | |
Namhyung Kim | 29d720e | 2013-01-22 18:09:33 +0900 | [diff] [blame] | 657 | if (hist_entry__sort_on_period(he, iter) > 0) |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 658 | p = &(*p)->rb_left; |
| 659 | else |
| 660 | p = &(*p)->rb_right; |
| 661 | } |
| 662 | |
| 663 | rb_link_node(&he->rb_node, parent, p); |
Arnaldo Carvalho de Melo | 1c02c4d | 2010-05-10 13:04:11 -0300 | [diff] [blame] | 664 | rb_insert_color(&he->rb_node, entries); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 665 | } |
| 666 | |
Namhyung Kim | 3a5714f | 2013-05-14 11:09:01 +0900 | [diff] [blame] | 667 | void hists__output_resort(struct hists *hists) |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 668 | { |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 669 | struct rb_root *root; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 670 | struct rb_node *next; |
| 671 | struct hist_entry *n; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 672 | u64 min_callchain_hits; |
| 673 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 674 | min_callchain_hits = hists->stats.total_period * (callchain_param.min_percent / 100); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 675 | |
Namhyung Kim | 3a5714f | 2013-05-14 11:09:01 +0900 | [diff] [blame] | 676 | if (sort__need_collapse) |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 677 | root = &hists->entries_collapsed; |
| 678 | else |
| 679 | root = hists->entries_in; |
| 680 | |
| 681 | next = rb_first(root); |
| 682 | hists->entries = RB_ROOT; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 683 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 684 | hists->nr_entries = 0; |
Arnaldo Carvalho de Melo | 7928631 | 2011-10-27 09:19:48 -0200 | [diff] [blame] | 685 | hists->stats.total_period = 0; |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 686 | hists__reset_col_len(hists); |
Arnaldo Carvalho de Melo | fefb0b9 | 2010-05-10 13:57:51 -0300 | [diff] [blame] | 687 | |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 688 | while (next) { |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 689 | n = rb_entry(next, struct hist_entry, rb_node_in); |
| 690 | next = rb_next(&n->rb_node_in); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 691 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 692 | __hists__insert_output_entry(&hists->entries, n, min_callchain_hits); |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 693 | hists__inc_nr_entries(hists, n); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 694 | } |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 695 | } |
Arnaldo Carvalho de Melo | b9bf089 | 2009-12-14 11:37:11 -0200 | [diff] [blame] | 696 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 697 | static void hists__remove_entry_filter(struct hists *hists, struct hist_entry *h, |
Arnaldo Carvalho de Melo | cc5edb0 | 2010-07-16 12:35:07 -0300 | [diff] [blame] | 698 | enum hist_filter filter) |
| 699 | { |
| 700 | h->filtered &= ~(1 << filter); |
| 701 | if (h->filtered) |
| 702 | return; |
| 703 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 704 | ++hists->nr_entries; |
Arnaldo Carvalho de Melo | 0f0cbf7 | 2010-07-26 17:13:40 -0300 | [diff] [blame] | 705 | if (h->ms.unfolded) |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 706 | hists->nr_entries += h->nr_rows; |
Arnaldo Carvalho de Melo | 0f0cbf7 | 2010-07-26 17:13:40 -0300 | [diff] [blame] | 707 | h->row_offset = 0; |
Namhyung Kim | b24c28f | 2012-10-04 21:49:41 +0900 | [diff] [blame] | 708 | hists->stats.total_period += h->stat.period; |
| 709 | hists->stats.nr_events[PERF_RECORD_SAMPLE] += h->stat.nr_events; |
Arnaldo Carvalho de Melo | cc5edb0 | 2010-07-16 12:35:07 -0300 | [diff] [blame] | 710 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 711 | hists__calc_col_len(hists, h); |
Arnaldo Carvalho de Melo | cc5edb0 | 2010-07-16 12:35:07 -0300 | [diff] [blame] | 712 | } |
| 713 | |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 714 | |
| 715 | static bool hists__filter_entry_by_dso(struct hists *hists, |
| 716 | struct hist_entry *he) |
| 717 | { |
| 718 | if (hists->dso_filter != NULL && |
| 719 | (he->ms.map == NULL || he->ms.map->dso != hists->dso_filter)) { |
| 720 | he->filtered |= (1 << HIST_FILTER__DSO); |
| 721 | return true; |
| 722 | } |
| 723 | |
| 724 | return false; |
| 725 | } |
| 726 | |
Arnaldo Carvalho de Melo | d7b76f0 | 2011-10-18 19:07:34 -0200 | [diff] [blame] | 727 | void hists__filter_by_dso(struct hists *hists) |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 728 | { |
| 729 | struct rb_node *nd; |
| 730 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 731 | hists->nr_entries = hists->stats.total_period = 0; |
| 732 | hists->stats.nr_events[PERF_RECORD_SAMPLE] = 0; |
| 733 | hists__reset_col_len(hists); |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 734 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 735 | for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) { |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 736 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
| 737 | |
| 738 | if (symbol_conf.exclude_other && !h->parent) |
| 739 | continue; |
| 740 | |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 741 | if (hists__filter_entry_by_dso(hists, h)) |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 742 | continue; |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 743 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 744 | hists__remove_entry_filter(hists, h, HIST_FILTER__DSO); |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 745 | } |
| 746 | } |
| 747 | |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 748 | static bool hists__filter_entry_by_thread(struct hists *hists, |
| 749 | struct hist_entry *he) |
| 750 | { |
| 751 | if (hists->thread_filter != NULL && |
| 752 | he->thread != hists->thread_filter) { |
| 753 | he->filtered |= (1 << HIST_FILTER__THREAD); |
| 754 | return true; |
| 755 | } |
| 756 | |
| 757 | return false; |
| 758 | } |
| 759 | |
Arnaldo Carvalho de Melo | d7b76f0 | 2011-10-18 19:07:34 -0200 | [diff] [blame] | 760 | void hists__filter_by_thread(struct hists *hists) |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 761 | { |
| 762 | struct rb_node *nd; |
| 763 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 764 | hists->nr_entries = hists->stats.total_period = 0; |
| 765 | hists->stats.nr_events[PERF_RECORD_SAMPLE] = 0; |
| 766 | hists__reset_col_len(hists); |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 767 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 768 | for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) { |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 769 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
| 770 | |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 771 | if (hists__filter_entry_by_thread(hists, h)) |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 772 | continue; |
Arnaldo Carvalho de Melo | cc5edb0 | 2010-07-16 12:35:07 -0300 | [diff] [blame] | 773 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 774 | hists__remove_entry_filter(hists, h, HIST_FILTER__THREAD); |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 775 | } |
| 776 | } |
Arnaldo Carvalho de Melo | ef7b93a | 2010-05-11 23:18:06 -0300 | [diff] [blame] | 777 | |
Namhyung Kim | e94d53e | 2012-03-16 17:50:51 +0900 | [diff] [blame] | 778 | static bool hists__filter_entry_by_symbol(struct hists *hists, |
| 779 | struct hist_entry *he) |
| 780 | { |
| 781 | if (hists->symbol_filter_str != NULL && |
| 782 | (!he->ms.sym || strstr(he->ms.sym->name, |
| 783 | hists->symbol_filter_str) == NULL)) { |
| 784 | he->filtered |= (1 << HIST_FILTER__SYMBOL); |
| 785 | return true; |
| 786 | } |
| 787 | |
| 788 | return false; |
| 789 | } |
| 790 | |
| 791 | void hists__filter_by_symbol(struct hists *hists) |
| 792 | { |
| 793 | struct rb_node *nd; |
| 794 | |
| 795 | hists->nr_entries = hists->stats.total_period = 0; |
| 796 | hists->stats.nr_events[PERF_RECORD_SAMPLE] = 0; |
| 797 | hists__reset_col_len(hists); |
| 798 | |
| 799 | for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) { |
| 800 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
| 801 | |
| 802 | if (hists__filter_entry_by_symbol(hists, h)) |
| 803 | continue; |
| 804 | |
| 805 | hists__remove_entry_filter(hists, h, HIST_FILTER__SYMBOL); |
| 806 | } |
| 807 | } |
| 808 | |
Arnaldo Carvalho de Melo | 28a6b6a | 2012-12-18 16:24:46 -0300 | [diff] [blame] | 809 | void events_stats__inc(struct events_stats *stats, u32 type) |
| 810 | { |
| 811 | ++stats->nr_events[0]; |
| 812 | ++stats->nr_events[type]; |
| 813 | } |
| 814 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 815 | void hists__inc_nr_events(struct hists *hists, u32 type) |
Arnaldo Carvalho de Melo | c8446b9 | 2010-05-14 10:36:42 -0300 | [diff] [blame] | 816 | { |
Arnaldo Carvalho de Melo | 28a6b6a | 2012-12-18 16:24:46 -0300 | [diff] [blame] | 817 | events_stats__inc(&hists->stats, type); |
Arnaldo Carvalho de Melo | c8446b9 | 2010-05-14 10:36:42 -0300 | [diff] [blame] | 818 | } |
Arnaldo Carvalho de Melo | 95529be | 2012-11-08 17:54:33 -0300 | [diff] [blame] | 819 | |
Arnaldo Carvalho de Melo | 494d70a | 2012-11-08 18:03:09 -0300 | [diff] [blame] | 820 | static struct hist_entry *hists__add_dummy_entry(struct hists *hists, |
| 821 | struct hist_entry *pair) |
| 822 | { |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 823 | struct rb_root *root; |
| 824 | struct rb_node **p; |
Arnaldo Carvalho de Melo | 494d70a | 2012-11-08 18:03:09 -0300 | [diff] [blame] | 825 | struct rb_node *parent = NULL; |
| 826 | struct hist_entry *he; |
Andi Kleen | 354cc40 | 2013-10-01 07:22:15 -0700 | [diff] [blame] | 827 | int64_t cmp; |
Arnaldo Carvalho de Melo | 494d70a | 2012-11-08 18:03:09 -0300 | [diff] [blame] | 828 | |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 829 | if (sort__need_collapse) |
| 830 | root = &hists->entries_collapsed; |
| 831 | else |
| 832 | root = hists->entries_in; |
| 833 | |
| 834 | p = &root->rb_node; |
| 835 | |
Arnaldo Carvalho de Melo | 494d70a | 2012-11-08 18:03:09 -0300 | [diff] [blame] | 836 | while (*p != NULL) { |
| 837 | parent = *p; |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 838 | he = rb_entry(parent, struct hist_entry, rb_node_in); |
Arnaldo Carvalho de Melo | 494d70a | 2012-11-08 18:03:09 -0300 | [diff] [blame] | 839 | |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 840 | cmp = hist_entry__collapse(he, pair); |
Arnaldo Carvalho de Melo | 494d70a | 2012-11-08 18:03:09 -0300 | [diff] [blame] | 841 | |
| 842 | if (!cmp) |
| 843 | goto out; |
| 844 | |
| 845 | if (cmp < 0) |
| 846 | p = &(*p)->rb_left; |
| 847 | else |
| 848 | p = &(*p)->rb_right; |
| 849 | } |
| 850 | |
| 851 | he = hist_entry__new(pair); |
| 852 | if (he) { |
Arnaldo Carvalho de Melo | 30193d7 | 2012-11-12 13:20:03 -0300 | [diff] [blame] | 853 | memset(&he->stat, 0, sizeof(he->stat)); |
| 854 | he->hists = hists; |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 855 | rb_link_node(&he->rb_node_in, parent, p); |
| 856 | rb_insert_color(&he->rb_node_in, root); |
Arnaldo Carvalho de Melo | 494d70a | 2012-11-08 18:03:09 -0300 | [diff] [blame] | 857 | hists__inc_nr_entries(hists, he); |
Jiri Olsa | e0af43d | 2012-12-01 21:18:20 +0100 | [diff] [blame] | 858 | he->dummy = true; |
Arnaldo Carvalho de Melo | 494d70a | 2012-11-08 18:03:09 -0300 | [diff] [blame] | 859 | } |
| 860 | out: |
| 861 | return he; |
| 862 | } |
| 863 | |
Arnaldo Carvalho de Melo | 95529be | 2012-11-08 17:54:33 -0300 | [diff] [blame] | 864 | static struct hist_entry *hists__find_entry(struct hists *hists, |
| 865 | struct hist_entry *he) |
| 866 | { |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 867 | struct rb_node *n; |
| 868 | |
| 869 | if (sort__need_collapse) |
| 870 | n = hists->entries_collapsed.rb_node; |
| 871 | else |
| 872 | n = hists->entries_in->rb_node; |
Arnaldo Carvalho de Melo | 95529be | 2012-11-08 17:54:33 -0300 | [diff] [blame] | 873 | |
| 874 | while (n) { |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 875 | struct hist_entry *iter = rb_entry(n, struct hist_entry, rb_node_in); |
| 876 | int64_t cmp = hist_entry__collapse(iter, he); |
Arnaldo Carvalho de Melo | 95529be | 2012-11-08 17:54:33 -0300 | [diff] [blame] | 877 | |
| 878 | if (cmp < 0) |
| 879 | n = n->rb_left; |
| 880 | else if (cmp > 0) |
| 881 | n = n->rb_right; |
| 882 | else |
| 883 | return iter; |
| 884 | } |
| 885 | |
| 886 | return NULL; |
| 887 | } |
| 888 | |
| 889 | /* |
| 890 | * Look for pairs to link to the leader buckets (hist_entries): |
| 891 | */ |
| 892 | void hists__match(struct hists *leader, struct hists *other) |
| 893 | { |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 894 | struct rb_root *root; |
Arnaldo Carvalho de Melo | 95529be | 2012-11-08 17:54:33 -0300 | [diff] [blame] | 895 | struct rb_node *nd; |
| 896 | struct hist_entry *pos, *pair; |
| 897 | |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 898 | if (sort__need_collapse) |
| 899 | root = &leader->entries_collapsed; |
| 900 | else |
| 901 | root = leader->entries_in; |
| 902 | |
| 903 | for (nd = rb_first(root); nd; nd = rb_next(nd)) { |
| 904 | pos = rb_entry(nd, struct hist_entry, rb_node_in); |
Arnaldo Carvalho de Melo | 95529be | 2012-11-08 17:54:33 -0300 | [diff] [blame] | 905 | pair = hists__find_entry(other, pos); |
| 906 | |
| 907 | if (pair) |
Namhyung Kim | 5fa9041 | 2012-11-29 15:38:34 +0900 | [diff] [blame] | 908 | hist_entry__add_pair(pair, pos); |
Arnaldo Carvalho de Melo | 95529be | 2012-11-08 17:54:33 -0300 | [diff] [blame] | 909 | } |
| 910 | } |
Arnaldo Carvalho de Melo | 494d70a | 2012-11-08 18:03:09 -0300 | [diff] [blame] | 911 | |
| 912 | /* |
| 913 | * Look for entries in the other hists that are not present in the leader, if |
| 914 | * we find them, just add a dummy entry on the leader hists, with period=0, |
| 915 | * nr_events=0, to serve as the list header. |
| 916 | */ |
| 917 | int hists__link(struct hists *leader, struct hists *other) |
| 918 | { |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 919 | struct rb_root *root; |
Arnaldo Carvalho de Melo | 494d70a | 2012-11-08 18:03:09 -0300 | [diff] [blame] | 920 | struct rb_node *nd; |
| 921 | struct hist_entry *pos, *pair; |
| 922 | |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 923 | if (sort__need_collapse) |
| 924 | root = &other->entries_collapsed; |
| 925 | else |
| 926 | root = other->entries_in; |
| 927 | |
| 928 | for (nd = rb_first(root); nd; nd = rb_next(nd)) { |
| 929 | pos = rb_entry(nd, struct hist_entry, rb_node_in); |
Arnaldo Carvalho de Melo | 494d70a | 2012-11-08 18:03:09 -0300 | [diff] [blame] | 930 | |
| 931 | if (!hist_entry__has_pairs(pos)) { |
| 932 | pair = hists__add_dummy_entry(leader, pos); |
| 933 | if (pair == NULL) |
| 934 | return -1; |
Namhyung Kim | 5fa9041 | 2012-11-29 15:38:34 +0900 | [diff] [blame] | 935 | hist_entry__add_pair(pos, pair); |
Arnaldo Carvalho de Melo | 494d70a | 2012-11-08 18:03:09 -0300 | [diff] [blame] | 936 | } |
| 937 | } |
| 938 | |
| 939 | return 0; |
| 940 | } |