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" |
Krister Johansen | 9c68ae9 | 2017-01-05 22:23:31 -0800 | [diff] [blame] | 4 | #include "map.h" |
Arnaldo Carvalho de Melo | 4e4f06e | 2009-12-14 13:10:39 -0200 | [diff] [blame] | 5 | #include "session.h" |
Hari Bathini | d890a98 | 2017-03-08 02:12:13 +0530 | [diff] [blame] | 6 | #include "namespaces.h" |
Arnaldo Carvalho de Melo | 4e4f06e | 2009-12-14 13:10:39 -0200 | [diff] [blame] | 7 | #include "sort.h" |
Arnaldo Carvalho de Melo | 2a1731f | 2014-10-10 15:49:21 -0300 | [diff] [blame] | 8 | #include "evlist.h" |
Namhyung Kim | 29d720e | 2013-01-22 18:09:33 +0900 | [diff] [blame] | 9 | #include "evsel.h" |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 10 | #include "annotate.h" |
Namhyung Kim | 740b97f | 2014-12-22 13:44:10 +0900 | [diff] [blame] | 11 | #include "ui/progress.h" |
Arnaldo Carvalho de Melo | 9b33827 | 2009-12-16 14:31:49 -0200 | [diff] [blame] | 12 | #include <math.h> |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 13 | |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 14 | static bool hists__filter_entry_by_dso(struct hists *hists, |
| 15 | struct hist_entry *he); |
| 16 | static bool hists__filter_entry_by_thread(struct hists *hists, |
| 17 | struct hist_entry *he); |
Namhyung Kim | e94d53e | 2012-03-16 17:50:51 +0900 | [diff] [blame] | 18 | static bool hists__filter_entry_by_symbol(struct hists *hists, |
| 19 | struct hist_entry *he); |
Kan Liang | 21394d9 | 2015-09-04 10:45:44 -0400 | [diff] [blame] | 20 | static bool hists__filter_entry_by_socket(struct hists *hists, |
| 21 | struct hist_entry *he); |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 22 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 23 | u16 hists__col_len(struct hists *hists, enum hist_column col) |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 24 | { |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 25 | return hists->col_len[col]; |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 26 | } |
| 27 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 28 | void hists__set_col_len(struct hists *hists, enum hist_column col, u16 len) |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 29 | { |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 30 | hists->col_len[col] = len; |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 31 | } |
| 32 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 33 | bool hists__new_col_len(struct hists *hists, enum hist_column col, u16 len) |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 34 | { |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 35 | if (len > hists__col_len(hists, col)) { |
| 36 | hists__set_col_len(hists, col, len); |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 37 | return true; |
| 38 | } |
| 39 | return false; |
| 40 | } |
| 41 | |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 42 | void hists__reset_col_len(struct hists *hists) |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 43 | { |
| 44 | enum hist_column col; |
| 45 | |
| 46 | for (col = 0; col < HISTC_NR_COLS; ++col) |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 47 | hists__set_col_len(hists, col, 0); |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 48 | } |
| 49 | |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 50 | static void hists__set_unres_dso_col_len(struct hists *hists, int dso) |
| 51 | { |
| 52 | const unsigned int unresolved_col_width = BITS_PER_LONG / 4; |
| 53 | |
| 54 | if (hists__col_len(hists, dso) < unresolved_col_width && |
| 55 | !symbol_conf.col_width_list_str && !symbol_conf.field_sep && |
| 56 | !symbol_conf.dso_list) |
| 57 | hists__set_col_len(hists, dso, unresolved_col_width); |
| 58 | } |
| 59 | |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 60 | void hists__calc_col_len(struct hists *hists, struct hist_entry *h) |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 61 | { |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 62 | const unsigned int unresolved_col_width = BITS_PER_LONG / 4; |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 63 | int symlen; |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 64 | u16 len; |
| 65 | |
Namhyung Kim | ded19d5 | 2013-04-01 20:35:19 +0900 | [diff] [blame] | 66 | /* |
| 67 | * +4 accounts for '[x] ' priv level info |
| 68 | * +2 accounts for 0x prefix on raw addresses |
| 69 | * +3 accounts for ' y ' symtab origin info |
| 70 | */ |
| 71 | if (h->ms.sym) { |
| 72 | symlen = h->ms.sym->namelen + 4; |
Namhyung Kim | bb963e1 | 2017-02-17 17:17:38 +0900 | [diff] [blame] | 73 | if (verbose > 0) |
Namhyung Kim | ded19d5 | 2013-04-01 20:35:19 +0900 | [diff] [blame] | 74 | symlen += BITS_PER_LONG / 4 + 2 + 3; |
| 75 | hists__new_col_len(hists, HISTC_SYMBOL, symlen); |
| 76 | } else { |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 77 | symlen = unresolved_col_width + 4 + 2; |
| 78 | hists__new_col_len(hists, HISTC_SYMBOL, symlen); |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 79 | hists__set_unres_dso_col_len(hists, HISTC_DSO); |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 80 | } |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 81 | |
| 82 | len = thread__comm_len(h->thread); |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 83 | if (hists__new_col_len(hists, HISTC_COMM, len)) |
Jiri Olsa | 89c7cb2 | 2016-06-20 23:58:19 +0200 | [diff] [blame] | 84 | hists__set_col_len(hists, HISTC_THREAD, len + 8); |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 85 | |
| 86 | if (h->ms.map) { |
| 87 | len = dso__name_len(h->ms.map->dso); |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 88 | hists__new_col_len(hists, HISTC_DSO, len); |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 89 | } |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 90 | |
Namhyung Kim | cb99374 | 2012-12-27 18:11:42 +0900 | [diff] [blame] | 91 | if (h->parent) |
| 92 | hists__new_col_len(hists, HISTC_PARENT, h->parent->namelen); |
| 93 | |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 94 | if (h->branch_info) { |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 95 | if (h->branch_info->from.sym) { |
| 96 | symlen = (int)h->branch_info->from.sym->namelen + 4; |
Namhyung Kim | bb963e1 | 2017-02-17 17:17:38 +0900 | [diff] [blame] | 97 | if (verbose > 0) |
Namhyung Kim | ded19d5 | 2013-04-01 20:35:19 +0900 | [diff] [blame] | 98 | symlen += BITS_PER_LONG / 4 + 2 + 3; |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 99 | hists__new_col_len(hists, HISTC_SYMBOL_FROM, symlen); |
| 100 | |
| 101 | symlen = dso__name_len(h->branch_info->from.map->dso); |
| 102 | hists__new_col_len(hists, HISTC_DSO_FROM, symlen); |
| 103 | } else { |
| 104 | symlen = unresolved_col_width + 4 + 2; |
| 105 | hists__new_col_len(hists, HISTC_SYMBOL_FROM, symlen); |
| 106 | hists__set_unres_dso_col_len(hists, HISTC_DSO_FROM); |
| 107 | } |
| 108 | |
| 109 | if (h->branch_info->to.sym) { |
| 110 | symlen = (int)h->branch_info->to.sym->namelen + 4; |
Namhyung Kim | bb963e1 | 2017-02-17 17:17:38 +0900 | [diff] [blame] | 111 | if (verbose > 0) |
Namhyung Kim | ded19d5 | 2013-04-01 20:35:19 +0900 | [diff] [blame] | 112 | symlen += BITS_PER_LONG / 4 + 2 + 3; |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 113 | hists__new_col_len(hists, HISTC_SYMBOL_TO, symlen); |
| 114 | |
| 115 | symlen = dso__name_len(h->branch_info->to.map->dso); |
| 116 | hists__new_col_len(hists, HISTC_DSO_TO, symlen); |
| 117 | } else { |
| 118 | symlen = unresolved_col_width + 4 + 2; |
| 119 | hists__new_col_len(hists, HISTC_SYMBOL_TO, symlen); |
| 120 | hists__set_unres_dso_col_len(hists, HISTC_DSO_TO); |
| 121 | } |
Andi Kleen | 508be0d | 2016-05-20 13:15:08 -0700 | [diff] [blame] | 122 | |
| 123 | if (h->branch_info->srcline_from) |
| 124 | hists__new_col_len(hists, HISTC_SRCLINE_FROM, |
| 125 | strlen(h->branch_info->srcline_from)); |
| 126 | if (h->branch_info->srcline_to) |
| 127 | hists__new_col_len(hists, HISTC_SRCLINE_TO, |
| 128 | strlen(h->branch_info->srcline_to)); |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 129 | } |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 130 | |
| 131 | if (h->mem_info) { |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 132 | if (h->mem_info->daddr.sym) { |
| 133 | symlen = (int)h->mem_info->daddr.sym->namelen + 4 |
| 134 | + unresolved_col_width + 2; |
| 135 | hists__new_col_len(hists, HISTC_MEM_DADDR_SYMBOL, |
| 136 | symlen); |
Don Zickus | 9b32ba7 | 2014-06-01 15:38:29 +0200 | [diff] [blame] | 137 | hists__new_col_len(hists, HISTC_MEM_DCACHELINE, |
| 138 | symlen + 1); |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 139 | } else { |
| 140 | symlen = unresolved_col_width + 4 + 2; |
| 141 | hists__new_col_len(hists, HISTC_MEM_DADDR_SYMBOL, |
| 142 | symlen); |
Jiri Olsa | 0805909 | 2016-01-20 12:56:33 +0100 | [diff] [blame] | 143 | hists__new_col_len(hists, HISTC_MEM_DCACHELINE, |
| 144 | symlen); |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 145 | } |
Jiri Olsa | b34b3bf | 2015-10-05 20:06:08 +0200 | [diff] [blame] | 146 | |
| 147 | if (h->mem_info->iaddr.sym) { |
| 148 | symlen = (int)h->mem_info->iaddr.sym->namelen + 4 |
| 149 | + unresolved_col_width + 2; |
| 150 | hists__new_col_len(hists, HISTC_MEM_IADDR_SYMBOL, |
| 151 | symlen); |
| 152 | } else { |
| 153 | symlen = unresolved_col_width + 4 + 2; |
| 154 | hists__new_col_len(hists, HISTC_MEM_IADDR_SYMBOL, |
| 155 | symlen); |
| 156 | } |
| 157 | |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 158 | if (h->mem_info->daddr.map) { |
| 159 | symlen = dso__name_len(h->mem_info->daddr.map->dso); |
| 160 | hists__new_col_len(hists, HISTC_MEM_DADDR_DSO, |
| 161 | symlen); |
| 162 | } else { |
| 163 | symlen = unresolved_col_width + 4 + 2; |
| 164 | hists__set_unres_dso_col_len(hists, HISTC_MEM_DADDR_DSO); |
| 165 | } |
| 166 | } else { |
| 167 | symlen = unresolved_col_width + 4 + 2; |
| 168 | hists__new_col_len(hists, HISTC_MEM_DADDR_SYMBOL, symlen); |
Jiri Olsa | b34b3bf | 2015-10-05 20:06:08 +0200 | [diff] [blame] | 169 | hists__new_col_len(hists, HISTC_MEM_IADDR_SYMBOL, symlen); |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 170 | hists__set_unres_dso_col_len(hists, HISTC_MEM_DADDR_DSO); |
| 171 | } |
| 172 | |
Hari Bathini | d890a98 | 2017-03-08 02:12:13 +0530 | [diff] [blame] | 173 | hists__new_col_len(hists, HISTC_CGROUP_ID, 20); |
Arnaldo Carvalho de Melo | a4978ec | 2015-09-09 12:14:00 -0300 | [diff] [blame] | 174 | hists__new_col_len(hists, HISTC_CPU, 3); |
Kan Liang | 2e7ea3a | 2015-09-04 10:45:43 -0400 | [diff] [blame] | 175 | hists__new_col_len(hists, HISTC_SOCKET, 6); |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 176 | hists__new_col_len(hists, HISTC_MEM_LOCKED, 6); |
| 177 | hists__new_col_len(hists, HISTC_MEM_TLB, 22); |
| 178 | hists__new_col_len(hists, HISTC_MEM_SNOOP, 12); |
| 179 | hists__new_col_len(hists, HISTC_MEM_LVL, 21 + 3); |
| 180 | hists__new_col_len(hists, HISTC_LOCAL_WEIGHT, 12); |
| 181 | hists__new_col_len(hists, HISTC_GLOBAL_WEIGHT, 12); |
Andi Kleen | 475eeab | 2013-09-20 07:40:43 -0700 | [diff] [blame] | 182 | |
Jiri Olsa | f666ac0 | 2016-09-19 15:10:10 +0200 | [diff] [blame] | 183 | if (h->srcline) { |
| 184 | len = MAX(strlen(h->srcline), strlen(sort_srcline.se_header)); |
| 185 | hists__new_col_len(hists, HISTC_SRCLINE, len); |
| 186 | } |
Arnaldo Carvalho de Melo | e8e6d37 | 2015-08-10 16:53:54 -0300 | [diff] [blame] | 187 | |
Andi Kleen | 31191a8 | 2015-08-07 15:54:24 -0700 | [diff] [blame] | 188 | if (h->srcfile) |
| 189 | hists__new_col_len(hists, HISTC_SRCFILE, strlen(h->srcfile)); |
| 190 | |
Andi Kleen | 475eeab | 2013-09-20 07:40:43 -0700 | [diff] [blame] | 191 | if (h->transaction) |
| 192 | hists__new_col_len(hists, HISTC_TRANSACTION, |
| 193 | hist_entry__transaction_len()); |
Namhyung Kim | 0c0af78 | 2016-02-21 23:22:38 +0900 | [diff] [blame] | 194 | |
| 195 | if (h->trace_output) |
| 196 | hists__new_col_len(hists, HISTC_TRACE, strlen(h->trace_output)); |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 197 | } |
| 198 | |
Namhyung Kim | 7ccf4f9 | 2012-08-20 13:52:05 +0900 | [diff] [blame] | 199 | void hists__output_recalc_col_len(struct hists *hists, int max_rows) |
| 200 | { |
| 201 | struct rb_node *next = rb_first(&hists->entries); |
| 202 | struct hist_entry *n; |
| 203 | int row = 0; |
| 204 | |
| 205 | hists__reset_col_len(hists); |
| 206 | |
| 207 | while (next && row++ < max_rows) { |
| 208 | n = rb_entry(next, struct hist_entry, rb_node); |
| 209 | if (!n->filtered) |
| 210 | hists__calc_col_len(hists, n); |
| 211 | next = rb_next(&n->rb_node); |
| 212 | } |
| 213 | } |
| 214 | |
Namhyung Kim | f39056f | 2014-01-14 14:25:37 +0900 | [diff] [blame] | 215 | static void he_stat__add_cpumode_period(struct he_stat *he_stat, |
| 216 | unsigned int cpumode, u64 period) |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 217 | { |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 218 | switch (cpumode) { |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 219 | case PERF_RECORD_MISC_KERNEL: |
Namhyung Kim | f39056f | 2014-01-14 14:25:37 +0900 | [diff] [blame] | 220 | he_stat->period_sys += period; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 221 | break; |
| 222 | case PERF_RECORD_MISC_USER: |
Namhyung Kim | f39056f | 2014-01-14 14:25:37 +0900 | [diff] [blame] | 223 | he_stat->period_us += period; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 224 | break; |
| 225 | case PERF_RECORD_MISC_GUEST_KERNEL: |
Namhyung Kim | f39056f | 2014-01-14 14:25:37 +0900 | [diff] [blame] | 226 | he_stat->period_guest_sys += period; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 227 | break; |
| 228 | case PERF_RECORD_MISC_GUEST_USER: |
Namhyung Kim | f39056f | 2014-01-14 14:25:37 +0900 | [diff] [blame] | 229 | he_stat->period_guest_us += period; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 230 | break; |
| 231 | default: |
| 232 | break; |
| 233 | } |
| 234 | } |
| 235 | |
Andi Kleen | 0548429 | 2013-01-24 16:10:29 +0100 | [diff] [blame] | 236 | static void he_stat__add_period(struct he_stat *he_stat, u64 period, |
| 237 | u64 weight) |
Namhyung Kim | 139c081 | 2012-10-04 21:49:43 +0900 | [diff] [blame] | 238 | { |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 239 | |
Namhyung Kim | 139c081 | 2012-10-04 21:49:43 +0900 | [diff] [blame] | 240 | he_stat->period += period; |
Andi Kleen | 0548429 | 2013-01-24 16:10:29 +0100 | [diff] [blame] | 241 | he_stat->weight += weight; |
Namhyung Kim | 139c081 | 2012-10-04 21:49:43 +0900 | [diff] [blame] | 242 | he_stat->nr_events += 1; |
| 243 | } |
| 244 | |
| 245 | static void he_stat__add_stat(struct he_stat *dest, struct he_stat *src) |
| 246 | { |
| 247 | dest->period += src->period; |
| 248 | dest->period_sys += src->period_sys; |
| 249 | dest->period_us += src->period_us; |
| 250 | dest->period_guest_sys += src->period_guest_sys; |
| 251 | dest->period_guest_us += src->period_guest_us; |
| 252 | dest->nr_events += src->nr_events; |
Andi Kleen | 0548429 | 2013-01-24 16:10:29 +0100 | [diff] [blame] | 253 | dest->weight += src->weight; |
Namhyung Kim | 139c081 | 2012-10-04 21:49:43 +0900 | [diff] [blame] | 254 | } |
| 255 | |
Namhyung Kim | f39056f | 2014-01-14 14:25:37 +0900 | [diff] [blame] | 256 | static void he_stat__decay(struct he_stat *he_stat) |
Arnaldo Carvalho de Melo | ab81f3fd | 2011-10-05 19:16:15 -0300 | [diff] [blame] | 257 | { |
Namhyung Kim | f39056f | 2014-01-14 14:25:37 +0900 | [diff] [blame] | 258 | he_stat->period = (he_stat->period * 7) / 8; |
| 259 | he_stat->nr_events = (he_stat->nr_events * 7) / 8; |
Andi Kleen | 0548429 | 2013-01-24 16:10:29 +0100 | [diff] [blame] | 260 | /* XXX need decay for weight too? */ |
Arnaldo Carvalho de Melo | ab81f3fd | 2011-10-05 19:16:15 -0300 | [diff] [blame] | 261 | } |
| 262 | |
Namhyung Kim | 5d8200a | 2016-02-25 00:13:49 +0900 | [diff] [blame] | 263 | static void hists__delete_entry(struct hists *hists, struct hist_entry *he); |
| 264 | |
Arnaldo Carvalho de Melo | ab81f3fd | 2011-10-05 19:16:15 -0300 | [diff] [blame] | 265 | static bool hists__decay_entry(struct hists *hists, struct hist_entry *he) |
| 266 | { |
Namhyung Kim | b24c28f | 2012-10-04 21:49:41 +0900 | [diff] [blame] | 267 | u64 prev_period = he->stat.period; |
Namhyung Kim | 3186b68 | 2014-04-22 13:44:23 +0900 | [diff] [blame] | 268 | u64 diff; |
Arnaldo Carvalho de Melo | c64550c | 2011-10-20 06:45:44 -0200 | [diff] [blame] | 269 | |
| 270 | if (prev_period == 0) |
Arnaldo Carvalho de Melo | df71d95 | 2011-10-13 08:01:33 -0300 | [diff] [blame] | 271 | return true; |
Arnaldo Carvalho de Melo | c64550c | 2011-10-20 06:45:44 -0200 | [diff] [blame] | 272 | |
Namhyung Kim | f39056f | 2014-01-14 14:25:37 +0900 | [diff] [blame] | 273 | he_stat__decay(&he->stat); |
Namhyung Kim | f8be1c8 | 2012-09-11 13:15:07 +0900 | [diff] [blame] | 274 | if (symbol_conf.cumulate_callchain) |
| 275 | he_stat__decay(he->stat_acc); |
Namhyung Kim | 42b276a | 2016-01-05 12:06:00 +0900 | [diff] [blame] | 276 | decay_callchain(he->callchain); |
Arnaldo Carvalho de Melo | c64550c | 2011-10-20 06:45:44 -0200 | [diff] [blame] | 277 | |
Namhyung Kim | 3186b68 | 2014-04-22 13:44:23 +0900 | [diff] [blame] | 278 | diff = prev_period - he->stat.period; |
| 279 | |
Namhyung Kim | 5d8200a | 2016-02-25 00:13:49 +0900 | [diff] [blame] | 280 | if (!he->depth) { |
| 281 | hists->stats.total_period -= diff; |
| 282 | if (!he->filtered) |
| 283 | hists->stats.total_non_filtered_period -= diff; |
| 284 | } |
| 285 | |
| 286 | if (!he->leaf) { |
| 287 | struct hist_entry *child; |
| 288 | struct rb_node *node = rb_first(&he->hroot_out); |
| 289 | while (node) { |
| 290 | child = rb_entry(node, struct hist_entry, rb_node); |
| 291 | node = rb_next(node); |
| 292 | |
| 293 | if (hists__decay_entry(hists, child)) |
| 294 | hists__delete_entry(hists, child); |
| 295 | } |
| 296 | } |
Arnaldo Carvalho de Melo | c64550c | 2011-10-20 06:45:44 -0200 | [diff] [blame] | 297 | |
Namhyung Kim | b24c28f | 2012-10-04 21:49:41 +0900 | [diff] [blame] | 298 | return he->stat.period == 0; |
Arnaldo Carvalho de Melo | ab81f3fd | 2011-10-05 19:16:15 -0300 | [diff] [blame] | 299 | } |
| 300 | |
Arnaldo Carvalho de Melo | 956b65e | 2014-12-19 12:41:28 -0300 | [diff] [blame] | 301 | static void hists__delete_entry(struct hists *hists, struct hist_entry *he) |
| 302 | { |
Namhyung Kim | 5d8200a | 2016-02-25 00:13:49 +0900 | [diff] [blame] | 303 | struct rb_root *root_in; |
| 304 | struct rb_root *root_out; |
Arnaldo Carvalho de Melo | 956b65e | 2014-12-19 12:41:28 -0300 | [diff] [blame] | 305 | |
Namhyung Kim | 5d8200a | 2016-02-25 00:13:49 +0900 | [diff] [blame] | 306 | if (he->parent_he) { |
| 307 | root_in = &he->parent_he->hroot_in; |
| 308 | root_out = &he->parent_he->hroot_out; |
| 309 | } else { |
Jiri Olsa | 5222503 | 2016-05-03 13:54:42 +0200 | [diff] [blame] | 310 | if (hists__has(hists, need_collapse)) |
Namhyung Kim | 5d8200a | 2016-02-25 00:13:49 +0900 | [diff] [blame] | 311 | root_in = &hists->entries_collapsed; |
| 312 | else |
| 313 | root_in = hists->entries_in; |
| 314 | root_out = &hists->entries; |
| 315 | } |
| 316 | |
| 317 | rb_erase(&he->rb_node_in, root_in); |
| 318 | rb_erase(&he->rb_node, root_out); |
Arnaldo Carvalho de Melo | 956b65e | 2014-12-19 12:41:28 -0300 | [diff] [blame] | 319 | |
| 320 | --hists->nr_entries; |
| 321 | if (!he->filtered) |
| 322 | --hists->nr_non_filtered_entries; |
| 323 | |
| 324 | hist_entry__delete(he); |
| 325 | } |
| 326 | |
Namhyung Kim | 3a5714f | 2013-05-14 11:09:01 +0900 | [diff] [blame] | 327 | void hists__decay_entries(struct hists *hists, bool zap_user, bool zap_kernel) |
Arnaldo Carvalho de Melo | ab81f3fd | 2011-10-05 19:16:15 -0300 | [diff] [blame] | 328 | { |
| 329 | struct rb_node *next = rb_first(&hists->entries); |
| 330 | struct hist_entry *n; |
| 331 | |
| 332 | while (next) { |
| 333 | n = rb_entry(next, struct hist_entry, rb_node); |
| 334 | next = rb_next(&n->rb_node); |
Arnaldo Carvalho de Melo | b079d4e | 2011-10-17 09:05:04 -0200 | [diff] [blame] | 335 | if (((zap_user && n->level == '.') || |
| 336 | (zap_kernel && n->level != '.') || |
Arnaldo Carvalho de Melo | 4c47f4f | 2015-03-17 17:18:58 -0300 | [diff] [blame] | 337 | hists__decay_entry(hists, n))) { |
Arnaldo Carvalho de Melo | 956b65e | 2014-12-19 12:41:28 -0300 | [diff] [blame] | 338 | hists__delete_entry(hists, n); |
Arnaldo Carvalho de Melo | ab81f3fd | 2011-10-05 19:16:15 -0300 | [diff] [blame] | 339 | } |
| 340 | } |
| 341 | } |
| 342 | |
Namhyung Kim | 701937b | 2014-08-12 17:16:05 +0900 | [diff] [blame] | 343 | void hists__delete_entries(struct hists *hists) |
| 344 | { |
| 345 | struct rb_node *next = rb_first(&hists->entries); |
| 346 | struct hist_entry *n; |
| 347 | |
| 348 | while (next) { |
| 349 | n = rb_entry(next, struct hist_entry, rb_node); |
| 350 | next = rb_next(&n->rb_node); |
| 351 | |
Arnaldo Carvalho de Melo | 956b65e | 2014-12-19 12:41:28 -0300 | [diff] [blame] | 352 | hists__delete_entry(hists, n); |
Namhyung Kim | 701937b | 2014-08-12 17:16:05 +0900 | [diff] [blame] | 353 | } |
| 354 | } |
| 355 | |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 356 | /* |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 357 | * histogram, sorted on item, collects periods |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 358 | */ |
| 359 | |
Jiri Olsa | 0a269a6 | 2016-07-05 08:56:03 +0200 | [diff] [blame] | 360 | static int hist_entry__init(struct hist_entry *he, |
| 361 | struct hist_entry *template, |
| 362 | bool sample_self) |
| 363 | { |
| 364 | *he = *template; |
| 365 | |
| 366 | if (symbol_conf.cumulate_callchain) { |
| 367 | he->stat_acc = malloc(sizeof(he->stat)); |
| 368 | if (he->stat_acc == NULL) |
| 369 | return -ENOMEM; |
| 370 | memcpy(he->stat_acc, &he->stat, sizeof(he->stat)); |
| 371 | if (!sample_self) |
| 372 | memset(&he->stat, 0, sizeof(he->stat)); |
| 373 | } |
| 374 | |
| 375 | map__get(he->ms.map); |
| 376 | |
| 377 | if (he->branch_info) { |
| 378 | /* |
| 379 | * This branch info is (a part of) allocated from |
| 380 | * sample__resolve_bstack() and will be freed after |
| 381 | * adding new entries. So we need to save a copy. |
| 382 | */ |
| 383 | he->branch_info = malloc(sizeof(*he->branch_info)); |
| 384 | if (he->branch_info == NULL) { |
| 385 | map__zput(he->ms.map); |
| 386 | free(he->stat_acc); |
| 387 | return -ENOMEM; |
| 388 | } |
| 389 | |
| 390 | memcpy(he->branch_info, template->branch_info, |
| 391 | sizeof(*he->branch_info)); |
| 392 | |
| 393 | map__get(he->branch_info->from.map); |
| 394 | map__get(he->branch_info->to.map); |
| 395 | } |
| 396 | |
| 397 | if (he->mem_info) { |
| 398 | map__get(he->mem_info->iaddr.map); |
| 399 | map__get(he->mem_info->daddr.map); |
| 400 | } |
| 401 | |
| 402 | if (symbol_conf.use_callchain) |
| 403 | callchain_init(he->callchain); |
| 404 | |
| 405 | if (he->raw_data) { |
| 406 | he->raw_data = memdup(he->raw_data, he->raw_size); |
| 407 | |
| 408 | if (he->raw_data == NULL) { |
| 409 | map__put(he->ms.map); |
| 410 | if (he->branch_info) { |
| 411 | map__put(he->branch_info->from.map); |
| 412 | map__put(he->branch_info->to.map); |
| 413 | free(he->branch_info); |
| 414 | } |
| 415 | if (he->mem_info) { |
| 416 | map__put(he->mem_info->iaddr.map); |
| 417 | map__put(he->mem_info->daddr.map); |
| 418 | } |
| 419 | free(he->stat_acc); |
| 420 | return -ENOMEM; |
| 421 | } |
| 422 | } |
| 423 | INIT_LIST_HEAD(&he->pairs.node); |
| 424 | thread__get(he->thread); |
Namhyung Kim | d2580c7 | 2016-09-13 16:45:48 +0900 | [diff] [blame] | 425 | he->hroot_in = RB_ROOT; |
| 426 | he->hroot_out = RB_ROOT; |
Jiri Olsa | 0a269a6 | 2016-07-05 08:56:03 +0200 | [diff] [blame] | 427 | |
| 428 | if (!symbol_conf.report_hierarchy) |
| 429 | he->leaf = true; |
| 430 | |
| 431 | return 0; |
| 432 | } |
| 433 | |
Jiri Olsa | f542e76 | 2016-07-05 08:56:04 +0200 | [diff] [blame] | 434 | static void *hist_entry__zalloc(size_t size) |
| 435 | { |
| 436 | return zalloc(size + sizeof(struct hist_entry)); |
| 437 | } |
| 438 | |
| 439 | static void hist_entry__free(void *ptr) |
| 440 | { |
| 441 | free(ptr); |
| 442 | } |
| 443 | |
| 444 | static struct hist_entry_ops default_ops = { |
| 445 | .new = hist_entry__zalloc, |
| 446 | .free = hist_entry__free, |
| 447 | }; |
| 448 | |
Namhyung Kim | a0b51af | 2012-09-11 13:34:27 +0900 | [diff] [blame] | 449 | static struct hist_entry *hist_entry__new(struct hist_entry *template, |
| 450 | bool sample_self) |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 451 | { |
Jiri Olsa | f542e76 | 2016-07-05 08:56:04 +0200 | [diff] [blame] | 452 | struct hist_entry_ops *ops = template->ops; |
Namhyung Kim | f8be1c8 | 2012-09-11 13:15:07 +0900 | [diff] [blame] | 453 | size_t callchain_size = 0; |
| 454 | struct hist_entry *he; |
Jiri Olsa | 0a269a6 | 2016-07-05 08:56:03 +0200 | [diff] [blame] | 455 | int err = 0; |
Namhyung Kim | f8be1c8 | 2012-09-11 13:15:07 +0900 | [diff] [blame] | 456 | |
Jiri Olsa | f542e76 | 2016-07-05 08:56:04 +0200 | [diff] [blame] | 457 | if (!ops) |
| 458 | ops = template->ops = &default_ops; |
| 459 | |
Namhyung Kim | 82aa019 | 2014-12-22 13:44:14 +0900 | [diff] [blame] | 460 | if (symbol_conf.use_callchain) |
Namhyung Kim | f8be1c8 | 2012-09-11 13:15:07 +0900 | [diff] [blame] | 461 | callchain_size = sizeof(struct callchain_root); |
| 462 | |
Jiri Olsa | f542e76 | 2016-07-05 08:56:04 +0200 | [diff] [blame] | 463 | he = ops->new(callchain_size); |
Jiri Olsa | 0a269a6 | 2016-07-05 08:56:03 +0200 | [diff] [blame] | 464 | if (he) { |
| 465 | err = hist_entry__init(he, template, sample_self); |
Jiri Olsa | f542e76 | 2016-07-05 08:56:04 +0200 | [diff] [blame] | 466 | if (err) { |
| 467 | ops->free(he); |
| 468 | he = NULL; |
| 469 | } |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 470 | } |
| 471 | |
Arnaldo Carvalho de Melo | 12c1427 | 2012-01-04 12:27:03 -0200 | [diff] [blame] | 472 | return he; |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 473 | } |
| 474 | |
Arnaldo Carvalho de Melo | 7a007ca | 2010-07-21 09:19:41 -0300 | [diff] [blame] | 475 | static u8 symbol__parent_filter(const struct symbol *parent) |
| 476 | { |
| 477 | if (symbol_conf.exclude_other && parent == NULL) |
| 478 | return 1 << HIST_FILTER__PARENT; |
| 479 | return 0; |
| 480 | } |
| 481 | |
Namhyung Kim | 467ef10 | 2016-02-16 23:08:19 +0900 | [diff] [blame] | 482 | static void hist_entry__add_callchain_period(struct hist_entry *he, u64 period) |
| 483 | { |
| 484 | if (!symbol_conf.use_callchain) |
| 485 | return; |
| 486 | |
| 487 | he->hists->callchain_period += period; |
| 488 | if (!he->filtered) |
| 489 | he->hists->callchain_non_filtered_period += period; |
| 490 | } |
| 491 | |
Arnaldo Carvalho de Melo | e7e0efc | 2015-05-19 11:31:22 -0300 | [diff] [blame] | 492 | static struct hist_entry *hists__findnew_entry(struct hists *hists, |
| 493 | struct hist_entry *entry, |
| 494 | struct addr_location *al, |
| 495 | bool sample_self) |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 496 | { |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 497 | struct rb_node **p; |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 498 | struct rb_node *parent = NULL; |
| 499 | struct hist_entry *he; |
Andi Kleen | 354cc40 | 2013-10-01 07:22:15 -0700 | [diff] [blame] | 500 | int64_t cmp; |
Namhyung Kim | f1cbf78 | 2013-12-18 14:21:11 +0900 | [diff] [blame] | 501 | u64 period = entry->stat.period; |
| 502 | u64 weight = entry->stat.weight; |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 503 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 504 | p = &hists->entries_in->rb_node; |
| 505 | |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 506 | while (*p != NULL) { |
| 507 | parent = *p; |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 508 | he = rb_entry(parent, struct hist_entry, rb_node_in); |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 509 | |
Namhyung Kim | 9afcf93 | 2012-12-10 17:29:54 +0900 | [diff] [blame] | 510 | /* |
| 511 | * Make sure that it receives arguments in a same order as |
| 512 | * hist_entry__collapse() so that we can use an appropriate |
| 513 | * function when searching an entry regardless which sort |
| 514 | * keys were used. |
| 515 | */ |
| 516 | cmp = hist_entry__cmp(he, entry); |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 517 | |
| 518 | if (!cmp) { |
Namhyung Kim | 0f58474 | 2016-01-28 00:40:49 +0900 | [diff] [blame] | 519 | if (sample_self) { |
Namhyung Kim | a0b51af | 2012-09-11 13:34:27 +0900 | [diff] [blame] | 520 | he_stat__add_period(&he->stat, period, weight); |
Namhyung Kim | 467ef10 | 2016-02-16 23:08:19 +0900 | [diff] [blame] | 521 | hist_entry__add_callchain_period(he, period); |
Namhyung Kim | 0f58474 | 2016-01-28 00:40:49 +0900 | [diff] [blame] | 522 | } |
Namhyung Kim | f8be1c8 | 2012-09-11 13:15:07 +0900 | [diff] [blame] | 523 | if (symbol_conf.cumulate_callchain) |
| 524 | he_stat__add_period(he->stat_acc, period, weight); |
David Miller | 63fa471 | 2012-03-27 03:14:18 -0400 | [diff] [blame] | 525 | |
Namhyung Kim | ceb2acb | 2013-04-01 20:35:18 +0900 | [diff] [blame] | 526 | /* |
Arnaldo Carvalho de Melo | e80faac | 2014-01-22 13:05:06 -0300 | [diff] [blame] | 527 | * This mem info was allocated from sample__resolve_mem |
Namhyung Kim | ceb2acb | 2013-04-01 20:35:18 +0900 | [diff] [blame] | 528 | * and will not be used anymore. |
| 529 | */ |
Arnaldo Carvalho de Melo | 74cf249 | 2013-12-27 16:55:14 -0300 | [diff] [blame] | 530 | zfree(&entry->mem_info); |
Namhyung Kim | ceb2acb | 2013-04-01 20:35:18 +0900 | [diff] [blame] | 531 | |
David Miller | 63fa471 | 2012-03-27 03:14:18 -0400 | [diff] [blame] | 532 | /* If the map of an existing hist_entry has |
| 533 | * become out-of-date due to an exec() or |
| 534 | * similar, update it. Otherwise we will |
| 535 | * mis-adjust symbol addresses when computing |
| 536 | * the history counter to increment. |
| 537 | */ |
| 538 | if (he->ms.map != entry->ms.map) { |
Arnaldo Carvalho de Melo | 5c24b67 | 2015-06-15 23:29:51 -0300 | [diff] [blame] | 539 | map__put(he->ms.map); |
| 540 | he->ms.map = map__get(entry->ms.map); |
David Miller | 63fa471 | 2012-03-27 03:14:18 -0400 | [diff] [blame] | 541 | } |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 542 | goto out; |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | if (cmp < 0) |
| 546 | p = &(*p)->rb_left; |
| 547 | else |
| 548 | p = &(*p)->rb_right; |
| 549 | } |
| 550 | |
Namhyung Kim | a0b51af | 2012-09-11 13:34:27 +0900 | [diff] [blame] | 551 | he = hist_entry__new(entry, sample_self); |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 552 | if (!he) |
Namhyung Kim | 27a0dcb | 2013-05-14 11:09:02 +0900 | [diff] [blame] | 553 | return NULL; |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 554 | |
Namhyung Kim | 0f58474 | 2016-01-28 00:40:49 +0900 | [diff] [blame] | 555 | if (sample_self) |
Namhyung Kim | 467ef10 | 2016-02-16 23:08:19 +0900 | [diff] [blame] | 556 | hist_entry__add_callchain_period(he, period); |
| 557 | hists->nr_entries++; |
Namhyung Kim | 590cd34 | 2014-12-22 13:44:09 +0900 | [diff] [blame] | 558 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 559 | rb_link_node(&he->rb_node_in, parent, p); |
| 560 | rb_insert_color(&he->rb_node_in, hists->entries_in); |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 561 | out: |
Namhyung Kim | a0b51af | 2012-09-11 13:34:27 +0900 | [diff] [blame] | 562 | if (sample_self) |
| 563 | he_stat__add_cpumode_period(&he->stat, al->cpumode, period); |
Namhyung Kim | f8be1c8 | 2012-09-11 13:15:07 +0900 | [diff] [blame] | 564 | if (symbol_conf.cumulate_callchain) |
| 565 | 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] | 566 | return he; |
| 567 | } |
| 568 | |
Jiri Olsa | a505197 | 2016-07-05 08:56:05 +0200 | [diff] [blame] | 569 | static struct hist_entry* |
| 570 | __hists__add_entry(struct hists *hists, |
| 571 | struct addr_location *al, |
| 572 | struct symbol *sym_parent, |
| 573 | struct branch_info *bi, |
| 574 | struct mem_info *mi, |
| 575 | struct perf_sample *sample, |
| 576 | bool sample_self, |
| 577 | struct hist_entry_ops *ops) |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 578 | { |
Hari Bathini | d890a98 | 2017-03-08 02:12:13 +0530 | [diff] [blame] | 579 | struct namespaces *ns = thread__namespaces(al->thread); |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 580 | struct hist_entry entry = { |
| 581 | .thread = al->thread, |
Namhyung Kim | 4dfced3 | 2013-09-13 16:28:57 +0900 | [diff] [blame] | 582 | .comm = thread__comm(al->thread), |
Hari Bathini | d890a98 | 2017-03-08 02:12:13 +0530 | [diff] [blame] | 583 | .cgroup_id = { |
| 584 | .dev = ns ? ns->link_info[CGROUP_NS_INDEX].dev : 0, |
| 585 | .ino = ns ? ns->link_info[CGROUP_NS_INDEX].ino : 0, |
| 586 | }, |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 587 | .ms = { |
| 588 | .map = al->map, |
| 589 | .sym = al->sym, |
| 590 | }, |
Kan Liang | 0c4c4deb | 2015-09-04 10:45:42 -0400 | [diff] [blame] | 591 | .socket = al->socket, |
Don Zickus | 7365be5 | 2014-05-27 12:28:05 -0400 | [diff] [blame] | 592 | .cpu = al->cpu, |
| 593 | .cpumode = al->cpumode, |
| 594 | .ip = al->addr, |
| 595 | .level = al->level, |
Namhyung Kim | b24c28f | 2012-10-04 21:49:41 +0900 | [diff] [blame] | 596 | .stat = { |
Namhyung Kim | c4b3535 | 2012-10-04 21:49:42 +0900 | [diff] [blame] | 597 | .nr_events = 1, |
Namhyung Kim | fd36f3d | 2015-12-23 02:06:58 +0900 | [diff] [blame] | 598 | .period = sample->period, |
| 599 | .weight = sample->weight, |
Namhyung Kim | b24c28f | 2012-10-04 21:49:41 +0900 | [diff] [blame] | 600 | }, |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 601 | .parent = sym_parent, |
Namhyung Kim | 2c86c7c | 2014-03-17 18:18:54 -0300 | [diff] [blame] | 602 | .filtered = symbol__parent_filter(sym_parent) | al->filtered, |
Arnaldo Carvalho de Melo | c824c43 | 2013-10-22 19:01:31 -0300 | [diff] [blame] | 603 | .hists = hists, |
Namhyung Kim | 41a4e6e | 2013-10-31 15:56:03 +0900 | [diff] [blame] | 604 | .branch_info = bi, |
| 605 | .mem_info = mi, |
Namhyung Kim | fd36f3d | 2015-12-23 02:06:58 +0900 | [diff] [blame] | 606 | .transaction = sample->transaction, |
Namhyung Kim | 7239283 | 2015-12-24 11:16:17 +0900 | [diff] [blame] | 607 | .raw_data = sample->raw_data, |
| 608 | .raw_size = sample->raw_size, |
Jiri Olsa | a505197 | 2016-07-05 08:56:05 +0200 | [diff] [blame] | 609 | .ops = ops, |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 610 | }; |
| 611 | |
Arnaldo Carvalho de Melo | e7e0efc | 2015-05-19 11:31:22 -0300 | [diff] [blame] | 612 | return hists__findnew_entry(hists, &entry, al, sample_self); |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 613 | } |
| 614 | |
Jiri Olsa | a505197 | 2016-07-05 08:56:05 +0200 | [diff] [blame] | 615 | struct hist_entry *hists__add_entry(struct hists *hists, |
| 616 | struct addr_location *al, |
| 617 | struct symbol *sym_parent, |
| 618 | struct branch_info *bi, |
| 619 | struct mem_info *mi, |
| 620 | struct perf_sample *sample, |
| 621 | bool sample_self) |
| 622 | { |
| 623 | return __hists__add_entry(hists, al, sym_parent, bi, mi, |
| 624 | sample, sample_self, NULL); |
| 625 | } |
| 626 | |
| 627 | struct hist_entry *hists__add_entry_ops(struct hists *hists, |
| 628 | struct hist_entry_ops *ops, |
| 629 | struct addr_location *al, |
| 630 | struct symbol *sym_parent, |
| 631 | struct branch_info *bi, |
| 632 | struct mem_info *mi, |
| 633 | struct perf_sample *sample, |
| 634 | bool sample_self) |
| 635 | { |
| 636 | return __hists__add_entry(hists, al, sym_parent, bi, mi, |
| 637 | sample, sample_self, ops); |
| 638 | } |
| 639 | |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 640 | static int |
| 641 | iter_next_nop_entry(struct hist_entry_iter *iter __maybe_unused, |
| 642 | struct addr_location *al __maybe_unused) |
| 643 | { |
| 644 | return 0; |
| 645 | } |
| 646 | |
| 647 | static int |
| 648 | iter_add_next_nop_entry(struct hist_entry_iter *iter __maybe_unused, |
| 649 | struct addr_location *al __maybe_unused) |
| 650 | { |
| 651 | return 0; |
| 652 | } |
| 653 | |
| 654 | static int |
| 655 | iter_prepare_mem_entry(struct hist_entry_iter *iter, struct addr_location *al) |
| 656 | { |
| 657 | struct perf_sample *sample = iter->sample; |
| 658 | struct mem_info *mi; |
| 659 | |
| 660 | mi = sample__resolve_mem(sample, al); |
| 661 | if (mi == NULL) |
| 662 | return -ENOMEM; |
| 663 | |
| 664 | iter->priv = mi; |
| 665 | return 0; |
| 666 | } |
| 667 | |
| 668 | static int |
| 669 | iter_add_single_mem_entry(struct hist_entry_iter *iter, struct addr_location *al) |
| 670 | { |
| 671 | u64 cost; |
| 672 | struct mem_info *mi = iter->priv; |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 673 | struct hists *hists = evsel__hists(iter->evsel); |
Namhyung Kim | fd36f3d | 2015-12-23 02:06:58 +0900 | [diff] [blame] | 674 | struct perf_sample *sample = iter->sample; |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 675 | struct hist_entry *he; |
| 676 | |
| 677 | if (mi == NULL) |
| 678 | return -EINVAL; |
| 679 | |
Namhyung Kim | fd36f3d | 2015-12-23 02:06:58 +0900 | [diff] [blame] | 680 | cost = sample->weight; |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 681 | if (!cost) |
| 682 | cost = 1; |
| 683 | |
| 684 | /* |
| 685 | * must pass period=weight in order to get the correct |
| 686 | * sorting from hists__collapse_resort() which is solely |
| 687 | * based on periods. We want sorting be done on nr_events * weight |
| 688 | * and this is indirectly achieved by passing period=weight here |
| 689 | * and the he_stat__add_period() function. |
| 690 | */ |
Namhyung Kim | fd36f3d | 2015-12-23 02:06:58 +0900 | [diff] [blame] | 691 | sample->period = cost; |
| 692 | |
Jiri Olsa | 0102ef3 | 2016-06-14 20:19:21 +0200 | [diff] [blame] | 693 | he = hists__add_entry(hists, al, iter->parent, NULL, mi, |
| 694 | sample, true); |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 695 | if (!he) |
| 696 | return -ENOMEM; |
| 697 | |
| 698 | iter->he = he; |
| 699 | return 0; |
| 700 | } |
| 701 | |
| 702 | static int |
Namhyung Kim | 9d3c02d | 2014-01-07 17:02:25 +0900 | [diff] [blame] | 703 | iter_finish_mem_entry(struct hist_entry_iter *iter, |
| 704 | struct addr_location *al __maybe_unused) |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 705 | { |
| 706 | struct perf_evsel *evsel = iter->evsel; |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 707 | struct hists *hists = evsel__hists(evsel); |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 708 | struct hist_entry *he = iter->he; |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 709 | int err = -EINVAL; |
| 710 | |
| 711 | if (he == NULL) |
| 712 | goto out; |
| 713 | |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 714 | hists__inc_nr_samples(hists, he->filtered); |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 715 | |
| 716 | err = hist_entry__append_callchain(he, iter->sample); |
| 717 | |
| 718 | out: |
| 719 | /* |
Arnaldo Carvalho de Melo | e7e0efc | 2015-05-19 11:31:22 -0300 | [diff] [blame] | 720 | * We don't need to free iter->priv (mem_info) here since the mem info |
| 721 | * was either already freed in hists__findnew_entry() or passed to a |
| 722 | * new hist entry by hist_entry__new(). |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 723 | */ |
| 724 | iter->priv = NULL; |
| 725 | |
| 726 | iter->he = NULL; |
| 727 | return err; |
| 728 | } |
| 729 | |
| 730 | static int |
| 731 | iter_prepare_branch_entry(struct hist_entry_iter *iter, struct addr_location *al) |
| 732 | { |
| 733 | struct branch_info *bi; |
| 734 | struct perf_sample *sample = iter->sample; |
| 735 | |
| 736 | bi = sample__resolve_bstack(sample, al); |
| 737 | if (!bi) |
| 738 | return -ENOMEM; |
| 739 | |
| 740 | iter->curr = 0; |
| 741 | iter->total = sample->branch_stack->nr; |
| 742 | |
| 743 | iter->priv = bi; |
| 744 | return 0; |
| 745 | } |
| 746 | |
| 747 | static int |
Arnaldo Carvalho de Melo | b8f8eb8 | 2016-03-22 13:09:37 -0300 | [diff] [blame] | 748 | iter_add_single_branch_entry(struct hist_entry_iter *iter, |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 749 | struct addr_location *al __maybe_unused) |
| 750 | { |
Namhyung Kim | 9d3c02d | 2014-01-07 17:02:25 +0900 | [diff] [blame] | 751 | /* to avoid calling callback function */ |
| 752 | iter->he = NULL; |
| 753 | |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 754 | return 0; |
| 755 | } |
| 756 | |
| 757 | static int |
| 758 | iter_next_branch_entry(struct hist_entry_iter *iter, struct addr_location *al) |
| 759 | { |
| 760 | struct branch_info *bi = iter->priv; |
| 761 | int i = iter->curr; |
| 762 | |
| 763 | if (bi == NULL) |
| 764 | return 0; |
| 765 | |
| 766 | if (iter->curr >= iter->total) |
| 767 | return 0; |
| 768 | |
| 769 | al->map = bi[i].to.map; |
| 770 | al->sym = bi[i].to.sym; |
| 771 | al->addr = bi[i].to.addr; |
| 772 | return 1; |
| 773 | } |
| 774 | |
| 775 | static int |
| 776 | iter_add_next_branch_entry(struct hist_entry_iter *iter, struct addr_location *al) |
| 777 | { |
Namhyung Kim | 9d3c02d | 2014-01-07 17:02:25 +0900 | [diff] [blame] | 778 | struct branch_info *bi; |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 779 | struct perf_evsel *evsel = iter->evsel; |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 780 | struct hists *hists = evsel__hists(evsel); |
Namhyung Kim | fd36f3d | 2015-12-23 02:06:58 +0900 | [diff] [blame] | 781 | struct perf_sample *sample = iter->sample; |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 782 | struct hist_entry *he = NULL; |
| 783 | int i = iter->curr; |
| 784 | int err = 0; |
| 785 | |
| 786 | bi = iter->priv; |
| 787 | |
| 788 | if (iter->hide_unresolved && !(bi[i].from.sym && bi[i].to.sym)) |
| 789 | goto out; |
| 790 | |
| 791 | /* |
| 792 | * The report shows the percentage of total branches captured |
| 793 | * and not events sampled. Thus we use a pseudo period of 1. |
| 794 | */ |
Namhyung Kim | fd36f3d | 2015-12-23 02:06:58 +0900 | [diff] [blame] | 795 | sample->period = 1; |
| 796 | sample->weight = bi->flags.cycles ? bi->flags.cycles : 1; |
| 797 | |
Jiri Olsa | 0102ef3 | 2016-06-14 20:19:21 +0200 | [diff] [blame] | 798 | he = hists__add_entry(hists, al, iter->parent, &bi[i], NULL, |
| 799 | sample, true); |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 800 | if (he == NULL) |
| 801 | return -ENOMEM; |
| 802 | |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 803 | hists__inc_nr_samples(hists, he->filtered); |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 804 | |
| 805 | out: |
| 806 | iter->he = he; |
| 807 | iter->curr++; |
| 808 | return err; |
| 809 | } |
| 810 | |
| 811 | static int |
| 812 | iter_finish_branch_entry(struct hist_entry_iter *iter, |
| 813 | struct addr_location *al __maybe_unused) |
| 814 | { |
| 815 | zfree(&iter->priv); |
| 816 | iter->he = NULL; |
| 817 | |
| 818 | return iter->curr >= iter->total ? 0 : -1; |
| 819 | } |
| 820 | |
| 821 | static int |
| 822 | iter_prepare_normal_entry(struct hist_entry_iter *iter __maybe_unused, |
| 823 | struct addr_location *al __maybe_unused) |
| 824 | { |
| 825 | return 0; |
| 826 | } |
| 827 | |
| 828 | static int |
| 829 | iter_add_single_normal_entry(struct hist_entry_iter *iter, struct addr_location *al) |
| 830 | { |
| 831 | struct perf_evsel *evsel = iter->evsel; |
| 832 | struct perf_sample *sample = iter->sample; |
| 833 | struct hist_entry *he; |
| 834 | |
Jiri Olsa | 0102ef3 | 2016-06-14 20:19:21 +0200 | [diff] [blame] | 835 | he = hists__add_entry(evsel__hists(evsel), al, iter->parent, NULL, NULL, |
| 836 | sample, true); |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 837 | if (he == NULL) |
| 838 | return -ENOMEM; |
| 839 | |
| 840 | iter->he = he; |
| 841 | return 0; |
| 842 | } |
| 843 | |
| 844 | static int |
Namhyung Kim | 9d3c02d | 2014-01-07 17:02:25 +0900 | [diff] [blame] | 845 | iter_finish_normal_entry(struct hist_entry_iter *iter, |
| 846 | struct addr_location *al __maybe_unused) |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 847 | { |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 848 | struct hist_entry *he = iter->he; |
| 849 | struct perf_evsel *evsel = iter->evsel; |
| 850 | struct perf_sample *sample = iter->sample; |
| 851 | |
| 852 | if (he == NULL) |
| 853 | return 0; |
| 854 | |
| 855 | iter->he = NULL; |
| 856 | |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 857 | hists__inc_nr_samples(evsel__hists(evsel), he->filtered); |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 858 | |
| 859 | return hist_entry__append_callchain(he, sample); |
| 860 | } |
| 861 | |
Namhyung Kim | 7a13aa2 | 2012-09-11 14:13:04 +0900 | [diff] [blame] | 862 | static int |
Adrian Hunter | 96b40f3 | 2015-09-25 16:15:47 +0300 | [diff] [blame] | 863 | iter_prepare_cumulative_entry(struct hist_entry_iter *iter, |
Namhyung Kim | 7a13aa2 | 2012-09-11 14:13:04 +0900 | [diff] [blame] | 864 | struct addr_location *al __maybe_unused) |
| 865 | { |
Namhyung Kim | b4d3c8b | 2013-10-31 10:05:29 +0900 | [diff] [blame] | 866 | struct hist_entry **he_cache; |
| 867 | |
Namhyung Kim | 7a13aa2 | 2012-09-11 14:13:04 +0900 | [diff] [blame] | 868 | callchain_cursor_commit(&callchain_cursor); |
Namhyung Kim | b4d3c8b | 2013-10-31 10:05:29 +0900 | [diff] [blame] | 869 | |
| 870 | /* |
| 871 | * This is for detecting cycles or recursions so that they're |
| 872 | * cumulated only one time to prevent entries more than 100% |
| 873 | * overhead. |
| 874 | */ |
Adrian Hunter | 96b40f3 | 2015-09-25 16:15:47 +0300 | [diff] [blame] | 875 | he_cache = malloc(sizeof(*he_cache) * (iter->max_stack + 1)); |
Namhyung Kim | b4d3c8b | 2013-10-31 10:05:29 +0900 | [diff] [blame] | 876 | if (he_cache == NULL) |
| 877 | return -ENOMEM; |
| 878 | |
| 879 | iter->priv = he_cache; |
| 880 | iter->curr = 0; |
| 881 | |
Namhyung Kim | 7a13aa2 | 2012-09-11 14:13:04 +0900 | [diff] [blame] | 882 | return 0; |
| 883 | } |
| 884 | |
| 885 | static int |
| 886 | iter_add_single_cumulative_entry(struct hist_entry_iter *iter, |
| 887 | struct addr_location *al) |
| 888 | { |
| 889 | struct perf_evsel *evsel = iter->evsel; |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 890 | struct hists *hists = evsel__hists(evsel); |
Namhyung Kim | 7a13aa2 | 2012-09-11 14:13:04 +0900 | [diff] [blame] | 891 | struct perf_sample *sample = iter->sample; |
Namhyung Kim | b4d3c8b | 2013-10-31 10:05:29 +0900 | [diff] [blame] | 892 | struct hist_entry **he_cache = iter->priv; |
Namhyung Kim | 7a13aa2 | 2012-09-11 14:13:04 +0900 | [diff] [blame] | 893 | struct hist_entry *he; |
| 894 | int err = 0; |
| 895 | |
Jiri Olsa | 0102ef3 | 2016-06-14 20:19:21 +0200 | [diff] [blame] | 896 | he = hists__add_entry(hists, al, iter->parent, NULL, NULL, |
| 897 | sample, true); |
Namhyung Kim | 7a13aa2 | 2012-09-11 14:13:04 +0900 | [diff] [blame] | 898 | if (he == NULL) |
| 899 | return -ENOMEM; |
| 900 | |
| 901 | iter->he = he; |
Namhyung Kim | b4d3c8b | 2013-10-31 10:05:29 +0900 | [diff] [blame] | 902 | he_cache[iter->curr++] = he; |
Namhyung Kim | 7a13aa2 | 2012-09-11 14:13:04 +0900 | [diff] [blame] | 903 | |
Namhyung Kim | 82aa019 | 2014-12-22 13:44:14 +0900 | [diff] [blame] | 904 | hist_entry__append_callchain(he, sample); |
Namhyung Kim | be7f855 | 2013-12-26 17:44:10 +0900 | [diff] [blame] | 905 | |
| 906 | /* |
| 907 | * We need to re-initialize the cursor since callchain_append() |
| 908 | * advanced the cursor to the end. |
| 909 | */ |
| 910 | callchain_cursor_commit(&callchain_cursor); |
| 911 | |
Arnaldo Carvalho de Melo | 4ea062ed | 2014-10-09 13:13:41 -0300 | [diff] [blame] | 912 | hists__inc_nr_samples(hists, he->filtered); |
Namhyung Kim | 7a13aa2 | 2012-09-11 14:13:04 +0900 | [diff] [blame] | 913 | |
| 914 | return err; |
| 915 | } |
| 916 | |
| 917 | static int |
| 918 | iter_next_cumulative_entry(struct hist_entry_iter *iter, |
| 919 | struct addr_location *al) |
| 920 | { |
| 921 | struct callchain_cursor_node *node; |
| 922 | |
| 923 | node = callchain_cursor_current(&callchain_cursor); |
| 924 | if (node == NULL) |
| 925 | return 0; |
| 926 | |
Namhyung Kim | c7405d8 | 2013-10-31 13:58:30 +0900 | [diff] [blame] | 927 | return fill_callchain_info(al, node, iter->hide_unresolved); |
Namhyung Kim | 7a13aa2 | 2012-09-11 14:13:04 +0900 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | static int |
| 931 | iter_add_next_cumulative_entry(struct hist_entry_iter *iter, |
| 932 | struct addr_location *al) |
| 933 | { |
| 934 | struct perf_evsel *evsel = iter->evsel; |
| 935 | struct perf_sample *sample = iter->sample; |
Namhyung Kim | b4d3c8b | 2013-10-31 10:05:29 +0900 | [diff] [blame] | 936 | struct hist_entry **he_cache = iter->priv; |
Namhyung Kim | 7a13aa2 | 2012-09-11 14:13:04 +0900 | [diff] [blame] | 937 | struct hist_entry *he; |
Namhyung Kim | b4d3c8b | 2013-10-31 10:05:29 +0900 | [diff] [blame] | 938 | struct hist_entry he_tmp = { |
Arnaldo Carvalho de Melo | 5cef897 | 2015-08-10 15:45:55 -0300 | [diff] [blame] | 939 | .hists = evsel__hists(evsel), |
Namhyung Kim | b4d3c8b | 2013-10-31 10:05:29 +0900 | [diff] [blame] | 940 | .cpu = al->cpu, |
| 941 | .thread = al->thread, |
| 942 | .comm = thread__comm(al->thread), |
| 943 | .ip = al->addr, |
| 944 | .ms = { |
| 945 | .map = al->map, |
| 946 | .sym = al->sym, |
| 947 | }, |
| 948 | .parent = iter->parent, |
Namhyung Kim | 7239283 | 2015-12-24 11:16:17 +0900 | [diff] [blame] | 949 | .raw_data = sample->raw_data, |
| 950 | .raw_size = sample->raw_size, |
Namhyung Kim | b4d3c8b | 2013-10-31 10:05:29 +0900 | [diff] [blame] | 951 | }; |
| 952 | int i; |
Namhyung Kim | be7f855 | 2013-12-26 17:44:10 +0900 | [diff] [blame] | 953 | struct callchain_cursor cursor; |
| 954 | |
| 955 | callchain_cursor_snapshot(&cursor, &callchain_cursor); |
| 956 | |
| 957 | callchain_cursor_advance(&callchain_cursor); |
Namhyung Kim | b4d3c8b | 2013-10-31 10:05:29 +0900 | [diff] [blame] | 958 | |
| 959 | /* |
| 960 | * Check if there's duplicate entries in the callchain. |
| 961 | * It's possible that it has cycles or recursive calls. |
| 962 | */ |
| 963 | for (i = 0; i < iter->curr; i++) { |
Namhyung Kim | 9d3c02d | 2014-01-07 17:02:25 +0900 | [diff] [blame] | 964 | if (hist_entry__cmp(he_cache[i], &he_tmp) == 0) { |
| 965 | /* to avoid calling callback function */ |
| 966 | iter->he = NULL; |
Namhyung Kim | b4d3c8b | 2013-10-31 10:05:29 +0900 | [diff] [blame] | 967 | return 0; |
Namhyung Kim | 9d3c02d | 2014-01-07 17:02:25 +0900 | [diff] [blame] | 968 | } |
Namhyung Kim | b4d3c8b | 2013-10-31 10:05:29 +0900 | [diff] [blame] | 969 | } |
Namhyung Kim | 7a13aa2 | 2012-09-11 14:13:04 +0900 | [diff] [blame] | 970 | |
Jiri Olsa | 0102ef3 | 2016-06-14 20:19:21 +0200 | [diff] [blame] | 971 | he = hists__add_entry(evsel__hists(evsel), al, iter->parent, NULL, NULL, |
| 972 | sample, false); |
Namhyung Kim | 7a13aa2 | 2012-09-11 14:13:04 +0900 | [diff] [blame] | 973 | if (he == NULL) |
| 974 | return -ENOMEM; |
| 975 | |
| 976 | iter->he = he; |
Namhyung Kim | b4d3c8b | 2013-10-31 10:05:29 +0900 | [diff] [blame] | 977 | he_cache[iter->curr++] = he; |
Namhyung Kim | 7a13aa2 | 2012-09-11 14:13:04 +0900 | [diff] [blame] | 978 | |
Namhyung Kim | 82aa019 | 2014-12-22 13:44:14 +0900 | [diff] [blame] | 979 | if (symbol_conf.use_callchain) |
| 980 | callchain_append(he->callchain, &cursor, sample->period); |
Namhyung Kim | 7a13aa2 | 2012-09-11 14:13:04 +0900 | [diff] [blame] | 981 | return 0; |
| 982 | } |
| 983 | |
| 984 | static int |
| 985 | iter_finish_cumulative_entry(struct hist_entry_iter *iter, |
| 986 | struct addr_location *al __maybe_unused) |
| 987 | { |
Namhyung Kim | b4d3c8b | 2013-10-31 10:05:29 +0900 | [diff] [blame] | 988 | zfree(&iter->priv); |
Namhyung Kim | 7a13aa2 | 2012-09-11 14:13:04 +0900 | [diff] [blame] | 989 | iter->he = NULL; |
Namhyung Kim | b4d3c8b | 2013-10-31 10:05:29 +0900 | [diff] [blame] | 990 | |
Namhyung Kim | 7a13aa2 | 2012-09-11 14:13:04 +0900 | [diff] [blame] | 991 | return 0; |
| 992 | } |
| 993 | |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 994 | const struct hist_iter_ops hist_iter_mem = { |
| 995 | .prepare_entry = iter_prepare_mem_entry, |
| 996 | .add_single_entry = iter_add_single_mem_entry, |
| 997 | .next_entry = iter_next_nop_entry, |
| 998 | .add_next_entry = iter_add_next_nop_entry, |
| 999 | .finish_entry = iter_finish_mem_entry, |
| 1000 | }; |
| 1001 | |
| 1002 | const struct hist_iter_ops hist_iter_branch = { |
| 1003 | .prepare_entry = iter_prepare_branch_entry, |
| 1004 | .add_single_entry = iter_add_single_branch_entry, |
| 1005 | .next_entry = iter_next_branch_entry, |
| 1006 | .add_next_entry = iter_add_next_branch_entry, |
| 1007 | .finish_entry = iter_finish_branch_entry, |
| 1008 | }; |
| 1009 | |
| 1010 | const struct hist_iter_ops hist_iter_normal = { |
| 1011 | .prepare_entry = iter_prepare_normal_entry, |
| 1012 | .add_single_entry = iter_add_single_normal_entry, |
| 1013 | .next_entry = iter_next_nop_entry, |
| 1014 | .add_next_entry = iter_add_next_nop_entry, |
| 1015 | .finish_entry = iter_finish_normal_entry, |
| 1016 | }; |
| 1017 | |
Namhyung Kim | 7a13aa2 | 2012-09-11 14:13:04 +0900 | [diff] [blame] | 1018 | const struct hist_iter_ops hist_iter_cumulative = { |
| 1019 | .prepare_entry = iter_prepare_cumulative_entry, |
| 1020 | .add_single_entry = iter_add_single_cumulative_entry, |
| 1021 | .next_entry = iter_next_cumulative_entry, |
| 1022 | .add_next_entry = iter_add_next_cumulative_entry, |
| 1023 | .finish_entry = iter_finish_cumulative_entry, |
| 1024 | }; |
| 1025 | |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 1026 | 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] | 1027 | int max_stack_depth, void *arg) |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 1028 | { |
| 1029 | int err, err2; |
Krister Johansen | 9c68ae9 | 2017-01-05 22:23:31 -0800 | [diff] [blame] | 1030 | struct map *alm = NULL; |
| 1031 | |
| 1032 | if (al && al->map) |
| 1033 | alm = map__get(al->map); |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 1034 | |
Arnaldo Carvalho de Melo | 91d7b2d | 2016-04-14 14:48:07 -0300 | [diff] [blame] | 1035 | err = sample__resolve_callchain(iter->sample, &callchain_cursor, &iter->parent, |
Namhyung Kim | 063bd93 | 2015-05-19 17:04:10 +0900 | [diff] [blame] | 1036 | iter->evsel, al, max_stack_depth); |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 1037 | if (err) |
| 1038 | return err; |
| 1039 | |
Adrian Hunter | 96b40f3 | 2015-09-25 16:15:47 +0300 | [diff] [blame] | 1040 | iter->max_stack = max_stack_depth; |
| 1041 | |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 1042 | err = iter->ops->prepare_entry(iter, al); |
| 1043 | if (err) |
| 1044 | goto out; |
| 1045 | |
| 1046 | err = iter->ops->add_single_entry(iter, al); |
| 1047 | if (err) |
| 1048 | goto out; |
| 1049 | |
Namhyung Kim | 9d3c02d | 2014-01-07 17:02:25 +0900 | [diff] [blame] | 1050 | if (iter->he && iter->add_entry_cb) { |
| 1051 | err = iter->add_entry_cb(iter, al, true, arg); |
| 1052 | if (err) |
| 1053 | goto out; |
| 1054 | } |
| 1055 | |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 1056 | while (iter->ops->next_entry(iter, al)) { |
| 1057 | err = iter->ops->add_next_entry(iter, al); |
| 1058 | if (err) |
| 1059 | break; |
Namhyung Kim | 9d3c02d | 2014-01-07 17:02:25 +0900 | [diff] [blame] | 1060 | |
| 1061 | if (iter->he && iter->add_entry_cb) { |
| 1062 | err = iter->add_entry_cb(iter, al, false, arg); |
| 1063 | if (err) |
| 1064 | goto out; |
| 1065 | } |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 1066 | } |
| 1067 | |
| 1068 | out: |
| 1069 | err2 = iter->ops->finish_entry(iter, al); |
| 1070 | if (!err) |
| 1071 | err = err2; |
| 1072 | |
Krister Johansen | 9c68ae9 | 2017-01-05 22:23:31 -0800 | [diff] [blame] | 1073 | map__put(alm); |
| 1074 | |
Namhyung Kim | 69bcb01 | 2013-10-30 09:40:34 +0900 | [diff] [blame] | 1075 | return err; |
| 1076 | } |
| 1077 | |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1078 | int64_t |
| 1079 | hist_entry__cmp(struct hist_entry *left, struct hist_entry *right) |
| 1080 | { |
Jiri Olsa | aa6f50a | 2016-01-18 10:24:24 +0100 | [diff] [blame] | 1081 | struct hists *hists = left->hists; |
Namhyung Kim | 093f0ef3 | 2014-03-03 12:07:47 +0900 | [diff] [blame] | 1082 | struct perf_hpp_fmt *fmt; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1083 | int64_t cmp = 0; |
| 1084 | |
Jiri Olsa | aa6f50a | 2016-01-18 10:24:24 +0100 | [diff] [blame] | 1085 | hists__for_each_sort_list(hists, fmt) { |
Namhyung Kim | 84b6ee8 | 2016-02-27 03:52:43 +0900 | [diff] [blame] | 1086 | if (perf_hpp__is_dynamic_entry(fmt) && |
| 1087 | !perf_hpp__defined_dynamic_entry(fmt, hists)) |
| 1088 | continue; |
| 1089 | |
Namhyung Kim | 87bbdf7 | 2015-01-08 09:45:46 +0900 | [diff] [blame] | 1090 | cmp = fmt->cmp(fmt, left, right); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1091 | if (cmp) |
| 1092 | break; |
| 1093 | } |
| 1094 | |
| 1095 | return cmp; |
| 1096 | } |
| 1097 | |
| 1098 | int64_t |
| 1099 | hist_entry__collapse(struct hist_entry *left, struct hist_entry *right) |
| 1100 | { |
Jiri Olsa | aa6f50a | 2016-01-18 10:24:24 +0100 | [diff] [blame] | 1101 | struct hists *hists = left->hists; |
Namhyung Kim | 093f0ef3 | 2014-03-03 12:07:47 +0900 | [diff] [blame] | 1102 | struct perf_hpp_fmt *fmt; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1103 | int64_t cmp = 0; |
| 1104 | |
Jiri Olsa | aa6f50a | 2016-01-18 10:24:24 +0100 | [diff] [blame] | 1105 | hists__for_each_sort_list(hists, fmt) { |
Namhyung Kim | 84b6ee8 | 2016-02-27 03:52:43 +0900 | [diff] [blame] | 1106 | if (perf_hpp__is_dynamic_entry(fmt) && |
| 1107 | !perf_hpp__defined_dynamic_entry(fmt, hists)) |
| 1108 | continue; |
| 1109 | |
Namhyung Kim | 87bbdf7 | 2015-01-08 09:45:46 +0900 | [diff] [blame] | 1110 | cmp = fmt->collapse(fmt, left, right); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1111 | if (cmp) |
| 1112 | break; |
| 1113 | } |
| 1114 | |
| 1115 | return cmp; |
| 1116 | } |
| 1117 | |
Arnaldo Carvalho de Melo | 6733d1b | 2014-12-19 12:31:40 -0300 | [diff] [blame] | 1118 | void hist_entry__delete(struct hist_entry *he) |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1119 | { |
Jiri Olsa | f542e76 | 2016-07-05 08:56:04 +0200 | [diff] [blame] | 1120 | struct hist_entry_ops *ops = he->ops; |
| 1121 | |
Arnaldo Carvalho de Melo | f3b623b | 2015-03-02 22:21:35 -0300 | [diff] [blame] | 1122 | thread__zput(he->thread); |
Arnaldo Carvalho de Melo | 5c24b67 | 2015-06-15 23:29:51 -0300 | [diff] [blame] | 1123 | map__zput(he->ms.map); |
| 1124 | |
| 1125 | if (he->branch_info) { |
| 1126 | map__zput(he->branch_info->from.map); |
| 1127 | map__zput(he->branch_info->to.map); |
Andi Kleen | 508be0d | 2016-05-20 13:15:08 -0700 | [diff] [blame] | 1128 | free_srcline(he->branch_info->srcline_from); |
| 1129 | free_srcline(he->branch_info->srcline_to); |
Arnaldo Carvalho de Melo | 5c24b67 | 2015-06-15 23:29:51 -0300 | [diff] [blame] | 1130 | zfree(&he->branch_info); |
| 1131 | } |
| 1132 | |
| 1133 | if (he->mem_info) { |
| 1134 | map__zput(he->mem_info->iaddr.map); |
| 1135 | map__zput(he->mem_info->daddr.map); |
| 1136 | zfree(&he->mem_info); |
| 1137 | } |
| 1138 | |
Jin Yao | 0d3eb0b | 2017-03-26 04:34:29 +0800 | [diff] [blame] | 1139 | if (he->inline_node) { |
| 1140 | inline_node__delete(he->inline_node); |
| 1141 | he->inline_node = NULL; |
| 1142 | } |
| 1143 | |
Namhyung Kim | f8be1c8 | 2012-09-11 13:15:07 +0900 | [diff] [blame] | 1144 | zfree(&he->stat_acc); |
Namhyung Kim | f048d54 | 2013-09-11 14:09:28 +0900 | [diff] [blame] | 1145 | free_srcline(he->srcline); |
Andi Kleen | 31191a8 | 2015-08-07 15:54:24 -0700 | [diff] [blame] | 1146 | if (he->srcfile && he->srcfile[0]) |
| 1147 | free(he->srcfile); |
Namhyung Kim | d114960 | 2014-12-30 14:38:13 +0900 | [diff] [blame] | 1148 | free_callchain(he->callchain); |
Namhyung Kim | 60517d2 | 2015-12-23 02:07:03 +0900 | [diff] [blame] | 1149 | free(he->trace_output); |
Namhyung Kim | 7239283 | 2015-12-24 11:16:17 +0900 | [diff] [blame] | 1150 | free(he->raw_data); |
Jiri Olsa | f542e76 | 2016-07-05 08:56:04 +0200 | [diff] [blame] | 1151 | ops->free(he); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1152 | } |
| 1153 | |
| 1154 | /* |
Arnaldo Carvalho de Melo | 89fee70 | 2016-02-11 17:14:13 -0300 | [diff] [blame] | 1155 | * If this is not the last column, then we need to pad it according to the |
| 1156 | * pre-calculated max lenght for this column, otherwise don't bother adding |
| 1157 | * spaces because that would break viewing this with, for instance, 'less', |
| 1158 | * that would show tons of trailing spaces when a long C++ demangled method |
| 1159 | * names is sampled. |
| 1160 | */ |
| 1161 | int hist_entry__snprintf_alignment(struct hist_entry *he, struct perf_hpp *hpp, |
| 1162 | struct perf_hpp_fmt *fmt, int printed) |
| 1163 | { |
| 1164 | if (!list_is_last(&fmt->list, &he->hists->hpp_list->fields)) { |
Jiri Olsa | da1b040 | 2016-06-14 20:19:20 +0200 | [diff] [blame] | 1165 | const int width = fmt->width(fmt, hpp, he->hists); |
Arnaldo Carvalho de Melo | 89fee70 | 2016-02-11 17:14:13 -0300 | [diff] [blame] | 1166 | if (printed < width) { |
| 1167 | advance_hpp(hpp, printed); |
| 1168 | printed = scnprintf(hpp->buf, hpp->size, "%-*s", width - printed, " "); |
| 1169 | } |
| 1170 | } |
| 1171 | |
| 1172 | return printed; |
| 1173 | } |
| 1174 | |
| 1175 | /* |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1176 | * collapse the histogram |
| 1177 | */ |
| 1178 | |
Namhyung Kim | aef810e | 2016-02-25 00:13:34 +0900 | [diff] [blame] | 1179 | static void hists__apply_filters(struct hists *hists, struct hist_entry *he); |
Namhyung Kim | aec13a7 | 2016-03-09 22:46:58 +0900 | [diff] [blame] | 1180 | static void hists__remove_entry_filter(struct hists *hists, struct hist_entry *he, |
| 1181 | enum hist_filter type); |
| 1182 | |
| 1183 | typedef bool (*fmt_chk_fn)(struct perf_hpp_fmt *fmt); |
| 1184 | |
| 1185 | static bool check_thread_entry(struct perf_hpp_fmt *fmt) |
| 1186 | { |
| 1187 | return perf_hpp__is_thread_entry(fmt) || perf_hpp__is_comm_entry(fmt); |
| 1188 | } |
| 1189 | |
| 1190 | static void hist_entry__check_and_remove_filter(struct hist_entry *he, |
| 1191 | enum hist_filter type, |
| 1192 | fmt_chk_fn check) |
| 1193 | { |
| 1194 | struct perf_hpp_fmt *fmt; |
| 1195 | bool type_match = false; |
| 1196 | struct hist_entry *parent = he->parent_he; |
| 1197 | |
| 1198 | switch (type) { |
| 1199 | case HIST_FILTER__THREAD: |
| 1200 | if (symbol_conf.comm_list == NULL && |
| 1201 | symbol_conf.pid_list == NULL && |
| 1202 | symbol_conf.tid_list == NULL) |
| 1203 | return; |
| 1204 | break; |
| 1205 | case HIST_FILTER__DSO: |
| 1206 | if (symbol_conf.dso_list == NULL) |
| 1207 | return; |
| 1208 | break; |
| 1209 | case HIST_FILTER__SYMBOL: |
| 1210 | if (symbol_conf.sym_list == NULL) |
| 1211 | return; |
| 1212 | break; |
| 1213 | case HIST_FILTER__PARENT: |
| 1214 | case HIST_FILTER__GUEST: |
| 1215 | case HIST_FILTER__HOST: |
| 1216 | case HIST_FILTER__SOCKET: |
Jiri Olsa | 9857b71 | 2016-08-17 14:55:23 +0200 | [diff] [blame] | 1217 | case HIST_FILTER__C2C: |
Namhyung Kim | aec13a7 | 2016-03-09 22:46:58 +0900 | [diff] [blame] | 1218 | default: |
| 1219 | return; |
| 1220 | } |
| 1221 | |
| 1222 | /* if it's filtered by own fmt, it has to have filter bits */ |
| 1223 | perf_hpp_list__for_each_format(he->hpp_list, fmt) { |
| 1224 | if (check(fmt)) { |
| 1225 | type_match = true; |
| 1226 | break; |
| 1227 | } |
| 1228 | } |
| 1229 | |
| 1230 | if (type_match) { |
| 1231 | /* |
| 1232 | * If the filter is for current level entry, propagate |
| 1233 | * filter marker to parents. The marker bit was |
| 1234 | * already set by default so it only needs to clear |
| 1235 | * non-filtered entries. |
| 1236 | */ |
| 1237 | if (!(he->filtered & (1 << type))) { |
| 1238 | while (parent) { |
| 1239 | parent->filtered &= ~(1 << type); |
| 1240 | parent = parent->parent_he; |
| 1241 | } |
| 1242 | } |
| 1243 | } else { |
| 1244 | /* |
| 1245 | * If current entry doesn't have matching formats, set |
| 1246 | * filter marker for upper level entries. it will be |
| 1247 | * cleared if its lower level entries is not filtered. |
| 1248 | * |
| 1249 | * For lower-level entries, it inherits parent's |
| 1250 | * filter bit so that lower level entries of a |
| 1251 | * non-filtered entry won't set the filter marker. |
| 1252 | */ |
| 1253 | if (parent == NULL) |
| 1254 | he->filtered |= (1 << type); |
| 1255 | else |
| 1256 | he->filtered |= (parent->filtered & (1 << type)); |
| 1257 | } |
| 1258 | } |
| 1259 | |
| 1260 | static void hist_entry__apply_hierarchy_filters(struct hist_entry *he) |
| 1261 | { |
| 1262 | hist_entry__check_and_remove_filter(he, HIST_FILTER__THREAD, |
| 1263 | check_thread_entry); |
| 1264 | |
| 1265 | hist_entry__check_and_remove_filter(he, HIST_FILTER__DSO, |
| 1266 | perf_hpp__is_dso_entry); |
| 1267 | |
| 1268 | hist_entry__check_and_remove_filter(he, HIST_FILTER__SYMBOL, |
| 1269 | perf_hpp__is_sym_entry); |
| 1270 | |
| 1271 | hists__apply_filters(he->hists, he); |
| 1272 | } |
Namhyung Kim | aef810e | 2016-02-25 00:13:34 +0900 | [diff] [blame] | 1273 | |
| 1274 | static struct hist_entry *hierarchy_insert_entry(struct hists *hists, |
| 1275 | struct rb_root *root, |
| 1276 | struct hist_entry *he, |
Namhyung Kim | aec13a7 | 2016-03-09 22:46:58 +0900 | [diff] [blame] | 1277 | struct hist_entry *parent_he, |
Namhyung Kim | 1b2dbbf | 2016-03-07 16:44:46 -0300 | [diff] [blame] | 1278 | struct perf_hpp_list *hpp_list) |
Namhyung Kim | aef810e | 2016-02-25 00:13:34 +0900 | [diff] [blame] | 1279 | { |
| 1280 | struct rb_node **p = &root->rb_node; |
| 1281 | struct rb_node *parent = NULL; |
| 1282 | struct hist_entry *iter, *new; |
Namhyung Kim | 1b2dbbf | 2016-03-07 16:44:46 -0300 | [diff] [blame] | 1283 | struct perf_hpp_fmt *fmt; |
Namhyung Kim | aef810e | 2016-02-25 00:13:34 +0900 | [diff] [blame] | 1284 | int64_t cmp; |
| 1285 | |
| 1286 | while (*p != NULL) { |
| 1287 | parent = *p; |
| 1288 | iter = rb_entry(parent, struct hist_entry, rb_node_in); |
| 1289 | |
Namhyung Kim | 1b2dbbf | 2016-03-07 16:44:46 -0300 | [diff] [blame] | 1290 | cmp = 0; |
| 1291 | perf_hpp_list__for_each_sort_list(hpp_list, fmt) { |
| 1292 | cmp = fmt->collapse(fmt, iter, he); |
| 1293 | if (cmp) |
| 1294 | break; |
| 1295 | } |
| 1296 | |
Namhyung Kim | aef810e | 2016-02-25 00:13:34 +0900 | [diff] [blame] | 1297 | if (!cmp) { |
| 1298 | he_stat__add_stat(&iter->stat, &he->stat); |
| 1299 | return iter; |
| 1300 | } |
| 1301 | |
| 1302 | if (cmp < 0) |
| 1303 | p = &parent->rb_left; |
| 1304 | else |
| 1305 | p = &parent->rb_right; |
| 1306 | } |
| 1307 | |
| 1308 | new = hist_entry__new(he, true); |
| 1309 | if (new == NULL) |
| 1310 | return NULL; |
| 1311 | |
Namhyung Kim | aef810e | 2016-02-25 00:13:34 +0900 | [diff] [blame] | 1312 | hists->nr_entries++; |
| 1313 | |
Namhyung Kim | 1b2dbbf | 2016-03-07 16:44:46 -0300 | [diff] [blame] | 1314 | /* save related format list for output */ |
| 1315 | new->hpp_list = hpp_list; |
Namhyung Kim | aec13a7 | 2016-03-09 22:46:58 +0900 | [diff] [blame] | 1316 | new->parent_he = parent_he; |
| 1317 | |
| 1318 | hist_entry__apply_hierarchy_filters(new); |
Namhyung Kim | aef810e | 2016-02-25 00:13:34 +0900 | [diff] [blame] | 1319 | |
| 1320 | /* some fields are now passed to 'new' */ |
Namhyung Kim | 1b2dbbf | 2016-03-07 16:44:46 -0300 | [diff] [blame] | 1321 | perf_hpp_list__for_each_sort_list(hpp_list, fmt) { |
| 1322 | if (perf_hpp__is_trace_entry(fmt) || perf_hpp__is_dynamic_entry(fmt)) |
| 1323 | he->trace_output = NULL; |
| 1324 | else |
| 1325 | new->trace_output = NULL; |
Namhyung Kim | aef810e | 2016-02-25 00:13:34 +0900 | [diff] [blame] | 1326 | |
Namhyung Kim | 1b2dbbf | 2016-03-07 16:44:46 -0300 | [diff] [blame] | 1327 | if (perf_hpp__is_srcline_entry(fmt)) |
| 1328 | he->srcline = NULL; |
| 1329 | else |
| 1330 | new->srcline = NULL; |
Namhyung Kim | aef810e | 2016-02-25 00:13:34 +0900 | [diff] [blame] | 1331 | |
Namhyung Kim | 1b2dbbf | 2016-03-07 16:44:46 -0300 | [diff] [blame] | 1332 | if (perf_hpp__is_srcfile_entry(fmt)) |
| 1333 | he->srcfile = NULL; |
| 1334 | else |
| 1335 | new->srcfile = NULL; |
| 1336 | } |
Namhyung Kim | aef810e | 2016-02-25 00:13:34 +0900 | [diff] [blame] | 1337 | |
| 1338 | rb_link_node(&new->rb_node_in, parent, p); |
| 1339 | rb_insert_color(&new->rb_node_in, root); |
| 1340 | return new; |
| 1341 | } |
| 1342 | |
| 1343 | static int hists__hierarchy_insert_entry(struct hists *hists, |
| 1344 | struct rb_root *root, |
| 1345 | struct hist_entry *he) |
| 1346 | { |
Namhyung Kim | 1b2dbbf | 2016-03-07 16:44:46 -0300 | [diff] [blame] | 1347 | struct perf_hpp_list_node *node; |
Namhyung Kim | aef810e | 2016-02-25 00:13:34 +0900 | [diff] [blame] | 1348 | struct hist_entry *new_he = NULL; |
| 1349 | struct hist_entry *parent = NULL; |
| 1350 | int depth = 0; |
| 1351 | int ret = 0; |
| 1352 | |
Namhyung Kim | 1b2dbbf | 2016-03-07 16:44:46 -0300 | [diff] [blame] | 1353 | list_for_each_entry(node, &hists->hpp_formats, list) { |
| 1354 | /* skip period (overhead) and elided columns */ |
| 1355 | if (node->level == 0 || node->skip) |
Namhyung Kim | aef810e | 2016-02-25 00:13:34 +0900 | [diff] [blame] | 1356 | continue; |
| 1357 | |
| 1358 | /* insert copy of 'he' for each fmt into the hierarchy */ |
Namhyung Kim | aec13a7 | 2016-03-09 22:46:58 +0900 | [diff] [blame] | 1359 | new_he = hierarchy_insert_entry(hists, root, he, parent, &node->hpp); |
Namhyung Kim | aef810e | 2016-02-25 00:13:34 +0900 | [diff] [blame] | 1360 | if (new_he == NULL) { |
| 1361 | ret = -1; |
| 1362 | break; |
| 1363 | } |
| 1364 | |
| 1365 | root = &new_he->hroot_in; |
Namhyung Kim | aef810e | 2016-02-25 00:13:34 +0900 | [diff] [blame] | 1366 | new_he->depth = depth++; |
| 1367 | parent = new_he; |
| 1368 | } |
| 1369 | |
| 1370 | if (new_he) { |
| 1371 | new_he->leaf = true; |
| 1372 | |
| 1373 | if (symbol_conf.use_callchain) { |
| 1374 | callchain_cursor_reset(&callchain_cursor); |
| 1375 | if (callchain_merge(&callchain_cursor, |
| 1376 | new_he->callchain, |
| 1377 | he->callchain) < 0) |
| 1378 | ret = -1; |
| 1379 | } |
| 1380 | } |
| 1381 | |
| 1382 | /* 'he' is no longer used */ |
| 1383 | hist_entry__delete(he); |
| 1384 | |
| 1385 | /* return 0 (or -1) since it already applied filters */ |
| 1386 | return ret; |
| 1387 | } |
| 1388 | |
Jiri Olsa | 592dac6 | 2016-03-24 13:52:17 +0100 | [diff] [blame] | 1389 | static int hists__collapse_insert_entry(struct hists *hists, |
| 1390 | struct rb_root *root, |
| 1391 | struct hist_entry *he) |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1392 | { |
Arnaldo Carvalho de Melo | b9bf089 | 2009-12-14 11:37:11 -0200 | [diff] [blame] | 1393 | struct rb_node **p = &root->rb_node; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1394 | struct rb_node *parent = NULL; |
| 1395 | struct hist_entry *iter; |
| 1396 | int64_t cmp; |
| 1397 | |
Namhyung Kim | aef810e | 2016-02-25 00:13:34 +0900 | [diff] [blame] | 1398 | if (symbol_conf.report_hierarchy) |
| 1399 | return hists__hierarchy_insert_entry(hists, root, he); |
| 1400 | |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1401 | while (*p != NULL) { |
| 1402 | parent = *p; |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 1403 | iter = rb_entry(parent, struct hist_entry, rb_node_in); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1404 | |
| 1405 | cmp = hist_entry__collapse(iter, he); |
| 1406 | |
| 1407 | if (!cmp) { |
Namhyung Kim | bba58cd | 2016-02-16 23:08:25 +0900 | [diff] [blame] | 1408 | int ret = 0; |
| 1409 | |
Namhyung Kim | 139c081 | 2012-10-04 21:49:43 +0900 | [diff] [blame] | 1410 | he_stat__add_stat(&iter->stat, &he->stat); |
Namhyung Kim | f8be1c8 | 2012-09-11 13:15:07 +0900 | [diff] [blame] | 1411 | if (symbol_conf.cumulate_callchain) |
| 1412 | he_stat__add_stat(iter->stat_acc, he->stat_acc); |
Namhyung Kim | 9ec6097 | 2012-09-26 16:47:28 +0900 | [diff] [blame] | 1413 | |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 1414 | if (symbol_conf.use_callchain) { |
Namhyung Kim | 4726064 | 2012-05-31 14:43:26 +0900 | [diff] [blame] | 1415 | callchain_cursor_reset(&callchain_cursor); |
Namhyung Kim | bba58cd | 2016-02-16 23:08:25 +0900 | [diff] [blame] | 1416 | if (callchain_merge(&callchain_cursor, |
| 1417 | iter->callchain, |
| 1418 | he->callchain) < 0) |
| 1419 | ret = -1; |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 1420 | } |
Arnaldo Carvalho de Melo | 6733d1b | 2014-12-19 12:31:40 -0300 | [diff] [blame] | 1421 | hist_entry__delete(he); |
Namhyung Kim | bba58cd | 2016-02-16 23:08:25 +0900 | [diff] [blame] | 1422 | return ret; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1423 | } |
| 1424 | |
| 1425 | if (cmp < 0) |
| 1426 | p = &(*p)->rb_left; |
| 1427 | else |
| 1428 | p = &(*p)->rb_right; |
| 1429 | } |
Namhyung Kim | 740b97f | 2014-12-22 13:44:10 +0900 | [diff] [blame] | 1430 | hists->nr_entries++; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1431 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 1432 | rb_link_node(&he->rb_node_in, parent, p); |
| 1433 | rb_insert_color(&he->rb_node_in, root); |
Namhyung Kim | bba58cd | 2016-02-16 23:08:25 +0900 | [diff] [blame] | 1434 | return 1; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1435 | } |
| 1436 | |
Namhyung Kim | fc284be | 2016-01-07 10:14:10 +0100 | [diff] [blame] | 1437 | 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] | 1438 | { |
| 1439 | struct rb_root *root; |
| 1440 | |
| 1441 | pthread_mutex_lock(&hists->lock); |
| 1442 | |
| 1443 | root = hists->entries_in; |
| 1444 | if (++hists->entries_in > &hists->entries_in_array[1]) |
| 1445 | hists->entries_in = &hists->entries_in_array[0]; |
| 1446 | |
| 1447 | pthread_mutex_unlock(&hists->lock); |
| 1448 | |
| 1449 | return root; |
| 1450 | } |
| 1451 | |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 1452 | static void hists__apply_filters(struct hists *hists, struct hist_entry *he) |
| 1453 | { |
| 1454 | hists__filter_entry_by_dso(hists, he); |
| 1455 | hists__filter_entry_by_thread(hists, he); |
Namhyung Kim | e94d53e | 2012-03-16 17:50:51 +0900 | [diff] [blame] | 1456 | hists__filter_entry_by_symbol(hists, he); |
Kan Liang | 21394d9 | 2015-09-04 10:45:44 -0400 | [diff] [blame] | 1457 | hists__filter_entry_by_socket(hists, he); |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 1458 | } |
| 1459 | |
Namhyung Kim | bba58cd | 2016-02-16 23:08:25 +0900 | [diff] [blame] | 1460 | int hists__collapse_resort(struct hists *hists, struct ui_progress *prog) |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 1461 | { |
| 1462 | struct rb_root *root; |
| 1463 | struct rb_node *next; |
| 1464 | struct hist_entry *n; |
Namhyung Kim | bba58cd | 2016-02-16 23:08:25 +0900 | [diff] [blame] | 1465 | int ret; |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 1466 | |
Jiri Olsa | 5222503 | 2016-05-03 13:54:42 +0200 | [diff] [blame] | 1467 | if (!hists__has(hists, need_collapse)) |
Namhyung Kim | bba58cd | 2016-02-16 23:08:25 +0900 | [diff] [blame] | 1468 | return 0; |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 1469 | |
Namhyung Kim | 740b97f | 2014-12-22 13:44:10 +0900 | [diff] [blame] | 1470 | hists->nr_entries = 0; |
| 1471 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 1472 | root = hists__get_rotate_entries_in(hists); |
Namhyung Kim | 740b97f | 2014-12-22 13:44:10 +0900 | [diff] [blame] | 1473 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 1474 | next = rb_first(root); |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 1475 | |
| 1476 | while (next) { |
Arnaldo Carvalho de Melo | 33e940a | 2013-09-17 16:34:28 -0300 | [diff] [blame] | 1477 | if (session_done()) |
| 1478 | break; |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 1479 | n = rb_entry(next, struct hist_entry, rb_node_in); |
| 1480 | next = rb_next(&n->rb_node_in); |
| 1481 | |
| 1482 | rb_erase(&n->rb_node_in, root); |
Namhyung Kim | bba58cd | 2016-02-16 23:08:25 +0900 | [diff] [blame] | 1483 | ret = hists__collapse_insert_entry(hists, &hists->entries_collapsed, n); |
| 1484 | if (ret < 0) |
| 1485 | return -1; |
| 1486 | |
| 1487 | if (ret) { |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 1488 | /* |
| 1489 | * If it wasn't combined with one of the entries already |
| 1490 | * collapsed, we need to apply the filters that may have |
| 1491 | * been set by, say, the hist_browser. |
| 1492 | */ |
| 1493 | hists__apply_filters(hists, n); |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 1494 | } |
Namhyung Kim | c1fb565 | 2013-10-11 14:15:38 +0900 | [diff] [blame] | 1495 | if (prog) |
| 1496 | ui_progress__update(prog, 1); |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 1497 | } |
Namhyung Kim | bba58cd | 2016-02-16 23:08:25 +0900 | [diff] [blame] | 1498 | return 0; |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 1499 | } |
| 1500 | |
Namhyung Kim | 043ca389 | 2014-03-03 14:18:00 +0900 | [diff] [blame] | 1501 | 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] | 1502 | { |
Jiri Olsa | aa6f50a | 2016-01-18 10:24:24 +0100 | [diff] [blame] | 1503 | struct hists *hists = a->hists; |
Namhyung Kim | 043ca389 | 2014-03-03 14:18:00 +0900 | [diff] [blame] | 1504 | struct perf_hpp_fmt *fmt; |
| 1505 | int64_t cmp = 0; |
Namhyung Kim | 29d720e | 2013-01-22 18:09:33 +0900 | [diff] [blame] | 1506 | |
Jiri Olsa | aa6f50a | 2016-01-18 10:24:24 +0100 | [diff] [blame] | 1507 | hists__for_each_sort_list(hists, fmt) { |
Namhyung Kim | 361459f | 2015-12-23 02:07:08 +0900 | [diff] [blame] | 1508 | if (perf_hpp__should_skip(fmt, a->hists)) |
Namhyung Kim | e67d49a | 2014-03-18 13:00:59 +0900 | [diff] [blame] | 1509 | continue; |
| 1510 | |
Namhyung Kim | 87bbdf7 | 2015-01-08 09:45:46 +0900 | [diff] [blame] | 1511 | cmp = fmt->sort(fmt, a, b); |
Namhyung Kim | 043ca389 | 2014-03-03 14:18:00 +0900 | [diff] [blame] | 1512 | if (cmp) |
Namhyung Kim | 29d720e | 2013-01-22 18:09:33 +0900 | [diff] [blame] | 1513 | break; |
| 1514 | } |
| 1515 | |
Namhyung Kim | 043ca389 | 2014-03-03 14:18:00 +0900 | [diff] [blame] | 1516 | return cmp; |
Namhyung Kim | 29d720e | 2013-01-22 18:09:33 +0900 | [diff] [blame] | 1517 | } |
| 1518 | |
Namhyung Kim | 9283ba9 | 2014-04-24 16:37:26 +0900 | [diff] [blame] | 1519 | static void hists__reset_filter_stats(struct hists *hists) |
| 1520 | { |
| 1521 | hists->nr_non_filtered_entries = 0; |
| 1522 | hists->stats.total_non_filtered_period = 0; |
| 1523 | } |
| 1524 | |
| 1525 | void hists__reset_stats(struct hists *hists) |
| 1526 | { |
| 1527 | hists->nr_entries = 0; |
| 1528 | hists->stats.total_period = 0; |
| 1529 | |
| 1530 | hists__reset_filter_stats(hists); |
| 1531 | } |
| 1532 | |
| 1533 | static void hists__inc_filter_stats(struct hists *hists, struct hist_entry *h) |
| 1534 | { |
| 1535 | hists->nr_non_filtered_entries++; |
| 1536 | hists->stats.total_non_filtered_period += h->stat.period; |
| 1537 | } |
| 1538 | |
| 1539 | void hists__inc_stats(struct hists *hists, struct hist_entry *h) |
| 1540 | { |
| 1541 | if (!h->filtered) |
| 1542 | hists__inc_filter_stats(hists, h); |
| 1543 | |
| 1544 | hists->nr_entries++; |
| 1545 | hists->stats.total_period += h->stat.period; |
| 1546 | } |
| 1547 | |
Namhyung Kim | f7fb538 | 2016-03-09 22:47:02 +0900 | [diff] [blame] | 1548 | static void hierarchy_recalc_total_periods(struct hists *hists) |
| 1549 | { |
| 1550 | struct rb_node *node; |
| 1551 | struct hist_entry *he; |
| 1552 | |
| 1553 | node = rb_first(&hists->entries); |
| 1554 | |
| 1555 | hists->stats.total_period = 0; |
| 1556 | hists->stats.total_non_filtered_period = 0; |
| 1557 | |
| 1558 | /* |
| 1559 | * recalculate total period using top-level entries only |
| 1560 | * since lower level entries only see non-filtered entries |
| 1561 | * but upper level entries have sum of both entries. |
| 1562 | */ |
| 1563 | while (node) { |
| 1564 | he = rb_entry(node, struct hist_entry, rb_node); |
| 1565 | node = rb_next(node); |
| 1566 | |
| 1567 | hists->stats.total_period += he->stat.period; |
| 1568 | if (!he->filtered) |
| 1569 | hists->stats.total_non_filtered_period += he->stat.period; |
| 1570 | } |
| 1571 | } |
| 1572 | |
Namhyung Kim | 1a3906a | 2016-02-25 00:13:35 +0900 | [diff] [blame] | 1573 | static void hierarchy_insert_output_entry(struct rb_root *root, |
| 1574 | struct hist_entry *he) |
| 1575 | { |
| 1576 | struct rb_node **p = &root->rb_node; |
| 1577 | struct rb_node *parent = NULL; |
| 1578 | struct hist_entry *iter; |
Namhyung Kim | 1b2dbbf | 2016-03-07 16:44:46 -0300 | [diff] [blame] | 1579 | struct perf_hpp_fmt *fmt; |
Namhyung Kim | 1a3906a | 2016-02-25 00:13:35 +0900 | [diff] [blame] | 1580 | |
| 1581 | while (*p != NULL) { |
| 1582 | parent = *p; |
| 1583 | iter = rb_entry(parent, struct hist_entry, rb_node); |
| 1584 | |
| 1585 | if (hist_entry__sort(he, iter) > 0) |
| 1586 | p = &parent->rb_left; |
| 1587 | else |
| 1588 | p = &parent->rb_right; |
| 1589 | } |
| 1590 | |
| 1591 | rb_link_node(&he->rb_node, parent, p); |
| 1592 | rb_insert_color(&he->rb_node, root); |
Namhyung Kim | abab5e7 | 2016-02-27 03:52:47 +0900 | [diff] [blame] | 1593 | |
| 1594 | /* update column width of dynamic entry */ |
Namhyung Kim | 1b2dbbf | 2016-03-07 16:44:46 -0300 | [diff] [blame] | 1595 | perf_hpp_list__for_each_sort_list(he->hpp_list, fmt) { |
| 1596 | if (perf_hpp__is_dynamic_entry(fmt)) |
| 1597 | fmt->sort(fmt, he, NULL); |
| 1598 | } |
Namhyung Kim | 1a3906a | 2016-02-25 00:13:35 +0900 | [diff] [blame] | 1599 | } |
| 1600 | |
| 1601 | static void hists__hierarchy_output_resort(struct hists *hists, |
| 1602 | struct ui_progress *prog, |
| 1603 | struct rb_root *root_in, |
| 1604 | struct rb_root *root_out, |
| 1605 | u64 min_callchain_hits, |
| 1606 | bool use_callchain) |
| 1607 | { |
| 1608 | struct rb_node *node; |
| 1609 | struct hist_entry *he; |
| 1610 | |
| 1611 | *root_out = RB_ROOT; |
| 1612 | node = rb_first(root_in); |
| 1613 | |
| 1614 | while (node) { |
| 1615 | he = rb_entry(node, struct hist_entry, rb_node_in); |
| 1616 | node = rb_next(node); |
| 1617 | |
| 1618 | hierarchy_insert_output_entry(root_out, he); |
| 1619 | |
| 1620 | if (prog) |
| 1621 | ui_progress__update(prog, 1); |
| 1622 | |
Namhyung Kim | c72ab44 | 2016-11-08 22:08:33 +0900 | [diff] [blame] | 1623 | hists->nr_entries++; |
| 1624 | if (!he->filtered) { |
| 1625 | hists->nr_non_filtered_entries++; |
| 1626 | hists__calc_col_len(hists, he); |
| 1627 | } |
| 1628 | |
Namhyung Kim | 1a3906a | 2016-02-25 00:13:35 +0900 | [diff] [blame] | 1629 | if (!he->leaf) { |
| 1630 | hists__hierarchy_output_resort(hists, prog, |
| 1631 | &he->hroot_in, |
| 1632 | &he->hroot_out, |
| 1633 | min_callchain_hits, |
| 1634 | use_callchain); |
Namhyung Kim | 1a3906a | 2016-02-25 00:13:35 +0900 | [diff] [blame] | 1635 | continue; |
| 1636 | } |
| 1637 | |
Namhyung Kim | 1a3906a | 2016-02-25 00:13:35 +0900 | [diff] [blame] | 1638 | if (!use_callchain) |
| 1639 | continue; |
| 1640 | |
| 1641 | if (callchain_param.mode == CHAIN_GRAPH_REL) { |
| 1642 | u64 total = he->stat.period; |
| 1643 | |
| 1644 | if (symbol_conf.cumulate_callchain) |
| 1645 | total = he->stat_acc->period; |
| 1646 | |
| 1647 | min_callchain_hits = total * (callchain_param.min_percent / 100); |
| 1648 | } |
| 1649 | |
| 1650 | callchain_param.sort(&he->sorted_chain, he->callchain, |
| 1651 | min_callchain_hits, &callchain_param); |
| 1652 | } |
| 1653 | } |
| 1654 | |
Arnaldo Carvalho de Melo | 1c02c4d | 2010-05-10 13:04:11 -0300 | [diff] [blame] | 1655 | static void __hists__insert_output_entry(struct rb_root *entries, |
| 1656 | struct hist_entry *he, |
Kan Liang | f9db0d0 | 2015-08-11 06:30:48 -0400 | [diff] [blame] | 1657 | u64 min_callchain_hits, |
| 1658 | bool use_callchain) |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1659 | { |
Arnaldo Carvalho de Melo | 1c02c4d | 2010-05-10 13:04:11 -0300 | [diff] [blame] | 1660 | struct rb_node **p = &entries->rb_node; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1661 | struct rb_node *parent = NULL; |
| 1662 | struct hist_entry *iter; |
Namhyung Kim | abab5e7 | 2016-02-27 03:52:47 +0900 | [diff] [blame] | 1663 | struct perf_hpp_fmt *fmt; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1664 | |
Namhyung Kim | 744070e | 2016-01-28 00:40:48 +0900 | [diff] [blame] | 1665 | if (use_callchain) { |
| 1666 | if (callchain_param.mode == CHAIN_GRAPH_REL) { |
| 1667 | u64 total = he->stat.period; |
| 1668 | |
| 1669 | if (symbol_conf.cumulate_callchain) |
| 1670 | total = he->stat_acc->period; |
| 1671 | |
| 1672 | min_callchain_hits = total * (callchain_param.min_percent / 100); |
| 1673 | } |
Arnaldo Carvalho de Melo | b9fb930 | 2010-04-02 09:50:42 -0300 | [diff] [blame] | 1674 | callchain_param.sort(&he->sorted_chain, he->callchain, |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1675 | min_callchain_hits, &callchain_param); |
Namhyung Kim | 744070e | 2016-01-28 00:40:48 +0900 | [diff] [blame] | 1676 | } |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1677 | |
| 1678 | while (*p != NULL) { |
| 1679 | parent = *p; |
| 1680 | iter = rb_entry(parent, struct hist_entry, rb_node); |
| 1681 | |
Namhyung Kim | 043ca389 | 2014-03-03 14:18:00 +0900 | [diff] [blame] | 1682 | if (hist_entry__sort(he, iter) > 0) |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1683 | p = &(*p)->rb_left; |
| 1684 | else |
| 1685 | p = &(*p)->rb_right; |
| 1686 | } |
| 1687 | |
| 1688 | rb_link_node(&he->rb_node, parent, p); |
Arnaldo Carvalho de Melo | 1c02c4d | 2010-05-10 13:04:11 -0300 | [diff] [blame] | 1689 | rb_insert_color(&he->rb_node, entries); |
Namhyung Kim | abab5e7 | 2016-02-27 03:52:47 +0900 | [diff] [blame] | 1690 | |
| 1691 | perf_hpp_list__for_each_sort_list(&perf_hpp_list, fmt) { |
| 1692 | if (perf_hpp__is_dynamic_entry(fmt) && |
| 1693 | perf_hpp__defined_dynamic_entry(fmt, he->hists)) |
| 1694 | fmt->sort(fmt, he, NULL); /* update column width */ |
| 1695 | } |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1696 | } |
| 1697 | |
Jiri Olsa | 01441af | 2016-01-18 10:23:59 +0100 | [diff] [blame] | 1698 | static void output_resort(struct hists *hists, struct ui_progress *prog, |
Jiri Olsa | 52c5cc3 | 2016-08-01 20:02:34 +0200 | [diff] [blame] | 1699 | bool use_callchain, hists__resort_cb_t cb) |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1700 | { |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 1701 | struct rb_root *root; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1702 | struct rb_node *next; |
| 1703 | struct hist_entry *n; |
Namhyung Kim | 467ef10 | 2016-02-16 23:08:19 +0900 | [diff] [blame] | 1704 | u64 callchain_total; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1705 | u64 min_callchain_hits; |
| 1706 | |
Namhyung Kim | 467ef10 | 2016-02-16 23:08:19 +0900 | [diff] [blame] | 1707 | callchain_total = hists->callchain_period; |
| 1708 | if (symbol_conf.filter_relative) |
| 1709 | callchain_total = hists->callchain_non_filtered_period; |
| 1710 | |
| 1711 | min_callchain_hits = callchain_total * (callchain_param.min_percent / 100); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1712 | |
Namhyung Kim | 1a3906a | 2016-02-25 00:13:35 +0900 | [diff] [blame] | 1713 | hists__reset_stats(hists); |
| 1714 | hists__reset_col_len(hists); |
| 1715 | |
| 1716 | if (symbol_conf.report_hierarchy) { |
Namhyung Kim | f7fb538 | 2016-03-09 22:47:02 +0900 | [diff] [blame] | 1717 | hists__hierarchy_output_resort(hists, prog, |
| 1718 | &hists->entries_collapsed, |
| 1719 | &hists->entries, |
| 1720 | min_callchain_hits, |
| 1721 | use_callchain); |
| 1722 | hierarchy_recalc_total_periods(hists); |
| 1723 | return; |
Namhyung Kim | 1a3906a | 2016-02-25 00:13:35 +0900 | [diff] [blame] | 1724 | } |
| 1725 | |
Jiri Olsa | 5222503 | 2016-05-03 13:54:42 +0200 | [diff] [blame] | 1726 | if (hists__has(hists, need_collapse)) |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 1727 | root = &hists->entries_collapsed; |
| 1728 | else |
| 1729 | root = hists->entries_in; |
| 1730 | |
| 1731 | next = rb_first(root); |
| 1732 | hists->entries = RB_ROOT; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1733 | |
| 1734 | while (next) { |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 1735 | n = rb_entry(next, struct hist_entry, rb_node_in); |
| 1736 | next = rb_next(&n->rb_node_in); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1737 | |
Jiri Olsa | 52c5cc3 | 2016-08-01 20:02:34 +0200 | [diff] [blame] | 1738 | if (cb && cb(n)) |
| 1739 | continue; |
| 1740 | |
Kan Liang | f9db0d0 | 2015-08-11 06:30:48 -0400 | [diff] [blame] | 1741 | __hists__insert_output_entry(&hists->entries, n, min_callchain_hits, use_callchain); |
Namhyung Kim | 6263835 | 2014-04-24 16:21:46 +0900 | [diff] [blame] | 1742 | hists__inc_stats(hists, n); |
Namhyung Kim | ae993ef | 2014-04-24 16:25:19 +0900 | [diff] [blame] | 1743 | |
| 1744 | if (!n->filtered) |
| 1745 | hists__calc_col_len(hists, n); |
Namhyung Kim | 740b97f | 2014-12-22 13:44:10 +0900 | [diff] [blame] | 1746 | |
| 1747 | if (prog) |
| 1748 | ui_progress__update(prog, 1); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 1749 | } |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 1750 | } |
Arnaldo Carvalho de Melo | b9bf089 | 2009-12-14 11:37:11 -0200 | [diff] [blame] | 1751 | |
Jiri Olsa | 452ce03 | 2016-01-18 10:24:00 +0100 | [diff] [blame] | 1752 | void perf_evsel__output_resort(struct perf_evsel *evsel, struct ui_progress *prog) |
Jiri Olsa | 01441af | 2016-01-18 10:23:59 +0100 | [diff] [blame] | 1753 | { |
Jiri Olsa | 01441af | 2016-01-18 10:23:59 +0100 | [diff] [blame] | 1754 | bool use_callchain; |
| 1755 | |
| 1756 | if (evsel && symbol_conf.use_callchain && !symbol_conf.show_ref_callgraph) |
| 1757 | use_callchain = evsel->attr.sample_type & PERF_SAMPLE_CALLCHAIN; |
| 1758 | else |
| 1759 | use_callchain = symbol_conf.use_callchain; |
| 1760 | |
Jiri Olsa | 52c5cc3 | 2016-08-01 20:02:34 +0200 | [diff] [blame] | 1761 | output_resort(evsel__hists(evsel), prog, use_callchain, NULL); |
Jiri Olsa | 452ce03 | 2016-01-18 10:24:00 +0100 | [diff] [blame] | 1762 | } |
| 1763 | |
| 1764 | void hists__output_resort(struct hists *hists, struct ui_progress *prog) |
| 1765 | { |
Jiri Olsa | 52c5cc3 | 2016-08-01 20:02:34 +0200 | [diff] [blame] | 1766 | output_resort(hists, prog, symbol_conf.use_callchain, NULL); |
| 1767 | } |
| 1768 | |
| 1769 | void hists__output_resort_cb(struct hists *hists, struct ui_progress *prog, |
| 1770 | hists__resort_cb_t cb) |
| 1771 | { |
| 1772 | output_resort(hists, prog, symbol_conf.use_callchain, cb); |
Jiri Olsa | 01441af | 2016-01-18 10:23:59 +0100 | [diff] [blame] | 1773 | } |
| 1774 | |
Namhyung Kim | 8c01872 | 2016-02-25 00:13:36 +0900 | [diff] [blame] | 1775 | static bool can_goto_child(struct hist_entry *he, enum hierarchy_move_dir hmd) |
| 1776 | { |
| 1777 | if (he->leaf || hmd == HMD_FORCE_SIBLING) |
| 1778 | return false; |
| 1779 | |
| 1780 | if (he->unfolded || hmd == HMD_FORCE_CHILD) |
| 1781 | return true; |
| 1782 | |
| 1783 | return false; |
| 1784 | } |
| 1785 | |
| 1786 | struct rb_node *rb_hierarchy_last(struct rb_node *node) |
| 1787 | { |
| 1788 | struct hist_entry *he = rb_entry(node, struct hist_entry, rb_node); |
| 1789 | |
| 1790 | while (can_goto_child(he, HMD_NORMAL)) { |
| 1791 | node = rb_last(&he->hroot_out); |
| 1792 | he = rb_entry(node, struct hist_entry, rb_node); |
| 1793 | } |
| 1794 | return node; |
| 1795 | } |
| 1796 | |
| 1797 | struct rb_node *__rb_hierarchy_next(struct rb_node *node, enum hierarchy_move_dir hmd) |
| 1798 | { |
| 1799 | struct hist_entry *he = rb_entry(node, struct hist_entry, rb_node); |
| 1800 | |
| 1801 | if (can_goto_child(he, hmd)) |
| 1802 | node = rb_first(&he->hroot_out); |
| 1803 | else |
| 1804 | node = rb_next(node); |
| 1805 | |
| 1806 | while (node == NULL) { |
| 1807 | he = he->parent_he; |
| 1808 | if (he == NULL) |
| 1809 | break; |
| 1810 | |
| 1811 | node = rb_next(&he->rb_node); |
| 1812 | } |
| 1813 | return node; |
| 1814 | } |
| 1815 | |
| 1816 | struct rb_node *rb_hierarchy_prev(struct rb_node *node) |
| 1817 | { |
| 1818 | struct hist_entry *he = rb_entry(node, struct hist_entry, rb_node); |
| 1819 | |
| 1820 | node = rb_prev(node); |
| 1821 | if (node) |
| 1822 | return rb_hierarchy_last(node); |
| 1823 | |
| 1824 | he = he->parent_he; |
| 1825 | if (he == NULL) |
| 1826 | return NULL; |
| 1827 | |
| 1828 | return &he->rb_node; |
| 1829 | } |
| 1830 | |
Namhyung Kim | a7b5895 | 2016-02-26 21:13:16 +0900 | [diff] [blame] | 1831 | bool hist_entry__has_hierarchy_children(struct hist_entry *he, float limit) |
| 1832 | { |
| 1833 | struct rb_node *node; |
| 1834 | struct hist_entry *child; |
| 1835 | float percent; |
| 1836 | |
| 1837 | if (he->leaf) |
| 1838 | return false; |
| 1839 | |
| 1840 | node = rb_first(&he->hroot_out); |
| 1841 | child = rb_entry(node, struct hist_entry, rb_node); |
| 1842 | |
| 1843 | while (node && child->filtered) { |
| 1844 | node = rb_next(node); |
| 1845 | child = rb_entry(node, struct hist_entry, rb_node); |
| 1846 | } |
| 1847 | |
| 1848 | if (node) |
| 1849 | percent = hist_entry__get_percent_limit(child); |
| 1850 | else |
| 1851 | percent = 0; |
| 1852 | |
| 1853 | return node && percent >= limit; |
| 1854 | } |
| 1855 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1856 | 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] | 1857 | enum hist_filter filter) |
| 1858 | { |
| 1859 | h->filtered &= ~(1 << filter); |
Namhyung Kim | 155e9af | 2016-02-25 00:13:38 +0900 | [diff] [blame] | 1860 | |
| 1861 | if (symbol_conf.report_hierarchy) { |
| 1862 | struct hist_entry *parent = h->parent_he; |
| 1863 | |
| 1864 | while (parent) { |
| 1865 | he_stat__add_stat(&parent->stat, &h->stat); |
| 1866 | |
| 1867 | parent->filtered &= ~(1 << filter); |
| 1868 | |
| 1869 | if (parent->filtered) |
| 1870 | goto next; |
| 1871 | |
| 1872 | /* force fold unfiltered entry for simplicity */ |
| 1873 | parent->unfolded = false; |
Namhyung Kim | 79dded8 | 2016-02-26 21:13:19 +0900 | [diff] [blame] | 1874 | parent->has_no_entry = false; |
Namhyung Kim | 155e9af | 2016-02-25 00:13:38 +0900 | [diff] [blame] | 1875 | parent->row_offset = 0; |
| 1876 | parent->nr_rows = 0; |
| 1877 | next: |
| 1878 | parent = parent->parent_he; |
| 1879 | } |
| 1880 | } |
| 1881 | |
Arnaldo Carvalho de Melo | cc5edb0 | 2010-07-16 12:35:07 -0300 | [diff] [blame] | 1882 | if (h->filtered) |
| 1883 | return; |
| 1884 | |
Namhyung Kim | 87e90f4 | 2014-04-24 16:44:16 +0900 | [diff] [blame] | 1885 | /* force fold unfiltered entry for simplicity */ |
Namhyung Kim | 3698dab | 2015-05-05 23:55:46 +0900 | [diff] [blame] | 1886 | h->unfolded = false; |
Namhyung Kim | 79dded8 | 2016-02-26 21:13:19 +0900 | [diff] [blame] | 1887 | h->has_no_entry = false; |
Arnaldo Carvalho de Melo | 0f0cbf7 | 2010-07-26 17:13:40 -0300 | [diff] [blame] | 1888 | h->row_offset = 0; |
He Kuang | a8cd1f4 | 2015-03-11 20:36:03 +0800 | [diff] [blame] | 1889 | h->nr_rows = 0; |
Namhyung Kim | 9283ba9 | 2014-04-24 16:37:26 +0900 | [diff] [blame] | 1890 | |
Namhyung Kim | 1ab1fa5 | 2013-12-26 15:11:52 +0900 | [diff] [blame] | 1891 | hists->stats.nr_non_filtered_samples += h->stat.nr_events; |
Arnaldo Carvalho de Melo | cc5edb0 | 2010-07-16 12:35:07 -0300 | [diff] [blame] | 1892 | |
Namhyung Kim | 9283ba9 | 2014-04-24 16:37:26 +0900 | [diff] [blame] | 1893 | hists__inc_filter_stats(hists, h); |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1894 | hists__calc_col_len(hists, h); |
Arnaldo Carvalho de Melo | cc5edb0 | 2010-07-16 12:35:07 -0300 | [diff] [blame] | 1895 | } |
| 1896 | |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 1897 | |
| 1898 | static bool hists__filter_entry_by_dso(struct hists *hists, |
| 1899 | struct hist_entry *he) |
| 1900 | { |
| 1901 | if (hists->dso_filter != NULL && |
| 1902 | (he->ms.map == NULL || he->ms.map->dso != hists->dso_filter)) { |
| 1903 | he->filtered |= (1 << HIST_FILTER__DSO); |
| 1904 | return true; |
| 1905 | } |
| 1906 | |
| 1907 | return false; |
| 1908 | } |
| 1909 | |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 1910 | static bool hists__filter_entry_by_thread(struct hists *hists, |
| 1911 | struct hist_entry *he) |
| 1912 | { |
| 1913 | if (hists->thread_filter != NULL && |
| 1914 | he->thread != hists->thread_filter) { |
| 1915 | he->filtered |= (1 << HIST_FILTER__THREAD); |
| 1916 | return true; |
| 1917 | } |
| 1918 | |
| 1919 | return false; |
| 1920 | } |
| 1921 | |
Namhyung Kim | e94d53e | 2012-03-16 17:50:51 +0900 | [diff] [blame] | 1922 | static bool hists__filter_entry_by_symbol(struct hists *hists, |
| 1923 | struct hist_entry *he) |
| 1924 | { |
| 1925 | if (hists->symbol_filter_str != NULL && |
| 1926 | (!he->ms.sym || strstr(he->ms.sym->name, |
| 1927 | hists->symbol_filter_str) == NULL)) { |
| 1928 | he->filtered |= (1 << HIST_FILTER__SYMBOL); |
| 1929 | return true; |
| 1930 | } |
| 1931 | |
| 1932 | return false; |
| 1933 | } |
| 1934 | |
Kan Liang | 21394d9 | 2015-09-04 10:45:44 -0400 | [diff] [blame] | 1935 | static bool hists__filter_entry_by_socket(struct hists *hists, |
| 1936 | struct hist_entry *he) |
| 1937 | { |
| 1938 | if ((hists->socket_filter > -1) && |
| 1939 | (he->socket != hists->socket_filter)) { |
| 1940 | he->filtered |= (1 << HIST_FILTER__SOCKET); |
| 1941 | return true; |
| 1942 | } |
| 1943 | |
| 1944 | return false; |
| 1945 | } |
| 1946 | |
Namhyung Kim | 1f7c254 | 2016-01-20 10:15:21 +0900 | [diff] [blame] | 1947 | typedef bool (*filter_fn_t)(struct hists *hists, struct hist_entry *he); |
| 1948 | |
| 1949 | 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] | 1950 | { |
| 1951 | struct rb_node *nd; |
| 1952 | |
| 1953 | hists->stats.nr_non_filtered_samples = 0; |
| 1954 | |
| 1955 | hists__reset_filter_stats(hists); |
| 1956 | hists__reset_col_len(hists); |
| 1957 | |
| 1958 | for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) { |
| 1959 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
| 1960 | |
Namhyung Kim | 1f7c254 | 2016-01-20 10:15:21 +0900 | [diff] [blame] | 1961 | if (filter(hists, h)) |
Kan Liang | 84734b0 | 2015-09-04 10:45:45 -0400 | [diff] [blame] | 1962 | continue; |
| 1963 | |
Namhyung Kim | 1f7c254 | 2016-01-20 10:15:21 +0900 | [diff] [blame] | 1964 | hists__remove_entry_filter(hists, h, type); |
Kan Liang | 84734b0 | 2015-09-04 10:45:45 -0400 | [diff] [blame] | 1965 | } |
| 1966 | } |
| 1967 | |
Namhyung Kim | 7064285 | 2016-02-25 00:13:39 +0900 | [diff] [blame] | 1968 | static void resort_filtered_entry(struct rb_root *root, struct hist_entry *he) |
| 1969 | { |
| 1970 | struct rb_node **p = &root->rb_node; |
| 1971 | struct rb_node *parent = NULL; |
| 1972 | struct hist_entry *iter; |
| 1973 | struct rb_root new_root = RB_ROOT; |
| 1974 | struct rb_node *nd; |
| 1975 | |
| 1976 | while (*p != NULL) { |
| 1977 | parent = *p; |
| 1978 | iter = rb_entry(parent, struct hist_entry, rb_node); |
| 1979 | |
| 1980 | if (hist_entry__sort(he, iter) > 0) |
| 1981 | p = &(*p)->rb_left; |
| 1982 | else |
| 1983 | p = &(*p)->rb_right; |
| 1984 | } |
| 1985 | |
| 1986 | rb_link_node(&he->rb_node, parent, p); |
| 1987 | rb_insert_color(&he->rb_node, root); |
| 1988 | |
| 1989 | if (he->leaf || he->filtered) |
| 1990 | return; |
| 1991 | |
| 1992 | nd = rb_first(&he->hroot_out); |
| 1993 | while (nd) { |
| 1994 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
| 1995 | |
| 1996 | nd = rb_next(nd); |
| 1997 | rb_erase(&h->rb_node, &he->hroot_out); |
| 1998 | |
| 1999 | resort_filtered_entry(&new_root, h); |
| 2000 | } |
| 2001 | |
| 2002 | he->hroot_out = new_root; |
| 2003 | } |
| 2004 | |
Namhyung Kim | 155e9af | 2016-02-25 00:13:38 +0900 | [diff] [blame] | 2005 | static void hists__filter_hierarchy(struct hists *hists, int type, const void *arg) |
| 2006 | { |
| 2007 | struct rb_node *nd; |
Namhyung Kim | 7064285 | 2016-02-25 00:13:39 +0900 | [diff] [blame] | 2008 | struct rb_root new_root = RB_ROOT; |
Namhyung Kim | 155e9af | 2016-02-25 00:13:38 +0900 | [diff] [blame] | 2009 | |
| 2010 | hists->stats.nr_non_filtered_samples = 0; |
| 2011 | |
| 2012 | hists__reset_filter_stats(hists); |
| 2013 | hists__reset_col_len(hists); |
| 2014 | |
| 2015 | nd = rb_first(&hists->entries); |
| 2016 | while (nd) { |
| 2017 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
| 2018 | int ret; |
| 2019 | |
| 2020 | ret = hist_entry__filter(h, type, arg); |
| 2021 | |
| 2022 | /* |
| 2023 | * case 1. non-matching type |
| 2024 | * zero out the period, set filter marker and move to child |
| 2025 | */ |
| 2026 | if (ret < 0) { |
| 2027 | memset(&h->stat, 0, sizeof(h->stat)); |
| 2028 | h->filtered |= (1 << type); |
| 2029 | |
| 2030 | nd = __rb_hierarchy_next(&h->rb_node, HMD_FORCE_CHILD); |
| 2031 | } |
| 2032 | /* |
| 2033 | * case 2. matched type (filter out) |
| 2034 | * set filter marker and move to next |
| 2035 | */ |
| 2036 | else if (ret == 1) { |
| 2037 | h->filtered |= (1 << type); |
| 2038 | |
| 2039 | nd = __rb_hierarchy_next(&h->rb_node, HMD_FORCE_SIBLING); |
| 2040 | } |
| 2041 | /* |
| 2042 | * case 3. ok (not filtered) |
| 2043 | * add period to hists and parents, erase the filter marker |
| 2044 | * and move to next sibling |
| 2045 | */ |
| 2046 | else { |
| 2047 | hists__remove_entry_filter(hists, h, type); |
| 2048 | |
| 2049 | nd = __rb_hierarchy_next(&h->rb_node, HMD_FORCE_SIBLING); |
| 2050 | } |
| 2051 | } |
Namhyung Kim | 7064285 | 2016-02-25 00:13:39 +0900 | [diff] [blame] | 2052 | |
Namhyung Kim | f7fb538 | 2016-03-09 22:47:02 +0900 | [diff] [blame] | 2053 | hierarchy_recalc_total_periods(hists); |
| 2054 | |
Namhyung Kim | 7064285 | 2016-02-25 00:13:39 +0900 | [diff] [blame] | 2055 | /* |
| 2056 | * resort output after applying a new filter since filter in a lower |
| 2057 | * hierarchy can change periods in a upper hierarchy. |
| 2058 | */ |
| 2059 | nd = rb_first(&hists->entries); |
| 2060 | while (nd) { |
| 2061 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
| 2062 | |
| 2063 | nd = rb_next(nd); |
| 2064 | rb_erase(&h->rb_node, &hists->entries); |
| 2065 | |
| 2066 | resort_filtered_entry(&new_root, h); |
| 2067 | } |
| 2068 | |
| 2069 | hists->entries = new_root; |
Namhyung Kim | 155e9af | 2016-02-25 00:13:38 +0900 | [diff] [blame] | 2070 | } |
| 2071 | |
Namhyung Kim | 1f7c254 | 2016-01-20 10:15:21 +0900 | [diff] [blame] | 2072 | void hists__filter_by_thread(struct hists *hists) |
| 2073 | { |
Namhyung Kim | 155e9af | 2016-02-25 00:13:38 +0900 | [diff] [blame] | 2074 | if (symbol_conf.report_hierarchy) |
| 2075 | hists__filter_hierarchy(hists, HIST_FILTER__THREAD, |
| 2076 | hists->thread_filter); |
| 2077 | else |
| 2078 | hists__filter_by_type(hists, HIST_FILTER__THREAD, |
| 2079 | hists__filter_entry_by_thread); |
Namhyung Kim | 1f7c254 | 2016-01-20 10:15:21 +0900 | [diff] [blame] | 2080 | } |
| 2081 | |
| 2082 | void hists__filter_by_dso(struct hists *hists) |
| 2083 | { |
Namhyung Kim | 155e9af | 2016-02-25 00:13:38 +0900 | [diff] [blame] | 2084 | if (symbol_conf.report_hierarchy) |
| 2085 | hists__filter_hierarchy(hists, HIST_FILTER__DSO, |
| 2086 | hists->dso_filter); |
| 2087 | else |
| 2088 | hists__filter_by_type(hists, HIST_FILTER__DSO, |
| 2089 | hists__filter_entry_by_dso); |
Namhyung Kim | 1f7c254 | 2016-01-20 10:15:21 +0900 | [diff] [blame] | 2090 | } |
| 2091 | |
| 2092 | void hists__filter_by_symbol(struct hists *hists) |
| 2093 | { |
Namhyung Kim | 155e9af | 2016-02-25 00:13:38 +0900 | [diff] [blame] | 2094 | if (symbol_conf.report_hierarchy) |
| 2095 | hists__filter_hierarchy(hists, HIST_FILTER__SYMBOL, |
| 2096 | hists->symbol_filter_str); |
| 2097 | else |
| 2098 | hists__filter_by_type(hists, HIST_FILTER__SYMBOL, |
| 2099 | hists__filter_entry_by_symbol); |
Namhyung Kim | 1f7c254 | 2016-01-20 10:15:21 +0900 | [diff] [blame] | 2100 | } |
| 2101 | |
| 2102 | void hists__filter_by_socket(struct hists *hists) |
| 2103 | { |
Namhyung Kim | 155e9af | 2016-02-25 00:13:38 +0900 | [diff] [blame] | 2104 | if (symbol_conf.report_hierarchy) |
| 2105 | hists__filter_hierarchy(hists, HIST_FILTER__SOCKET, |
| 2106 | &hists->socket_filter); |
| 2107 | else |
| 2108 | hists__filter_by_type(hists, HIST_FILTER__SOCKET, |
| 2109 | hists__filter_entry_by_socket); |
Namhyung Kim | 1f7c254 | 2016-01-20 10:15:21 +0900 | [diff] [blame] | 2110 | } |
| 2111 | |
Arnaldo Carvalho de Melo | 28a6b6a | 2012-12-18 16:24:46 -0300 | [diff] [blame] | 2112 | void events_stats__inc(struct events_stats *stats, u32 type) |
| 2113 | { |
| 2114 | ++stats->nr_events[0]; |
| 2115 | ++stats->nr_events[type]; |
| 2116 | } |
| 2117 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 2118 | void hists__inc_nr_events(struct hists *hists, u32 type) |
Arnaldo Carvalho de Melo | c8446b9 | 2010-05-14 10:36:42 -0300 | [diff] [blame] | 2119 | { |
Arnaldo Carvalho de Melo | 28a6b6a | 2012-12-18 16:24:46 -0300 | [diff] [blame] | 2120 | events_stats__inc(&hists->stats, type); |
Arnaldo Carvalho de Melo | c8446b9 | 2010-05-14 10:36:42 -0300 | [diff] [blame] | 2121 | } |
Arnaldo Carvalho de Melo | 95529be | 2012-11-08 17:54:33 -0300 | [diff] [blame] | 2122 | |
Namhyung Kim | 1844dbc | 2014-05-28 14:12:18 +0900 | [diff] [blame] | 2123 | void hists__inc_nr_samples(struct hists *hists, bool filtered) |
| 2124 | { |
| 2125 | events_stats__inc(&hists->stats, PERF_RECORD_SAMPLE); |
| 2126 | if (!filtered) |
| 2127 | hists->stats.nr_non_filtered_samples++; |
| 2128 | } |
| 2129 | |
Arnaldo Carvalho de Melo | 494d70a | 2012-11-08 18:03:09 -0300 | [diff] [blame] | 2130 | static struct hist_entry *hists__add_dummy_entry(struct hists *hists, |
| 2131 | struct hist_entry *pair) |
| 2132 | { |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 2133 | struct rb_root *root; |
| 2134 | struct rb_node **p; |
Arnaldo Carvalho de Melo | 494d70a | 2012-11-08 18:03:09 -0300 | [diff] [blame] | 2135 | struct rb_node *parent = NULL; |
| 2136 | struct hist_entry *he; |
Andi Kleen | 354cc40 | 2013-10-01 07:22:15 -0700 | [diff] [blame] | 2137 | int64_t cmp; |
Arnaldo Carvalho de Melo | 494d70a | 2012-11-08 18:03:09 -0300 | [diff] [blame] | 2138 | |
Jiri Olsa | 5222503 | 2016-05-03 13:54:42 +0200 | [diff] [blame] | 2139 | if (hists__has(hists, need_collapse)) |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 2140 | root = &hists->entries_collapsed; |
| 2141 | else |
| 2142 | root = hists->entries_in; |
| 2143 | |
| 2144 | p = &root->rb_node; |
| 2145 | |
Arnaldo Carvalho de Melo | 494d70a | 2012-11-08 18:03:09 -0300 | [diff] [blame] | 2146 | while (*p != NULL) { |
| 2147 | parent = *p; |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 2148 | he = rb_entry(parent, struct hist_entry, rb_node_in); |
Arnaldo Carvalho de Melo | 494d70a | 2012-11-08 18:03:09 -0300 | [diff] [blame] | 2149 | |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 2150 | cmp = hist_entry__collapse(he, pair); |
Arnaldo Carvalho de Melo | 494d70a | 2012-11-08 18:03:09 -0300 | [diff] [blame] | 2151 | |
| 2152 | if (!cmp) |
| 2153 | goto out; |
| 2154 | |
| 2155 | if (cmp < 0) |
| 2156 | p = &(*p)->rb_left; |
| 2157 | else |
| 2158 | p = &(*p)->rb_right; |
| 2159 | } |
| 2160 | |
Namhyung Kim | a0b51af | 2012-09-11 13:34:27 +0900 | [diff] [blame] | 2161 | he = hist_entry__new(pair, true); |
Arnaldo Carvalho de Melo | 494d70a | 2012-11-08 18:03:09 -0300 | [diff] [blame] | 2162 | if (he) { |
Arnaldo Carvalho de Melo | 30193d7 | 2012-11-12 13:20:03 -0300 | [diff] [blame] | 2163 | memset(&he->stat, 0, sizeof(he->stat)); |
| 2164 | he->hists = hists; |
Kan Liang | 09623d7 | 2016-04-24 23:28:09 -0700 | [diff] [blame] | 2165 | if (symbol_conf.cumulate_callchain) |
| 2166 | memset(he->stat_acc, 0, sizeof(he->stat)); |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 2167 | rb_link_node(&he->rb_node_in, parent, p); |
| 2168 | rb_insert_color(&he->rb_node_in, root); |
Namhyung Kim | 6263835 | 2014-04-24 16:21:46 +0900 | [diff] [blame] | 2169 | hists__inc_stats(hists, he); |
Jiri Olsa | e0af43d | 2012-12-01 21:18:20 +0100 | [diff] [blame] | 2170 | he->dummy = true; |
Arnaldo Carvalho de Melo | 494d70a | 2012-11-08 18:03:09 -0300 | [diff] [blame] | 2171 | } |
| 2172 | out: |
| 2173 | return he; |
| 2174 | } |
| 2175 | |
Namhyung Kim | 9d97b8f | 2016-09-13 16:45:47 +0900 | [diff] [blame] | 2176 | static struct hist_entry *add_dummy_hierarchy_entry(struct hists *hists, |
| 2177 | struct rb_root *root, |
| 2178 | struct hist_entry *pair) |
| 2179 | { |
| 2180 | struct rb_node **p; |
| 2181 | struct rb_node *parent = NULL; |
| 2182 | struct hist_entry *he; |
| 2183 | struct perf_hpp_fmt *fmt; |
| 2184 | |
| 2185 | p = &root->rb_node; |
| 2186 | while (*p != NULL) { |
| 2187 | int64_t cmp = 0; |
| 2188 | |
| 2189 | parent = *p; |
| 2190 | he = rb_entry(parent, struct hist_entry, rb_node_in); |
| 2191 | |
| 2192 | perf_hpp_list__for_each_sort_list(he->hpp_list, fmt) { |
| 2193 | cmp = fmt->collapse(fmt, he, pair); |
| 2194 | if (cmp) |
| 2195 | break; |
| 2196 | } |
| 2197 | if (!cmp) |
| 2198 | goto out; |
| 2199 | |
| 2200 | if (cmp < 0) |
| 2201 | p = &parent->rb_left; |
| 2202 | else |
| 2203 | p = &parent->rb_right; |
| 2204 | } |
| 2205 | |
| 2206 | he = hist_entry__new(pair, true); |
| 2207 | if (he) { |
| 2208 | rb_link_node(&he->rb_node_in, parent, p); |
| 2209 | rb_insert_color(&he->rb_node_in, root); |
| 2210 | |
| 2211 | he->dummy = true; |
| 2212 | he->hists = hists; |
| 2213 | memset(&he->stat, 0, sizeof(he->stat)); |
| 2214 | hists__inc_stats(hists, he); |
| 2215 | } |
| 2216 | out: |
| 2217 | return he; |
| 2218 | } |
| 2219 | |
Arnaldo Carvalho de Melo | 95529be | 2012-11-08 17:54:33 -0300 | [diff] [blame] | 2220 | static struct hist_entry *hists__find_entry(struct hists *hists, |
| 2221 | struct hist_entry *he) |
| 2222 | { |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 2223 | struct rb_node *n; |
| 2224 | |
Jiri Olsa | 5222503 | 2016-05-03 13:54:42 +0200 | [diff] [blame] | 2225 | if (hists__has(hists, need_collapse)) |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 2226 | n = hists->entries_collapsed.rb_node; |
| 2227 | else |
| 2228 | n = hists->entries_in->rb_node; |
Arnaldo Carvalho de Melo | 95529be | 2012-11-08 17:54:33 -0300 | [diff] [blame] | 2229 | |
| 2230 | while (n) { |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 2231 | struct hist_entry *iter = rb_entry(n, struct hist_entry, rb_node_in); |
| 2232 | int64_t cmp = hist_entry__collapse(iter, he); |
Arnaldo Carvalho de Melo | 95529be | 2012-11-08 17:54:33 -0300 | [diff] [blame] | 2233 | |
| 2234 | if (cmp < 0) |
| 2235 | n = n->rb_left; |
| 2236 | else if (cmp > 0) |
| 2237 | n = n->rb_right; |
| 2238 | else |
| 2239 | return iter; |
| 2240 | } |
| 2241 | |
| 2242 | return NULL; |
| 2243 | } |
| 2244 | |
Namhyung Kim | 09034de | 2016-09-13 16:45:46 +0900 | [diff] [blame] | 2245 | static struct hist_entry *hists__find_hierarchy_entry(struct rb_root *root, |
| 2246 | struct hist_entry *he) |
| 2247 | { |
| 2248 | struct rb_node *n = root->rb_node; |
| 2249 | |
| 2250 | while (n) { |
| 2251 | struct hist_entry *iter; |
| 2252 | struct perf_hpp_fmt *fmt; |
| 2253 | int64_t cmp = 0; |
| 2254 | |
| 2255 | iter = rb_entry(n, struct hist_entry, rb_node_in); |
| 2256 | perf_hpp_list__for_each_sort_list(he->hpp_list, fmt) { |
| 2257 | cmp = fmt->collapse(fmt, iter, he); |
| 2258 | if (cmp) |
| 2259 | break; |
| 2260 | } |
| 2261 | |
| 2262 | if (cmp < 0) |
| 2263 | n = n->rb_left; |
| 2264 | else if (cmp > 0) |
| 2265 | n = n->rb_right; |
| 2266 | else |
| 2267 | return iter; |
| 2268 | } |
| 2269 | |
| 2270 | return NULL; |
| 2271 | } |
| 2272 | |
| 2273 | static void hists__match_hierarchy(struct rb_root *leader_root, |
| 2274 | struct rb_root *other_root) |
| 2275 | { |
| 2276 | struct rb_node *nd; |
| 2277 | struct hist_entry *pos, *pair; |
| 2278 | |
| 2279 | for (nd = rb_first(leader_root); nd; nd = rb_next(nd)) { |
| 2280 | pos = rb_entry(nd, struct hist_entry, rb_node_in); |
| 2281 | pair = hists__find_hierarchy_entry(other_root, pos); |
| 2282 | |
| 2283 | if (pair) { |
| 2284 | hist_entry__add_pair(pair, pos); |
| 2285 | hists__match_hierarchy(&pos->hroot_in, &pair->hroot_in); |
| 2286 | } |
| 2287 | } |
| 2288 | } |
| 2289 | |
Arnaldo Carvalho de Melo | 95529be | 2012-11-08 17:54:33 -0300 | [diff] [blame] | 2290 | /* |
| 2291 | * Look for pairs to link to the leader buckets (hist_entries): |
| 2292 | */ |
| 2293 | void hists__match(struct hists *leader, struct hists *other) |
| 2294 | { |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 2295 | struct rb_root *root; |
Arnaldo Carvalho de Melo | 95529be | 2012-11-08 17:54:33 -0300 | [diff] [blame] | 2296 | struct rb_node *nd; |
| 2297 | struct hist_entry *pos, *pair; |
| 2298 | |
Namhyung Kim | 09034de | 2016-09-13 16:45:46 +0900 | [diff] [blame] | 2299 | if (symbol_conf.report_hierarchy) { |
| 2300 | /* hierarchy report always collapses entries */ |
| 2301 | return hists__match_hierarchy(&leader->entries_collapsed, |
| 2302 | &other->entries_collapsed); |
| 2303 | } |
| 2304 | |
Jiri Olsa | 5222503 | 2016-05-03 13:54:42 +0200 | [diff] [blame] | 2305 | if (hists__has(leader, need_collapse)) |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 2306 | root = &leader->entries_collapsed; |
| 2307 | else |
| 2308 | root = leader->entries_in; |
| 2309 | |
| 2310 | for (nd = rb_first(root); nd; nd = rb_next(nd)) { |
| 2311 | pos = rb_entry(nd, struct hist_entry, rb_node_in); |
Arnaldo Carvalho de Melo | 95529be | 2012-11-08 17:54:33 -0300 | [diff] [blame] | 2312 | pair = hists__find_entry(other, pos); |
| 2313 | |
| 2314 | if (pair) |
Namhyung Kim | 5fa9041 | 2012-11-29 15:38:34 +0900 | [diff] [blame] | 2315 | hist_entry__add_pair(pair, pos); |
Arnaldo Carvalho de Melo | 95529be | 2012-11-08 17:54:33 -0300 | [diff] [blame] | 2316 | } |
| 2317 | } |
Arnaldo Carvalho de Melo | 494d70a | 2012-11-08 18:03:09 -0300 | [diff] [blame] | 2318 | |
Namhyung Kim | 9d97b8f | 2016-09-13 16:45:47 +0900 | [diff] [blame] | 2319 | static int hists__link_hierarchy(struct hists *leader_hists, |
| 2320 | struct hist_entry *parent, |
| 2321 | struct rb_root *leader_root, |
| 2322 | struct rb_root *other_root) |
| 2323 | { |
| 2324 | struct rb_node *nd; |
| 2325 | struct hist_entry *pos, *leader; |
| 2326 | |
| 2327 | for (nd = rb_first(other_root); nd; nd = rb_next(nd)) { |
| 2328 | pos = rb_entry(nd, struct hist_entry, rb_node_in); |
| 2329 | |
| 2330 | if (hist_entry__has_pairs(pos)) { |
| 2331 | bool found = false; |
| 2332 | |
| 2333 | list_for_each_entry(leader, &pos->pairs.head, pairs.node) { |
| 2334 | if (leader->hists == leader_hists) { |
| 2335 | found = true; |
| 2336 | break; |
| 2337 | } |
| 2338 | } |
| 2339 | if (!found) |
| 2340 | return -1; |
| 2341 | } else { |
| 2342 | leader = add_dummy_hierarchy_entry(leader_hists, |
| 2343 | leader_root, pos); |
| 2344 | if (leader == NULL) |
| 2345 | return -1; |
| 2346 | |
| 2347 | /* do not point parent in the pos */ |
| 2348 | leader->parent_he = parent; |
| 2349 | |
| 2350 | hist_entry__add_pair(pos, leader); |
| 2351 | } |
| 2352 | |
| 2353 | if (!pos->leaf) { |
| 2354 | if (hists__link_hierarchy(leader_hists, leader, |
| 2355 | &leader->hroot_in, |
| 2356 | &pos->hroot_in) < 0) |
| 2357 | return -1; |
| 2358 | } |
| 2359 | } |
| 2360 | return 0; |
| 2361 | } |
| 2362 | |
Arnaldo Carvalho de Melo | 494d70a | 2012-11-08 18:03:09 -0300 | [diff] [blame] | 2363 | /* |
| 2364 | * Look for entries in the other hists that are not present in the leader, if |
| 2365 | * we find them, just add a dummy entry on the leader hists, with period=0, |
| 2366 | * nr_events=0, to serve as the list header. |
| 2367 | */ |
| 2368 | int hists__link(struct hists *leader, struct hists *other) |
| 2369 | { |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 2370 | struct rb_root *root; |
Arnaldo Carvalho de Melo | 494d70a | 2012-11-08 18:03:09 -0300 | [diff] [blame] | 2371 | struct rb_node *nd; |
| 2372 | struct hist_entry *pos, *pair; |
| 2373 | |
Namhyung Kim | 9d97b8f | 2016-09-13 16:45:47 +0900 | [diff] [blame] | 2374 | if (symbol_conf.report_hierarchy) { |
| 2375 | /* hierarchy report always collapses entries */ |
| 2376 | return hists__link_hierarchy(leader, NULL, |
| 2377 | &leader->entries_collapsed, |
| 2378 | &other->entries_collapsed); |
| 2379 | } |
| 2380 | |
Jiri Olsa | 5222503 | 2016-05-03 13:54:42 +0200 | [diff] [blame] | 2381 | if (hists__has(other, need_collapse)) |
Namhyung Kim | ce74f60 | 2012-12-10 17:29:55 +0900 | [diff] [blame] | 2382 | root = &other->entries_collapsed; |
| 2383 | else |
| 2384 | root = other->entries_in; |
| 2385 | |
| 2386 | for (nd = rb_first(root); nd; nd = rb_next(nd)) { |
| 2387 | pos = rb_entry(nd, struct hist_entry, rb_node_in); |
Arnaldo Carvalho de Melo | 494d70a | 2012-11-08 18:03:09 -0300 | [diff] [blame] | 2388 | |
| 2389 | if (!hist_entry__has_pairs(pos)) { |
| 2390 | pair = hists__add_dummy_entry(leader, pos); |
| 2391 | if (pair == NULL) |
| 2392 | return -1; |
Namhyung Kim | 5fa9041 | 2012-11-29 15:38:34 +0900 | [diff] [blame] | 2393 | hist_entry__add_pair(pos, pair); |
Arnaldo Carvalho de Melo | 494d70a | 2012-11-08 18:03:09 -0300 | [diff] [blame] | 2394 | } |
| 2395 | } |
| 2396 | |
| 2397 | return 0; |
| 2398 | } |
Namhyung Kim | f214833 | 2014-01-14 11:52:48 +0900 | [diff] [blame] | 2399 | |
Andi Kleen | 57849998 | 2015-07-18 08:24:49 -0700 | [diff] [blame] | 2400 | void hist__account_cycles(struct branch_stack *bs, struct addr_location *al, |
| 2401 | struct perf_sample *sample, bool nonany_branch_mode) |
| 2402 | { |
| 2403 | struct branch_info *bi; |
| 2404 | |
| 2405 | /* If we have branch cycles always annotate them. */ |
| 2406 | if (bs && bs->nr && bs->entries[0].flags.cycles) { |
| 2407 | int i; |
| 2408 | |
| 2409 | bi = sample__resolve_bstack(sample, al); |
| 2410 | if (bi) { |
| 2411 | struct addr_map_symbol *prev = NULL; |
| 2412 | |
| 2413 | /* |
| 2414 | * Ignore errors, still want to process the |
| 2415 | * other entries. |
| 2416 | * |
| 2417 | * For non standard branch modes always |
| 2418 | * force no IPC (prev == NULL) |
| 2419 | * |
| 2420 | * Note that perf stores branches reversed from |
| 2421 | * program order! |
| 2422 | */ |
| 2423 | for (i = bs->nr - 1; i >= 0; i--) { |
| 2424 | addr_map_symbol__account_cycles(&bi[i].from, |
| 2425 | nonany_branch_mode ? NULL : prev, |
| 2426 | bi[i].flags.cycles); |
| 2427 | prev = &bi[i].to; |
| 2428 | } |
| 2429 | free(bi); |
| 2430 | } |
| 2431 | } |
| 2432 | } |
Arnaldo Carvalho de Melo | 2a1731f | 2014-10-10 15:49:21 -0300 | [diff] [blame] | 2433 | |
| 2434 | size_t perf_evlist__fprintf_nr_events(struct perf_evlist *evlist, FILE *fp) |
| 2435 | { |
| 2436 | struct perf_evsel *pos; |
| 2437 | size_t ret = 0; |
| 2438 | |
Arnaldo Carvalho de Melo | e5cadb9 | 2016-06-23 11:26:15 -0300 | [diff] [blame] | 2439 | evlist__for_each_entry(evlist, pos) { |
Arnaldo Carvalho de Melo | 2a1731f | 2014-10-10 15:49:21 -0300 | [diff] [blame] | 2440 | ret += fprintf(fp, "%s stats:\n", perf_evsel__name(pos)); |
| 2441 | ret += events_stats__fprintf(&evsel__hists(pos)->stats, fp); |
| 2442 | } |
| 2443 | |
| 2444 | return ret; |
| 2445 | } |
| 2446 | |
| 2447 | |
Namhyung Kim | f214833 | 2014-01-14 11:52:48 +0900 | [diff] [blame] | 2448 | u64 hists__total_period(struct hists *hists) |
| 2449 | { |
| 2450 | return symbol_conf.filter_relative ? hists->stats.total_non_filtered_period : |
| 2451 | hists->stats.total_period; |
| 2452 | } |
Namhyung Kim | 33db456 | 2014-02-07 12:06:07 +0900 | [diff] [blame] | 2453 | |
| 2454 | int parse_filter_percentage(const struct option *opt __maybe_unused, |
| 2455 | const char *arg, int unset __maybe_unused) |
| 2456 | { |
| 2457 | if (!strcmp(arg, "relative")) |
| 2458 | symbol_conf.filter_relative = true; |
| 2459 | else if (!strcmp(arg, "absolute")) |
| 2460 | symbol_conf.filter_relative = false; |
Arnaldo Carvalho de Melo | ecc4c56 | 2017-01-24 13:44:10 -0300 | [diff] [blame] | 2461 | else { |
Colin Ian King | a596a87 | 2017-03-30 10:54:40 +0100 | [diff] [blame^] | 2462 | pr_debug("Invalid percentage: %s\n", arg); |
Namhyung Kim | 33db456 | 2014-02-07 12:06:07 +0900 | [diff] [blame] | 2463 | return -1; |
Arnaldo Carvalho de Melo | ecc4c56 | 2017-01-24 13:44:10 -0300 | [diff] [blame] | 2464 | } |
Namhyung Kim | 33db456 | 2014-02-07 12:06:07 +0900 | [diff] [blame] | 2465 | |
| 2466 | return 0; |
| 2467 | } |
Namhyung Kim | 0b93da1 | 2014-01-14 12:02:15 +0900 | [diff] [blame] | 2468 | |
| 2469 | int perf_hist_config(const char *var, const char *value) |
| 2470 | { |
| 2471 | if (!strcmp(var, "hist.percentage")) |
| 2472 | return parse_filter_percentage(NULL, value, 0); |
| 2473 | |
| 2474 | return 0; |
| 2475 | } |
Arnaldo Carvalho de Melo | a635fc5 | 2014-10-09 16:16:00 -0300 | [diff] [blame] | 2476 | |
Jiri Olsa | 5b65855 | 2016-01-18 10:24:22 +0100 | [diff] [blame] | 2477 | int __hists__init(struct hists *hists, struct perf_hpp_list *hpp_list) |
Arnaldo Carvalho de Melo | a635fc5 | 2014-10-09 16:16:00 -0300 | [diff] [blame] | 2478 | { |
Arnaldo Carvalho de Melo | a635fc5 | 2014-10-09 16:16:00 -0300 | [diff] [blame] | 2479 | memset(hists, 0, sizeof(*hists)); |
| 2480 | hists->entries_in_array[0] = hists->entries_in_array[1] = RB_ROOT; |
| 2481 | hists->entries_in = &hists->entries_in_array[0]; |
| 2482 | hists->entries_collapsed = RB_ROOT; |
| 2483 | hists->entries = RB_ROOT; |
| 2484 | pthread_mutex_init(&hists->lock, NULL); |
Kan Liang | 21394d9 | 2015-09-04 10:45:44 -0400 | [diff] [blame] | 2485 | hists->socket_filter = -1; |
Jiri Olsa | 5b65855 | 2016-01-18 10:24:22 +0100 | [diff] [blame] | 2486 | hists->hpp_list = hpp_list; |
Namhyung Kim | c3bc0c4 | 2016-03-07 16:44:45 -0300 | [diff] [blame] | 2487 | INIT_LIST_HEAD(&hists->hpp_formats); |
Arnaldo Carvalho de Melo | a635fc5 | 2014-10-09 16:16:00 -0300 | [diff] [blame] | 2488 | return 0; |
| 2489 | } |
| 2490 | |
Namhyung Kim | 61fa0e9 | 2015-12-10 16:53:20 +0900 | [diff] [blame] | 2491 | static void hists__delete_remaining_entries(struct rb_root *root) |
| 2492 | { |
| 2493 | struct rb_node *node; |
| 2494 | struct hist_entry *he; |
| 2495 | |
| 2496 | while (!RB_EMPTY_ROOT(root)) { |
| 2497 | node = rb_first(root); |
| 2498 | rb_erase(node, root); |
| 2499 | |
| 2500 | he = rb_entry(node, struct hist_entry, rb_node_in); |
| 2501 | hist_entry__delete(he); |
| 2502 | } |
| 2503 | } |
| 2504 | |
| 2505 | static void hists__delete_all_entries(struct hists *hists) |
| 2506 | { |
| 2507 | hists__delete_entries(hists); |
| 2508 | hists__delete_remaining_entries(&hists->entries_in_array[0]); |
| 2509 | hists__delete_remaining_entries(&hists->entries_in_array[1]); |
| 2510 | hists__delete_remaining_entries(&hists->entries_collapsed); |
| 2511 | } |
| 2512 | |
Masami Hiramatsu | 17577de | 2015-12-09 11:11:29 +0900 | [diff] [blame] | 2513 | static void hists_evsel__exit(struct perf_evsel *evsel) |
| 2514 | { |
| 2515 | struct hists *hists = evsel__hists(evsel); |
Namhyung Kim | c3bc0c4 | 2016-03-07 16:44:45 -0300 | [diff] [blame] | 2516 | struct perf_hpp_fmt *fmt, *pos; |
| 2517 | struct perf_hpp_list_node *node, *tmp; |
Masami Hiramatsu | 17577de | 2015-12-09 11:11:29 +0900 | [diff] [blame] | 2518 | |
Namhyung Kim | 61fa0e9 | 2015-12-10 16:53:20 +0900 | [diff] [blame] | 2519 | hists__delete_all_entries(hists); |
Namhyung Kim | c3bc0c4 | 2016-03-07 16:44:45 -0300 | [diff] [blame] | 2520 | |
| 2521 | list_for_each_entry_safe(node, tmp, &hists->hpp_formats, list) { |
| 2522 | perf_hpp_list__for_each_format_safe(&node->hpp, fmt, pos) { |
| 2523 | list_del(&fmt->list); |
| 2524 | free(fmt); |
| 2525 | } |
| 2526 | list_del(&node->list); |
| 2527 | free(node); |
| 2528 | } |
Masami Hiramatsu | 17577de | 2015-12-09 11:11:29 +0900 | [diff] [blame] | 2529 | } |
| 2530 | |
Namhyung Kim | fc284be | 2016-01-07 10:14:10 +0100 | [diff] [blame] | 2531 | static int hists_evsel__init(struct perf_evsel *evsel) |
| 2532 | { |
| 2533 | struct hists *hists = evsel__hists(evsel); |
| 2534 | |
Jiri Olsa | 5b65855 | 2016-01-18 10:24:22 +0100 | [diff] [blame] | 2535 | __hists__init(hists, &perf_hpp_list); |
Namhyung Kim | fc284be | 2016-01-07 10:14:10 +0100 | [diff] [blame] | 2536 | return 0; |
| 2537 | } |
| 2538 | |
Arnaldo Carvalho de Melo | a635fc5 | 2014-10-09 16:16:00 -0300 | [diff] [blame] | 2539 | /* |
| 2540 | * XXX We probably need a hists_evsel__exit() to free the hist_entries |
| 2541 | * stored in the rbtree... |
| 2542 | */ |
| 2543 | |
| 2544 | int hists__init(void) |
| 2545 | { |
| 2546 | int err = perf_evsel__object_config(sizeof(struct hists_evsel), |
Masami Hiramatsu | 17577de | 2015-12-09 11:11:29 +0900 | [diff] [blame] | 2547 | hists_evsel__init, |
| 2548 | hists_evsel__exit); |
Arnaldo Carvalho de Melo | a635fc5 | 2014-10-09 16:16:00 -0300 | [diff] [blame] | 2549 | if (err) |
| 2550 | fputs("FATAL ERROR: Couldn't setup hists class\n", stderr); |
| 2551 | |
| 2552 | return err; |
| 2553 | } |
Jiri Olsa | 94b3dc3 | 2016-01-18 10:24:13 +0100 | [diff] [blame] | 2554 | |
| 2555 | void perf_hpp_list__init(struct perf_hpp_list *list) |
| 2556 | { |
| 2557 | INIT_LIST_HEAD(&list->fields); |
| 2558 | INIT_LIST_HEAD(&list->sorts); |
| 2559 | } |