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" |
Arnaldo Carvalho de Melo | 2a1731f | 2014-10-10 15:49:21 -0300 | [diff] [blame] | 6 | #include "evlist.h" |
Namhyung Kim | 29d720e | 2013-01-22 18:09:33 +0900 | [diff] [blame] | 7 | #include "evsel.h" |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 8 | #include "annotate.h" |
Namhyung Kim | 740b97f | 2014-12-22 13:44:10 +0900 | [diff] [blame] | 9 | #include "ui/progress.h" |
Arnaldo Carvalho de Melo | 9b33827 | 2009-12-16 14:31:49 -0200 | [diff] [blame] | 10 | #include <math.h> |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 11 | |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 12 | static bool hists__filter_entry_by_dso(struct hists *hists, |
| 13 | struct hist_entry *he); |
| 14 | static bool hists__filter_entry_by_thread(struct hists *hists, |
| 15 | struct hist_entry *he); |
Namhyung Kim | e94d53e | 2012-03-16 17:50:51 +0900 | [diff] [blame] | 16 | static bool hists__filter_entry_by_symbol(struct hists *hists, |
| 17 | struct hist_entry *he); |
Kan Liang | 21394d9 | 2015-09-04 10:45:44 -0400 | [diff] [blame] | 18 | static bool hists__filter_entry_by_socket(struct hists *hists, |
| 19 | struct hist_entry *he); |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 20 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 21 | 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] | 22 | { |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 23 | return hists->col_len[col]; |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 24 | } |
| 25 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 26 | 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] | 27 | { |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 28 | hists->col_len[col] = len; |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 29 | } |
| 30 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 31 | 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] | 32 | { |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 33 | if (len > hists__col_len(hists, col)) { |
| 34 | hists__set_col_len(hists, col, len); |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 35 | return true; |
| 36 | } |
| 37 | return false; |
| 38 | } |
| 39 | |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 40 | void hists__reset_col_len(struct hists *hists) |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 41 | { |
| 42 | enum hist_column col; |
| 43 | |
| 44 | for (col = 0; col < HISTC_NR_COLS; ++col) |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 45 | hists__set_col_len(hists, col, 0); |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 46 | } |
| 47 | |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 48 | static void hists__set_unres_dso_col_len(struct hists *hists, int dso) |
| 49 | { |
| 50 | const unsigned int unresolved_col_width = BITS_PER_LONG / 4; |
| 51 | |
| 52 | if (hists__col_len(hists, dso) < unresolved_col_width && |
| 53 | !symbol_conf.col_width_list_str && !symbol_conf.field_sep && |
| 54 | !symbol_conf.dso_list) |
| 55 | hists__set_col_len(hists, dso, unresolved_col_width); |
| 56 | } |
| 57 | |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 58 | 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] | 59 | { |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 60 | const unsigned int unresolved_col_width = BITS_PER_LONG / 4; |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 61 | int symlen; |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 62 | u16 len; |
| 63 | |
Namhyung Kim | ded19d5 | 2013-04-01 20:35:19 +0900 | [diff] [blame] | 64 | /* |
| 65 | * +4 accounts for '[x] ' priv level info |
| 66 | * +2 accounts for 0x prefix on raw addresses |
| 67 | * +3 accounts for ' y ' symtab origin info |
| 68 | */ |
| 69 | if (h->ms.sym) { |
| 70 | symlen = h->ms.sym->namelen + 4; |
| 71 | if (verbose) |
| 72 | symlen += BITS_PER_LONG / 4 + 2 + 3; |
| 73 | hists__new_col_len(hists, HISTC_SYMBOL, symlen); |
| 74 | } else { |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 75 | symlen = unresolved_col_width + 4 + 2; |
| 76 | hists__new_col_len(hists, HISTC_SYMBOL, symlen); |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 77 | hists__set_unres_dso_col_len(hists, HISTC_DSO); |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 78 | } |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 79 | |
| 80 | len = thread__comm_len(h->thread); |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 81 | if (hists__new_col_len(hists, HISTC_COMM, len)) |
| 82 | hists__set_col_len(hists, HISTC_THREAD, len + 6); |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 83 | |
| 84 | if (h->ms.map) { |
| 85 | len = dso__name_len(h->ms.map->dso); |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 86 | hists__new_col_len(hists, HISTC_DSO, len); |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 87 | } |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 88 | |
Namhyung Kim | cb99374 | 2012-12-27 18:11:42 +0900 | [diff] [blame] | 89 | if (h->parent) |
| 90 | hists__new_col_len(hists, HISTC_PARENT, h->parent->namelen); |
| 91 | |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 92 | if (h->branch_info) { |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 93 | if (h->branch_info->from.sym) { |
| 94 | symlen = (int)h->branch_info->from.sym->namelen + 4; |
Namhyung Kim | ded19d5 | 2013-04-01 20:35:19 +0900 | [diff] [blame] | 95 | if (verbose) |
| 96 | symlen += BITS_PER_LONG / 4 + 2 + 3; |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 97 | hists__new_col_len(hists, HISTC_SYMBOL_FROM, symlen); |
| 98 | |
| 99 | symlen = dso__name_len(h->branch_info->from.map->dso); |
| 100 | hists__new_col_len(hists, HISTC_DSO_FROM, symlen); |
| 101 | } else { |
| 102 | symlen = unresolved_col_width + 4 + 2; |
| 103 | hists__new_col_len(hists, HISTC_SYMBOL_FROM, symlen); |
| 104 | hists__set_unres_dso_col_len(hists, HISTC_DSO_FROM); |
| 105 | } |
| 106 | |
| 107 | if (h->branch_info->to.sym) { |
| 108 | symlen = (int)h->branch_info->to.sym->namelen + 4; |
Namhyung Kim | ded19d5 | 2013-04-01 20:35:19 +0900 | [diff] [blame] | 109 | if (verbose) |
| 110 | symlen += BITS_PER_LONG / 4 + 2 + 3; |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 111 | hists__new_col_len(hists, HISTC_SYMBOL_TO, symlen); |
| 112 | |
| 113 | symlen = dso__name_len(h->branch_info->to.map->dso); |
| 114 | hists__new_col_len(hists, HISTC_DSO_TO, symlen); |
| 115 | } else { |
| 116 | symlen = unresolved_col_width + 4 + 2; |
| 117 | hists__new_col_len(hists, HISTC_SYMBOL_TO, symlen); |
| 118 | hists__set_unres_dso_col_len(hists, HISTC_DSO_TO); |
| 119 | } |
| 120 | } |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 121 | |
| 122 | if (h->mem_info) { |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 123 | if (h->mem_info->daddr.sym) { |
| 124 | symlen = (int)h->mem_info->daddr.sym->namelen + 4 |
| 125 | + unresolved_col_width + 2; |
| 126 | hists__new_col_len(hists, HISTC_MEM_DADDR_SYMBOL, |
| 127 | symlen); |
Don Zickus | 9b32ba7 | 2014-06-01 15:38:29 +0200 | [diff] [blame] | 128 | hists__new_col_len(hists, HISTC_MEM_DCACHELINE, |
| 129 | symlen + 1); |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 130 | } else { |
| 131 | symlen = unresolved_col_width + 4 + 2; |
| 132 | hists__new_col_len(hists, HISTC_MEM_DADDR_SYMBOL, |
| 133 | symlen); |
| 134 | } |
Jiri Olsa | b34b3bf | 2015-10-05 20:06:08 +0200 | [diff] [blame] | 135 | |
| 136 | if (h->mem_info->iaddr.sym) { |
| 137 | symlen = (int)h->mem_info->iaddr.sym->namelen + 4 |
| 138 | + unresolved_col_width + 2; |
| 139 | hists__new_col_len(hists, HISTC_MEM_IADDR_SYMBOL, |
| 140 | symlen); |
| 141 | } else { |
| 142 | symlen = unresolved_col_width + 4 + 2; |
| 143 | hists__new_col_len(hists, HISTC_MEM_IADDR_SYMBOL, |
| 144 | symlen); |
| 145 | } |
| 146 | |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 147 | if (h->mem_info->daddr.map) { |
| 148 | symlen = dso__name_len(h->mem_info->daddr.map->dso); |
| 149 | hists__new_col_len(hists, HISTC_MEM_DADDR_DSO, |
| 150 | symlen); |
| 151 | } else { |
| 152 | symlen = unresolved_col_width + 4 + 2; |
| 153 | hists__set_unres_dso_col_len(hists, HISTC_MEM_DADDR_DSO); |
| 154 | } |
| 155 | } else { |
| 156 | symlen = unresolved_col_width + 4 + 2; |
| 157 | hists__new_col_len(hists, HISTC_MEM_DADDR_SYMBOL, symlen); |
Jiri Olsa | b34b3bf | 2015-10-05 20:06:08 +0200 | [diff] [blame] | 158 | hists__new_col_len(hists, HISTC_MEM_IADDR_SYMBOL, symlen); |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 159 | hists__set_unres_dso_col_len(hists, HISTC_MEM_DADDR_DSO); |
| 160 | } |
| 161 | |
Arnaldo Carvalho de Melo | a4978ec | 2015-09-09 12:14:00 -0300 | [diff] [blame] | 162 | hists__new_col_len(hists, HISTC_CPU, 3); |
Kan Liang | 2e7ea3a | 2015-09-04 10:45:43 -0400 | [diff] [blame] | 163 | hists__new_col_len(hists, HISTC_SOCKET, 6); |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 164 | hists__new_col_len(hists, HISTC_MEM_LOCKED, 6); |
| 165 | hists__new_col_len(hists, HISTC_MEM_TLB, 22); |
| 166 | hists__new_col_len(hists, HISTC_MEM_SNOOP, 12); |
| 167 | hists__new_col_len(hists, HISTC_MEM_LVL, 21 + 3); |
| 168 | hists__new_col_len(hists, HISTC_LOCAL_WEIGHT, 12); |
| 169 | hists__new_col_len(hists, HISTC_GLOBAL_WEIGHT, 12); |
Andi Kleen | 475eeab | 2013-09-20 07:40:43 -0700 | [diff] [blame] | 170 | |
Arnaldo Carvalho de Melo | e8e6d37 | 2015-08-10 16:53:54 -0300 | [diff] [blame] | 171 | if (h->srcline) |
| 172 | hists__new_col_len(hists, HISTC_SRCLINE, strlen(h->srcline)); |
| 173 | |
Andi Kleen | 31191a8 | 2015-08-07 15:54:24 -0700 | [diff] [blame] | 174 | if (h->srcfile) |
| 175 | hists__new_col_len(hists, HISTC_SRCFILE, strlen(h->srcfile)); |
| 176 | |
Andi Kleen | 475eeab | 2013-09-20 07:40:43 -0700 | [diff] [blame] | 177 | if (h->transaction) |
| 178 | hists__new_col_len(hists, HISTC_TRANSACTION, |
| 179 | hist_entry__transaction_len()); |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 180 | } |
| 181 | |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 182 | void hists__output_recalc_col_len(struct hists *hists, int max_rows) |
| 183 | { |
| 184 | struct rb_node *next = rb_first(&hists->entries); |
| 185 | struct hist_entry *n; |
| 186 | int row = 0; |
| 187 | |
| 188 | hists__reset_col_len(hists); |
| 189 | |
| 190 | while (next && row++ < max_rows) { |
| 191 | n = rb_entry(next, struct hist_entry, rb_node); |
| 192 | if (!n->filtered) |
| 193 | hists__calc_col_len(hists, n); |
| 194 | next = rb_next(&n->rb_node); |
| 195 | } |
| 196 | } |
| 197 | |
Namhyung Kim | f39056f | 2014-01-14 14:25:37 +0900 | [diff] [blame] | 198 | static void he_stat__add_cpumode_period(struct he_stat *he_stat, |
| 199 | unsigned int cpumode, u64 period) |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 200 | { |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 201 | switch (cpumode) { |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 202 | case PERF_RECORD_MISC_KERNEL: |
Namhyung Kim | f39056f | 2014-01-14 14:25:37 +0900 | [diff] [blame] | 203 | he_stat->period_sys += period; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 204 | break; |
| 205 | case PERF_RECORD_MISC_USER: |
Namhyung Kim | f39056f | 2014-01-14 14:25:37 +0900 | [diff] [blame] | 206 | he_stat->period_us += period; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 207 | break; |
| 208 | case PERF_RECORD_MISC_GUEST_KERNEL: |
Namhyung Kim | f39056f | 2014-01-14 14:25:37 +0900 | [diff] [blame] | 209 | he_stat->period_guest_sys += period; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 210 | break; |
| 211 | case PERF_RECORD_MISC_GUEST_USER: |
Namhyung Kim | f39056f | 2014-01-14 14:25:37 +0900 | [diff] [blame] | 212 | he_stat->period_guest_us += period; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 213 | break; |
| 214 | default: |
| 215 | break; |
| 216 | } |
| 217 | } |
| 218 | |
Andi Kleen | 0548429 | 2013-01-24 16:10:29 +0100 | [diff] [blame] | 219 | static void he_stat__add_period(struct he_stat *he_stat, u64 period, |
| 220 | u64 weight) |
Namhyung Kim | 139c081 | 2012-10-04 21:49:43 +0900 | [diff] [blame] | 221 | { |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 222 | |
Namhyung Kim | 139c081 | 2012-10-04 21:49:43 +0900 | [diff] [blame] | 223 | he_stat->period += period; |
Andi Kleen | 0548429 | 2013-01-24 16:10:29 +0100 | [diff] [blame] | 224 | he_stat->weight += weight; |
Namhyung Kim | 139c081 | 2012-10-04 21:49:43 +0900 | [diff] [blame] | 225 | he_stat->nr_events += 1; |
| 226 | } |
| 227 | |
| 228 | static void he_stat__add_stat(struct he_stat *dest, struct he_stat *src) |
| 229 | { |
| 230 | dest->period += src->period; |
| 231 | dest->period_sys += src->period_sys; |
| 232 | dest->period_us += src->period_us; |
| 233 | dest->period_guest_sys += src->period_guest_sys; |
| 234 | dest->period_guest_us += src->period_guest_us; |
| 235 | dest->nr_events += src->nr_events; |
Andi Kleen | 0548429 | 2013-01-24 16:10:29 +0100 | [diff] [blame] | 236 | dest->weight += src->weight; |
Namhyung Kim | 139c081 | 2012-10-04 21:49:43 +0900 | [diff] [blame] | 237 | } |
| 238 | |
Namhyung Kim | f39056f | 2014-01-14 14:25:37 +0900 | [diff] [blame] | 239 | static void he_stat__decay(struct he_stat *he_stat) |
Arnaldo Carvalho de Melo | ab81f3f | 2011-10-05 19:16:15 -0300 | [diff] [blame] | 240 | { |
Namhyung Kim | f39056f | 2014-01-14 14:25:37 +0900 | [diff] [blame] | 241 | he_stat->period = (he_stat->period * 7) / 8; |
| 242 | he_stat->nr_events = (he_stat->nr_events * 7) / 8; |
Andi Kleen | 0548429 | 2013-01-24 16:10:29 +0100 | [diff] [blame] | 243 | /* XXX need decay for weight too? */ |
Arnaldo Carvalho de Melo | ab81f3f | 2011-10-05 19:16:15 -0300 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | static bool hists__decay_entry(struct hists *hists, struct hist_entry *he) |
| 247 | { |
Namhyung Kim | b24c28f | 2012-10-04 21:49:41 +0900 | [diff] [blame] | 248 | u64 prev_period = he->stat.period; |
Namhyung Kim | 3186b68 | 2014-04-22 13:44:23 +0900 | [diff] [blame] | 249 | u64 diff; |
Arnaldo Carvalho de Melo | c64550c | 2011-10-20 06:45:44 -0200 | [diff] [blame] | 250 | |
| 251 | if (prev_period == 0) |
Arnaldo Carvalho de Melo | df71d95 | 2011-10-13 08:01:33 -0300 | [diff] [blame] | 252 | return true; |
Arnaldo Carvalho de Melo | c64550c | 2011-10-20 06:45:44 -0200 | [diff] [blame] | 253 | |
Namhyung Kim | f39056f | 2014-01-14 14:25:37 +0900 | [diff] [blame] | 254 | he_stat__decay(&he->stat); |
Namhyung Kim | f8be1c8 | 2012-09-11 13:15:07 +0900 | [diff] [blame] | 255 | if (symbol_conf.cumulate_callchain) |
| 256 | he_stat__decay(he->stat_acc); |
Arnaldo Carvalho de Melo | c64550c | 2011-10-20 06:45:44 -0200 | [diff] [blame] | 257 | |
Namhyung Kim | 3186b68 | 2014-04-22 13:44:23 +0900 | [diff] [blame] | 258 | diff = prev_period - he->stat.period; |
| 259 | |
| 260 | hists->stats.total_period -= diff; |
Arnaldo Carvalho de Melo | c64550c | 2011-10-20 06:45:44 -0200 | [diff] [blame] | 261 | if (!he->filtered) |
Namhyung Kim | 3186b68 | 2014-04-22 13:44:23 +0900 | [diff] [blame] | 262 | hists->stats.total_non_filtered_period -= diff; |
Arnaldo Carvalho de Melo | c64550c | 2011-10-20 06:45:44 -0200 | [diff] [blame] | 263 | |
Namhyung Kim | b24c28f | 2012-10-04 21:49:41 +0900 | [diff] [blame] | 264 | return he->stat.period == 0; |
Arnaldo Carvalho de Melo | ab81f3f | 2011-10-05 19:16:15 -0300 | [diff] [blame] | 265 | } |
| 266 | |
Arnaldo Carvalho de Melo | 956b65e | 2014-12-19 12:41:28 -0300 | [diff] [blame] | 267 | static void hists__delete_entry(struct hists *hists, struct hist_entry *he) |
| 268 | { |
| 269 | rb_erase(&he->rb_node, &hists->entries); |
| 270 | |
| 271 | if (sort__need_collapse) |
| 272 | rb_erase(&he->rb_node_in, &hists->entries_collapsed); |
Namhyung Kim | 61fa0e9 | 2015-12-10 16:53:20 +0900 | [diff] [blame] | 273 | else |
| 274 | rb_erase(&he->rb_node_in, hists->entries_in); |
Arnaldo Carvalho de Melo | 956b65e | 2014-12-19 12:41:28 -0300 | [diff] [blame] | 275 | |
| 276 | --hists->nr_entries; |
| 277 | if (!he->filtered) |
| 278 | --hists->nr_non_filtered_entries; |
| 279 | |
| 280 | hist_entry__delete(he); |
| 281 | } |
| 282 | |
Namhyung Kim | 3a5714f | 2013-05-14 11:09:01 +0900 | [diff] [blame] | 283 | void hists__decay_entries(struct hists *hists, bool zap_user, bool zap_kernel) |
Arnaldo Carvalho de Melo | ab81f3f | 2011-10-05 19:16:15 -0300 | [diff] [blame] | 284 | { |
| 285 | struct rb_node *next = rb_first(&hists->entries); |
| 286 | struct hist_entry *n; |
| 287 | |
| 288 | while (next) { |
| 289 | n = rb_entry(next, struct hist_entry, rb_node); |
| 290 | next = rb_next(&n->rb_node); |
Arnaldo Carvalho de Melo | b079d4e | 2011-10-17 09:05:04 -0200 | [diff] [blame] | 291 | if (((zap_user && n->level == '.') || |
| 292 | (zap_kernel && n->level != '.') || |
Arnaldo Carvalho de Melo | 4c47f4f | 2015-03-17 17:18:58 -0300 | [diff] [blame] | 293 | hists__decay_entry(hists, n))) { |
Arnaldo Carvalho de Melo | 956b65e | 2014-12-19 12:41:28 -0300 | [diff] [blame] | 294 | hists__delete_entry(hists, n); |
Arnaldo Carvalho de Melo | ab81f3f | 2011-10-05 19:16:15 -0300 | [diff] [blame] | 295 | } |
| 296 | } |
| 297 | } |
| 298 | |
Namhyung Kim | 701937b | 2014-08-12 17:16:05 +0900 | [diff] [blame] | 299 | void hists__delete_entries(struct hists *hists) |
| 300 | { |
| 301 | struct rb_node *next = rb_first(&hists->entries); |
| 302 | struct hist_entry *n; |
| 303 | |
| 304 | while (next) { |
| 305 | n = rb_entry(next, struct hist_entry, rb_node); |
| 306 | next = rb_next(&n->rb_node); |
| 307 | |
Arnaldo Carvalho de Melo | 956b65e | 2014-12-19 12:41:28 -0300 | [diff] [blame] | 308 | hists__delete_entry(hists, n); |
Namhyung Kim | 701937b | 2014-08-12 17:16:05 +0900 | [diff] [blame] | 309 | } |
| 310 | } |
| 311 | |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 312 | /* |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 313 | * histogram, sorted on item, collects periods |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 314 | */ |
| 315 | |
Namhyung Kim | a0b51af | 2012-09-11 13:34:27 +0900 | [diff] [blame] | 316 | static struct hist_entry *hist_entry__new(struct hist_entry *template, |
| 317 | bool sample_self) |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 318 | { |
Namhyung Kim | f8be1c8 | 2012-09-11 13:15:07 +0900 | [diff] [blame] | 319 | size_t callchain_size = 0; |
| 320 | struct hist_entry *he; |
| 321 | |
Namhyung Kim | 82aa019 | 2014-12-22 13:44:14 +0900 | [diff] [blame] | 322 | if (symbol_conf.use_callchain) |
Namhyung Kim | f8be1c8 | 2012-09-11 13:15:07 +0900 | [diff] [blame] | 323 | callchain_size = sizeof(struct callchain_root); |
| 324 | |
| 325 | he = zalloc(sizeof(*he) + callchain_size); |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 326 | |
Arnaldo Carvalho de Melo | 12c1427 | 2012-01-04 12:27:03 -0200 | [diff] [blame] | 327 | if (he != NULL) { |
| 328 | *he = *template; |
Namhyung Kim | c4b3535 | 2012-10-04 21:49:42 +0900 | [diff] [blame] | 329 | |
Namhyung Kim | f8be1c8 | 2012-09-11 13:15:07 +0900 | [diff] [blame] | 330 | if (symbol_conf.cumulate_callchain) { |
| 331 | he->stat_acc = malloc(sizeof(he->stat)); |
| 332 | if (he->stat_acc == NULL) { |
| 333 | free(he); |
| 334 | return NULL; |
| 335 | } |
| 336 | memcpy(he->stat_acc, &he->stat, sizeof(he->stat)); |
Namhyung Kim | a0b51af | 2012-09-11 13:34:27 +0900 | [diff] [blame] | 337 | if (!sample_self) |
| 338 | memset(&he->stat, 0, sizeof(he->stat)); |
Namhyung Kim | f8be1c8 | 2012-09-11 13:15:07 +0900 | [diff] [blame] | 339 | } |
| 340 | |
Arnaldo Carvalho de Melo | 5c24b67 | 2015-06-15 23:29:51 -0300 | [diff] [blame] | 341 | map__get(he->ms.map); |
Stephane Eranian | 3cf0cb1 | 2013-01-14 15:02:45 +0100 | [diff] [blame] | 342 | |
| 343 | if (he->branch_info) { |
Namhyung Kim | 26353a6 | 2013-04-01 20:35:17 +0900 | [diff] [blame] | 344 | /* |
| 345 | * This branch info is (a part of) allocated from |
Arnaldo Carvalho de Melo | 644f2df | 2014-01-22 13:15:36 -0300 | [diff] [blame] | 346 | * sample__resolve_bstack() and will be freed after |
Namhyung Kim | 26353a6 | 2013-04-01 20:35:17 +0900 | [diff] [blame] | 347 | * adding new entries. So we need to save a copy. |
| 348 | */ |
| 349 | he->branch_info = malloc(sizeof(*he->branch_info)); |
| 350 | if (he->branch_info == NULL) { |
Arnaldo Carvalho de Melo | 5c24b67 | 2015-06-15 23:29:51 -0300 | [diff] [blame] | 351 | map__zput(he->ms.map); |
Namhyung Kim | f8be1c8 | 2012-09-11 13:15:07 +0900 | [diff] [blame] | 352 | free(he->stat_acc); |
Namhyung Kim | 26353a6 | 2013-04-01 20:35:17 +0900 | [diff] [blame] | 353 | free(he); |
| 354 | return NULL; |
| 355 | } |
| 356 | |
| 357 | memcpy(he->branch_info, template->branch_info, |
| 358 | sizeof(*he->branch_info)); |
| 359 | |
Arnaldo Carvalho de Melo | 5c24b67 | 2015-06-15 23:29:51 -0300 | [diff] [blame] | 360 | map__get(he->branch_info->from.map); |
| 361 | map__get(he->branch_info->to.map); |
Stephane Eranian | 3cf0cb1 | 2013-01-14 15:02:45 +0100 | [diff] [blame] | 362 | } |
| 363 | |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 364 | if (he->mem_info) { |
Arnaldo Carvalho de Melo | 5c24b67 | 2015-06-15 23:29:51 -0300 | [diff] [blame] | 365 | map__get(he->mem_info->iaddr.map); |
| 366 | map__get(he->mem_info->daddr.map); |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 367 | } |
| 368 | |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 369 | if (symbol_conf.use_callchain) |
Arnaldo Carvalho de Melo | 12c1427 | 2012-01-04 12:27:03 -0200 | [diff] [blame] | 370 | callchain_init(he->callchain); |
Arnaldo Carvalho de Melo | b821c73 | 2012-10-25 14:42:45 -0200 | [diff] [blame] | 371 | |
Namhyung Kim | 7239283 | 2015-12-24 11:16:17 +0900 | [diff] [blame^] | 372 | if (he->raw_data) { |
| 373 | he->raw_data = memdup(he->raw_data, he->raw_size); |
| 374 | |
| 375 | if (he->raw_data == NULL) { |
| 376 | map__put(he->ms.map); |
| 377 | if (he->branch_info) { |
| 378 | map__put(he->branch_info->from.map); |
| 379 | map__put(he->branch_info->to.map); |
| 380 | free(he->branch_info); |
| 381 | } |
| 382 | if (he->mem_info) { |
| 383 | map__put(he->mem_info->iaddr.map); |
| 384 | map__put(he->mem_info->daddr.map); |
| 385 | } |
| 386 | free(he->stat_acc); |
| 387 | free(he); |
| 388 | return NULL; |
| 389 | } |
| 390 | } |
Arnaldo Carvalho de Melo | b821c73 | 2012-10-25 14:42:45 -0200 | [diff] [blame] | 391 | INIT_LIST_HEAD(&he->pairs.node); |
Arnaldo Carvalho de Melo | f3b623b | 2015-03-02 22:21:35 -0300 | [diff] [blame] | 392 | thread__get(he->thread); |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 393 | } |
| 394 | |
Arnaldo Carvalho de Melo | 12c1427 | 2012-01-04 12:27:03 -0200 | [diff] [blame] | 395 | return he; |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 396 | } |
| 397 | |
Arnaldo Carvalho de Melo | 7a007ca | 2010-07-21 09:19:41 -0300 | [diff] [blame] | 398 | static u8 symbol__parent_filter(const struct symbol *parent) |
| 399 | { |
| 400 | if (symbol_conf.exclude_other && parent == NULL) |
| 401 | return 1 << HIST_FILTER__PARENT; |
| 402 | return 0; |
| 403 | } |
| 404 | |
Arnaldo Carvalho de Melo | e7e0efc | 2015-05-19 11:31:22 -0300 | [diff] [blame] | 405 | static struct hist_entry *hists__findnew_entry(struct hists *hists, |
| 406 | struct hist_entry *entry, |
| 407 | struct addr_location *al, |
| 408 | bool sample_self) |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 409 | { |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 410 | struct rb_node **p; |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 411 | struct rb_node *parent = NULL; |
| 412 | struct hist_entry *he; |
Andi Kleen | 354cc40 | 2013-10-01 07:22:15 -0700 | [diff] [blame] | 413 | int64_t cmp; |
Namhyung Kim | f1cbf78 | 2013-12-18 14:21:11 +0900 | [diff] [blame] | 414 | u64 period = entry->stat.period; |
| 415 | u64 weight = entry->stat.weight; |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 416 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 417 | p = &hists->entries_in->rb_node; |
| 418 | |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 419 | while (*p != NULL) { |
| 420 | parent = *p; |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 421 | he = rb_entry(parent, struct hist_entry, rb_node_in); |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 422 | |
Namhyung Kim | 9afcf93 | 2012-12-10 17:29:54 +0900 | [diff] [blame] | 423 | /* |
| 424 | * Make sure that it receives arguments in a same order as |
| 425 | * hist_entry__collapse() so that we can use an appropriate |
| 426 | * function when searching an entry regardless which sort |
| 427 | * keys were used. |
| 428 | */ |
| 429 | cmp = hist_entry__cmp(he, entry); |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 430 | |
| 431 | if (!cmp) { |
Namhyung Kim | a0b51af | 2012-09-11 13:34:27 +0900 | [diff] [blame] | 432 | if (sample_self) |
| 433 | he_stat__add_period(&he->stat, period, weight); |
Namhyung Kim | f8be1c8 | 2012-09-11 13:15:07 +0900 | [diff] [blame] | 434 | if (symbol_conf.cumulate_callchain) |
| 435 | he_stat__add_period(he->stat_acc, period, weight); |
David Miller | 63fa471 | 2012-03-27 03:14:18 -0400 | [diff] [blame] | 436 | |
Namhyung Kim | ceb2acb | 2013-04-01 20:35:18 +0900 | [diff] [blame] | 437 | /* |
Arnaldo Carvalho de Melo | e80faac | 2014-01-22 13:05:06 -0300 | [diff] [blame] | 438 | * This mem info was allocated from sample__resolve_mem |
Namhyung Kim | ceb2acb | 2013-04-01 20:35:18 +0900 | [diff] [blame] | 439 | * and will not be used anymore. |
| 440 | */ |
Arnaldo Carvalho de Melo | 74cf249 | 2013-12-27 16:55:14 -0300 | [diff] [blame] | 441 | zfree(&entry->mem_info); |
Namhyung Kim | ceb2acb | 2013-04-01 20:35:18 +0900 | [diff] [blame] | 442 | |
David Miller | 63fa471 | 2012-03-27 03:14:18 -0400 | [diff] [blame] | 443 | /* If the map of an existing hist_entry has |
| 444 | * become out-of-date due to an exec() or |
| 445 | * similar, update it. Otherwise we will |
| 446 | * mis-adjust symbol addresses when computing |
| 447 | * the history counter to increment. |
| 448 | */ |
| 449 | if (he->ms.map != entry->ms.map) { |
Arnaldo Carvalho de Melo | 5c24b67 | 2015-06-15 23:29:51 -0300 | [diff] [blame] | 450 | map__put(he->ms.map); |
| 451 | he->ms.map = map__get(entry->ms.map); |
David Miller | 63fa471 | 2012-03-27 03:14:18 -0400 | [diff] [blame] | 452 | } |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 453 | goto out; |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | if (cmp < 0) |
| 457 | p = &(*p)->rb_left; |
| 458 | else |
| 459 | p = &(*p)->rb_right; |
| 460 | } |
| 461 | |
Namhyung Kim | a0b51af | 2012-09-11 13:34:27 +0900 | [diff] [blame] | 462 | he = hist_entry__new(entry, sample_self); |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 463 | if (!he) |
Namhyung Kim | 27a0dcb | 2013-05-14 11:09:02 +0900 | [diff] [blame] | 464 | return NULL; |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 465 | |
Namhyung Kim | 590cd34 | 2014-12-22 13:44:09 +0900 | [diff] [blame] | 466 | hists->nr_entries++; |
| 467 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 468 | rb_link_node(&he->rb_node_in, parent, p); |
| 469 | rb_insert_color(&he->rb_node_in, hists->entries_in); |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 470 | out: |
Namhyung Kim | a0b51af | 2012-09-11 13:34:27 +0900 | [diff] [blame] | 471 | if (sample_self) |
| 472 | he_stat__add_cpumode_period(&he->stat, al->cpumode, period); |
Namhyung Kim | f8be1c8 | 2012-09-11 13:15:07 +0900 | [diff] [blame] | 473 | if (symbol_conf.cumulate_callchain) |
| 474 | he_stat__add_cpumode_period(he->stat_acc, al->cpumode, period); |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 475 | return he; |
| 476 | } |
| 477 | |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 478 | struct hist_entry *__hists__add_entry(struct hists *hists, |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 479 | struct addr_location *al, |
Namhyung Kim | 41a4e6e | 2013-10-31 15:56:03 +0900 | [diff] [blame] | 480 | struct symbol *sym_parent, |
| 481 | struct branch_info *bi, |
| 482 | struct mem_info *mi, |
Namhyung Kim | fd36f3d | 2015-12-23 02:06:58 +0900 | [diff] [blame] | 483 | struct perf_sample *sample, |
Namhyung Kim | a0b51af | 2012-09-11 13:34:27 +0900 | [diff] [blame] | 484 | bool sample_self) |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 485 | { |
| 486 | struct hist_entry entry = { |
| 487 | .thread = al->thread, |
Namhyung Kim | 4dfced3 | 2013-09-13 16:28:57 +0900 | [diff] [blame] | 488 | .comm = thread__comm(al->thread), |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 489 | .ms = { |
| 490 | .map = al->map, |
| 491 | .sym = al->sym, |
| 492 | }, |
Kan Liang | 0c4c4de | 2015-09-04 10:45:42 -0400 | [diff] [blame] | 493 | .socket = al->socket, |
Don Zickus | 7365be5 | 2014-05-27 12:28:05 -0400 | [diff] [blame] | 494 | .cpu = al->cpu, |
| 495 | .cpumode = al->cpumode, |
| 496 | .ip = al->addr, |
| 497 | .level = al->level, |
Namhyung Kim | b24c28f | 2012-10-04 21:49:41 +0900 | [diff] [blame] | 498 | .stat = { |
Namhyung Kim | c4b3535 | 2012-10-04 21:49:42 +0900 | [diff] [blame] | 499 | .nr_events = 1, |
Namhyung Kim | fd36f3d | 2015-12-23 02:06:58 +0900 | [diff] [blame] | 500 | .period = sample->period, |
| 501 | .weight = sample->weight, |
Namhyung Kim | b24c28f | 2012-10-04 21:49:41 +0900 | [diff] [blame] | 502 | }, |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 503 | .parent = sym_parent, |
Namhyung Kim | 2c86c7c | 2014-03-17 18:18:54 -0300 | [diff] [blame] | 504 | .filtered = symbol__parent_filter(sym_parent) | al->filtered, |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 505 | .hists = hists, |
Namhyung Kim | 41a4e6e | 2013-10-31 15:56:03 +0900 | [diff] [blame] | 506 | .branch_info = bi, |
| 507 | .mem_info = mi, |
Namhyung Kim | fd36f3d | 2015-12-23 02:06:58 +0900 | [diff] [blame] | 508 | .transaction = sample->transaction, |
Namhyung Kim | 7239283 | 2015-12-24 11:16:17 +0900 | [diff] [blame^] | 509 | .raw_data = sample->raw_data, |
| 510 | .raw_size = sample->raw_size, |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 511 | }; |
| 512 | |
Arnaldo Carvalho de Melo | e7e0efc | 2015-05-19 11:31:22 -0300 | [diff] [blame] | 513 | return hists__findnew_entry(hists, &entry, al, sample_self); |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 514 | } |
| 515 | |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 516 | static int |
| 517 | iter_next_nop_entry(struct hist_entry_iter *iter __maybe_unused, |
| 518 | struct addr_location *al __maybe_unused) |
| 519 | { |
| 520 | return 0; |
| 521 | } |
| 522 | |
| 523 | static int |
| 524 | iter_add_next_nop_entry(struct hist_entry_iter *iter __maybe_unused, |
| 525 | struct addr_location *al __maybe_unused) |
| 526 | { |
| 527 | return 0; |
| 528 | } |
| 529 | |
| 530 | static int |
| 531 | iter_prepare_mem_entry(struct hist_entry_iter *iter, struct addr_location *al) |
| 532 | { |
| 533 | struct perf_sample *sample = iter->sample; |
| 534 | struct mem_info *mi; |
| 535 | |
| 536 | mi = sample__resolve_mem(sample, al); |
| 537 | if (mi == NULL) |
| 538 | return -ENOMEM; |
| 539 | |
| 540 | iter->priv = mi; |
| 541 | return 0; |
| 542 | } |
| 543 | |
| 544 | static int |
| 545 | iter_add_single_mem_entry(struct hist_entry_iter *iter, struct addr_location *al) |
| 546 | { |
| 547 | u64 cost; |
| 548 | struct mem_info *mi = iter->priv; |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 549 | struct hists *hists = evsel__hists(iter->evsel); |
Namhyung Kim | fd36f3d | 2015-12-23 02:06:58 +0900 | [diff] [blame] | 550 | struct perf_sample *sample = iter->sample; |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 551 | struct hist_entry *he; |
| 552 | |
| 553 | if (mi == NULL) |
| 554 | return -EINVAL; |
| 555 | |
Namhyung Kim | fd36f3d | 2015-12-23 02:06:58 +0900 | [diff] [blame] | 556 | cost = sample->weight; |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 557 | if (!cost) |
| 558 | cost = 1; |
| 559 | |
| 560 | /* |
| 561 | * must pass period=weight in order to get the correct |
| 562 | * sorting from hists__collapse_resort() which is solely |
| 563 | * based on periods. We want sorting be done on nr_events * weight |
| 564 | * and this is indirectly achieved by passing period=weight here |
| 565 | * and the he_stat__add_period() function. |
| 566 | */ |
Namhyung Kim | fd36f3d | 2015-12-23 02:06:58 +0900 | [diff] [blame] | 567 | sample->period = cost; |
| 568 | |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 569 | he = __hists__add_entry(hists, al, iter->parent, NULL, mi, |
Namhyung Kim | fd36f3d | 2015-12-23 02:06:58 +0900 | [diff] [blame] | 570 | sample, true); |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 571 | if (!he) |
| 572 | return -ENOMEM; |
| 573 | |
| 574 | iter->he = he; |
| 575 | return 0; |
| 576 | } |
| 577 | |
| 578 | static int |
Namhyung Kim | 9d3c02d | 2014-01-07 17:02:25 +0900 | [diff] [blame] | 579 | iter_finish_mem_entry(struct hist_entry_iter *iter, |
| 580 | struct addr_location *al __maybe_unused) |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 581 | { |
| 582 | struct perf_evsel *evsel = iter->evsel; |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 583 | struct hists *hists = evsel__hists(evsel); |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 584 | struct hist_entry *he = iter->he; |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 585 | int err = -EINVAL; |
| 586 | |
| 587 | if (he == NULL) |
| 588 | goto out; |
| 589 | |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 590 | hists__inc_nr_samples(hists, he->filtered); |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 591 | |
| 592 | err = hist_entry__append_callchain(he, iter->sample); |
| 593 | |
| 594 | out: |
| 595 | /* |
Arnaldo Carvalho de Melo | e7e0efc | 2015-05-19 11:31:22 -0300 | [diff] [blame] | 596 | * We don't need to free iter->priv (mem_info) here since the mem info |
| 597 | * was either already freed in hists__findnew_entry() or passed to a |
| 598 | * new hist entry by hist_entry__new(). |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 599 | */ |
| 600 | iter->priv = NULL; |
| 601 | |
| 602 | iter->he = NULL; |
| 603 | return err; |
| 604 | } |
| 605 | |
| 606 | static int |
| 607 | iter_prepare_branch_entry(struct hist_entry_iter *iter, struct addr_location *al) |
| 608 | { |
| 609 | struct branch_info *bi; |
| 610 | struct perf_sample *sample = iter->sample; |
| 611 | |
| 612 | bi = sample__resolve_bstack(sample, al); |
| 613 | if (!bi) |
| 614 | return -ENOMEM; |
| 615 | |
| 616 | iter->curr = 0; |
| 617 | iter->total = sample->branch_stack->nr; |
| 618 | |
| 619 | iter->priv = bi; |
| 620 | return 0; |
| 621 | } |
| 622 | |
| 623 | static int |
| 624 | iter_add_single_branch_entry(struct hist_entry_iter *iter __maybe_unused, |
| 625 | struct addr_location *al __maybe_unused) |
| 626 | { |
Namhyung Kim | 9d3c02d | 2014-01-07 17:02:25 +0900 | [diff] [blame] | 627 | /* to avoid calling callback function */ |
| 628 | iter->he = NULL; |
| 629 | |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 630 | return 0; |
| 631 | } |
| 632 | |
| 633 | static int |
| 634 | iter_next_branch_entry(struct hist_entry_iter *iter, struct addr_location *al) |
| 635 | { |
| 636 | struct branch_info *bi = iter->priv; |
| 637 | int i = iter->curr; |
| 638 | |
| 639 | if (bi == NULL) |
| 640 | return 0; |
| 641 | |
| 642 | if (iter->curr >= iter->total) |
| 643 | return 0; |
| 644 | |
| 645 | al->map = bi[i].to.map; |
| 646 | al->sym = bi[i].to.sym; |
| 647 | al->addr = bi[i].to.addr; |
| 648 | return 1; |
| 649 | } |
| 650 | |
| 651 | static int |
| 652 | iter_add_next_branch_entry(struct hist_entry_iter *iter, struct addr_location *al) |
| 653 | { |
Namhyung Kim | 9d3c02d | 2014-01-07 17:02:25 +0900 | [diff] [blame] | 654 | struct branch_info *bi; |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 655 | struct perf_evsel *evsel = iter->evsel; |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 656 | struct hists *hists = evsel__hists(evsel); |
Namhyung Kim | fd36f3d | 2015-12-23 02:06:58 +0900 | [diff] [blame] | 657 | struct perf_sample *sample = iter->sample; |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 658 | struct hist_entry *he = NULL; |
| 659 | int i = iter->curr; |
| 660 | int err = 0; |
| 661 | |
| 662 | bi = iter->priv; |
| 663 | |
| 664 | if (iter->hide_unresolved && !(bi[i].from.sym && bi[i].to.sym)) |
| 665 | goto out; |
| 666 | |
| 667 | /* |
| 668 | * The report shows the percentage of total branches captured |
| 669 | * and not events sampled. Thus we use a pseudo period of 1. |
| 670 | */ |
Namhyung Kim | fd36f3d | 2015-12-23 02:06:58 +0900 | [diff] [blame] | 671 | sample->period = 1; |
| 672 | sample->weight = bi->flags.cycles ? bi->flags.cycles : 1; |
| 673 | |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 674 | he = __hists__add_entry(hists, al, iter->parent, &bi[i], NULL, |
Namhyung Kim | fd36f3d | 2015-12-23 02:06:58 +0900 | [diff] [blame] | 675 | sample, true); |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 676 | if (he == NULL) |
| 677 | return -ENOMEM; |
| 678 | |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 679 | hists__inc_nr_samples(hists, he->filtered); |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 680 | |
| 681 | out: |
| 682 | iter->he = he; |
| 683 | iter->curr++; |
| 684 | return err; |
| 685 | } |
| 686 | |
| 687 | static int |
| 688 | iter_finish_branch_entry(struct hist_entry_iter *iter, |
| 689 | struct addr_location *al __maybe_unused) |
| 690 | { |
| 691 | zfree(&iter->priv); |
| 692 | iter->he = NULL; |
| 693 | |
| 694 | return iter->curr >= iter->total ? 0 : -1; |
| 695 | } |
| 696 | |
| 697 | static int |
| 698 | iter_prepare_normal_entry(struct hist_entry_iter *iter __maybe_unused, |
| 699 | struct addr_location *al __maybe_unused) |
| 700 | { |
| 701 | return 0; |
| 702 | } |
| 703 | |
| 704 | static int |
| 705 | iter_add_single_normal_entry(struct hist_entry_iter *iter, struct addr_location *al) |
| 706 | { |
| 707 | struct perf_evsel *evsel = iter->evsel; |
| 708 | struct perf_sample *sample = iter->sample; |
| 709 | struct hist_entry *he; |
| 710 | |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 711 | he = __hists__add_entry(evsel__hists(evsel), al, iter->parent, NULL, NULL, |
Namhyung Kim | fd36f3d | 2015-12-23 02:06:58 +0900 | [diff] [blame] | 712 | sample, true); |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 713 | if (he == NULL) |
| 714 | return -ENOMEM; |
| 715 | |
| 716 | iter->he = he; |
| 717 | return 0; |
| 718 | } |
| 719 | |
| 720 | static int |
Namhyung Kim | 9d3c02d | 2014-01-07 17:02:25 +0900 | [diff] [blame] | 721 | iter_finish_normal_entry(struct hist_entry_iter *iter, |
| 722 | struct addr_location *al __maybe_unused) |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 723 | { |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 724 | struct hist_entry *he = iter->he; |
| 725 | struct perf_evsel *evsel = iter->evsel; |
| 726 | struct perf_sample *sample = iter->sample; |
| 727 | |
| 728 | if (he == NULL) |
| 729 | return 0; |
| 730 | |
| 731 | iter->he = NULL; |
| 732 | |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 733 | hists__inc_nr_samples(evsel__hists(evsel), he->filtered); |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 734 | |
| 735 | return hist_entry__append_callchain(he, sample); |
| 736 | } |
| 737 | |
Namhyung Kim | 7a13aa2 | 2012-09-11 14:13:04 +0900 | [diff] [blame] | 738 | static int |
Adrian Hunter | 96b40f3 | 2015-09-25 16:15:47 +0300 | [diff] [blame] | 739 | iter_prepare_cumulative_entry(struct hist_entry_iter *iter, |
Namhyung Kim | 7a13aa2 | 2012-09-11 14:13:04 +0900 | [diff] [blame] | 740 | struct addr_location *al __maybe_unused) |
| 741 | { |
Namhyung Kim | b4d3c8b | 2013-10-31 10:05:29 +0900 | [diff] [blame] | 742 | struct hist_entry **he_cache; |
| 743 | |
Namhyung Kim | 7a13aa2 | 2012-09-11 14:13:04 +0900 | [diff] [blame] | 744 | callchain_cursor_commit(&callchain_cursor); |
Namhyung Kim | b4d3c8b | 2013-10-31 10:05:29 +0900 | [diff] [blame] | 745 | |
| 746 | /* |
| 747 | * This is for detecting cycles or recursions so that they're |
| 748 | * cumulated only one time to prevent entries more than 100% |
| 749 | * overhead. |
| 750 | */ |
Adrian Hunter | 96b40f3 | 2015-09-25 16:15:47 +0300 | [diff] [blame] | 751 | he_cache = malloc(sizeof(*he_cache) * (iter->max_stack + 1)); |
Namhyung Kim | b4d3c8b | 2013-10-31 10:05:29 +0900 | [diff] [blame] | 752 | if (he_cache == NULL) |
| 753 | return -ENOMEM; |
| 754 | |
| 755 | iter->priv = he_cache; |
| 756 | iter->curr = 0; |
| 757 | |
Namhyung Kim | 7a13aa2 | 2012-09-11 14:13:04 +0900 | [diff] [blame] | 758 | return 0; |
| 759 | } |
| 760 | |
| 761 | static int |
| 762 | iter_add_single_cumulative_entry(struct hist_entry_iter *iter, |
| 763 | struct addr_location *al) |
| 764 | { |
| 765 | struct perf_evsel *evsel = iter->evsel; |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 766 | struct hists *hists = evsel__hists(evsel); |
Namhyung Kim | 7a13aa2 | 2012-09-11 14:13:04 +0900 | [diff] [blame] | 767 | struct perf_sample *sample = iter->sample; |
Namhyung Kim | b4d3c8b | 2013-10-31 10:05:29 +0900 | [diff] [blame] | 768 | struct hist_entry **he_cache = iter->priv; |
Namhyung Kim | 7a13aa2 | 2012-09-11 14:13:04 +0900 | [diff] [blame] | 769 | struct hist_entry *he; |
| 770 | int err = 0; |
| 771 | |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 772 | he = __hists__add_entry(hists, al, iter->parent, NULL, NULL, |
Namhyung Kim | fd36f3d | 2015-12-23 02:06:58 +0900 | [diff] [blame] | 773 | sample, true); |
Namhyung Kim | 7a13aa2 | 2012-09-11 14:13:04 +0900 | [diff] [blame] | 774 | if (he == NULL) |
| 775 | return -ENOMEM; |
| 776 | |
| 777 | iter->he = he; |
Namhyung Kim | b4d3c8b | 2013-10-31 10:05:29 +0900 | [diff] [blame] | 778 | he_cache[iter->curr++] = he; |
Namhyung Kim | 7a13aa2 | 2012-09-11 14:13:04 +0900 | [diff] [blame] | 779 | |
Namhyung Kim | 82aa019 | 2014-12-22 13:44:14 +0900 | [diff] [blame] | 780 | hist_entry__append_callchain(he, sample); |
Namhyung Kim | be7f855 | 2013-12-26 17:44:10 +0900 | [diff] [blame] | 781 | |
| 782 | /* |
| 783 | * We need to re-initialize the cursor since callchain_append() |
| 784 | * advanced the cursor to the end. |
| 785 | */ |
| 786 | callchain_cursor_commit(&callchain_cursor); |
| 787 | |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 788 | hists__inc_nr_samples(hists, he->filtered); |
Namhyung Kim | 7a13aa2 | 2012-09-11 14:13:04 +0900 | [diff] [blame] | 789 | |
| 790 | return err; |
| 791 | } |
| 792 | |
| 793 | static int |
| 794 | iter_next_cumulative_entry(struct hist_entry_iter *iter, |
| 795 | struct addr_location *al) |
| 796 | { |
| 797 | struct callchain_cursor_node *node; |
| 798 | |
| 799 | node = callchain_cursor_current(&callchain_cursor); |
| 800 | if (node == NULL) |
| 801 | return 0; |
| 802 | |
Namhyung Kim | c7405d8 | 2013-10-31 13:58:30 +0900 | [diff] [blame] | 803 | return fill_callchain_info(al, node, iter->hide_unresolved); |
Namhyung Kim | 7a13aa2 | 2012-09-11 14:13:04 +0900 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | static int |
| 807 | iter_add_next_cumulative_entry(struct hist_entry_iter *iter, |
| 808 | struct addr_location *al) |
| 809 | { |
| 810 | struct perf_evsel *evsel = iter->evsel; |
| 811 | struct perf_sample *sample = iter->sample; |
Namhyung Kim | b4d3c8b | 2013-10-31 10:05:29 +0900 | [diff] [blame] | 812 | struct hist_entry **he_cache = iter->priv; |
Namhyung Kim | 7a13aa2 | 2012-09-11 14:13:04 +0900 | [diff] [blame] | 813 | struct hist_entry *he; |
Namhyung Kim | b4d3c8b | 2013-10-31 10:05:29 +0900 | [diff] [blame] | 814 | struct hist_entry he_tmp = { |
Arnaldo Carvalho de Melo | 5cef897 | 2015-08-10 15:45:55 -0300 | [diff] [blame] | 815 | .hists = evsel__hists(evsel), |
Namhyung Kim | b4d3c8b | 2013-10-31 10:05:29 +0900 | [diff] [blame] | 816 | .cpu = al->cpu, |
| 817 | .thread = al->thread, |
| 818 | .comm = thread__comm(al->thread), |
| 819 | .ip = al->addr, |
| 820 | .ms = { |
| 821 | .map = al->map, |
| 822 | .sym = al->sym, |
| 823 | }, |
| 824 | .parent = iter->parent, |
Namhyung Kim | 7239283 | 2015-12-24 11:16:17 +0900 | [diff] [blame^] | 825 | .raw_data = sample->raw_data, |
| 826 | .raw_size = sample->raw_size, |
Namhyung Kim | b4d3c8b | 2013-10-31 10:05:29 +0900 | [diff] [blame] | 827 | }; |
| 828 | int i; |
Namhyung Kim | be7f855 | 2013-12-26 17:44:10 +0900 | [diff] [blame] | 829 | struct callchain_cursor cursor; |
| 830 | |
| 831 | callchain_cursor_snapshot(&cursor, &callchain_cursor); |
| 832 | |
| 833 | callchain_cursor_advance(&callchain_cursor); |
Namhyung Kim | b4d3c8b | 2013-10-31 10:05:29 +0900 | [diff] [blame] | 834 | |
| 835 | /* |
| 836 | * Check if there's duplicate entries in the callchain. |
| 837 | * It's possible that it has cycles or recursive calls. |
| 838 | */ |
| 839 | for (i = 0; i < iter->curr; i++) { |
Namhyung Kim | 9d3c02d | 2014-01-07 17:02:25 +0900 | [diff] [blame] | 840 | if (hist_entry__cmp(he_cache[i], &he_tmp) == 0) { |
| 841 | /* to avoid calling callback function */ |
| 842 | iter->he = NULL; |
Namhyung Kim | b4d3c8b | 2013-10-31 10:05:29 +0900 | [diff] [blame] | 843 | return 0; |
Namhyung Kim | 9d3c02d | 2014-01-07 17:02:25 +0900 | [diff] [blame] | 844 | } |
Namhyung Kim | b4d3c8b | 2013-10-31 10:05:29 +0900 | [diff] [blame] | 845 | } |
Namhyung Kim | 7a13aa2 | 2012-09-11 14:13:04 +0900 | [diff] [blame] | 846 | |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 847 | he = __hists__add_entry(evsel__hists(evsel), al, iter->parent, NULL, NULL, |
Namhyung Kim | fd36f3d | 2015-12-23 02:06:58 +0900 | [diff] [blame] | 848 | sample, false); |
Namhyung Kim | 7a13aa2 | 2012-09-11 14:13:04 +0900 | [diff] [blame] | 849 | if (he == NULL) |
| 850 | return -ENOMEM; |
| 851 | |
| 852 | iter->he = he; |
Namhyung Kim | b4d3c8b | 2013-10-31 10:05:29 +0900 | [diff] [blame] | 853 | he_cache[iter->curr++] = he; |
Namhyung Kim | 7a13aa2 | 2012-09-11 14:13:04 +0900 | [diff] [blame] | 854 | |
Namhyung Kim | 82aa019 | 2014-12-22 13:44:14 +0900 | [diff] [blame] | 855 | if (symbol_conf.use_callchain) |
| 856 | callchain_append(he->callchain, &cursor, sample->period); |
Namhyung Kim | 7a13aa2 | 2012-09-11 14:13:04 +0900 | [diff] [blame] | 857 | return 0; |
| 858 | } |
| 859 | |
| 860 | static int |
| 861 | iter_finish_cumulative_entry(struct hist_entry_iter *iter, |
| 862 | struct addr_location *al __maybe_unused) |
| 863 | { |
Namhyung Kim | b4d3c8b | 2013-10-31 10:05:29 +0900 | [diff] [blame] | 864 | zfree(&iter->priv); |
Namhyung Kim | 7a13aa2 | 2012-09-11 14:13:04 +0900 | [diff] [blame] | 865 | iter->he = NULL; |
Namhyung Kim | b4d3c8b | 2013-10-31 10:05:29 +0900 | [diff] [blame] | 866 | |
Namhyung Kim | 7a13aa2 | 2012-09-11 14:13:04 +0900 | [diff] [blame] | 867 | return 0; |
| 868 | } |
| 869 | |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 870 | const struct hist_iter_ops hist_iter_mem = { |
| 871 | .prepare_entry = iter_prepare_mem_entry, |
| 872 | .add_single_entry = iter_add_single_mem_entry, |
| 873 | .next_entry = iter_next_nop_entry, |
| 874 | .add_next_entry = iter_add_next_nop_entry, |
| 875 | .finish_entry = iter_finish_mem_entry, |
| 876 | }; |
| 877 | |
| 878 | const struct hist_iter_ops hist_iter_branch = { |
| 879 | .prepare_entry = iter_prepare_branch_entry, |
| 880 | .add_single_entry = iter_add_single_branch_entry, |
| 881 | .next_entry = iter_next_branch_entry, |
| 882 | .add_next_entry = iter_add_next_branch_entry, |
| 883 | .finish_entry = iter_finish_branch_entry, |
| 884 | }; |
| 885 | |
| 886 | const struct hist_iter_ops hist_iter_normal = { |
| 887 | .prepare_entry = iter_prepare_normal_entry, |
| 888 | .add_single_entry = iter_add_single_normal_entry, |
| 889 | .next_entry = iter_next_nop_entry, |
| 890 | .add_next_entry = iter_add_next_nop_entry, |
| 891 | .finish_entry = iter_finish_normal_entry, |
| 892 | }; |
| 893 | |
Namhyung Kim | 7a13aa2 | 2012-09-11 14:13:04 +0900 | [diff] [blame] | 894 | const struct hist_iter_ops hist_iter_cumulative = { |
| 895 | .prepare_entry = iter_prepare_cumulative_entry, |
| 896 | .add_single_entry = iter_add_single_cumulative_entry, |
| 897 | .next_entry = iter_next_cumulative_entry, |
| 898 | .add_next_entry = iter_add_next_cumulative_entry, |
| 899 | .finish_entry = iter_finish_cumulative_entry, |
| 900 | }; |
| 901 | |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 902 | int hist_entry_iter__add(struct hist_entry_iter *iter, struct addr_location *al, |
Namhyung Kim | 9d3c02d | 2014-01-07 17:02:25 +0900 | [diff] [blame] | 903 | int max_stack_depth, void *arg) |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 904 | { |
| 905 | int err, err2; |
| 906 | |
Namhyung Kim | 063bd93 | 2015-05-19 17:04:10 +0900 | [diff] [blame] | 907 | err = sample__resolve_callchain(iter->sample, &iter->parent, |
| 908 | iter->evsel, al, max_stack_depth); |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 909 | if (err) |
| 910 | return err; |
| 911 | |
Adrian Hunter | 96b40f3 | 2015-09-25 16:15:47 +0300 | [diff] [blame] | 912 | iter->max_stack = max_stack_depth; |
| 913 | |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 914 | err = iter->ops->prepare_entry(iter, al); |
| 915 | if (err) |
| 916 | goto out; |
| 917 | |
| 918 | err = iter->ops->add_single_entry(iter, al); |
| 919 | if (err) |
| 920 | goto out; |
| 921 | |
Namhyung Kim | 9d3c02d | 2014-01-07 17:02:25 +0900 | [diff] [blame] | 922 | if (iter->he && iter->add_entry_cb) { |
| 923 | err = iter->add_entry_cb(iter, al, true, arg); |
| 924 | if (err) |
| 925 | goto out; |
| 926 | } |
| 927 | |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 928 | while (iter->ops->next_entry(iter, al)) { |
| 929 | err = iter->ops->add_next_entry(iter, al); |
| 930 | if (err) |
| 931 | break; |
Namhyung Kim | 9d3c02d | 2014-01-07 17:02:25 +0900 | [diff] [blame] | 932 | |
| 933 | if (iter->he && iter->add_entry_cb) { |
| 934 | err = iter->add_entry_cb(iter, al, false, arg); |
| 935 | if (err) |
| 936 | goto out; |
| 937 | } |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | out: |
| 941 | err2 = iter->ops->finish_entry(iter, al); |
| 942 | if (!err) |
| 943 | err = err2; |
| 944 | |
| 945 | return err; |
| 946 | } |
| 947 | |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 948 | int64_t |
| 949 | hist_entry__cmp(struct hist_entry *left, struct hist_entry *right) |
| 950 | { |
Namhyung Kim | 093f0ef3 | 2014-03-03 12:07:47 +0900 | [diff] [blame] | 951 | struct perf_hpp_fmt *fmt; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 952 | int64_t cmp = 0; |
| 953 | |
Namhyung Kim | 093f0ef3 | 2014-03-03 12:07:47 +0900 | [diff] [blame] | 954 | perf_hpp__for_each_sort_list(fmt) { |
Namhyung Kim | 87bbdf7 | 2015-01-08 09:45:46 +0900 | [diff] [blame] | 955 | cmp = fmt->cmp(fmt, left, right); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 956 | if (cmp) |
| 957 | break; |
| 958 | } |
| 959 | |
| 960 | return cmp; |
| 961 | } |
| 962 | |
| 963 | int64_t |
| 964 | hist_entry__collapse(struct hist_entry *left, struct hist_entry *right) |
| 965 | { |
Namhyung Kim | 093f0ef3 | 2014-03-03 12:07:47 +0900 | [diff] [blame] | 966 | struct perf_hpp_fmt *fmt; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 967 | int64_t cmp = 0; |
| 968 | |
Namhyung Kim | 093f0ef3 | 2014-03-03 12:07:47 +0900 | [diff] [blame] | 969 | perf_hpp__for_each_sort_list(fmt) { |
Namhyung Kim | 87bbdf7 | 2015-01-08 09:45:46 +0900 | [diff] [blame] | 970 | cmp = fmt->collapse(fmt, left, right); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 971 | if (cmp) |
| 972 | break; |
| 973 | } |
| 974 | |
| 975 | return cmp; |
| 976 | } |
| 977 | |
Arnaldo Carvalho de Melo | 6733d1b | 2014-12-19 12:31:40 -0300 | [diff] [blame] | 978 | void hist_entry__delete(struct hist_entry *he) |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 979 | { |
Arnaldo Carvalho de Melo | f3b623b | 2015-03-02 22:21:35 -0300 | [diff] [blame] | 980 | thread__zput(he->thread); |
Arnaldo Carvalho de Melo | 5c24b67 | 2015-06-15 23:29:51 -0300 | [diff] [blame] | 981 | map__zput(he->ms.map); |
| 982 | |
| 983 | if (he->branch_info) { |
| 984 | map__zput(he->branch_info->from.map); |
| 985 | map__zput(he->branch_info->to.map); |
| 986 | zfree(&he->branch_info); |
| 987 | } |
| 988 | |
| 989 | if (he->mem_info) { |
| 990 | map__zput(he->mem_info->iaddr.map); |
| 991 | map__zput(he->mem_info->daddr.map); |
| 992 | zfree(&he->mem_info); |
| 993 | } |
| 994 | |
Namhyung Kim | f8be1c8 | 2012-09-11 13:15:07 +0900 | [diff] [blame] | 995 | zfree(&he->stat_acc); |
Namhyung Kim | f048d54 | 2013-09-11 14:09:28 +0900 | [diff] [blame] | 996 | free_srcline(he->srcline); |
Andi Kleen | 31191a8 | 2015-08-07 15:54:24 -0700 | [diff] [blame] | 997 | if (he->srcfile && he->srcfile[0]) |
| 998 | free(he->srcfile); |
Namhyung Kim | d114960 | 2014-12-30 14:38:13 +0900 | [diff] [blame] | 999 | free_callchain(he->callchain); |
Namhyung Kim | 7239283 | 2015-12-24 11:16:17 +0900 | [diff] [blame^] | 1000 | free(he->raw_data); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1001 | free(he); |
| 1002 | } |
| 1003 | |
| 1004 | /* |
| 1005 | * collapse the histogram |
| 1006 | */ |
| 1007 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 1008 | static bool hists__collapse_insert_entry(struct hists *hists __maybe_unused, |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 1009 | struct rb_root *root, |
| 1010 | struct hist_entry *he) |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1011 | { |
Arnaldo Carvalho de Melo | b9bf089 | 2009-12-14 11:37:11 -0200 | [diff] [blame] | 1012 | struct rb_node **p = &root->rb_node; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1013 | struct rb_node *parent = NULL; |
| 1014 | struct hist_entry *iter; |
| 1015 | int64_t cmp; |
| 1016 | |
| 1017 | while (*p != NULL) { |
| 1018 | parent = *p; |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 1019 | iter = rb_entry(parent, struct hist_entry, rb_node_in); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1020 | |
| 1021 | cmp = hist_entry__collapse(iter, he); |
| 1022 | |
| 1023 | if (!cmp) { |
Namhyung Kim | 139c081 | 2012-10-04 21:49:43 +0900 | [diff] [blame] | 1024 | he_stat__add_stat(&iter->stat, &he->stat); |
Namhyung Kim | f8be1c8 | 2012-09-11 13:15:07 +0900 | [diff] [blame] | 1025 | if (symbol_conf.cumulate_callchain) |
| 1026 | he_stat__add_stat(iter->stat_acc, he->stat_acc); |
Namhyung Kim | 9ec6097 | 2012-09-26 16:47:28 +0900 | [diff] [blame] | 1027 | |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 1028 | if (symbol_conf.use_callchain) { |
Namhyung Kim | 4726064 | 2012-05-31 14:43:26 +0900 | [diff] [blame] | 1029 | callchain_cursor_reset(&callchain_cursor); |
| 1030 | callchain_merge(&callchain_cursor, |
| 1031 | iter->callchain, |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 1032 | he->callchain); |
| 1033 | } |
Arnaldo Carvalho de Melo | 6733d1b | 2014-12-19 12:31:40 -0300 | [diff] [blame] | 1034 | hist_entry__delete(he); |
Arnaldo Carvalho de Melo | fefb0b9 | 2010-05-10 13:57:51 -0300 | [diff] [blame] | 1035 | return false; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1036 | } |
| 1037 | |
| 1038 | if (cmp < 0) |
| 1039 | p = &(*p)->rb_left; |
| 1040 | else |
| 1041 | p = &(*p)->rb_right; |
| 1042 | } |
Namhyung Kim | 740b97f | 2014-12-22 13:44:10 +0900 | [diff] [blame] | 1043 | hists->nr_entries++; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1044 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 1045 | rb_link_node(&he->rb_node_in, parent, p); |
| 1046 | rb_insert_color(&he->rb_node_in, root); |
Arnaldo Carvalho de Melo | fefb0b9 | 2010-05-10 13:57:51 -0300 | [diff] [blame] | 1047 | return true; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1048 | } |
| 1049 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 1050 | static struct rb_root *hists__get_rotate_entries_in(struct hists *hists) |
| 1051 | { |
| 1052 | struct rb_root *root; |
| 1053 | |
| 1054 | pthread_mutex_lock(&hists->lock); |
| 1055 | |
| 1056 | root = hists->entries_in; |
| 1057 | if (++hists->entries_in > &hists->entries_in_array[1]) |
| 1058 | hists->entries_in = &hists->entries_in_array[0]; |
| 1059 | |
| 1060 | pthread_mutex_unlock(&hists->lock); |
| 1061 | |
| 1062 | return root; |
| 1063 | } |
| 1064 | |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 1065 | static void hists__apply_filters(struct hists *hists, struct hist_entry *he) |
| 1066 | { |
| 1067 | hists__filter_entry_by_dso(hists, he); |
| 1068 | hists__filter_entry_by_thread(hists, he); |
Namhyung Kim | e94d53e | 2012-03-16 17:50:51 +0900 | [diff] [blame] | 1069 | hists__filter_entry_by_symbol(hists, he); |
Kan Liang | 21394d9 | 2015-09-04 10:45:44 -0400 | [diff] [blame] | 1070 | hists__filter_entry_by_socket(hists, he); |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 1071 | } |
| 1072 | |
Namhyung Kim | c1fb565 | 2013-10-11 14:15:38 +0900 | [diff] [blame] | 1073 | 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] | 1074 | { |
| 1075 | struct rb_root *root; |
| 1076 | struct rb_node *next; |
| 1077 | struct hist_entry *n; |
| 1078 | |
Namhyung Kim | 3a5714f | 2013-05-14 11:09:01 +0900 | [diff] [blame] | 1079 | if (!sort__need_collapse) |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 1080 | return; |
| 1081 | |
Namhyung Kim | 740b97f | 2014-12-22 13:44:10 +0900 | [diff] [blame] | 1082 | hists->nr_entries = 0; |
| 1083 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 1084 | root = hists__get_rotate_entries_in(hists); |
Namhyung Kim | 740b97f | 2014-12-22 13:44:10 +0900 | [diff] [blame] | 1085 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 1086 | next = rb_first(root); |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 1087 | |
| 1088 | while (next) { |
Arnaldo Carvalho de Melo | 33e940a | 2013-09-17 16:34:28 -0300 | [diff] [blame] | 1089 | if (session_done()) |
| 1090 | break; |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 1091 | n = rb_entry(next, struct hist_entry, rb_node_in); |
| 1092 | next = rb_next(&n->rb_node_in); |
| 1093 | |
| 1094 | rb_erase(&n->rb_node_in, root); |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 1095 | if (hists__collapse_insert_entry(hists, &hists->entries_collapsed, n)) { |
| 1096 | /* |
| 1097 | * If it wasn't combined with one of the entries already |
| 1098 | * collapsed, we need to apply the filters that may have |
| 1099 | * been set by, say, the hist_browser. |
| 1100 | */ |
| 1101 | hists__apply_filters(hists, n); |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 1102 | } |
Namhyung Kim | c1fb565 | 2013-10-11 14:15:38 +0900 | [diff] [blame] | 1103 | if (prog) |
| 1104 | ui_progress__update(prog, 1); |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 1105 | } |
| 1106 | } |
| 1107 | |
Namhyung Kim | 043ca389 | 2014-03-03 14:18:00 +0900 | [diff] [blame] | 1108 | static int hist_entry__sort(struct hist_entry *a, struct hist_entry *b) |
Namhyung Kim | 29d720e | 2013-01-22 18:09:33 +0900 | [diff] [blame] | 1109 | { |
Namhyung Kim | 043ca389 | 2014-03-03 14:18:00 +0900 | [diff] [blame] | 1110 | struct perf_hpp_fmt *fmt; |
| 1111 | int64_t cmp = 0; |
Namhyung Kim | 29d720e | 2013-01-22 18:09:33 +0900 | [diff] [blame] | 1112 | |
Namhyung Kim | 26d8b33 | 2014-03-03 16:16:20 +0900 | [diff] [blame] | 1113 | perf_hpp__for_each_sort_list(fmt) { |
Namhyung Kim | e67d49a | 2014-03-18 13:00:59 +0900 | [diff] [blame] | 1114 | if (perf_hpp__should_skip(fmt)) |
| 1115 | continue; |
| 1116 | |
Namhyung Kim | 87bbdf7 | 2015-01-08 09:45:46 +0900 | [diff] [blame] | 1117 | cmp = fmt->sort(fmt, a, b); |
Namhyung Kim | 043ca389 | 2014-03-03 14:18:00 +0900 | [diff] [blame] | 1118 | if (cmp) |
Namhyung Kim | 29d720e | 2013-01-22 18:09:33 +0900 | [diff] [blame] | 1119 | break; |
| 1120 | } |
| 1121 | |
Namhyung Kim | 043ca389 | 2014-03-03 14:18:00 +0900 | [diff] [blame] | 1122 | return cmp; |
Namhyung Kim | 29d720e | 2013-01-22 18:09:33 +0900 | [diff] [blame] | 1123 | } |
| 1124 | |
Namhyung Kim | 9283ba9 | 2014-04-24 16:37:26 +0900 | [diff] [blame] | 1125 | static void hists__reset_filter_stats(struct hists *hists) |
| 1126 | { |
| 1127 | hists->nr_non_filtered_entries = 0; |
| 1128 | hists->stats.total_non_filtered_period = 0; |
| 1129 | } |
| 1130 | |
| 1131 | void hists__reset_stats(struct hists *hists) |
| 1132 | { |
| 1133 | hists->nr_entries = 0; |
| 1134 | hists->stats.total_period = 0; |
| 1135 | |
| 1136 | hists__reset_filter_stats(hists); |
| 1137 | } |
| 1138 | |
| 1139 | static void hists__inc_filter_stats(struct hists *hists, struct hist_entry *h) |
| 1140 | { |
| 1141 | hists->nr_non_filtered_entries++; |
| 1142 | hists->stats.total_non_filtered_period += h->stat.period; |
| 1143 | } |
| 1144 | |
| 1145 | void hists__inc_stats(struct hists *hists, struct hist_entry *h) |
| 1146 | { |
| 1147 | if (!h->filtered) |
| 1148 | hists__inc_filter_stats(hists, h); |
| 1149 | |
| 1150 | hists->nr_entries++; |
| 1151 | hists->stats.total_period += h->stat.period; |
| 1152 | } |
| 1153 | |
Arnaldo Carvalho de Melo | 1c02c4d | 2010-05-10 13:04:11 -0300 | [diff] [blame] | 1154 | static void __hists__insert_output_entry(struct rb_root *entries, |
| 1155 | struct hist_entry *he, |
Kan Liang | f9db0d0 | 2015-08-11 06:30:48 -0400 | [diff] [blame] | 1156 | u64 min_callchain_hits, |
| 1157 | bool use_callchain) |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1158 | { |
Arnaldo Carvalho de Melo | 1c02c4d | 2010-05-10 13:04:11 -0300 | [diff] [blame] | 1159 | struct rb_node **p = &entries->rb_node; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1160 | struct rb_node *parent = NULL; |
| 1161 | struct hist_entry *iter; |
| 1162 | |
Kan Liang | f9db0d0 | 2015-08-11 06:30:48 -0400 | [diff] [blame] | 1163 | if (use_callchain) |
Arnaldo Carvalho de Melo | b9fb930 | 2010-04-02 09:50:42 -0300 | [diff] [blame] | 1164 | callchain_param.sort(&he->sorted_chain, he->callchain, |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1165 | min_callchain_hits, &callchain_param); |
| 1166 | |
| 1167 | while (*p != NULL) { |
| 1168 | parent = *p; |
| 1169 | iter = rb_entry(parent, struct hist_entry, rb_node); |
| 1170 | |
Namhyung Kim | 043ca389 | 2014-03-03 14:18:00 +0900 | [diff] [blame] | 1171 | if (hist_entry__sort(he, iter) > 0) |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1172 | p = &(*p)->rb_left; |
| 1173 | else |
| 1174 | p = &(*p)->rb_right; |
| 1175 | } |
| 1176 | |
| 1177 | rb_link_node(&he->rb_node, parent, p); |
Arnaldo Carvalho de Melo | 1c02c4d | 2010-05-10 13:04:11 -0300 | [diff] [blame] | 1178 | rb_insert_color(&he->rb_node, entries); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1179 | } |
| 1180 | |
Namhyung Kim | 740b97f | 2014-12-22 13:44:10 +0900 | [diff] [blame] | 1181 | void hists__output_resort(struct hists *hists, struct ui_progress *prog) |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1182 | { |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 1183 | struct rb_root *root; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1184 | struct rb_node *next; |
| 1185 | struct hist_entry *n; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1186 | u64 min_callchain_hits; |
Kan Liang | f9db0d0 | 2015-08-11 06:30:48 -0400 | [diff] [blame] | 1187 | struct perf_evsel *evsel = hists_to_evsel(hists); |
Kan Liang | 9e207dd | 2015-08-11 06:30:49 -0400 | [diff] [blame] | 1188 | bool use_callchain; |
| 1189 | |
Namhyung Kim | 208e760 | 2015-09-30 13:34:00 +0900 | [diff] [blame] | 1190 | if (evsel && symbol_conf.use_callchain && !symbol_conf.show_ref_callgraph) |
Kan Liang | 9e207dd | 2015-08-11 06:30:49 -0400 | [diff] [blame] | 1191 | use_callchain = evsel->attr.sample_type & PERF_SAMPLE_CALLCHAIN; |
| 1192 | else |
| 1193 | use_callchain = symbol_conf.use_callchain; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1194 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1195 | min_callchain_hits = hists->stats.total_period * (callchain_param.min_percent / 100); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1196 | |
Namhyung Kim | 3a5714f | 2013-05-14 11:09:01 +0900 | [diff] [blame] | 1197 | if (sort__need_collapse) |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 1198 | root = &hists->entries_collapsed; |
| 1199 | else |
| 1200 | root = hists->entries_in; |
| 1201 | |
| 1202 | next = rb_first(root); |
| 1203 | hists->entries = RB_ROOT; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1204 | |
Namhyung Kim | 9283ba9 | 2014-04-24 16:37:26 +0900 | [diff] [blame] | 1205 | hists__reset_stats(hists); |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1206 | hists__reset_col_len(hists); |
Arnaldo Carvalho de Melo | fefb0b9 | 2010-05-10 13:57:51 -0300 | [diff] [blame] | 1207 | |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1208 | while (next) { |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 1209 | n = rb_entry(next, struct hist_entry, rb_node_in); |
| 1210 | next = rb_next(&n->rb_node_in); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1211 | |
Kan Liang | f9db0d0 | 2015-08-11 06:30:48 -0400 | [diff] [blame] | 1212 | __hists__insert_output_entry(&hists->entries, n, min_callchain_hits, use_callchain); |
Namhyung Kim | 6263835 | 2014-04-24 16:21:46 +0900 | [diff] [blame] | 1213 | hists__inc_stats(hists, n); |
Namhyung Kim | ae993ef | 2014-04-24 16:25:19 +0900 | [diff] [blame] | 1214 | |
| 1215 | if (!n->filtered) |
| 1216 | hists__calc_col_len(hists, n); |
Namhyung Kim | 740b97f | 2014-12-22 13:44:10 +0900 | [diff] [blame] | 1217 | |
| 1218 | if (prog) |
| 1219 | ui_progress__update(prog, 1); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1220 | } |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 1221 | } |
Arnaldo Carvalho de Melo | b9bf089 | 2009-12-14 11:37:11 -0200 | [diff] [blame] | 1222 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1223 | 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] | 1224 | enum hist_filter filter) |
| 1225 | { |
| 1226 | h->filtered &= ~(1 << filter); |
| 1227 | if (h->filtered) |
| 1228 | return; |
| 1229 | |
Namhyung Kim | 87e90f4 | 2014-04-24 16:44:16 +0900 | [diff] [blame] | 1230 | /* force fold unfiltered entry for simplicity */ |
Namhyung Kim | 3698dab | 2015-05-05 23:55:46 +0900 | [diff] [blame] | 1231 | h->unfolded = false; |
Arnaldo Carvalho de Melo | 0f0cbf7 | 2010-07-26 17:13:40 -0300 | [diff] [blame] | 1232 | h->row_offset = 0; |
He Kuang | a8cd1f4 | 2015-03-11 20:36:03 +0800 | [diff] [blame] | 1233 | h->nr_rows = 0; |
Namhyung Kim | 9283ba9 | 2014-04-24 16:37:26 +0900 | [diff] [blame] | 1234 | |
Namhyung Kim | 1ab1fa5 | 2013-12-26 15:11:52 +0900 | [diff] [blame] | 1235 | hists->stats.nr_non_filtered_samples += h->stat.nr_events; |
Arnaldo Carvalho de Melo | cc5edb0 | 2010-07-16 12:35:07 -0300 | [diff] [blame] | 1236 | |
Namhyung Kim | 9283ba9 | 2014-04-24 16:37:26 +0900 | [diff] [blame] | 1237 | hists__inc_filter_stats(hists, h); |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1238 | hists__calc_col_len(hists, h); |
Arnaldo Carvalho de Melo | cc5edb0 | 2010-07-16 12:35:07 -0300 | [diff] [blame] | 1239 | } |
| 1240 | |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 1241 | |
| 1242 | static bool hists__filter_entry_by_dso(struct hists *hists, |
| 1243 | struct hist_entry *he) |
| 1244 | { |
| 1245 | if (hists->dso_filter != NULL && |
| 1246 | (he->ms.map == NULL || he->ms.map->dso != hists->dso_filter)) { |
| 1247 | he->filtered |= (1 << HIST_FILTER__DSO); |
| 1248 | return true; |
| 1249 | } |
| 1250 | |
| 1251 | return false; |
| 1252 | } |
| 1253 | |
Arnaldo Carvalho de Melo | d7b76f0 | 2011-10-18 19:07:34 -0200 | [diff] [blame] | 1254 | void hists__filter_by_dso(struct hists *hists) |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 1255 | { |
| 1256 | struct rb_node *nd; |
| 1257 | |
Namhyung Kim | 1ab1fa5 | 2013-12-26 15:11:52 +0900 | [diff] [blame] | 1258 | hists->stats.nr_non_filtered_samples = 0; |
Namhyung Kim | 9283ba9 | 2014-04-24 16:37:26 +0900 | [diff] [blame] | 1259 | |
| 1260 | hists__reset_filter_stats(hists); |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1261 | hists__reset_col_len(hists); |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 1262 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1263 | 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] | 1264 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
| 1265 | |
| 1266 | if (symbol_conf.exclude_other && !h->parent) |
| 1267 | continue; |
| 1268 | |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 1269 | if (hists__filter_entry_by_dso(hists, h)) |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 1270 | continue; |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 1271 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1272 | hists__remove_entry_filter(hists, h, HIST_FILTER__DSO); |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 1273 | } |
| 1274 | } |
| 1275 | |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 1276 | static bool hists__filter_entry_by_thread(struct hists *hists, |
| 1277 | struct hist_entry *he) |
| 1278 | { |
| 1279 | if (hists->thread_filter != NULL && |
| 1280 | he->thread != hists->thread_filter) { |
| 1281 | he->filtered |= (1 << HIST_FILTER__THREAD); |
| 1282 | return true; |
| 1283 | } |
| 1284 | |
| 1285 | return false; |
| 1286 | } |
| 1287 | |
Arnaldo Carvalho de Melo | d7b76f0 | 2011-10-18 19:07:34 -0200 | [diff] [blame] | 1288 | void hists__filter_by_thread(struct hists *hists) |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 1289 | { |
| 1290 | struct rb_node *nd; |
| 1291 | |
Namhyung Kim | 1ab1fa5 | 2013-12-26 15:11:52 +0900 | [diff] [blame] | 1292 | hists->stats.nr_non_filtered_samples = 0; |
Namhyung Kim | 9283ba9 | 2014-04-24 16:37:26 +0900 | [diff] [blame] | 1293 | |
| 1294 | hists__reset_filter_stats(hists); |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1295 | hists__reset_col_len(hists); |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 1296 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1297 | 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] | 1298 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
| 1299 | |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 1300 | if (hists__filter_entry_by_thread(hists, h)) |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 1301 | continue; |
Arnaldo Carvalho de Melo | cc5edb0 | 2010-07-16 12:35:07 -0300 | [diff] [blame] | 1302 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1303 | hists__remove_entry_filter(hists, h, HIST_FILTER__THREAD); |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 1304 | } |
| 1305 | } |
Arnaldo Carvalho de Melo | ef7b93a | 2010-05-11 23:18:06 -0300 | [diff] [blame] | 1306 | |
Namhyung Kim | e94d53e | 2012-03-16 17:50:51 +0900 | [diff] [blame] | 1307 | static bool hists__filter_entry_by_symbol(struct hists *hists, |
| 1308 | struct hist_entry *he) |
| 1309 | { |
| 1310 | if (hists->symbol_filter_str != NULL && |
| 1311 | (!he->ms.sym || strstr(he->ms.sym->name, |
| 1312 | hists->symbol_filter_str) == NULL)) { |
| 1313 | he->filtered |= (1 << HIST_FILTER__SYMBOL); |
| 1314 | return true; |
| 1315 | } |
| 1316 | |
| 1317 | return false; |
| 1318 | } |
| 1319 | |
| 1320 | void hists__filter_by_symbol(struct hists *hists) |
| 1321 | { |
| 1322 | struct rb_node *nd; |
| 1323 | |
Namhyung Kim | 1ab1fa5 | 2013-12-26 15:11:52 +0900 | [diff] [blame] | 1324 | hists->stats.nr_non_filtered_samples = 0; |
Namhyung Kim | 9283ba9 | 2014-04-24 16:37:26 +0900 | [diff] [blame] | 1325 | |
| 1326 | hists__reset_filter_stats(hists); |
Namhyung Kim | e94d53e | 2012-03-16 17:50:51 +0900 | [diff] [blame] | 1327 | hists__reset_col_len(hists); |
| 1328 | |
| 1329 | for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) { |
| 1330 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
| 1331 | |
| 1332 | if (hists__filter_entry_by_symbol(hists, h)) |
| 1333 | continue; |
| 1334 | |
| 1335 | hists__remove_entry_filter(hists, h, HIST_FILTER__SYMBOL); |
| 1336 | } |
| 1337 | } |
| 1338 | |
Kan Liang | 21394d9 | 2015-09-04 10:45:44 -0400 | [diff] [blame] | 1339 | static bool hists__filter_entry_by_socket(struct hists *hists, |
| 1340 | struct hist_entry *he) |
| 1341 | { |
| 1342 | if ((hists->socket_filter > -1) && |
| 1343 | (he->socket != hists->socket_filter)) { |
| 1344 | he->filtered |= (1 << HIST_FILTER__SOCKET); |
| 1345 | return true; |
| 1346 | } |
| 1347 | |
| 1348 | return false; |
| 1349 | } |
| 1350 | |
Kan Liang | 84734b0 | 2015-09-04 10:45:45 -0400 | [diff] [blame] | 1351 | void hists__filter_by_socket(struct hists *hists) |
| 1352 | { |
| 1353 | struct rb_node *nd; |
| 1354 | |
| 1355 | hists->stats.nr_non_filtered_samples = 0; |
| 1356 | |
| 1357 | hists__reset_filter_stats(hists); |
| 1358 | hists__reset_col_len(hists); |
| 1359 | |
| 1360 | for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) { |
| 1361 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
| 1362 | |
| 1363 | if (hists__filter_entry_by_socket(hists, h)) |
| 1364 | continue; |
| 1365 | |
| 1366 | hists__remove_entry_filter(hists, h, HIST_FILTER__SOCKET); |
| 1367 | } |
| 1368 | } |
| 1369 | |
Arnaldo Carvalho de Melo | 28a6b6a | 2012-12-18 16:24:46 -0300 | [diff] [blame] | 1370 | void events_stats__inc(struct events_stats *stats, u32 type) |
| 1371 | { |
| 1372 | ++stats->nr_events[0]; |
| 1373 | ++stats->nr_events[type]; |
| 1374 | } |
| 1375 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1376 | void hists__inc_nr_events(struct hists *hists, u32 type) |
Arnaldo Carvalho de Melo | c8446b9 | 2010-05-14 10:36:42 -0300 | [diff] [blame] | 1377 | { |
Arnaldo Carvalho de Melo | 28a6b6a | 2012-12-18 16:24:46 -0300 | [diff] [blame] | 1378 | events_stats__inc(&hists->stats, type); |
Arnaldo Carvalho de Melo | c8446b9 | 2010-05-14 10:36:42 -0300 | [diff] [blame] | 1379 | } |
Arnaldo Carvalho de Melo | 95529be | 2012-11-08 17:54:33 -0300 | [diff] [blame] | 1380 | |
Namhyung Kim | 1844dbc | 2014-05-28 14:12:18 +0900 | [diff] [blame] | 1381 | void hists__inc_nr_samples(struct hists *hists, bool filtered) |
| 1382 | { |
| 1383 | events_stats__inc(&hists->stats, PERF_RECORD_SAMPLE); |
| 1384 | if (!filtered) |
| 1385 | hists->stats.nr_non_filtered_samples++; |
| 1386 | } |
| 1387 | |
Arnaldo Carvalho de Melo | 494d70a | 2012-11-08 18:03:09 -0300 | [diff] [blame] | 1388 | static struct hist_entry *hists__add_dummy_entry(struct hists *hists, |
| 1389 | struct hist_entry *pair) |
| 1390 | { |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 1391 | struct rb_root *root; |
| 1392 | struct rb_node **p; |
Arnaldo Carvalho de Melo | 494d70a | 2012-11-08 18:03:09 -0300 | [diff] [blame] | 1393 | struct rb_node *parent = NULL; |
| 1394 | struct hist_entry *he; |
Andi Kleen | 354cc40 | 2013-10-01 07:22:15 -0700 | [diff] [blame] | 1395 | int64_t cmp; |
Arnaldo Carvalho de Melo | 494d70a | 2012-11-08 18:03:09 -0300 | [diff] [blame] | 1396 | |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 1397 | if (sort__need_collapse) |
| 1398 | root = &hists->entries_collapsed; |
| 1399 | else |
| 1400 | root = hists->entries_in; |
| 1401 | |
| 1402 | p = &root->rb_node; |
| 1403 | |
Arnaldo Carvalho de Melo | 494d70a | 2012-11-08 18:03:09 -0300 | [diff] [blame] | 1404 | while (*p != NULL) { |
| 1405 | parent = *p; |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 1406 | he = rb_entry(parent, struct hist_entry, rb_node_in); |
Arnaldo Carvalho de Melo | 494d70a | 2012-11-08 18:03:09 -0300 | [diff] [blame] | 1407 | |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 1408 | cmp = hist_entry__collapse(he, pair); |
Arnaldo Carvalho de Melo | 494d70a | 2012-11-08 18:03:09 -0300 | [diff] [blame] | 1409 | |
| 1410 | if (!cmp) |
| 1411 | goto out; |
| 1412 | |
| 1413 | if (cmp < 0) |
| 1414 | p = &(*p)->rb_left; |
| 1415 | else |
| 1416 | p = &(*p)->rb_right; |
| 1417 | } |
| 1418 | |
Namhyung Kim | a0b51af | 2012-09-11 13:34:27 +0900 | [diff] [blame] | 1419 | he = hist_entry__new(pair, true); |
Arnaldo Carvalho de Melo | 494d70a | 2012-11-08 18:03:09 -0300 | [diff] [blame] | 1420 | if (he) { |
Arnaldo Carvalho de Melo | 30193d7 | 2012-11-12 13:20:03 -0300 | [diff] [blame] | 1421 | memset(&he->stat, 0, sizeof(he->stat)); |
| 1422 | he->hists = hists; |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 1423 | rb_link_node(&he->rb_node_in, parent, p); |
| 1424 | rb_insert_color(&he->rb_node_in, root); |
Namhyung Kim | 6263835 | 2014-04-24 16:21:46 +0900 | [diff] [blame] | 1425 | hists__inc_stats(hists, he); |
Jiri Olsa | e0af43d | 2012-12-01 21:18:20 +0100 | [diff] [blame] | 1426 | he->dummy = true; |
Arnaldo Carvalho de Melo | 494d70a | 2012-11-08 18:03:09 -0300 | [diff] [blame] | 1427 | } |
| 1428 | out: |
| 1429 | return he; |
| 1430 | } |
| 1431 | |
Arnaldo Carvalho de Melo | 95529be | 2012-11-08 17:54:33 -0300 | [diff] [blame] | 1432 | static struct hist_entry *hists__find_entry(struct hists *hists, |
| 1433 | struct hist_entry *he) |
| 1434 | { |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 1435 | struct rb_node *n; |
| 1436 | |
| 1437 | if (sort__need_collapse) |
| 1438 | n = hists->entries_collapsed.rb_node; |
| 1439 | else |
| 1440 | n = hists->entries_in->rb_node; |
Arnaldo Carvalho de Melo | 95529be | 2012-11-08 17:54:33 -0300 | [diff] [blame] | 1441 | |
| 1442 | while (n) { |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 1443 | struct hist_entry *iter = rb_entry(n, struct hist_entry, rb_node_in); |
| 1444 | int64_t cmp = hist_entry__collapse(iter, he); |
Arnaldo Carvalho de Melo | 95529be | 2012-11-08 17:54:33 -0300 | [diff] [blame] | 1445 | |
| 1446 | if (cmp < 0) |
| 1447 | n = n->rb_left; |
| 1448 | else if (cmp > 0) |
| 1449 | n = n->rb_right; |
| 1450 | else |
| 1451 | return iter; |
| 1452 | } |
| 1453 | |
| 1454 | return NULL; |
| 1455 | } |
| 1456 | |
| 1457 | /* |
| 1458 | * Look for pairs to link to the leader buckets (hist_entries): |
| 1459 | */ |
| 1460 | void hists__match(struct hists *leader, struct hists *other) |
| 1461 | { |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 1462 | struct rb_root *root; |
Arnaldo Carvalho de Melo | 95529be | 2012-11-08 17:54:33 -0300 | [diff] [blame] | 1463 | struct rb_node *nd; |
| 1464 | struct hist_entry *pos, *pair; |
| 1465 | |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 1466 | if (sort__need_collapse) |
| 1467 | root = &leader->entries_collapsed; |
| 1468 | else |
| 1469 | root = leader->entries_in; |
| 1470 | |
| 1471 | for (nd = rb_first(root); nd; nd = rb_next(nd)) { |
| 1472 | pos = rb_entry(nd, struct hist_entry, rb_node_in); |
Arnaldo Carvalho de Melo | 95529be | 2012-11-08 17:54:33 -0300 | [diff] [blame] | 1473 | pair = hists__find_entry(other, pos); |
| 1474 | |
| 1475 | if (pair) |
Namhyung Kim | 5fa9041 | 2012-11-29 15:38:34 +0900 | [diff] [blame] | 1476 | hist_entry__add_pair(pair, pos); |
Arnaldo Carvalho de Melo | 95529be | 2012-11-08 17:54:33 -0300 | [diff] [blame] | 1477 | } |
| 1478 | } |
Arnaldo Carvalho de Melo | 494d70a | 2012-11-08 18:03:09 -0300 | [diff] [blame] | 1479 | |
| 1480 | /* |
| 1481 | * Look for entries in the other hists that are not present in the leader, if |
| 1482 | * we find them, just add a dummy entry on the leader hists, with period=0, |
| 1483 | * nr_events=0, to serve as the list header. |
| 1484 | */ |
| 1485 | int hists__link(struct hists *leader, struct hists *other) |
| 1486 | { |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 1487 | struct rb_root *root; |
Arnaldo Carvalho de Melo | 494d70a | 2012-11-08 18:03:09 -0300 | [diff] [blame] | 1488 | struct rb_node *nd; |
| 1489 | struct hist_entry *pos, *pair; |
| 1490 | |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 1491 | if (sort__need_collapse) |
| 1492 | root = &other->entries_collapsed; |
| 1493 | else |
| 1494 | root = other->entries_in; |
| 1495 | |
| 1496 | for (nd = rb_first(root); nd; nd = rb_next(nd)) { |
| 1497 | pos = rb_entry(nd, struct hist_entry, rb_node_in); |
Arnaldo Carvalho de Melo | 494d70a | 2012-11-08 18:03:09 -0300 | [diff] [blame] | 1498 | |
| 1499 | if (!hist_entry__has_pairs(pos)) { |
| 1500 | pair = hists__add_dummy_entry(leader, pos); |
| 1501 | if (pair == NULL) |
| 1502 | return -1; |
Namhyung Kim | 5fa9041 | 2012-11-29 15:38:34 +0900 | [diff] [blame] | 1503 | hist_entry__add_pair(pos, pair); |
Arnaldo Carvalho de Melo | 494d70a | 2012-11-08 18:03:09 -0300 | [diff] [blame] | 1504 | } |
| 1505 | } |
| 1506 | |
| 1507 | return 0; |
| 1508 | } |
Namhyung Kim | f214833 | 2014-01-14 11:52:48 +0900 | [diff] [blame] | 1509 | |
Andi Kleen | 57849998 | 2015-07-18 08:24:49 -0700 | [diff] [blame] | 1510 | void hist__account_cycles(struct branch_stack *bs, struct addr_location *al, |
| 1511 | struct perf_sample *sample, bool nonany_branch_mode) |
| 1512 | { |
| 1513 | struct branch_info *bi; |
| 1514 | |
| 1515 | /* If we have branch cycles always annotate them. */ |
| 1516 | if (bs && bs->nr && bs->entries[0].flags.cycles) { |
| 1517 | int i; |
| 1518 | |
| 1519 | bi = sample__resolve_bstack(sample, al); |
| 1520 | if (bi) { |
| 1521 | struct addr_map_symbol *prev = NULL; |
| 1522 | |
| 1523 | /* |
| 1524 | * Ignore errors, still want to process the |
| 1525 | * other entries. |
| 1526 | * |
| 1527 | * For non standard branch modes always |
| 1528 | * force no IPC (prev == NULL) |
| 1529 | * |
| 1530 | * Note that perf stores branches reversed from |
| 1531 | * program order! |
| 1532 | */ |
| 1533 | for (i = bs->nr - 1; i >= 0; i--) { |
| 1534 | addr_map_symbol__account_cycles(&bi[i].from, |
| 1535 | nonany_branch_mode ? NULL : prev, |
| 1536 | bi[i].flags.cycles); |
| 1537 | prev = &bi[i].to; |
| 1538 | } |
| 1539 | free(bi); |
| 1540 | } |
| 1541 | } |
| 1542 | } |
Arnaldo Carvalho de Melo | 2a1731f | 2014-10-10 15:49:21 -0300 | [diff] [blame] | 1543 | |
| 1544 | size_t perf_evlist__fprintf_nr_events(struct perf_evlist *evlist, FILE *fp) |
| 1545 | { |
| 1546 | struct perf_evsel *pos; |
| 1547 | size_t ret = 0; |
| 1548 | |
| 1549 | evlist__for_each(evlist, pos) { |
| 1550 | ret += fprintf(fp, "%s stats:\n", perf_evsel__name(pos)); |
| 1551 | ret += events_stats__fprintf(&evsel__hists(pos)->stats, fp); |
| 1552 | } |
| 1553 | |
| 1554 | return ret; |
| 1555 | } |
| 1556 | |
| 1557 | |
Namhyung Kim | f214833 | 2014-01-14 11:52:48 +0900 | [diff] [blame] | 1558 | u64 hists__total_period(struct hists *hists) |
| 1559 | { |
| 1560 | return symbol_conf.filter_relative ? hists->stats.total_non_filtered_period : |
| 1561 | hists->stats.total_period; |
| 1562 | } |
Namhyung Kim | 33db456 | 2014-02-07 12:06:07 +0900 | [diff] [blame] | 1563 | |
| 1564 | int parse_filter_percentage(const struct option *opt __maybe_unused, |
| 1565 | const char *arg, int unset __maybe_unused) |
| 1566 | { |
| 1567 | if (!strcmp(arg, "relative")) |
| 1568 | symbol_conf.filter_relative = true; |
| 1569 | else if (!strcmp(arg, "absolute")) |
| 1570 | symbol_conf.filter_relative = false; |
| 1571 | else |
| 1572 | return -1; |
| 1573 | |
| 1574 | return 0; |
| 1575 | } |
Namhyung Kim | 0b93da1 | 2014-01-14 12:02:15 +0900 | [diff] [blame] | 1576 | |
| 1577 | int perf_hist_config(const char *var, const char *value) |
| 1578 | { |
| 1579 | if (!strcmp(var, "hist.percentage")) |
| 1580 | return parse_filter_percentage(NULL, value, 0); |
| 1581 | |
| 1582 | return 0; |
| 1583 | } |
Arnaldo Carvalho de Melo | a635fc5 | 2014-10-09 16:16:00 -0300 | [diff] [blame] | 1584 | |
| 1585 | static int hists_evsel__init(struct perf_evsel *evsel) |
| 1586 | { |
| 1587 | struct hists *hists = evsel__hists(evsel); |
| 1588 | |
| 1589 | memset(hists, 0, sizeof(*hists)); |
| 1590 | hists->entries_in_array[0] = hists->entries_in_array[1] = RB_ROOT; |
| 1591 | hists->entries_in = &hists->entries_in_array[0]; |
| 1592 | hists->entries_collapsed = RB_ROOT; |
| 1593 | hists->entries = RB_ROOT; |
| 1594 | pthread_mutex_init(&hists->lock, NULL); |
Kan Liang | 21394d9 | 2015-09-04 10:45:44 -0400 | [diff] [blame] | 1595 | hists->socket_filter = -1; |
Arnaldo Carvalho de Melo | a635fc5 | 2014-10-09 16:16:00 -0300 | [diff] [blame] | 1596 | return 0; |
| 1597 | } |
| 1598 | |
Namhyung Kim | 61fa0e9 | 2015-12-10 16:53:20 +0900 | [diff] [blame] | 1599 | static void hists__delete_remaining_entries(struct rb_root *root) |
| 1600 | { |
| 1601 | struct rb_node *node; |
| 1602 | struct hist_entry *he; |
| 1603 | |
| 1604 | while (!RB_EMPTY_ROOT(root)) { |
| 1605 | node = rb_first(root); |
| 1606 | rb_erase(node, root); |
| 1607 | |
| 1608 | he = rb_entry(node, struct hist_entry, rb_node_in); |
| 1609 | hist_entry__delete(he); |
| 1610 | } |
| 1611 | } |
| 1612 | |
| 1613 | static void hists__delete_all_entries(struct hists *hists) |
| 1614 | { |
| 1615 | hists__delete_entries(hists); |
| 1616 | hists__delete_remaining_entries(&hists->entries_in_array[0]); |
| 1617 | hists__delete_remaining_entries(&hists->entries_in_array[1]); |
| 1618 | hists__delete_remaining_entries(&hists->entries_collapsed); |
| 1619 | } |
| 1620 | |
Masami Hiramatsu | 17577de | 2015-12-09 11:11:29 +0900 | [diff] [blame] | 1621 | static void hists_evsel__exit(struct perf_evsel *evsel) |
| 1622 | { |
| 1623 | struct hists *hists = evsel__hists(evsel); |
| 1624 | |
Namhyung Kim | 61fa0e9 | 2015-12-10 16:53:20 +0900 | [diff] [blame] | 1625 | hists__delete_all_entries(hists); |
Masami Hiramatsu | 17577de | 2015-12-09 11:11:29 +0900 | [diff] [blame] | 1626 | } |
| 1627 | |
Arnaldo Carvalho de Melo | a635fc5 | 2014-10-09 16:16:00 -0300 | [diff] [blame] | 1628 | /* |
| 1629 | * XXX We probably need a hists_evsel__exit() to free the hist_entries |
| 1630 | * stored in the rbtree... |
| 1631 | */ |
| 1632 | |
| 1633 | int hists__init(void) |
| 1634 | { |
| 1635 | int err = perf_evsel__object_config(sizeof(struct hists_evsel), |
Masami Hiramatsu | 17577de | 2015-12-09 11:11:29 +0900 | [diff] [blame] | 1636 | hists_evsel__init, |
| 1637 | hists_evsel__exit); |
Arnaldo Carvalho de Melo | a635fc5 | 2014-10-09 16:16:00 -0300 | [diff] [blame] | 1638 | if (err) |
| 1639 | fputs("FATAL ERROR: Couldn't setup hists class\n", stderr); |
| 1640 | |
| 1641 | return err; |
| 1642 | } |