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