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