Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1 | #include "annotate.h" |
Frederic Weisbecker | 8a0ecfb | 2010-05-13 19:47:16 +0200 | [diff] [blame] | 2 | #include "util.h" |
Frederic Weisbecker | 598357e | 2010-05-21 12:48:39 +0200 | [diff] [blame] | 3 | #include "build-id.h" |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 4 | #include "hist.h" |
Arnaldo Carvalho de Melo | 4e4f06e | 2009-12-14 13:10:39 -0200 | [diff] [blame] | 5 | #include "session.h" |
| 6 | #include "sort.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, |
| 26 | .order = ORDER_CALLEE |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 27 | }; |
| 28 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 29 | 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] | 30 | { |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 31 | return hists->col_len[col]; |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 32 | } |
| 33 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 34 | 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] | 35 | { |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 36 | hists->col_len[col] = len; |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 37 | } |
| 38 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 39 | 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] | 40 | { |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 41 | if (len > hists__col_len(hists, col)) { |
| 42 | hists__set_col_len(hists, col, len); |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 43 | return true; |
| 44 | } |
| 45 | return false; |
| 46 | } |
| 47 | |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 48 | void hists__reset_col_len(struct hists *hists) |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 49 | { |
| 50 | enum hist_column col; |
| 51 | |
| 52 | for (col = 0; col < HISTC_NR_COLS; ++col) |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 53 | hists__set_col_len(hists, col, 0); |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 54 | } |
| 55 | |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 56 | static void hists__set_unres_dso_col_len(struct hists *hists, int dso) |
| 57 | { |
| 58 | const unsigned int unresolved_col_width = BITS_PER_LONG / 4; |
| 59 | |
| 60 | if (hists__col_len(hists, dso) < unresolved_col_width && |
| 61 | !symbol_conf.col_width_list_str && !symbol_conf.field_sep && |
| 62 | !symbol_conf.dso_list) |
| 63 | hists__set_col_len(hists, dso, unresolved_col_width); |
| 64 | } |
| 65 | |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 66 | 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] | 67 | { |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 68 | const unsigned int unresolved_col_width = BITS_PER_LONG / 4; |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 69 | u16 len; |
| 70 | |
| 71 | if (h->ms.sym) |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 72 | hists__new_col_len(hists, HISTC_SYMBOL, h->ms.sym->namelen + 4); |
| 73 | else |
| 74 | hists__set_unres_dso_col_len(hists, HISTC_DSO); |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 75 | |
| 76 | len = thread__comm_len(h->thread); |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 77 | if (hists__new_col_len(hists, HISTC_COMM, len)) |
| 78 | hists__set_col_len(hists, HISTC_THREAD, len + 6); |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 79 | |
| 80 | if (h->ms.map) { |
| 81 | len = dso__name_len(h->ms.map->dso); |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 82 | hists__new_col_len(hists, HISTC_DSO, len); |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 83 | } |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 84 | |
| 85 | if (h->branch_info) { |
| 86 | int symlen; |
| 87 | /* |
| 88 | * +4 accounts for '[x] ' priv level info |
| 89 | * +2 account of 0x prefix on raw addresses |
| 90 | */ |
| 91 | if (h->branch_info->from.sym) { |
| 92 | symlen = (int)h->branch_info->from.sym->namelen + 4; |
| 93 | hists__new_col_len(hists, HISTC_SYMBOL_FROM, symlen); |
| 94 | |
| 95 | symlen = dso__name_len(h->branch_info->from.map->dso); |
| 96 | hists__new_col_len(hists, HISTC_DSO_FROM, symlen); |
| 97 | } else { |
| 98 | symlen = unresolved_col_width + 4 + 2; |
| 99 | hists__new_col_len(hists, HISTC_SYMBOL_FROM, symlen); |
| 100 | hists__set_unres_dso_col_len(hists, HISTC_DSO_FROM); |
| 101 | } |
| 102 | |
| 103 | if (h->branch_info->to.sym) { |
| 104 | symlen = (int)h->branch_info->to.sym->namelen + 4; |
| 105 | hists__new_col_len(hists, HISTC_SYMBOL_TO, symlen); |
| 106 | |
| 107 | symlen = dso__name_len(h->branch_info->to.map->dso); |
| 108 | hists__new_col_len(hists, HISTC_DSO_TO, symlen); |
| 109 | } else { |
| 110 | symlen = unresolved_col_width + 4 + 2; |
| 111 | hists__new_col_len(hists, HISTC_SYMBOL_TO, symlen); |
| 112 | hists__set_unres_dso_col_len(hists, HISTC_DSO_TO); |
| 113 | } |
| 114 | } |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 115 | } |
| 116 | |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 117 | void hists__output_recalc_col_len(struct hists *hists, int max_rows) |
| 118 | { |
| 119 | struct rb_node *next = rb_first(&hists->entries); |
| 120 | struct hist_entry *n; |
| 121 | int row = 0; |
| 122 | |
| 123 | hists__reset_col_len(hists); |
| 124 | |
| 125 | while (next && row++ < max_rows) { |
| 126 | n = rb_entry(next, struct hist_entry, rb_node); |
| 127 | if (!n->filtered) |
| 128 | hists__calc_col_len(hists, n); |
| 129 | next = rb_next(&n->rb_node); |
| 130 | } |
| 131 | } |
| 132 | |
Arnaldo Carvalho de Melo | 12c1427 | 2012-01-04 12:27:03 -0200 | [diff] [blame] | 133 | static void hist_entry__add_cpumode_period(struct hist_entry *he, |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 134 | unsigned int cpumode, u64 period) |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 135 | { |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 136 | switch (cpumode) { |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 137 | case PERF_RECORD_MISC_KERNEL: |
Arnaldo Carvalho de Melo | 12c1427 | 2012-01-04 12:27:03 -0200 | [diff] [blame] | 138 | he->period_sys += period; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 139 | break; |
| 140 | case PERF_RECORD_MISC_USER: |
Arnaldo Carvalho de Melo | 12c1427 | 2012-01-04 12:27:03 -0200 | [diff] [blame] | 141 | he->period_us += period; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 142 | break; |
| 143 | case PERF_RECORD_MISC_GUEST_KERNEL: |
Arnaldo Carvalho de Melo | 12c1427 | 2012-01-04 12:27:03 -0200 | [diff] [blame] | 144 | he->period_guest_sys += period; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 145 | break; |
| 146 | case PERF_RECORD_MISC_GUEST_USER: |
Arnaldo Carvalho de Melo | 12c1427 | 2012-01-04 12:27:03 -0200 | [diff] [blame] | 147 | he->period_guest_us += period; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 148 | break; |
| 149 | default: |
| 150 | break; |
| 151 | } |
| 152 | } |
| 153 | |
Arnaldo Carvalho de Melo | ab81f3fd | 2011-10-05 19:16:15 -0300 | [diff] [blame] | 154 | static void hist_entry__decay(struct hist_entry *he) |
| 155 | { |
| 156 | he->period = (he->period * 7) / 8; |
| 157 | he->nr_events = (he->nr_events * 7) / 8; |
| 158 | } |
| 159 | |
| 160 | static bool hists__decay_entry(struct hists *hists, struct hist_entry *he) |
| 161 | { |
Arnaldo Carvalho de Melo | c64550c | 2011-10-20 06:45:44 -0200 | [diff] [blame] | 162 | u64 prev_period = he->period; |
| 163 | |
| 164 | if (prev_period == 0) |
Arnaldo Carvalho de Melo | df71d95 | 2011-10-13 08:01:33 -0300 | [diff] [blame] | 165 | return true; |
Arnaldo Carvalho de Melo | c64550c | 2011-10-20 06:45:44 -0200 | [diff] [blame] | 166 | |
Arnaldo Carvalho de Melo | ab81f3fd | 2011-10-05 19:16:15 -0300 | [diff] [blame] | 167 | hist_entry__decay(he); |
Arnaldo Carvalho de Melo | c64550c | 2011-10-20 06:45:44 -0200 | [diff] [blame] | 168 | |
| 169 | if (!he->filtered) |
| 170 | hists->stats.total_period -= prev_period - he->period; |
| 171 | |
Arnaldo Carvalho de Melo | ab81f3fd | 2011-10-05 19:16:15 -0300 | [diff] [blame] | 172 | return he->period == 0; |
| 173 | } |
| 174 | |
Arnaldo Carvalho de Melo | b079d4e | 2011-10-17 09:05:04 -0200 | [diff] [blame] | 175 | static void __hists__decay_entries(struct hists *hists, bool zap_user, |
| 176 | bool zap_kernel, bool threaded) |
Arnaldo Carvalho de Melo | ab81f3fd | 2011-10-05 19:16:15 -0300 | [diff] [blame] | 177 | { |
| 178 | struct rb_node *next = rb_first(&hists->entries); |
| 179 | struct hist_entry *n; |
| 180 | |
| 181 | while (next) { |
| 182 | n = rb_entry(next, struct hist_entry, rb_node); |
| 183 | next = rb_next(&n->rb_node); |
Arnaldo Carvalho de Melo | df71d95 | 2011-10-13 08:01:33 -0300 | [diff] [blame] | 184 | /* |
| 185 | * We may be annotating this, for instance, so keep it here in |
| 186 | * case some it gets new samples, we'll eventually free it when |
| 187 | * the user stops browsing and it agains gets fully decayed. |
| 188 | */ |
Arnaldo Carvalho de Melo | b079d4e | 2011-10-17 09:05:04 -0200 | [diff] [blame] | 189 | if (((zap_user && n->level == '.') || |
| 190 | (zap_kernel && n->level != '.') || |
| 191 | hists__decay_entry(hists, n)) && |
| 192 | !n->used) { |
Arnaldo Carvalho de Melo | ab81f3fd | 2011-10-05 19:16:15 -0300 | [diff] [blame] | 193 | rb_erase(&n->rb_node, &hists->entries); |
| 194 | |
Arnaldo Carvalho de Melo | e345fa1 | 2011-10-13 09:06:54 -0300 | [diff] [blame] | 195 | if (sort__need_collapse || threaded) |
Arnaldo Carvalho de Melo | ab81f3fd | 2011-10-05 19:16:15 -0300 | [diff] [blame] | 196 | rb_erase(&n->rb_node_in, &hists->entries_collapsed); |
| 197 | |
| 198 | hist_entry__free(n); |
| 199 | --hists->nr_entries; |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | |
Arnaldo Carvalho de Melo | b079d4e | 2011-10-17 09:05:04 -0200 | [diff] [blame] | 204 | void hists__decay_entries(struct hists *hists, bool zap_user, bool zap_kernel) |
Arnaldo Carvalho de Melo | e345fa1 | 2011-10-13 09:06:54 -0300 | [diff] [blame] | 205 | { |
Arnaldo Carvalho de Melo | b079d4e | 2011-10-17 09:05:04 -0200 | [diff] [blame] | 206 | return __hists__decay_entries(hists, zap_user, zap_kernel, false); |
Arnaldo Carvalho de Melo | e345fa1 | 2011-10-13 09:06:54 -0300 | [diff] [blame] | 207 | } |
| 208 | |
Arnaldo Carvalho de Melo | b079d4e | 2011-10-17 09:05:04 -0200 | [diff] [blame] | 209 | void hists__decay_entries_threaded(struct hists *hists, |
| 210 | bool zap_user, bool zap_kernel) |
Arnaldo Carvalho de Melo | e345fa1 | 2011-10-13 09:06:54 -0300 | [diff] [blame] | 211 | { |
Arnaldo Carvalho de Melo | b079d4e | 2011-10-17 09:05:04 -0200 | [diff] [blame] | 212 | return __hists__decay_entries(hists, zap_user, zap_kernel, true); |
Arnaldo Carvalho de Melo | e345fa1 | 2011-10-13 09:06:54 -0300 | [diff] [blame] | 213 | } |
| 214 | |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 215 | /* |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 216 | * histogram, sorted on item, collects periods |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 217 | */ |
| 218 | |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 219 | static struct hist_entry *hist_entry__new(struct hist_entry *template) |
| 220 | { |
Frederic Weisbecker | d2009c5 | 2010-08-22 20:05:22 +0200 | [diff] [blame] | 221 | size_t callchain_size = symbol_conf.use_callchain ? sizeof(struct callchain_root) : 0; |
Arnaldo Carvalho de Melo | 12c1427 | 2012-01-04 12:27:03 -0200 | [diff] [blame] | 222 | struct hist_entry *he = malloc(sizeof(*he) + callchain_size); |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 223 | |
Arnaldo Carvalho de Melo | 12c1427 | 2012-01-04 12:27:03 -0200 | [diff] [blame] | 224 | if (he != NULL) { |
| 225 | *he = *template; |
| 226 | he->nr_events = 1; |
| 227 | if (he->ms.map) |
| 228 | he->ms.map->referenced = true; |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 229 | if (symbol_conf.use_callchain) |
Arnaldo Carvalho de Melo | 12c1427 | 2012-01-04 12:27:03 -0200 | [diff] [blame] | 230 | callchain_init(he->callchain); |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 231 | } |
| 232 | |
Arnaldo Carvalho de Melo | 12c1427 | 2012-01-04 12:27:03 -0200 | [diff] [blame] | 233 | return he; |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 234 | } |
| 235 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 236 | static 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] | 237 | { |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 238 | if (!h->filtered) { |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 239 | hists__calc_col_len(hists, h); |
| 240 | ++hists->nr_entries; |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 241 | hists->stats.total_period += h->period; |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 242 | } |
Arnaldo Carvalho de Melo | fefb0b9 | 2010-05-10 13:57:51 -0300 | [diff] [blame] | 243 | } |
| 244 | |
Arnaldo Carvalho de Melo | 7a007ca | 2010-07-21 09:19:41 -0300 | [diff] [blame] | 245 | static u8 symbol__parent_filter(const struct symbol *parent) |
| 246 | { |
| 247 | if (symbol_conf.exclude_other && parent == NULL) |
| 248 | return 1 << HIST_FILTER__PARENT; |
| 249 | return 0; |
| 250 | } |
| 251 | |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 252 | static struct hist_entry *add_hist_entry(struct hists *hists, |
| 253 | struct hist_entry *entry, |
Arnaldo Carvalho de Melo | 1c02c4d | 2010-05-10 13:04:11 -0300 | [diff] [blame] | 254 | struct addr_location *al, |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 255 | u64 period) |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 256 | { |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 257 | struct rb_node **p; |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 258 | struct rb_node *parent = NULL; |
| 259 | struct hist_entry *he; |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 260 | int cmp; |
| 261 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 262 | pthread_mutex_lock(&hists->lock); |
| 263 | |
| 264 | p = &hists->entries_in->rb_node; |
| 265 | |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 266 | while (*p != NULL) { |
| 267 | parent = *p; |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 268 | he = rb_entry(parent, struct hist_entry, rb_node_in); |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 269 | |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 270 | cmp = hist_entry__cmp(entry, he); |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 271 | |
| 272 | if (!cmp) { |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 273 | he->period += period; |
| 274 | ++he->nr_events; |
David Miller | 63fa471 | 2012-03-27 03:14:18 -0400 | [diff] [blame] | 275 | |
| 276 | /* If the map of an existing hist_entry has |
| 277 | * become out-of-date due to an exec() or |
| 278 | * similar, update it. Otherwise we will |
| 279 | * mis-adjust symbol addresses when computing |
| 280 | * the history counter to increment. |
| 281 | */ |
| 282 | if (he->ms.map != entry->ms.map) { |
| 283 | he->ms.map = entry->ms.map; |
| 284 | if (he->ms.map) |
| 285 | he->ms.map->referenced = true; |
| 286 | } |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 287 | goto out; |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | if (cmp < 0) |
| 291 | p = &(*p)->rb_left; |
| 292 | else |
| 293 | p = &(*p)->rb_right; |
| 294 | } |
| 295 | |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 296 | he = hist_entry__new(entry); |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 297 | if (!he) |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 298 | goto out_unlock; |
| 299 | |
| 300 | rb_link_node(&he->rb_node_in, parent, p); |
| 301 | rb_insert_color(&he->rb_node_in, hists->entries_in); |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 302 | out: |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 303 | hist_entry__add_cpumode_period(he, al->cpumode, period); |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 304 | out_unlock: |
| 305 | pthread_mutex_unlock(&hists->lock); |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 306 | return he; |
| 307 | } |
| 308 | |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 309 | struct hist_entry *__hists__add_branch_entry(struct hists *self, |
| 310 | struct addr_location *al, |
| 311 | struct symbol *sym_parent, |
| 312 | struct branch_info *bi, |
| 313 | u64 period) |
| 314 | { |
| 315 | struct hist_entry entry = { |
| 316 | .thread = al->thread, |
| 317 | .ms = { |
| 318 | .map = bi->to.map, |
| 319 | .sym = bi->to.sym, |
| 320 | }, |
| 321 | .cpu = al->cpu, |
| 322 | .ip = bi->to.addr, |
| 323 | .level = al->level, |
| 324 | .period = period, |
| 325 | .parent = sym_parent, |
| 326 | .filtered = symbol__parent_filter(sym_parent), |
| 327 | .branch_info = bi, |
| 328 | }; |
| 329 | |
| 330 | return add_hist_entry(self, &entry, al, period); |
| 331 | } |
| 332 | |
| 333 | struct hist_entry *__hists__add_entry(struct hists *self, |
| 334 | struct addr_location *al, |
| 335 | struct symbol *sym_parent, u64 period) |
| 336 | { |
| 337 | struct hist_entry entry = { |
| 338 | .thread = al->thread, |
| 339 | .ms = { |
| 340 | .map = al->map, |
| 341 | .sym = al->sym, |
| 342 | }, |
| 343 | .cpu = al->cpu, |
| 344 | .ip = al->addr, |
| 345 | .level = al->level, |
| 346 | .period = period, |
| 347 | .parent = sym_parent, |
| 348 | .filtered = symbol__parent_filter(sym_parent), |
| 349 | }; |
| 350 | |
| 351 | return add_hist_entry(self, &entry, al, period); |
| 352 | } |
| 353 | |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 354 | int64_t |
| 355 | hist_entry__cmp(struct hist_entry *left, struct hist_entry *right) |
| 356 | { |
| 357 | struct sort_entry *se; |
| 358 | int64_t cmp = 0; |
| 359 | |
| 360 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
Frederic Weisbecker | fcd1498 | 2010-04-14 19:11:29 +0200 | [diff] [blame] | 361 | cmp = se->se_cmp(left, right); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 362 | if (cmp) |
| 363 | break; |
| 364 | } |
| 365 | |
| 366 | return cmp; |
| 367 | } |
| 368 | |
| 369 | int64_t |
| 370 | hist_entry__collapse(struct hist_entry *left, struct hist_entry *right) |
| 371 | { |
| 372 | struct sort_entry *se; |
| 373 | int64_t cmp = 0; |
| 374 | |
| 375 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
| 376 | int64_t (*f)(struct hist_entry *, struct hist_entry *); |
| 377 | |
Frederic Weisbecker | fcd1498 | 2010-04-14 19:11:29 +0200 | [diff] [blame] | 378 | f = se->se_collapse ?: se->se_cmp; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 379 | |
| 380 | cmp = f(left, right); |
| 381 | if (cmp) |
| 382 | break; |
| 383 | } |
| 384 | |
| 385 | return cmp; |
| 386 | } |
| 387 | |
| 388 | void hist_entry__free(struct hist_entry *he) |
| 389 | { |
| 390 | free(he); |
| 391 | } |
| 392 | |
| 393 | /* |
| 394 | * collapse the histogram |
| 395 | */ |
| 396 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame^] | 397 | static bool hists__collapse_insert_entry(struct hists *hists __maybe_unused, |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 398 | struct rb_root *root, |
| 399 | struct hist_entry *he) |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 400 | { |
Arnaldo Carvalho de Melo | b9bf089 | 2009-12-14 11:37:11 -0200 | [diff] [blame] | 401 | struct rb_node **p = &root->rb_node; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 402 | struct rb_node *parent = NULL; |
| 403 | struct hist_entry *iter; |
| 404 | int64_t cmp; |
| 405 | |
| 406 | while (*p != NULL) { |
| 407 | parent = *p; |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 408 | iter = rb_entry(parent, struct hist_entry, rb_node_in); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 409 | |
| 410 | cmp = hist_entry__collapse(iter, he); |
| 411 | |
| 412 | if (!cmp) { |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 413 | iter->period += he->period; |
Stephane Eranian | e39622c | 2011-10-03 11:38:15 +0200 | [diff] [blame] | 414 | iter->nr_events += he->nr_events; |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 415 | if (symbol_conf.use_callchain) { |
Namhyung Kim | 4726064 | 2012-05-31 14:43:26 +0900 | [diff] [blame] | 416 | callchain_cursor_reset(&callchain_cursor); |
| 417 | callchain_merge(&callchain_cursor, |
| 418 | iter->callchain, |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 419 | he->callchain); |
| 420 | } |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 421 | hist_entry__free(he); |
Arnaldo Carvalho de Melo | fefb0b9 | 2010-05-10 13:57:51 -0300 | [diff] [blame] | 422 | return false; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | if (cmp < 0) |
| 426 | p = &(*p)->rb_left; |
| 427 | else |
| 428 | p = &(*p)->rb_right; |
| 429 | } |
| 430 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 431 | rb_link_node(&he->rb_node_in, parent, p); |
| 432 | rb_insert_color(&he->rb_node_in, root); |
Arnaldo Carvalho de Melo | fefb0b9 | 2010-05-10 13:57:51 -0300 | [diff] [blame] | 433 | return true; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 434 | } |
| 435 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 436 | static struct rb_root *hists__get_rotate_entries_in(struct hists *hists) |
| 437 | { |
| 438 | struct rb_root *root; |
| 439 | |
| 440 | pthread_mutex_lock(&hists->lock); |
| 441 | |
| 442 | root = hists->entries_in; |
| 443 | if (++hists->entries_in > &hists->entries_in_array[1]) |
| 444 | hists->entries_in = &hists->entries_in_array[0]; |
| 445 | |
| 446 | pthread_mutex_unlock(&hists->lock); |
| 447 | |
| 448 | return root; |
| 449 | } |
| 450 | |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 451 | static void hists__apply_filters(struct hists *hists, struct hist_entry *he) |
| 452 | { |
| 453 | hists__filter_entry_by_dso(hists, he); |
| 454 | hists__filter_entry_by_thread(hists, he); |
Namhyung Kim | e94d53e | 2012-03-16 17:50:51 +0900 | [diff] [blame] | 455 | hists__filter_entry_by_symbol(hists, he); |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 456 | } |
| 457 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 458 | static void __hists__collapse_resort(struct hists *hists, bool threaded) |
| 459 | { |
| 460 | struct rb_root *root; |
| 461 | struct rb_node *next; |
| 462 | struct hist_entry *n; |
| 463 | |
| 464 | if (!sort__need_collapse && !threaded) |
| 465 | return; |
| 466 | |
| 467 | root = hists__get_rotate_entries_in(hists); |
| 468 | next = rb_first(root); |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 469 | |
| 470 | while (next) { |
| 471 | n = rb_entry(next, struct hist_entry, rb_node_in); |
| 472 | next = rb_next(&n->rb_node_in); |
| 473 | |
| 474 | rb_erase(&n->rb_node_in, root); |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 475 | if (hists__collapse_insert_entry(hists, &hists->entries_collapsed, n)) { |
| 476 | /* |
| 477 | * If it wasn't combined with one of the entries already |
| 478 | * collapsed, we need to apply the filters that may have |
| 479 | * been set by, say, the hist_browser. |
| 480 | */ |
| 481 | hists__apply_filters(hists, n); |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 482 | } |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 483 | } |
| 484 | } |
| 485 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 486 | void hists__collapse_resort(struct hists *hists) |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 487 | { |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 488 | return __hists__collapse_resort(hists, false); |
| 489 | } |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 490 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 491 | void hists__collapse_resort_threaded(struct hists *hists) |
| 492 | { |
| 493 | return __hists__collapse_resort(hists, true); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | /* |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 497 | * reverse the map, sort on period. |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 498 | */ |
| 499 | |
Arnaldo Carvalho de Melo | 1c02c4d | 2010-05-10 13:04:11 -0300 | [diff] [blame] | 500 | static void __hists__insert_output_entry(struct rb_root *entries, |
| 501 | struct hist_entry *he, |
| 502 | u64 min_callchain_hits) |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 503 | { |
Arnaldo Carvalho de Melo | 1c02c4d | 2010-05-10 13:04:11 -0300 | [diff] [blame] | 504 | struct rb_node **p = &entries->rb_node; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 505 | struct rb_node *parent = NULL; |
| 506 | struct hist_entry *iter; |
| 507 | |
Arnaldo Carvalho de Melo | d599db3 | 2009-12-15 20:04:42 -0200 | [diff] [blame] | 508 | if (symbol_conf.use_callchain) |
Arnaldo Carvalho de Melo | b9fb930 | 2010-04-02 09:50:42 -0300 | [diff] [blame] | 509 | callchain_param.sort(&he->sorted_chain, he->callchain, |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 510 | min_callchain_hits, &callchain_param); |
| 511 | |
| 512 | while (*p != NULL) { |
| 513 | parent = *p; |
| 514 | iter = rb_entry(parent, struct hist_entry, rb_node); |
| 515 | |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 516 | if (he->period > iter->period) |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 517 | p = &(*p)->rb_left; |
| 518 | else |
| 519 | p = &(*p)->rb_right; |
| 520 | } |
| 521 | |
| 522 | rb_link_node(&he->rb_node, parent, p); |
Arnaldo Carvalho de Melo | 1c02c4d | 2010-05-10 13:04:11 -0300 | [diff] [blame] | 523 | rb_insert_color(&he->rb_node, entries); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 524 | } |
| 525 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 526 | static void __hists__output_resort(struct hists *hists, bool threaded) |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 527 | { |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 528 | struct rb_root *root; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 529 | struct rb_node *next; |
| 530 | struct hist_entry *n; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 531 | u64 min_callchain_hits; |
| 532 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 533 | min_callchain_hits = hists->stats.total_period * (callchain_param.min_percent / 100); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 534 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 535 | if (sort__need_collapse || threaded) |
| 536 | root = &hists->entries_collapsed; |
| 537 | else |
| 538 | root = hists->entries_in; |
| 539 | |
| 540 | next = rb_first(root); |
| 541 | hists->entries = RB_ROOT; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 542 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 543 | hists->nr_entries = 0; |
Arnaldo Carvalho de Melo | 7928631 | 2011-10-27 09:19:48 -0200 | [diff] [blame] | 544 | hists->stats.total_period = 0; |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 545 | hists__reset_col_len(hists); |
Arnaldo Carvalho de Melo | fefb0b9 | 2010-05-10 13:57:51 -0300 | [diff] [blame] | 546 | |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 547 | while (next) { |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 548 | n = rb_entry(next, struct hist_entry, rb_node_in); |
| 549 | next = rb_next(&n->rb_node_in); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 550 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 551 | __hists__insert_output_entry(&hists->entries, n, min_callchain_hits); |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 552 | hists__inc_nr_entries(hists, n); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 553 | } |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 554 | } |
Arnaldo Carvalho de Melo | b9bf089 | 2009-12-14 11:37:11 -0200 | [diff] [blame] | 555 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 556 | void hists__output_resort(struct hists *hists) |
| 557 | { |
| 558 | return __hists__output_resort(hists, false); |
| 559 | } |
| 560 | |
| 561 | void hists__output_resort_threaded(struct hists *hists) |
| 562 | { |
| 563 | return __hists__output_resort(hists, true); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 564 | } |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 565 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 566 | 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] | 567 | enum hist_filter filter) |
| 568 | { |
| 569 | h->filtered &= ~(1 << filter); |
| 570 | if (h->filtered) |
| 571 | return; |
| 572 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 573 | ++hists->nr_entries; |
Arnaldo Carvalho de Melo | 0f0cbf7 | 2010-07-26 17:13:40 -0300 | [diff] [blame] | 574 | if (h->ms.unfolded) |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 575 | hists->nr_entries += h->nr_rows; |
Arnaldo Carvalho de Melo | 0f0cbf7 | 2010-07-26 17:13:40 -0300 | [diff] [blame] | 576 | h->row_offset = 0; |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 577 | hists->stats.total_period += h->period; |
| 578 | hists->stats.nr_events[PERF_RECORD_SAMPLE] += h->nr_events; |
Arnaldo Carvalho de Melo | cc5edb0 | 2010-07-16 12:35:07 -0300 | [diff] [blame] | 579 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 580 | hists__calc_col_len(hists, h); |
Arnaldo Carvalho de Melo | cc5edb0 | 2010-07-16 12:35:07 -0300 | [diff] [blame] | 581 | } |
| 582 | |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 583 | |
| 584 | static bool hists__filter_entry_by_dso(struct hists *hists, |
| 585 | struct hist_entry *he) |
| 586 | { |
| 587 | if (hists->dso_filter != NULL && |
| 588 | (he->ms.map == NULL || he->ms.map->dso != hists->dso_filter)) { |
| 589 | he->filtered |= (1 << HIST_FILTER__DSO); |
| 590 | return true; |
| 591 | } |
| 592 | |
| 593 | return false; |
| 594 | } |
| 595 | |
Arnaldo Carvalho de Melo | d7b76f0 | 2011-10-18 19:07:34 -0200 | [diff] [blame] | 596 | void hists__filter_by_dso(struct hists *hists) |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 597 | { |
| 598 | struct rb_node *nd; |
| 599 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 600 | hists->nr_entries = hists->stats.total_period = 0; |
| 601 | hists->stats.nr_events[PERF_RECORD_SAMPLE] = 0; |
| 602 | hists__reset_col_len(hists); |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 603 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 604 | 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] | 605 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
| 606 | |
| 607 | if (symbol_conf.exclude_other && !h->parent) |
| 608 | continue; |
| 609 | |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 610 | if (hists__filter_entry_by_dso(hists, h)) |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 611 | continue; |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 612 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 613 | hists__remove_entry_filter(hists, h, HIST_FILTER__DSO); |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 614 | } |
| 615 | } |
| 616 | |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 617 | static bool hists__filter_entry_by_thread(struct hists *hists, |
| 618 | struct hist_entry *he) |
| 619 | { |
| 620 | if (hists->thread_filter != NULL && |
| 621 | he->thread != hists->thread_filter) { |
| 622 | he->filtered |= (1 << HIST_FILTER__THREAD); |
| 623 | return true; |
| 624 | } |
| 625 | |
| 626 | return false; |
| 627 | } |
| 628 | |
Arnaldo Carvalho de Melo | d7b76f0 | 2011-10-18 19:07:34 -0200 | [diff] [blame] | 629 | void hists__filter_by_thread(struct hists *hists) |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 630 | { |
| 631 | struct rb_node *nd; |
| 632 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 633 | hists->nr_entries = hists->stats.total_period = 0; |
| 634 | hists->stats.nr_events[PERF_RECORD_SAMPLE] = 0; |
| 635 | hists__reset_col_len(hists); |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 636 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 637 | 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] | 638 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
| 639 | |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 640 | if (hists__filter_entry_by_thread(hists, h)) |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 641 | continue; |
Arnaldo Carvalho de Melo | cc5edb0 | 2010-07-16 12:35:07 -0300 | [diff] [blame] | 642 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 643 | hists__remove_entry_filter(hists, h, HIST_FILTER__THREAD); |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 644 | } |
| 645 | } |
Arnaldo Carvalho de Melo | ef7b93a | 2010-05-11 23:18:06 -0300 | [diff] [blame] | 646 | |
Namhyung Kim | e94d53e | 2012-03-16 17:50:51 +0900 | [diff] [blame] | 647 | static bool hists__filter_entry_by_symbol(struct hists *hists, |
| 648 | struct hist_entry *he) |
| 649 | { |
| 650 | if (hists->symbol_filter_str != NULL && |
| 651 | (!he->ms.sym || strstr(he->ms.sym->name, |
| 652 | hists->symbol_filter_str) == NULL)) { |
| 653 | he->filtered |= (1 << HIST_FILTER__SYMBOL); |
| 654 | return true; |
| 655 | } |
| 656 | |
| 657 | return false; |
| 658 | } |
| 659 | |
| 660 | void hists__filter_by_symbol(struct hists *hists) |
| 661 | { |
| 662 | struct rb_node *nd; |
| 663 | |
| 664 | hists->nr_entries = hists->stats.total_period = 0; |
| 665 | hists->stats.nr_events[PERF_RECORD_SAMPLE] = 0; |
| 666 | hists__reset_col_len(hists); |
| 667 | |
| 668 | for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) { |
| 669 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
| 670 | |
| 671 | if (hists__filter_entry_by_symbol(hists, h)) |
| 672 | continue; |
| 673 | |
| 674 | hists__remove_entry_filter(hists, h, HIST_FILTER__SYMBOL); |
| 675 | } |
| 676 | } |
| 677 | |
Arnaldo Carvalho de Melo | 2f525d0 | 2011-02-04 13:43:24 -0200 | [diff] [blame] | 678 | int hist_entry__inc_addr_samples(struct hist_entry *he, int evidx, u64 ip) |
Arnaldo Carvalho de Melo | ef7b93a | 2010-05-11 23:18:06 -0300 | [diff] [blame] | 679 | { |
Arnaldo Carvalho de Melo | 2f525d0 | 2011-02-04 13:43:24 -0200 | [diff] [blame] | 680 | return symbol__inc_addr_samples(he->ms.sym, he->ms.map, evidx, ip); |
Arnaldo Carvalho de Melo | ef7b93a | 2010-05-11 23:18:06 -0300 | [diff] [blame] | 681 | } |
| 682 | |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 683 | int hist_entry__annotate(struct hist_entry *he, size_t privsize) |
Arnaldo Carvalho de Melo | ef7b93a | 2010-05-11 23:18:06 -0300 | [diff] [blame] | 684 | { |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 685 | return symbol__annotate(he->ms.sym, he->ms.map, privsize); |
Arnaldo Carvalho de Melo | ef7b93a | 2010-05-11 23:18:06 -0300 | [diff] [blame] | 686 | } |
Arnaldo Carvalho de Melo | c8446b9 | 2010-05-14 10:36:42 -0300 | [diff] [blame] | 687 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 688 | void hists__inc_nr_events(struct hists *hists, u32 type) |
Arnaldo Carvalho de Melo | c8446b9 | 2010-05-14 10:36:42 -0300 | [diff] [blame] | 689 | { |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 690 | ++hists->stats.nr_events[0]; |
| 691 | ++hists->stats.nr_events[type]; |
Arnaldo Carvalho de Melo | c8446b9 | 2010-05-14 10:36:42 -0300 | [diff] [blame] | 692 | } |