Arnaldo Carvalho de Melo | 78f7def | 2011-02-04 09:45:46 -0200 | [diff] [blame] | 1 | #include "annotate.h" |
Frederic Weisbecker | 8a0ecfb | 2010-05-13 19:47:16 +0200 | [diff] [blame] | 2 | #include "util.h" |
Frederic Weisbecker | 598357e | 2010-05-21 12:48:39 +0200 | [diff] [blame] | 3 | #include "build-id.h" |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 4 | #include "hist.h" |
Arnaldo Carvalho de Melo | 4e4f06e | 2009-12-14 13:10:39 -0200 | [diff] [blame] | 5 | #include "session.h" |
| 6 | #include "sort.h" |
Arnaldo Carvalho de Melo | 9b33827 | 2009-12-16 14:31:49 -0200 | [diff] [blame] | 7 | #include <math.h> |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 8 | |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 9 | static bool hists__filter_entry_by_dso(struct hists *hists, |
| 10 | struct hist_entry *he); |
| 11 | static bool hists__filter_entry_by_thread(struct hists *hists, |
| 12 | struct hist_entry *he); |
Namhyung Kim | e94d53e | 2012-03-16 17:50:51 +0900 | [diff] [blame] | 13 | static bool hists__filter_entry_by_symbol(struct hists *hists, |
| 14 | struct hist_entry *he); |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 15 | |
Arnaldo Carvalho de Melo | 7a007ca | 2010-07-21 09:19:41 -0300 | [diff] [blame] | 16 | enum hist_filter { |
| 17 | HIST_FILTER__DSO, |
| 18 | HIST_FILTER__THREAD, |
| 19 | HIST_FILTER__PARENT, |
Namhyung Kim | e94d53e | 2012-03-16 17:50:51 +0900 | [diff] [blame] | 20 | HIST_FILTER__SYMBOL, |
Arnaldo Carvalho de Melo | 7a007ca | 2010-07-21 09:19:41 -0300 | [diff] [blame] | 21 | }; |
| 22 | |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 23 | struct callchain_param callchain_param = { |
| 24 | .mode = CHAIN_GRAPH_REL, |
Sam Liao | d797fdc | 2011-06-07 23:49:46 +0800 | [diff] [blame] | 25 | .min_percent = 0.5, |
| 26 | .order = ORDER_CALLEE |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 27 | }; |
| 28 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 29 | u16 hists__col_len(struct hists *hists, enum hist_column col) |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 30 | { |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 31 | return hists->col_len[col]; |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 32 | } |
| 33 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 34 | void hists__set_col_len(struct hists *hists, enum hist_column col, u16 len) |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 35 | { |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 36 | hists->col_len[col] = len; |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 37 | } |
| 38 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 39 | bool hists__new_col_len(struct hists *hists, enum hist_column col, u16 len) |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 40 | { |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 41 | if (len > hists__col_len(hists, col)) { |
| 42 | hists__set_col_len(hists, col, len); |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 43 | return true; |
| 44 | } |
| 45 | return false; |
| 46 | } |
| 47 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 48 | static void hists__reset_col_len(struct hists *hists) |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 49 | { |
| 50 | enum hist_column col; |
| 51 | |
| 52 | for (col = 0; col < HISTC_NR_COLS; ++col) |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 53 | hists__set_col_len(hists, col, 0); |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 54 | } |
| 55 | |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 56 | static void hists__set_unres_dso_col_len(struct hists *hists, int dso) |
| 57 | { |
| 58 | const unsigned int unresolved_col_width = BITS_PER_LONG / 4; |
| 59 | |
| 60 | if (hists__col_len(hists, dso) < unresolved_col_width && |
| 61 | !symbol_conf.col_width_list_str && !symbol_conf.field_sep && |
| 62 | !symbol_conf.dso_list) |
| 63 | hists__set_col_len(hists, dso, unresolved_col_width); |
| 64 | } |
| 65 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 66 | static void hists__calc_col_len(struct hists *hists, struct hist_entry *h) |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 67 | { |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 68 | const unsigned int unresolved_col_width = BITS_PER_LONG / 4; |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 69 | u16 len; |
| 70 | |
| 71 | if (h->ms.sym) |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 72 | hists__new_col_len(hists, HISTC_SYMBOL, h->ms.sym->namelen + 4); |
| 73 | else |
| 74 | hists__set_unres_dso_col_len(hists, HISTC_DSO); |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 75 | |
| 76 | len = thread__comm_len(h->thread); |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 77 | if (hists__new_col_len(hists, HISTC_COMM, len)) |
| 78 | hists__set_col_len(hists, HISTC_THREAD, len + 6); |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 79 | |
| 80 | if (h->ms.map) { |
| 81 | len = dso__name_len(h->ms.map->dso); |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 82 | hists__new_col_len(hists, HISTC_DSO, len); |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 83 | } |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 84 | |
| 85 | if (h->branch_info) { |
| 86 | int symlen; |
| 87 | /* |
| 88 | * +4 accounts for '[x] ' priv level info |
| 89 | * +2 account of 0x prefix on raw addresses |
| 90 | */ |
| 91 | if (h->branch_info->from.sym) { |
| 92 | symlen = (int)h->branch_info->from.sym->namelen + 4; |
| 93 | hists__new_col_len(hists, HISTC_SYMBOL_FROM, symlen); |
| 94 | |
| 95 | symlen = dso__name_len(h->branch_info->from.map->dso); |
| 96 | hists__new_col_len(hists, HISTC_DSO_FROM, symlen); |
| 97 | } else { |
| 98 | symlen = unresolved_col_width + 4 + 2; |
| 99 | hists__new_col_len(hists, HISTC_SYMBOL_FROM, symlen); |
| 100 | hists__set_unres_dso_col_len(hists, HISTC_DSO_FROM); |
| 101 | } |
| 102 | |
| 103 | if (h->branch_info->to.sym) { |
| 104 | symlen = (int)h->branch_info->to.sym->namelen + 4; |
| 105 | hists__new_col_len(hists, HISTC_SYMBOL_TO, symlen); |
| 106 | |
| 107 | symlen = dso__name_len(h->branch_info->to.map->dso); |
| 108 | hists__new_col_len(hists, HISTC_DSO_TO, symlen); |
| 109 | } else { |
| 110 | symlen = unresolved_col_width + 4 + 2; |
| 111 | hists__new_col_len(hists, HISTC_SYMBOL_TO, symlen); |
| 112 | hists__set_unres_dso_col_len(hists, HISTC_DSO_TO); |
| 113 | } |
| 114 | } |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 115 | } |
| 116 | |
Arnaldo Carvalho de Melo | 12c1427 | 2012-01-04 12:27:03 -0200 | [diff] [blame] | 117 | static void hist_entry__add_cpumode_period(struct hist_entry *he, |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 118 | unsigned int cpumode, u64 period) |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 119 | { |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 120 | switch (cpumode) { |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 121 | case PERF_RECORD_MISC_KERNEL: |
Arnaldo Carvalho de Melo | 12c1427 | 2012-01-04 12:27:03 -0200 | [diff] [blame] | 122 | he->period_sys += period; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 123 | break; |
| 124 | case PERF_RECORD_MISC_USER: |
Arnaldo Carvalho de Melo | 12c1427 | 2012-01-04 12:27:03 -0200 | [diff] [blame] | 125 | he->period_us += period; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 126 | break; |
| 127 | case PERF_RECORD_MISC_GUEST_KERNEL: |
Arnaldo Carvalho de Melo | 12c1427 | 2012-01-04 12:27:03 -0200 | [diff] [blame] | 128 | he->period_guest_sys += period; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 129 | break; |
| 130 | case PERF_RECORD_MISC_GUEST_USER: |
Arnaldo Carvalho de Melo | 12c1427 | 2012-01-04 12:27:03 -0200 | [diff] [blame] | 131 | he->period_guest_us += period; |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 132 | break; |
| 133 | default: |
| 134 | break; |
| 135 | } |
| 136 | } |
| 137 | |
Arnaldo Carvalho de Melo | ab81f3f | 2011-10-05 19:16:15 -0300 | [diff] [blame] | 138 | static void hist_entry__decay(struct hist_entry *he) |
| 139 | { |
| 140 | he->period = (he->period * 7) / 8; |
| 141 | he->nr_events = (he->nr_events * 7) / 8; |
| 142 | } |
| 143 | |
| 144 | static bool hists__decay_entry(struct hists *hists, struct hist_entry *he) |
| 145 | { |
Arnaldo Carvalho de Melo | c64550c | 2011-10-20 06:45:44 -0200 | [diff] [blame] | 146 | u64 prev_period = he->period; |
| 147 | |
| 148 | if (prev_period == 0) |
Arnaldo Carvalho de Melo | df71d95 | 2011-10-13 08:01:33 -0300 | [diff] [blame] | 149 | return true; |
Arnaldo Carvalho de Melo | c64550c | 2011-10-20 06:45:44 -0200 | [diff] [blame] | 150 | |
Arnaldo Carvalho de Melo | ab81f3f | 2011-10-05 19:16:15 -0300 | [diff] [blame] | 151 | hist_entry__decay(he); |
Arnaldo Carvalho de Melo | c64550c | 2011-10-20 06:45:44 -0200 | [diff] [blame] | 152 | |
| 153 | if (!he->filtered) |
| 154 | hists->stats.total_period -= prev_period - he->period; |
| 155 | |
Arnaldo Carvalho de Melo | ab81f3f | 2011-10-05 19:16:15 -0300 | [diff] [blame] | 156 | return he->period == 0; |
| 157 | } |
| 158 | |
Arnaldo Carvalho de Melo | b079d4e | 2011-10-17 09:05:04 -0200 | [diff] [blame] | 159 | static void __hists__decay_entries(struct hists *hists, bool zap_user, |
| 160 | bool zap_kernel, bool threaded) |
Arnaldo Carvalho de Melo | ab81f3f | 2011-10-05 19:16:15 -0300 | [diff] [blame] | 161 | { |
| 162 | struct rb_node *next = rb_first(&hists->entries); |
| 163 | struct hist_entry *n; |
| 164 | |
| 165 | while (next) { |
| 166 | n = rb_entry(next, struct hist_entry, rb_node); |
| 167 | next = rb_next(&n->rb_node); |
Arnaldo Carvalho de Melo | df71d95 | 2011-10-13 08:01:33 -0300 | [diff] [blame] | 168 | /* |
| 169 | * We may be annotating this, for instance, so keep it here in |
| 170 | * case some it gets new samples, we'll eventually free it when |
| 171 | * the user stops browsing and it agains gets fully decayed. |
| 172 | */ |
Arnaldo Carvalho de Melo | b079d4e | 2011-10-17 09:05:04 -0200 | [diff] [blame] | 173 | if (((zap_user && n->level == '.') || |
| 174 | (zap_kernel && n->level != '.') || |
| 175 | hists__decay_entry(hists, n)) && |
| 176 | !n->used) { |
Arnaldo Carvalho de Melo | ab81f3f | 2011-10-05 19:16:15 -0300 | [diff] [blame] | 177 | rb_erase(&n->rb_node, &hists->entries); |
| 178 | |
Arnaldo Carvalho de Melo | e345fa1 | 2011-10-13 09:06:54 -0300 | [diff] [blame] | 179 | if (sort__need_collapse || threaded) |
Arnaldo Carvalho de Melo | ab81f3f | 2011-10-05 19:16:15 -0300 | [diff] [blame] | 180 | rb_erase(&n->rb_node_in, &hists->entries_collapsed); |
| 181 | |
| 182 | hist_entry__free(n); |
| 183 | --hists->nr_entries; |
| 184 | } |
| 185 | } |
| 186 | } |
| 187 | |
Arnaldo Carvalho de Melo | b079d4e | 2011-10-17 09:05:04 -0200 | [diff] [blame] | 188 | void hists__decay_entries(struct hists *hists, bool zap_user, bool zap_kernel) |
Arnaldo Carvalho de Melo | e345fa1 | 2011-10-13 09:06:54 -0300 | [diff] [blame] | 189 | { |
Arnaldo Carvalho de Melo | b079d4e | 2011-10-17 09:05:04 -0200 | [diff] [blame] | 190 | return __hists__decay_entries(hists, zap_user, zap_kernel, false); |
Arnaldo Carvalho de Melo | e345fa1 | 2011-10-13 09:06:54 -0300 | [diff] [blame] | 191 | } |
| 192 | |
Arnaldo Carvalho de Melo | b079d4e | 2011-10-17 09:05:04 -0200 | [diff] [blame] | 193 | void hists__decay_entries_threaded(struct hists *hists, |
| 194 | bool zap_user, bool zap_kernel) |
Arnaldo Carvalho de Melo | e345fa1 | 2011-10-13 09:06:54 -0300 | [diff] [blame] | 195 | { |
Arnaldo Carvalho de Melo | b079d4e | 2011-10-17 09:05:04 -0200 | [diff] [blame] | 196 | return __hists__decay_entries(hists, zap_user, zap_kernel, true); |
Arnaldo Carvalho de Melo | e345fa1 | 2011-10-13 09:06:54 -0300 | [diff] [blame] | 197 | } |
| 198 | |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 199 | /* |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 200 | * histogram, sorted on item, collects periods |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 201 | */ |
| 202 | |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 203 | static struct hist_entry *hist_entry__new(struct hist_entry *template) |
| 204 | { |
Frederic Weisbecker | d2009c5 | 2010-08-22 20:05:22 +0200 | [diff] [blame] | 205 | size_t callchain_size = symbol_conf.use_callchain ? sizeof(struct callchain_root) : 0; |
Arnaldo Carvalho de Melo | 12c1427 | 2012-01-04 12:27:03 -0200 | [diff] [blame] | 206 | struct hist_entry *he = malloc(sizeof(*he) + callchain_size); |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 207 | |
Arnaldo Carvalho de Melo | 12c1427 | 2012-01-04 12:27:03 -0200 | [diff] [blame] | 208 | if (he != NULL) { |
| 209 | *he = *template; |
| 210 | he->nr_events = 1; |
| 211 | if (he->ms.map) |
| 212 | he->ms.map->referenced = true; |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 213 | if (symbol_conf.use_callchain) |
Arnaldo Carvalho de Melo | 12c1427 | 2012-01-04 12:27:03 -0200 | [diff] [blame] | 214 | callchain_init(he->callchain); |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 215 | } |
| 216 | |
Arnaldo Carvalho de Melo | 12c1427 | 2012-01-04 12:27:03 -0200 | [diff] [blame] | 217 | return he; |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 218 | } |
| 219 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 220 | static void hists__inc_nr_entries(struct hists *hists, struct hist_entry *h) |
Arnaldo Carvalho de Melo | fefb0b9 | 2010-05-10 13:57:51 -0300 | [diff] [blame] | 221 | { |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 222 | if (!h->filtered) { |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 223 | hists__calc_col_len(hists, h); |
| 224 | ++hists->nr_entries; |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 225 | hists->stats.total_period += h->period; |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 226 | } |
Arnaldo Carvalho de Melo | fefb0b9 | 2010-05-10 13:57:51 -0300 | [diff] [blame] | 227 | } |
| 228 | |
Arnaldo Carvalho de Melo | 7a007ca | 2010-07-21 09:19:41 -0300 | [diff] [blame] | 229 | static u8 symbol__parent_filter(const struct symbol *parent) |
| 230 | { |
| 231 | if (symbol_conf.exclude_other && parent == NULL) |
| 232 | return 1 << HIST_FILTER__PARENT; |
| 233 | return 0; |
| 234 | } |
| 235 | |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 236 | static struct hist_entry *add_hist_entry(struct hists *hists, |
| 237 | struct hist_entry *entry, |
Arnaldo Carvalho de Melo | 1c02c4d | 2010-05-10 13:04:11 -0300 | [diff] [blame] | 238 | struct addr_location *al, |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 239 | u64 period) |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 240 | { |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 241 | struct rb_node **p; |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 242 | struct rb_node *parent = NULL; |
| 243 | struct hist_entry *he; |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 244 | int cmp; |
| 245 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 246 | pthread_mutex_lock(&hists->lock); |
| 247 | |
| 248 | p = &hists->entries_in->rb_node; |
| 249 | |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 250 | while (*p != NULL) { |
| 251 | parent = *p; |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 252 | he = rb_entry(parent, struct hist_entry, rb_node_in); |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 253 | |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 254 | cmp = hist_entry__cmp(entry, he); |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 255 | |
| 256 | if (!cmp) { |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 257 | he->period += period; |
| 258 | ++he->nr_events; |
David Miller | 63fa471 | 2012-03-27 03:14:18 -0400 | [diff] [blame] | 259 | |
| 260 | /* If the map of an existing hist_entry has |
| 261 | * become out-of-date due to an exec() or |
| 262 | * similar, update it. Otherwise we will |
| 263 | * mis-adjust symbol addresses when computing |
| 264 | * the history counter to increment. |
| 265 | */ |
| 266 | if (he->ms.map != entry->ms.map) { |
| 267 | he->ms.map = entry->ms.map; |
| 268 | if (he->ms.map) |
| 269 | he->ms.map->referenced = true; |
| 270 | } |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 271 | goto out; |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | if (cmp < 0) |
| 275 | p = &(*p)->rb_left; |
| 276 | else |
| 277 | p = &(*p)->rb_right; |
| 278 | } |
| 279 | |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 280 | he = hist_entry__new(entry); |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 281 | if (!he) |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 282 | goto out_unlock; |
| 283 | |
| 284 | rb_link_node(&he->rb_node_in, parent, p); |
| 285 | rb_insert_color(&he->rb_node_in, hists->entries_in); |
Arnaldo Carvalho de Melo | 28e2a10 | 2010-05-09 13:02:23 -0300 | [diff] [blame] | 286 | out: |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 287 | hist_entry__add_cpumode_period(he, al->cpumode, period); |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 288 | out_unlock: |
| 289 | pthread_mutex_unlock(&hists->lock); |
Arnaldo Carvalho de Melo | 9735abf | 2009-10-03 10:42:45 -0300 | [diff] [blame] | 290 | return he; |
| 291 | } |
| 292 | |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 293 | struct hist_entry *__hists__add_branch_entry(struct hists *self, |
| 294 | struct addr_location *al, |
| 295 | struct symbol *sym_parent, |
| 296 | struct branch_info *bi, |
| 297 | u64 period) |
| 298 | { |
| 299 | struct hist_entry entry = { |
| 300 | .thread = al->thread, |
| 301 | .ms = { |
| 302 | .map = bi->to.map, |
| 303 | .sym = bi->to.sym, |
| 304 | }, |
| 305 | .cpu = al->cpu, |
| 306 | .ip = bi->to.addr, |
| 307 | .level = al->level, |
| 308 | .period = period, |
| 309 | .parent = sym_parent, |
| 310 | .filtered = symbol__parent_filter(sym_parent), |
| 311 | .branch_info = bi, |
| 312 | }; |
| 313 | |
| 314 | return add_hist_entry(self, &entry, al, period); |
| 315 | } |
| 316 | |
| 317 | struct hist_entry *__hists__add_entry(struct hists *self, |
| 318 | struct addr_location *al, |
| 319 | struct symbol *sym_parent, u64 period) |
| 320 | { |
| 321 | struct hist_entry entry = { |
| 322 | .thread = al->thread, |
| 323 | .ms = { |
| 324 | .map = al->map, |
| 325 | .sym = al->sym, |
| 326 | }, |
| 327 | .cpu = al->cpu, |
| 328 | .ip = al->addr, |
| 329 | .level = al->level, |
| 330 | .period = period, |
| 331 | .parent = sym_parent, |
| 332 | .filtered = symbol__parent_filter(sym_parent), |
| 333 | }; |
| 334 | |
| 335 | return add_hist_entry(self, &entry, al, period); |
| 336 | } |
| 337 | |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 338 | int64_t |
| 339 | hist_entry__cmp(struct hist_entry *left, struct hist_entry *right) |
| 340 | { |
| 341 | struct sort_entry *se; |
| 342 | int64_t cmp = 0; |
| 343 | |
| 344 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
Frederic Weisbecker | fcd1498 | 2010-04-14 19:11:29 +0200 | [diff] [blame] | 345 | cmp = se->se_cmp(left, right); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 346 | if (cmp) |
| 347 | break; |
| 348 | } |
| 349 | |
| 350 | return cmp; |
| 351 | } |
| 352 | |
| 353 | int64_t |
| 354 | hist_entry__collapse(struct hist_entry *left, struct hist_entry *right) |
| 355 | { |
| 356 | struct sort_entry *se; |
| 357 | int64_t cmp = 0; |
| 358 | |
| 359 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
| 360 | int64_t (*f)(struct hist_entry *, struct hist_entry *); |
| 361 | |
Frederic Weisbecker | fcd1498 | 2010-04-14 19:11:29 +0200 | [diff] [blame] | 362 | f = se->se_collapse ?: se->se_cmp; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 363 | |
| 364 | cmp = f(left, right); |
| 365 | if (cmp) |
| 366 | break; |
| 367 | } |
| 368 | |
| 369 | return cmp; |
| 370 | } |
| 371 | |
| 372 | void hist_entry__free(struct hist_entry *he) |
| 373 | { |
| 374 | free(he); |
| 375 | } |
| 376 | |
| 377 | /* |
| 378 | * collapse the histogram |
| 379 | */ |
| 380 | |
Namhyung Kim | 4726064 | 2012-05-31 14:43:26 +0900 | [diff] [blame] | 381 | static bool hists__collapse_insert_entry(struct hists *hists __used, |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 382 | struct rb_root *root, |
| 383 | struct hist_entry *he) |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 384 | { |
Arnaldo Carvalho de Melo | b9bf089 | 2009-12-14 11:37:11 -0200 | [diff] [blame] | 385 | struct rb_node **p = &root->rb_node; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 386 | struct rb_node *parent = NULL; |
| 387 | struct hist_entry *iter; |
| 388 | int64_t cmp; |
| 389 | |
| 390 | while (*p != NULL) { |
| 391 | parent = *p; |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 392 | iter = rb_entry(parent, struct hist_entry, rb_node_in); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 393 | |
| 394 | cmp = hist_entry__collapse(iter, he); |
| 395 | |
| 396 | if (!cmp) { |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 397 | iter->period += he->period; |
Stephane Eranian | e39622c | 2011-10-03 11:38:15 +0200 | [diff] [blame] | 398 | iter->nr_events += he->nr_events; |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 399 | if (symbol_conf.use_callchain) { |
Namhyung Kim | 4726064 | 2012-05-31 14:43:26 +0900 | [diff] [blame] | 400 | callchain_cursor_reset(&callchain_cursor); |
| 401 | callchain_merge(&callchain_cursor, |
| 402 | iter->callchain, |
Frederic Weisbecker | 1b3a0e9 | 2011-01-14 04:51:58 +0100 | [diff] [blame] | 403 | he->callchain); |
| 404 | } |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 405 | hist_entry__free(he); |
Arnaldo Carvalho de Melo | fefb0b9 | 2010-05-10 13:57:51 -0300 | [diff] [blame] | 406 | return false; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | if (cmp < 0) |
| 410 | p = &(*p)->rb_left; |
| 411 | else |
| 412 | p = &(*p)->rb_right; |
| 413 | } |
| 414 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 415 | rb_link_node(&he->rb_node_in, parent, p); |
| 416 | rb_insert_color(&he->rb_node_in, root); |
Arnaldo Carvalho de Melo | fefb0b9 | 2010-05-10 13:57:51 -0300 | [diff] [blame] | 417 | return true; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 418 | } |
| 419 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 420 | static struct rb_root *hists__get_rotate_entries_in(struct hists *hists) |
| 421 | { |
| 422 | struct rb_root *root; |
| 423 | |
| 424 | pthread_mutex_lock(&hists->lock); |
| 425 | |
| 426 | root = hists->entries_in; |
| 427 | if (++hists->entries_in > &hists->entries_in_array[1]) |
| 428 | hists->entries_in = &hists->entries_in_array[0]; |
| 429 | |
| 430 | pthread_mutex_unlock(&hists->lock); |
| 431 | |
| 432 | return root; |
| 433 | } |
| 434 | |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 435 | static void hists__apply_filters(struct hists *hists, struct hist_entry *he) |
| 436 | { |
| 437 | hists__filter_entry_by_dso(hists, he); |
| 438 | hists__filter_entry_by_thread(hists, he); |
Namhyung Kim | e94d53e | 2012-03-16 17:50:51 +0900 | [diff] [blame] | 439 | hists__filter_entry_by_symbol(hists, he); |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 440 | } |
| 441 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 442 | static void __hists__collapse_resort(struct hists *hists, bool threaded) |
| 443 | { |
| 444 | struct rb_root *root; |
| 445 | struct rb_node *next; |
| 446 | struct hist_entry *n; |
| 447 | |
| 448 | if (!sort__need_collapse && !threaded) |
| 449 | return; |
| 450 | |
| 451 | root = hists__get_rotate_entries_in(hists); |
| 452 | next = rb_first(root); |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 453 | |
| 454 | while (next) { |
| 455 | n = rb_entry(next, struct hist_entry, rb_node_in); |
| 456 | next = rb_next(&n->rb_node_in); |
| 457 | |
| 458 | rb_erase(&n->rb_node_in, root); |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 459 | if (hists__collapse_insert_entry(hists, &hists->entries_collapsed, n)) { |
| 460 | /* |
| 461 | * If it wasn't combined with one of the entries already |
| 462 | * collapsed, we need to apply the filters that may have |
| 463 | * been set by, say, the hist_browser. |
| 464 | */ |
| 465 | hists__apply_filters(hists, n); |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 466 | } |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 467 | } |
| 468 | } |
| 469 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 470 | void hists__collapse_resort(struct hists *hists) |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 471 | { |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 472 | return __hists__collapse_resort(hists, false); |
| 473 | } |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 474 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 475 | void hists__collapse_resort_threaded(struct hists *hists) |
| 476 | { |
| 477 | return __hists__collapse_resort(hists, true); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | /* |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 481 | * reverse the map, sort on period. |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 482 | */ |
| 483 | |
Arnaldo Carvalho de Melo | 1c02c4d | 2010-05-10 13:04:11 -0300 | [diff] [blame] | 484 | static void __hists__insert_output_entry(struct rb_root *entries, |
| 485 | struct hist_entry *he, |
| 486 | u64 min_callchain_hits) |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 487 | { |
Arnaldo Carvalho de Melo | 1c02c4d | 2010-05-10 13:04:11 -0300 | [diff] [blame] | 488 | struct rb_node **p = &entries->rb_node; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 489 | struct rb_node *parent = NULL; |
| 490 | struct hist_entry *iter; |
| 491 | |
Arnaldo Carvalho de Melo | d599db3 | 2009-12-15 20:04:42 -0200 | [diff] [blame] | 492 | if (symbol_conf.use_callchain) |
Arnaldo Carvalho de Melo | b9fb930 | 2010-04-02 09:50:42 -0300 | [diff] [blame] | 493 | callchain_param.sort(&he->sorted_chain, he->callchain, |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 494 | min_callchain_hits, &callchain_param); |
| 495 | |
| 496 | while (*p != NULL) { |
| 497 | parent = *p; |
| 498 | iter = rb_entry(parent, struct hist_entry, rb_node); |
| 499 | |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 500 | if (he->period > iter->period) |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 501 | p = &(*p)->rb_left; |
| 502 | else |
| 503 | p = &(*p)->rb_right; |
| 504 | } |
| 505 | |
| 506 | rb_link_node(&he->rb_node, parent, p); |
Arnaldo Carvalho de Melo | 1c02c4d | 2010-05-10 13:04:11 -0300 | [diff] [blame] | 507 | rb_insert_color(&he->rb_node, entries); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 508 | } |
| 509 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 510 | static void __hists__output_resort(struct hists *hists, bool threaded) |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 511 | { |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 512 | struct rb_root *root; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 513 | struct rb_node *next; |
| 514 | struct hist_entry *n; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 515 | u64 min_callchain_hits; |
| 516 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 517 | min_callchain_hits = hists->stats.total_period * (callchain_param.min_percent / 100); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 518 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 519 | if (sort__need_collapse || threaded) |
| 520 | root = &hists->entries_collapsed; |
| 521 | else |
| 522 | root = hists->entries_in; |
| 523 | |
| 524 | next = rb_first(root); |
| 525 | hists->entries = RB_ROOT; |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 526 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 527 | hists->nr_entries = 0; |
Arnaldo Carvalho de Melo | 7928631 | 2011-10-27 09:19:48 -0200 | [diff] [blame] | 528 | hists->stats.total_period = 0; |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 529 | hists__reset_col_len(hists); |
Arnaldo Carvalho de Melo | fefb0b9 | 2010-05-10 13:57:51 -0300 | [diff] [blame] | 530 | |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 531 | while (next) { |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 532 | n = rb_entry(next, struct hist_entry, rb_node_in); |
| 533 | next = rb_next(&n->rb_node_in); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 534 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 535 | __hists__insert_output_entry(&hists->entries, n, min_callchain_hits); |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 536 | hists__inc_nr_entries(hists, n); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 537 | } |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 538 | } |
Arnaldo Carvalho de Melo | b9bf089 | 2009-12-14 11:37:11 -0200 | [diff] [blame] | 539 | |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 540 | void hists__output_resort(struct hists *hists) |
| 541 | { |
| 542 | return __hists__output_resort(hists, false); |
| 543 | } |
| 544 | |
| 545 | void hists__output_resort_threaded(struct hists *hists) |
| 546 | { |
| 547 | return __hists__output_resort(hists, true); |
John Kacur | 3d1d07e | 2009-09-28 15:32:55 +0200 | [diff] [blame] | 548 | } |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 549 | |
| 550 | static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin) |
| 551 | { |
| 552 | int i; |
| 553 | int ret = fprintf(fp, " "); |
| 554 | |
| 555 | for (i = 0; i < left_margin; i++) |
| 556 | ret += fprintf(fp, " "); |
| 557 | |
| 558 | return ret; |
| 559 | } |
| 560 | |
| 561 | static size_t ipchain__fprintf_graph_line(FILE *fp, int depth, int depth_mask, |
| 562 | int left_margin) |
| 563 | { |
| 564 | int i; |
| 565 | size_t ret = callchain__fprintf_left_margin(fp, left_margin); |
| 566 | |
| 567 | for (i = 0; i < depth; i++) |
| 568 | if (depth_mask & (1 << i)) |
| 569 | ret += fprintf(fp, "| "); |
| 570 | else |
| 571 | ret += fprintf(fp, " "); |
| 572 | |
| 573 | ret += fprintf(fp, "\n"); |
| 574 | |
| 575 | return ret; |
| 576 | } |
| 577 | |
| 578 | static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain, |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 579 | int depth, int depth_mask, int period, |
Frederic Weisbecker | d425de5 | 2011-01-03 16:13:11 +0100 | [diff] [blame] | 580 | u64 total_samples, u64 hits, |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 581 | int left_margin) |
| 582 | { |
| 583 | int i; |
| 584 | size_t ret = 0; |
| 585 | |
| 586 | ret += callchain__fprintf_left_margin(fp, left_margin); |
| 587 | for (i = 0; i < depth; i++) { |
| 588 | if (depth_mask & (1 << i)) |
| 589 | ret += fprintf(fp, "|"); |
| 590 | else |
| 591 | ret += fprintf(fp, " "); |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 592 | if (!period && i == depth - 1) { |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 593 | double percent; |
| 594 | |
| 595 | percent = hits * 100.0 / total_samples; |
| 596 | ret += percent_color_fprintf(fp, "--%2.2f%%-- ", percent); |
| 597 | } else |
| 598 | ret += fprintf(fp, "%s", " "); |
| 599 | } |
Arnaldo Carvalho de Melo | b3c9ac0 | 2010-03-24 16:40:18 -0300 | [diff] [blame] | 600 | if (chain->ms.sym) |
| 601 | ret += fprintf(fp, "%s\n", chain->ms.sym->name); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 602 | else |
Jiri Olsa | a018706 | 2012-05-16 08:59:08 +0200 | [diff] [blame] | 603 | ret += fprintf(fp, "0x%0" PRIx64 "\n", chain->ip); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 604 | |
| 605 | return ret; |
| 606 | } |
| 607 | |
| 608 | static struct symbol *rem_sq_bracket; |
| 609 | static struct callchain_list rem_hits; |
| 610 | |
| 611 | static void init_rem_hits(void) |
| 612 | { |
| 613 | rem_sq_bracket = malloc(sizeof(*rem_sq_bracket) + 6); |
| 614 | if (!rem_sq_bracket) { |
| 615 | fprintf(stderr, "Not enough memory to display remaining hits\n"); |
| 616 | return; |
| 617 | } |
| 618 | |
| 619 | strcpy(rem_sq_bracket->name, "[...]"); |
Arnaldo Carvalho de Melo | b3c9ac0 | 2010-03-24 16:40:18 -0300 | [diff] [blame] | 620 | rem_hits.ms.sym = rem_sq_bracket; |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 621 | } |
| 622 | |
Frederic Weisbecker | 6d4818c | 2012-03-23 19:06:50 +0100 | [diff] [blame] | 623 | static size_t __callchain__fprintf_graph(FILE *fp, struct rb_root *root, |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 624 | u64 total_samples, int depth, |
| 625 | int depth_mask, int left_margin) |
| 626 | { |
| 627 | struct rb_node *node, *next; |
| 628 | struct callchain_node *child; |
| 629 | struct callchain_list *chain; |
| 630 | int new_depth_mask = depth_mask; |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 631 | u64 remaining; |
| 632 | size_t ret = 0; |
| 633 | int i; |
Arnaldo Carvalho de Melo | 232a5c9 | 2010-05-09 20:28:10 -0300 | [diff] [blame] | 634 | uint entries_printed = 0; |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 635 | |
Frederic Weisbecker | 6d4818c | 2012-03-23 19:06:50 +0100 | [diff] [blame] | 636 | remaining = total_samples; |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 637 | |
Frederic Weisbecker | 6d4818c | 2012-03-23 19:06:50 +0100 | [diff] [blame] | 638 | node = rb_first(root); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 639 | while (node) { |
Frederic Weisbecker | 6d4818c | 2012-03-23 19:06:50 +0100 | [diff] [blame] | 640 | u64 new_total; |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 641 | u64 cumul; |
| 642 | |
| 643 | child = rb_entry(node, struct callchain_node, rb_node); |
Frederic Weisbecker | f08c315 | 2011-01-14 04:51:59 +0100 | [diff] [blame] | 644 | cumul = callchain_cumul_hits(child); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 645 | remaining -= cumul; |
| 646 | |
| 647 | /* |
| 648 | * The depth mask manages the output of pipes that show |
| 649 | * the depth. We don't want to keep the pipes of the current |
| 650 | * level for the last child of this depth. |
| 651 | * Except if we have remaining filtered hits. They will |
| 652 | * supersede the last child |
| 653 | */ |
| 654 | next = rb_next(node); |
| 655 | if (!next && (callchain_param.mode != CHAIN_GRAPH_REL || !remaining)) |
| 656 | new_depth_mask &= ~(1 << (depth - 1)); |
| 657 | |
| 658 | /* |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 659 | * But we keep the older depth mask for the line separator |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 660 | * to keep the level link until we reach the last child |
| 661 | */ |
| 662 | ret += ipchain__fprintf_graph_line(fp, depth, depth_mask, |
| 663 | left_margin); |
| 664 | i = 0; |
| 665 | list_for_each_entry(chain, &child->val, list) { |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 666 | ret += ipchain__fprintf_graph(fp, chain, depth, |
| 667 | new_depth_mask, i++, |
Frederic Weisbecker | 6d4818c | 2012-03-23 19:06:50 +0100 | [diff] [blame] | 668 | total_samples, |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 669 | cumul, |
| 670 | left_margin); |
| 671 | } |
Frederic Weisbecker | 6d4818c | 2012-03-23 19:06:50 +0100 | [diff] [blame] | 672 | |
| 673 | if (callchain_param.mode == CHAIN_GRAPH_REL) |
| 674 | new_total = child->children_hit; |
| 675 | else |
| 676 | new_total = total_samples; |
| 677 | |
| 678 | ret += __callchain__fprintf_graph(fp, &child->rb_root, new_total, |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 679 | depth + 1, |
| 680 | new_depth_mask | (1 << depth), |
| 681 | left_margin); |
| 682 | node = next; |
Arnaldo Carvalho de Melo | 232a5c9 | 2010-05-09 20:28:10 -0300 | [diff] [blame] | 683 | if (++entries_printed == callchain_param.print_limit) |
| 684 | break; |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | if (callchain_param.mode == CHAIN_GRAPH_REL && |
Frederic Weisbecker | 6d4818c | 2012-03-23 19:06:50 +0100 | [diff] [blame] | 688 | remaining && remaining != total_samples) { |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 689 | |
| 690 | if (!rem_sq_bracket) |
| 691 | return ret; |
| 692 | |
| 693 | new_depth_mask &= ~(1 << (depth - 1)); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 694 | ret += ipchain__fprintf_graph(fp, &rem_hits, depth, |
Frederic Weisbecker | 6d4818c | 2012-03-23 19:06:50 +0100 | [diff] [blame] | 695 | new_depth_mask, 0, total_samples, |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 696 | remaining, left_margin); |
| 697 | } |
| 698 | |
| 699 | return ret; |
| 700 | } |
| 701 | |
Frederic Weisbecker | 6d4818c | 2012-03-23 19:06:50 +0100 | [diff] [blame] | 702 | static size_t callchain__fprintf_graph(FILE *fp, struct rb_root *root, |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 703 | u64 total_samples, int left_margin) |
| 704 | { |
Frederic Weisbecker | 6d4818c | 2012-03-23 19:06:50 +0100 | [diff] [blame] | 705 | struct callchain_node *cnode; |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 706 | struct callchain_list *chain; |
Arnaldo Carvalho de Melo | 232a5c9 | 2010-05-09 20:28:10 -0300 | [diff] [blame] | 707 | u32 entries_printed = 0; |
Frederic Weisbecker | 6d4818c | 2012-03-23 19:06:50 +0100 | [diff] [blame] | 708 | bool printed = false; |
| 709 | struct rb_node *node; |
| 710 | int i = 0; |
Frederic Weisbecker | 8760db7 | 2012-07-18 19:10:55 +0200 | [diff] [blame] | 711 | int ret = 0; |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 712 | |
Frederic Weisbecker | 6d4818c | 2012-03-23 19:06:50 +0100 | [diff] [blame] | 713 | /* |
| 714 | * If have one single callchain root, don't bother printing |
| 715 | * its percentage (100 % in fractal mode and the same percentage |
| 716 | * than the hist in graph mode). This also avoid one level of column. |
| 717 | */ |
| 718 | node = rb_first(root); |
| 719 | if (node && !rb_next(node)) { |
| 720 | cnode = rb_entry(node, struct callchain_node, rb_node); |
| 721 | list_for_each_entry(chain, &cnode->val, list) { |
| 722 | /* |
| 723 | * If we sort by symbol, the first entry is the same than |
| 724 | * the symbol. No need to print it otherwise it appears as |
| 725 | * displayed twice. |
| 726 | */ |
| 727 | if (!i++ && sort__first_dimension == SORT_SYM) |
| 728 | continue; |
| 729 | if (!printed) { |
| 730 | ret += callchain__fprintf_left_margin(fp, left_margin); |
| 731 | ret += fprintf(fp, "|\n"); |
| 732 | ret += callchain__fprintf_left_margin(fp, left_margin); |
| 733 | ret += fprintf(fp, "---"); |
| 734 | left_margin += 3; |
| 735 | printed = true; |
| 736 | } else |
| 737 | ret += callchain__fprintf_left_margin(fp, left_margin); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 738 | |
Frederic Weisbecker | 6d4818c | 2012-03-23 19:06:50 +0100 | [diff] [blame] | 739 | if (chain->ms.sym) |
| 740 | ret += fprintf(fp, " %s\n", chain->ms.sym->name); |
| 741 | else |
| 742 | ret += fprintf(fp, " %p\n", (void *)(long)chain->ip); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 743 | |
Frederic Weisbecker | 6d4818c | 2012-03-23 19:06:50 +0100 | [diff] [blame] | 744 | if (++entries_printed == callchain_param.print_limit) |
| 745 | break; |
| 746 | } |
| 747 | root = &cnode->rb_root; |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 748 | } |
| 749 | |
Frederic Weisbecker | 8760db7 | 2012-07-18 19:10:55 +0200 | [diff] [blame] | 750 | ret += __callchain__fprintf_graph(fp, root, total_samples, |
Frederic Weisbecker | 6d4818c | 2012-03-23 19:06:50 +0100 | [diff] [blame] | 751 | 1, 1, left_margin); |
Frederic Weisbecker | 6654f5d | 2012-07-18 19:10:56 +0200 | [diff] [blame] | 752 | ret += fprintf(fp, "\n"); |
| 753 | |
Frederic Weisbecker | 8760db7 | 2012-07-18 19:10:55 +0200 | [diff] [blame] | 754 | return ret; |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 755 | } |
| 756 | |
Frederic Weisbecker | 6d4818c | 2012-03-23 19:06:50 +0100 | [diff] [blame] | 757 | static size_t __callchain__fprintf_flat(FILE *fp, |
| 758 | struct callchain_node *self, |
| 759 | u64 total_samples) |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 760 | { |
| 761 | struct callchain_list *chain; |
| 762 | size_t ret = 0; |
| 763 | |
| 764 | if (!self) |
| 765 | return 0; |
| 766 | |
Frederic Weisbecker | 6d4818c | 2012-03-23 19:06:50 +0100 | [diff] [blame] | 767 | ret += __callchain__fprintf_flat(fp, self->parent, total_samples); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 768 | |
| 769 | |
| 770 | list_for_each_entry(chain, &self->val, list) { |
| 771 | if (chain->ip >= PERF_CONTEXT_MAX) |
| 772 | continue; |
Arnaldo Carvalho de Melo | b3c9ac0 | 2010-03-24 16:40:18 -0300 | [diff] [blame] | 773 | if (chain->ms.sym) |
| 774 | ret += fprintf(fp, " %s\n", chain->ms.sym->name); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 775 | else |
| 776 | ret += fprintf(fp, " %p\n", |
| 777 | (void *)(long)chain->ip); |
| 778 | } |
| 779 | |
| 780 | return ret; |
| 781 | } |
| 782 | |
Frederic Weisbecker | 6d4818c | 2012-03-23 19:06:50 +0100 | [diff] [blame] | 783 | static size_t callchain__fprintf_flat(FILE *fp, struct rb_root *self, |
| 784 | u64 total_samples) |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 785 | { |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 786 | size_t ret = 0; |
Arnaldo Carvalho de Melo | 232a5c9 | 2010-05-09 20:28:10 -0300 | [diff] [blame] | 787 | u32 entries_printed = 0; |
Frederic Weisbecker | 6d4818c | 2012-03-23 19:06:50 +0100 | [diff] [blame] | 788 | struct rb_node *rb_node; |
| 789 | struct callchain_node *chain; |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 790 | |
Frederic Weisbecker | 6d4818c | 2012-03-23 19:06:50 +0100 | [diff] [blame] | 791 | rb_node = rb_first(self); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 792 | while (rb_node) { |
| 793 | double percent; |
| 794 | |
| 795 | chain = rb_entry(rb_node, struct callchain_node, rb_node); |
| 796 | percent = chain->hit * 100.0 / total_samples; |
Frederic Weisbecker | 6d4818c | 2012-03-23 19:06:50 +0100 | [diff] [blame] | 797 | |
| 798 | ret = percent_color_fprintf(fp, " %6.2f%%\n", percent); |
| 799 | ret += __callchain__fprintf_flat(fp, chain, total_samples); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 800 | ret += fprintf(fp, "\n"); |
Arnaldo Carvalho de Melo | 232a5c9 | 2010-05-09 20:28:10 -0300 | [diff] [blame] | 801 | if (++entries_printed == callchain_param.print_limit) |
| 802 | break; |
Frederic Weisbecker | 6d4818c | 2012-03-23 19:06:50 +0100 | [diff] [blame] | 803 | |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 804 | rb_node = rb_next(rb_node); |
| 805 | } |
| 806 | |
| 807 | return ret; |
| 808 | } |
| 809 | |
Frederic Weisbecker | 6d4818c | 2012-03-23 19:06:50 +0100 | [diff] [blame] | 810 | static size_t hist_entry_callchain__fprintf(struct hist_entry *he, |
| 811 | u64 total_samples, int left_margin, |
| 812 | FILE *fp) |
| 813 | { |
| 814 | switch (callchain_param.mode) { |
| 815 | case CHAIN_GRAPH_REL: |
| 816 | return callchain__fprintf_graph(fp, &he->sorted_chain, he->period, |
| 817 | left_margin); |
| 818 | break; |
| 819 | case CHAIN_GRAPH_ABS: |
| 820 | return callchain__fprintf_graph(fp, &he->sorted_chain, total_samples, |
| 821 | left_margin); |
| 822 | break; |
| 823 | case CHAIN_FLAT: |
| 824 | return callchain__fprintf_flat(fp, &he->sorted_chain, total_samples); |
| 825 | break; |
| 826 | case CHAIN_NONE: |
| 827 | break; |
| 828 | default: |
| 829 | pr_err("Bad callchain mode\n"); |
| 830 | } |
| 831 | |
| 832 | return 0; |
| 833 | } |
| 834 | |
Arnaldo Carvalho de Melo | ab81f3f | 2011-10-05 19:16:15 -0300 | [diff] [blame] | 835 | void hists__output_recalc_col_len(struct hists *hists, int max_rows) |
| 836 | { |
| 837 | struct rb_node *next = rb_first(&hists->entries); |
| 838 | struct hist_entry *n; |
| 839 | int row = 0; |
| 840 | |
| 841 | hists__reset_col_len(hists); |
| 842 | |
| 843 | while (next && row++ < max_rows) { |
| 844 | n = rb_entry(next, struct hist_entry, rb_node); |
Arnaldo Carvalho de Melo | d197fd5 | 2011-10-20 07:35:45 -0200 | [diff] [blame] | 845 | if (!n->filtered) |
| 846 | hists__calc_col_len(hists, n); |
Arnaldo Carvalho de Melo | ab81f3f | 2011-10-05 19:16:15 -0300 | [diff] [blame] | 847 | next = rb_next(&n->rb_node); |
| 848 | } |
| 849 | } |
| 850 | |
Arnaldo Carvalho de Melo | 12c1427 | 2012-01-04 12:27:03 -0200 | [diff] [blame] | 851 | static int hist_entry__pcnt_snprintf(struct hist_entry *he, char *s, |
Arnaldo Carvalho de Melo | f1cf602 | 2011-10-18 14:37:34 -0200 | [diff] [blame] | 852 | size_t size, struct hists *pair_hists, |
| 853 | bool show_displacement, long displacement, |
Arnaldo Carvalho de Melo | 13d3ee5 | 2012-01-04 11:37:15 -0200 | [diff] [blame] | 854 | bool color, u64 total_period) |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 855 | { |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 856 | u64 period, total, period_sys, period_us, period_guest_sys, period_guest_us; |
Arnaldo Carvalho de Melo | fec9cbd | 2011-02-17 10:37:23 -0200 | [diff] [blame] | 857 | u64 nr_events; |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 858 | const char *sep = symbol_conf.field_sep; |
Arnaldo Carvalho de Melo | a4e3b95 | 2010-03-31 11:33:40 -0300 | [diff] [blame] | 859 | int ret; |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 860 | |
Arnaldo Carvalho de Melo | 12c1427 | 2012-01-04 12:27:03 -0200 | [diff] [blame] | 861 | if (symbol_conf.exclude_other && !he->parent) |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 862 | return 0; |
| 863 | |
Arnaldo Carvalho de Melo | 1c02c4d | 2010-05-10 13:04:11 -0300 | [diff] [blame] | 864 | if (pair_hists) { |
Arnaldo Carvalho de Melo | 12c1427 | 2012-01-04 12:27:03 -0200 | [diff] [blame] | 865 | period = he->pair ? he->pair->period : 0; |
| 866 | nr_events = he->pair ? he->pair->nr_events : 0; |
Arnaldo Carvalho de Melo | cee75ac | 2010-05-14 13:16:55 -0300 | [diff] [blame] | 867 | total = pair_hists->stats.total_period; |
Arnaldo Carvalho de Melo | 12c1427 | 2012-01-04 12:27:03 -0200 | [diff] [blame] | 868 | period_sys = he->pair ? he->pair->period_sys : 0; |
| 869 | period_us = he->pair ? he->pair->period_us : 0; |
| 870 | period_guest_sys = he->pair ? he->pair->period_guest_sys : 0; |
| 871 | period_guest_us = he->pair ? he->pair->period_guest_us : 0; |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 872 | } else { |
Arnaldo Carvalho de Melo | 12c1427 | 2012-01-04 12:27:03 -0200 | [diff] [blame] | 873 | period = he->period; |
| 874 | nr_events = he->nr_events; |
Arnaldo Carvalho de Melo | 13d3ee5 | 2012-01-04 11:37:15 -0200 | [diff] [blame] | 875 | total = total_period; |
Arnaldo Carvalho de Melo | 12c1427 | 2012-01-04 12:27:03 -0200 | [diff] [blame] | 876 | period_sys = he->period_sys; |
| 877 | period_us = he->period_us; |
| 878 | period_guest_sys = he->period_guest_sys; |
| 879 | period_guest_us = he->period_guest_us; |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 880 | } |
| 881 | |
Arnaldo Carvalho de Melo | a4e3b95 | 2010-03-31 11:33:40 -0300 | [diff] [blame] | 882 | if (total) { |
| 883 | if (color) |
| 884 | ret = percent_color_snprintf(s, size, |
| 885 | sep ? "%.2f" : " %6.2f%%", |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 886 | (period * 100.0) / total); |
Arnaldo Carvalho de Melo | a4e3b95 | 2010-03-31 11:33:40 -0300 | [diff] [blame] | 887 | else |
Arnaldo Carvalho de Melo | e7f01d1 | 2012-03-14 12:29:29 -0300 | [diff] [blame] | 888 | ret = scnprintf(s, size, sep ? "%.2f" : " %6.2f%%", |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 889 | (period * 100.0) / total); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 890 | if (symbol_conf.show_cpu_utilization) { |
| 891 | ret += percent_color_snprintf(s + ret, size - ret, |
| 892 | sep ? "%.2f" : " %6.2f%%", |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 893 | (period_sys * 100.0) / total); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 894 | ret += percent_color_snprintf(s + ret, size - ret, |
| 895 | sep ? "%.2f" : " %6.2f%%", |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 896 | (period_us * 100.0) / total); |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 897 | if (perf_guest) { |
| 898 | ret += percent_color_snprintf(s + ret, |
| 899 | size - ret, |
| 900 | sep ? "%.2f" : " %6.2f%%", |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 901 | (period_guest_sys * 100.0) / |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 902 | total); |
| 903 | ret += percent_color_snprintf(s + ret, |
| 904 | size - ret, |
| 905 | sep ? "%.2f" : " %6.2f%%", |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 906 | (period_guest_us * 100.0) / |
Zhang, Yanmin | a1645ce | 2010-04-19 13:32:50 +0800 | [diff] [blame] | 907 | total); |
| 908 | } |
| 909 | } |
Arnaldo Carvalho de Melo | a4e3b95 | 2010-03-31 11:33:40 -0300 | [diff] [blame] | 910 | } else |
Arnaldo Carvalho de Melo | e7f01d1 | 2012-03-14 12:29:29 -0300 | [diff] [blame] | 911 | ret = scnprintf(s, size, sep ? "%" PRIu64 : "%12" PRIu64 " ", period); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 912 | |
| 913 | if (symbol_conf.show_nr_samples) { |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 914 | if (sep) |
Arnaldo Carvalho de Melo | e7f01d1 | 2012-03-14 12:29:29 -0300 | [diff] [blame] | 915 | ret += scnprintf(s + ret, size - ret, "%c%" PRIu64, *sep, nr_events); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 916 | else |
Arnaldo Carvalho de Melo | e7f01d1 | 2012-03-14 12:29:29 -0300 | [diff] [blame] | 917 | ret += scnprintf(s + ret, size - ret, "%11" PRIu64, nr_events); |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 918 | } |
| 919 | |
Arnaldo Carvalho de Melo | 3f2728b | 2011-10-05 16:10:06 -0300 | [diff] [blame] | 920 | if (symbol_conf.show_total_period) { |
| 921 | if (sep) |
Arnaldo Carvalho de Melo | e7f01d1 | 2012-03-14 12:29:29 -0300 | [diff] [blame] | 922 | ret += scnprintf(s + ret, size - ret, "%c%" PRIu64, *sep, period); |
Arnaldo Carvalho de Melo | 3f2728b | 2011-10-05 16:10:06 -0300 | [diff] [blame] | 923 | else |
Arnaldo Carvalho de Melo | e7f01d1 | 2012-03-14 12:29:29 -0300 | [diff] [blame] | 924 | ret += scnprintf(s + ret, size - ret, " %12" PRIu64, period); |
Arnaldo Carvalho de Melo | 3f2728b | 2011-10-05 16:10:06 -0300 | [diff] [blame] | 925 | } |
| 926 | |
Arnaldo Carvalho de Melo | 1c02c4d | 2010-05-10 13:04:11 -0300 | [diff] [blame] | 927 | if (pair_hists) { |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 928 | char bf[32]; |
| 929 | double old_percent = 0, new_percent = 0, diff; |
| 930 | |
| 931 | if (total > 0) |
Arnaldo Carvalho de Melo | c82ee82 | 2010-05-14 14:19:35 -0300 | [diff] [blame] | 932 | old_percent = (period * 100.0) / total; |
Arnaldo Carvalho de Melo | 13d3ee5 | 2012-01-04 11:37:15 -0200 | [diff] [blame] | 933 | if (total_period > 0) |
Arnaldo Carvalho de Melo | 12c1427 | 2012-01-04 12:27:03 -0200 | [diff] [blame] | 934 | new_percent = (he->period * 100.0) / total_period; |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 935 | |
Arnaldo Carvalho de Melo | 9b33827 | 2009-12-16 14:31:49 -0200 | [diff] [blame] | 936 | diff = new_percent - old_percent; |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 937 | |
Arnaldo Carvalho de Melo | 9b33827 | 2009-12-16 14:31:49 -0200 | [diff] [blame] | 938 | if (fabs(diff) >= 0.01) |
Jiri Olsa | 4bf9ce1 | 2012-03-22 14:37:26 +0100 | [diff] [blame] | 939 | scnprintf(bf, sizeof(bf), "%+4.2F%%", diff); |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 940 | else |
Jiri Olsa | 4bf9ce1 | 2012-03-22 14:37:26 +0100 | [diff] [blame] | 941 | scnprintf(bf, sizeof(bf), " "); |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 942 | |
| 943 | if (sep) |
Arnaldo Carvalho de Melo | e7f01d1 | 2012-03-14 12:29:29 -0300 | [diff] [blame] | 944 | ret += scnprintf(s + ret, size - ret, "%c%s", *sep, bf); |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 945 | else |
Arnaldo Carvalho de Melo | e7f01d1 | 2012-03-14 12:29:29 -0300 | [diff] [blame] | 946 | ret += scnprintf(s + ret, size - ret, "%11.11s", bf); |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 947 | |
| 948 | if (show_displacement) { |
| 949 | if (displacement) |
Jiri Olsa | 4bf9ce1 | 2012-03-22 14:37:26 +0100 | [diff] [blame] | 950 | scnprintf(bf, sizeof(bf), "%+4ld", displacement); |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 951 | else |
Jiri Olsa | 4bf9ce1 | 2012-03-22 14:37:26 +0100 | [diff] [blame] | 952 | scnprintf(bf, sizeof(bf), " "); |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 953 | |
| 954 | if (sep) |
Arnaldo Carvalho de Melo | e7f01d1 | 2012-03-14 12:29:29 -0300 | [diff] [blame] | 955 | ret += scnprintf(s + ret, size - ret, "%c%s", *sep, bf); |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 956 | else |
Arnaldo Carvalho de Melo | e7f01d1 | 2012-03-14 12:29:29 -0300 | [diff] [blame] | 957 | ret += scnprintf(s + ret, size - ret, "%6.6s", bf); |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 958 | } |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 959 | } |
| 960 | |
Arnaldo Carvalho de Melo | f1cf602 | 2011-10-18 14:37:34 -0200 | [diff] [blame] | 961 | return ret; |
| 962 | } |
| 963 | |
| 964 | int hist_entry__snprintf(struct hist_entry *he, char *s, size_t size, |
| 965 | struct hists *hists) |
| 966 | { |
| 967 | const char *sep = symbol_conf.field_sep; |
| 968 | struct sort_entry *se; |
| 969 | int ret = 0; |
| 970 | |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 971 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
| 972 | if (se->elide) |
| 973 | continue; |
| 974 | |
Arnaldo Carvalho de Melo | e7f01d1 | 2012-03-14 12:29:29 -0300 | [diff] [blame] | 975 | ret += scnprintf(s + ret, size - ret, "%s", sep ?: " "); |
Arnaldo Carvalho de Melo | f1cf602 | 2011-10-18 14:37:34 -0200 | [diff] [blame] | 976 | ret += se->se_snprintf(he, s + ret, size - ret, |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 977 | hists__col_len(hists, se->se_width_idx)); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 978 | } |
| 979 | |
Arnaldo Carvalho de Melo | a4e3b95 | 2010-03-31 11:33:40 -0300 | [diff] [blame] | 980 | return ret; |
| 981 | } |
| 982 | |
Arnaldo Carvalho de Melo | 12c1427 | 2012-01-04 12:27:03 -0200 | [diff] [blame] | 983 | static int hist_entry__fprintf(struct hist_entry *he, size_t size, |
| 984 | struct hists *hists, struct hists *pair_hists, |
| 985 | bool show_displacement, long displacement, |
| 986 | u64 total_period, FILE *fp) |
Arnaldo Carvalho de Melo | a4e3b95 | 2010-03-31 11:33:40 -0300 | [diff] [blame] | 987 | { |
| 988 | char bf[512]; |
Arnaldo Carvalho de Melo | f1cf602 | 2011-10-18 14:37:34 -0200 | [diff] [blame] | 989 | int ret; |
Arnaldo Carvalho de Melo | ef9dfe6 | 2011-09-26 12:46:11 -0300 | [diff] [blame] | 990 | |
| 991 | if (size == 0 || size > sizeof(bf)) |
| 992 | size = sizeof(bf); |
| 993 | |
Arnaldo Carvalho de Melo | f1cf602 | 2011-10-18 14:37:34 -0200 | [diff] [blame] | 994 | ret = hist_entry__pcnt_snprintf(he, bf, size, pair_hists, |
| 995 | show_displacement, displacement, |
Arnaldo Carvalho de Melo | 13d3ee5 | 2012-01-04 11:37:15 -0200 | [diff] [blame] | 996 | true, total_period); |
Arnaldo Carvalho de Melo | f1cf602 | 2011-10-18 14:37:34 -0200 | [diff] [blame] | 997 | hist_entry__snprintf(he, bf + ret, size - ret, hists); |
Arnaldo Carvalho de Melo | a4e3b95 | 2010-03-31 11:33:40 -0300 | [diff] [blame] | 998 | return fprintf(fp, "%s\n", bf); |
Arnaldo Carvalho de Melo | 3997d37 | 2010-03-12 12:46:48 -0300 | [diff] [blame] | 999 | } |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 1000 | |
Arnaldo Carvalho de Melo | 12c1427 | 2012-01-04 12:27:03 -0200 | [diff] [blame] | 1001 | static size_t hist_entry__fprintf_callchain(struct hist_entry *he, |
| 1002 | struct hists *hists, |
| 1003 | u64 total_period, FILE *fp) |
Arnaldo Carvalho de Melo | 3997d37 | 2010-03-12 12:46:48 -0300 | [diff] [blame] | 1004 | { |
| 1005 | int left_margin = 0; |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 1006 | |
Arnaldo Carvalho de Melo | 3997d37 | 2010-03-12 12:46:48 -0300 | [diff] [blame] | 1007 | if (sort__first_dimension == SORT_COMM) { |
| 1008 | struct sort_entry *se = list_first_entry(&hist_entry__sort_list, |
| 1009 | typeof(*se), list); |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 1010 | left_margin = hists__col_len(hists, se->se_width_idx); |
Arnaldo Carvalho de Melo | 12c1427 | 2012-01-04 12:27:03 -0200 | [diff] [blame] | 1011 | left_margin -= thread__comm_len(he->thread); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 1012 | } |
| 1013 | |
Arnaldo Carvalho de Melo | 12c1427 | 2012-01-04 12:27:03 -0200 | [diff] [blame] | 1014 | return hist_entry_callchain__fprintf(he, total_period, left_margin, fp); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 1015 | } |
| 1016 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1017 | size_t hists__fprintf(struct hists *hists, struct hists *pair, |
Arnaldo Carvalho de Melo | ef9dfe6 | 2011-09-26 12:46:11 -0300 | [diff] [blame] | 1018 | bool show_displacement, bool show_header, int max_rows, |
| 1019 | int max_cols, FILE *fp) |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 1020 | { |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 1021 | struct sort_entry *se; |
| 1022 | struct rb_node *nd; |
| 1023 | size_t ret = 0; |
Arnaldo Carvalho de Melo | 12c1427 | 2012-01-04 12:27:03 -0200 | [diff] [blame] | 1024 | u64 total_period; |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 1025 | unsigned long position = 1; |
| 1026 | long displacement = 0; |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 1027 | unsigned int width; |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 1028 | const char *sep = symbol_conf.field_sep; |
Arnaldo Carvalho de Melo | edb7c60 | 2010-05-17 16:22:41 -0300 | [diff] [blame] | 1029 | const char *col_width = symbol_conf.col_width_list_str; |
Arnaldo Carvalho de Melo | ef9dfe6 | 2011-09-26 12:46:11 -0300 | [diff] [blame] | 1030 | int nr_rows = 0; |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 1031 | |
| 1032 | init_rem_hits(); |
| 1033 | |
Arnaldo Carvalho de Melo | ef9dfe6 | 2011-09-26 12:46:11 -0300 | [diff] [blame] | 1034 | if (!show_header) |
| 1035 | goto print_entries; |
| 1036 | |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 1037 | fprintf(fp, "# %s", pair ? "Baseline" : "Overhead"); |
| 1038 | |
Namhyung Kim | 0ed35abc | 2012-01-08 02:25:32 +0900 | [diff] [blame] | 1039 | if (symbol_conf.show_cpu_utilization) { |
| 1040 | if (sep) { |
| 1041 | ret += fprintf(fp, "%csys", *sep); |
| 1042 | ret += fprintf(fp, "%cus", *sep); |
| 1043 | if (perf_guest) { |
| 1044 | ret += fprintf(fp, "%cguest sys", *sep); |
| 1045 | ret += fprintf(fp, "%cguest us", *sep); |
| 1046 | } |
| 1047 | } else { |
| 1048 | ret += fprintf(fp, " sys "); |
| 1049 | ret += fprintf(fp, " us "); |
| 1050 | if (perf_guest) { |
| 1051 | ret += fprintf(fp, " guest sys "); |
| 1052 | ret += fprintf(fp, " guest us "); |
| 1053 | } |
| 1054 | } |
| 1055 | } |
| 1056 | |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 1057 | if (symbol_conf.show_nr_samples) { |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 1058 | if (sep) |
| 1059 | fprintf(fp, "%cSamples", *sep); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 1060 | else |
| 1061 | fputs(" Samples ", fp); |
| 1062 | } |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 1063 | |
Arnaldo Carvalho de Melo | 3f2728b | 2011-10-05 16:10:06 -0300 | [diff] [blame] | 1064 | if (symbol_conf.show_total_period) { |
| 1065 | if (sep) |
| 1066 | ret += fprintf(fp, "%cPeriod", *sep); |
| 1067 | else |
| 1068 | ret += fprintf(fp, " Period "); |
| 1069 | } |
| 1070 | |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 1071 | if (pair) { |
| 1072 | if (sep) |
| 1073 | ret += fprintf(fp, "%cDelta", *sep); |
| 1074 | else |
| 1075 | ret += fprintf(fp, " Delta "); |
| 1076 | |
| 1077 | if (show_displacement) { |
| 1078 | if (sep) |
| 1079 | ret += fprintf(fp, "%cDisplacement", *sep); |
| 1080 | else |
| 1081 | ret += fprintf(fp, " Displ"); |
| 1082 | } |
| 1083 | } |
| 1084 | |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 1085 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
| 1086 | if (se->elide) |
| 1087 | continue; |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 1088 | if (sep) { |
Frederic Weisbecker | fcd1498 | 2010-04-14 19:11:29 +0200 | [diff] [blame] | 1089 | fprintf(fp, "%c%s", *sep, se->se_header); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 1090 | continue; |
| 1091 | } |
Frederic Weisbecker | fcd1498 | 2010-04-14 19:11:29 +0200 | [diff] [blame] | 1092 | width = strlen(se->se_header); |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 1093 | if (symbol_conf.col_width_list_str) { |
| 1094 | if (col_width) { |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1095 | hists__set_col_len(hists, se->se_width_idx, |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 1096 | atoi(col_width)); |
| 1097 | col_width = strchr(col_width, ','); |
| 1098 | if (col_width) |
| 1099 | ++col_width; |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 1100 | } |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 1101 | } |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1102 | if (!hists__new_col_len(hists, se->se_width_idx, width)) |
| 1103 | width = hists__col_len(hists, se->se_width_idx); |
Frederic Weisbecker | fcd1498 | 2010-04-14 19:11:29 +0200 | [diff] [blame] | 1104 | fprintf(fp, " %*s", width, se->se_header); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 1105 | } |
Arnaldo Carvalho de Melo | ef9dfe6 | 2011-09-26 12:46:11 -0300 | [diff] [blame] | 1106 | |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 1107 | fprintf(fp, "\n"); |
Arnaldo Carvalho de Melo | ef9dfe6 | 2011-09-26 12:46:11 -0300 | [diff] [blame] | 1108 | if (max_rows && ++nr_rows >= max_rows) |
| 1109 | goto out; |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 1110 | |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 1111 | if (sep) |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 1112 | goto print_entries; |
| 1113 | |
| 1114 | fprintf(fp, "# ........"); |
Namhyung Kim | 0ed35abc | 2012-01-08 02:25:32 +0900 | [diff] [blame] | 1115 | if (symbol_conf.show_cpu_utilization) |
| 1116 | fprintf(fp, " ....... ......."); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 1117 | if (symbol_conf.show_nr_samples) |
| 1118 | fprintf(fp, " .........."); |
Arnaldo Carvalho de Melo | 3f2728b | 2011-10-05 16:10:06 -0300 | [diff] [blame] | 1119 | if (symbol_conf.show_total_period) |
| 1120 | fprintf(fp, " ............"); |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 1121 | if (pair) { |
| 1122 | fprintf(fp, " .........."); |
| 1123 | if (show_displacement) |
| 1124 | fprintf(fp, " ....."); |
| 1125 | } |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 1126 | list_for_each_entry(se, &hist_entry__sort_list, list) { |
| 1127 | unsigned int i; |
| 1128 | |
| 1129 | if (se->elide) |
| 1130 | continue; |
| 1131 | |
| 1132 | fprintf(fp, " "); |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1133 | width = hists__col_len(hists, se->se_width_idx); |
Arnaldo Carvalho de Melo | 8a6c5b2 | 2010-07-20 14:42:52 -0300 | [diff] [blame] | 1134 | if (width == 0) |
Frederic Weisbecker | fcd1498 | 2010-04-14 19:11:29 +0200 | [diff] [blame] | 1135 | width = strlen(se->se_header); |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 1136 | for (i = 0; i < width; i++) |
| 1137 | fprintf(fp, "."); |
| 1138 | } |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 1139 | |
Arnaldo Carvalho de Melo | ef9dfe6 | 2011-09-26 12:46:11 -0300 | [diff] [blame] | 1140 | fprintf(fp, "\n"); |
| 1141 | if (max_rows && ++nr_rows >= max_rows) |
| 1142 | goto out; |
| 1143 | |
| 1144 | fprintf(fp, "#\n"); |
| 1145 | if (max_rows && ++nr_rows >= max_rows) |
| 1146 | goto out; |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 1147 | |
| 1148 | print_entries: |
Arnaldo Carvalho de Melo | 12c1427 | 2012-01-04 12:27:03 -0200 | [diff] [blame] | 1149 | total_period = hists->stats.total_period; |
| 1150 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1151 | for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) { |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 1152 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
| 1153 | |
Frederic Weisbecker | e84d212 | 2011-06-29 22:23:03 +0200 | [diff] [blame] | 1154 | if (h->filtered) |
| 1155 | continue; |
| 1156 | |
Arnaldo Carvalho de Melo | c351c28 | 2009-12-16 13:49:27 -0200 | [diff] [blame] | 1157 | if (show_displacement) { |
| 1158 | if (h->pair != NULL) |
| 1159 | displacement = ((long)h->pair->position - |
| 1160 | (long)position); |
| 1161 | else |
| 1162 | displacement = 0; |
| 1163 | ++position; |
| 1164 | } |
Arnaldo Carvalho de Melo | ef9dfe6 | 2011-09-26 12:46:11 -0300 | [diff] [blame] | 1165 | ret += hist_entry__fprintf(h, max_cols, hists, pair, show_displacement, |
Arnaldo Carvalho de Melo | 12c1427 | 2012-01-04 12:27:03 -0200 | [diff] [blame] | 1166 | displacement, total_period, fp); |
Arnaldo Carvalho de Melo | 3997d37 | 2010-03-12 12:46:48 -0300 | [diff] [blame] | 1167 | |
| 1168 | if (symbol_conf.use_callchain) |
Arnaldo Carvalho de Melo | 12c1427 | 2012-01-04 12:27:03 -0200 | [diff] [blame] | 1169 | ret += hist_entry__fprintf_callchain(h, hists, total_period, fp); |
Arnaldo Carvalho de Melo | ef9dfe6 | 2011-09-26 12:46:11 -0300 | [diff] [blame] | 1170 | if (max_rows && ++nr_rows >= max_rows) |
| 1171 | goto out; |
| 1172 | |
Arnaldo Carvalho de Melo | 59fd530 | 2010-03-24 16:40:17 -0300 | [diff] [blame] | 1173 | if (h->ms.map == NULL && verbose > 1) { |
Arnaldo Carvalho de Melo | 65f2ed2 | 2010-03-09 15:58:17 -0300 | [diff] [blame] | 1174 | __map_groups__fprintf_maps(&h->thread->mg, |
Arnaldo Carvalho de Melo | c6e718f | 2010-03-26 12:11:06 -0300 | [diff] [blame] | 1175 | MAP__FUNCTION, verbose, fp); |
Arnaldo Carvalho de Melo | 65f2ed2 | 2010-03-09 15:58:17 -0300 | [diff] [blame] | 1176 | fprintf(fp, "%.10s end\n", graph_dotted_line); |
| 1177 | } |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 1178 | } |
Arnaldo Carvalho de Melo | ef9dfe6 | 2011-09-26 12:46:11 -0300 | [diff] [blame] | 1179 | out: |
Arnaldo Carvalho de Melo | 4ecf84d0 | 2009-12-16 12:27:09 -0200 | [diff] [blame] | 1180 | free(rem_sq_bracket); |
| 1181 | |
| 1182 | return ret; |
| 1183 | } |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 1184 | |
Arnaldo Carvalho de Melo | 06daaab | 2010-07-21 17:58:25 -0300 | [diff] [blame] | 1185 | /* |
| 1186 | * See hists__fprintf to match the column widths |
| 1187 | */ |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1188 | unsigned int hists__sort_list_width(struct hists *hists) |
Arnaldo Carvalho de Melo | 06daaab | 2010-07-21 17:58:25 -0300 | [diff] [blame] | 1189 | { |
| 1190 | struct sort_entry *se; |
| 1191 | int ret = 9; /* total % */ |
| 1192 | |
| 1193 | if (symbol_conf.show_cpu_utilization) { |
| 1194 | ret += 7; /* count_sys % */ |
| 1195 | ret += 6; /* count_us % */ |
| 1196 | if (perf_guest) { |
| 1197 | ret += 13; /* count_guest_sys % */ |
| 1198 | ret += 12; /* count_guest_us % */ |
| 1199 | } |
| 1200 | } |
| 1201 | |
| 1202 | if (symbol_conf.show_nr_samples) |
| 1203 | ret += 11; |
| 1204 | |
Arnaldo Carvalho de Melo | 3f2728b | 2011-10-05 16:10:06 -0300 | [diff] [blame] | 1205 | if (symbol_conf.show_total_period) |
| 1206 | ret += 13; |
| 1207 | |
Arnaldo Carvalho de Melo | 06daaab | 2010-07-21 17:58:25 -0300 | [diff] [blame] | 1208 | list_for_each_entry(se, &hist_entry__sort_list, list) |
| 1209 | if (!se->elide) |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1210 | ret += 2 + hists__col_len(hists, se->se_width_idx); |
Arnaldo Carvalho de Melo | 06daaab | 2010-07-21 17:58:25 -0300 | [diff] [blame] | 1211 | |
Arnaldo Carvalho de Melo | 903cce6 | 2010-08-05 19:15:48 -0300 | [diff] [blame] | 1212 | if (verbose) /* Addr + origin */ |
| 1213 | ret += 3 + BITS_PER_LONG / 4; |
| 1214 | |
Arnaldo Carvalho de Melo | 06daaab | 2010-07-21 17:58:25 -0300 | [diff] [blame] | 1215 | return ret; |
| 1216 | } |
| 1217 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1218 | 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] | 1219 | enum hist_filter filter) |
| 1220 | { |
| 1221 | h->filtered &= ~(1 << filter); |
| 1222 | if (h->filtered) |
| 1223 | return; |
| 1224 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1225 | ++hists->nr_entries; |
Arnaldo Carvalho de Melo | 0f0cbf7 | 2010-07-26 17:13:40 -0300 | [diff] [blame] | 1226 | if (h->ms.unfolded) |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1227 | hists->nr_entries += h->nr_rows; |
Arnaldo Carvalho de Melo | 0f0cbf7 | 2010-07-26 17:13:40 -0300 | [diff] [blame] | 1228 | h->row_offset = 0; |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1229 | hists->stats.total_period += h->period; |
| 1230 | hists->stats.nr_events[PERF_RECORD_SAMPLE] += h->nr_events; |
Arnaldo Carvalho de Melo | cc5edb0 | 2010-07-16 12:35:07 -0300 | [diff] [blame] | 1231 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1232 | hists__calc_col_len(hists, h); |
Arnaldo Carvalho de Melo | cc5edb0 | 2010-07-16 12:35:07 -0300 | [diff] [blame] | 1233 | } |
| 1234 | |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 1235 | |
| 1236 | static bool hists__filter_entry_by_dso(struct hists *hists, |
| 1237 | struct hist_entry *he) |
| 1238 | { |
| 1239 | if (hists->dso_filter != NULL && |
| 1240 | (he->ms.map == NULL || he->ms.map->dso != hists->dso_filter)) { |
| 1241 | he->filtered |= (1 << HIST_FILTER__DSO); |
| 1242 | return true; |
| 1243 | } |
| 1244 | |
| 1245 | return false; |
| 1246 | } |
| 1247 | |
Arnaldo Carvalho de Melo | d7b76f0 | 2011-10-18 19:07:34 -0200 | [diff] [blame] | 1248 | void hists__filter_by_dso(struct hists *hists) |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 1249 | { |
| 1250 | struct rb_node *nd; |
| 1251 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1252 | hists->nr_entries = hists->stats.total_period = 0; |
| 1253 | hists->stats.nr_events[PERF_RECORD_SAMPLE] = 0; |
| 1254 | hists__reset_col_len(hists); |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 1255 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1256 | for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) { |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 1257 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
| 1258 | |
| 1259 | if (symbol_conf.exclude_other && !h->parent) |
| 1260 | continue; |
| 1261 | |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 1262 | if (hists__filter_entry_by_dso(hists, h)) |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 1263 | continue; |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 1264 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1265 | hists__remove_entry_filter(hists, h, HIST_FILTER__DSO); |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 1266 | } |
| 1267 | } |
| 1268 | |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 1269 | static bool hists__filter_entry_by_thread(struct hists *hists, |
| 1270 | struct hist_entry *he) |
| 1271 | { |
| 1272 | if (hists->thread_filter != NULL && |
| 1273 | he->thread != hists->thread_filter) { |
| 1274 | he->filtered |= (1 << HIST_FILTER__THREAD); |
| 1275 | return true; |
| 1276 | } |
| 1277 | |
| 1278 | return false; |
| 1279 | } |
| 1280 | |
Arnaldo Carvalho de Melo | d7b76f0 | 2011-10-18 19:07:34 -0200 | [diff] [blame] | 1281 | void hists__filter_by_thread(struct hists *hists) |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 1282 | { |
| 1283 | struct rb_node *nd; |
| 1284 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1285 | hists->nr_entries = hists->stats.total_period = 0; |
| 1286 | hists->stats.nr_events[PERF_RECORD_SAMPLE] = 0; |
| 1287 | hists__reset_col_len(hists); |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 1288 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1289 | for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) { |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 1290 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
| 1291 | |
Arnaldo Carvalho de Melo | 90cf1fb | 2011-10-19 13:09:10 -0200 | [diff] [blame] | 1292 | if (hists__filter_entry_by_thread(hists, h)) |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 1293 | continue; |
Arnaldo Carvalho de Melo | cc5edb0 | 2010-07-16 12:35:07 -0300 | [diff] [blame] | 1294 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1295 | hists__remove_entry_filter(hists, h, HIST_FILTER__THREAD); |
Arnaldo Carvalho de Melo | b09e019 | 2010-05-11 11:10:15 -0300 | [diff] [blame] | 1296 | } |
| 1297 | } |
Arnaldo Carvalho de Melo | ef7b93a | 2010-05-11 23:18:06 -0300 | [diff] [blame] | 1298 | |
Namhyung Kim | e94d53e | 2012-03-16 17:50:51 +0900 | [diff] [blame] | 1299 | static bool hists__filter_entry_by_symbol(struct hists *hists, |
| 1300 | struct hist_entry *he) |
| 1301 | { |
| 1302 | if (hists->symbol_filter_str != NULL && |
| 1303 | (!he->ms.sym || strstr(he->ms.sym->name, |
| 1304 | hists->symbol_filter_str) == NULL)) { |
| 1305 | he->filtered |= (1 << HIST_FILTER__SYMBOL); |
| 1306 | return true; |
| 1307 | } |
| 1308 | |
| 1309 | return false; |
| 1310 | } |
| 1311 | |
| 1312 | void hists__filter_by_symbol(struct hists *hists) |
| 1313 | { |
| 1314 | struct rb_node *nd; |
| 1315 | |
| 1316 | hists->nr_entries = hists->stats.total_period = 0; |
| 1317 | hists->stats.nr_events[PERF_RECORD_SAMPLE] = 0; |
| 1318 | hists__reset_col_len(hists); |
| 1319 | |
| 1320 | for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) { |
| 1321 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); |
| 1322 | |
| 1323 | if (hists__filter_entry_by_symbol(hists, h)) |
| 1324 | continue; |
| 1325 | |
| 1326 | hists__remove_entry_filter(hists, h, HIST_FILTER__SYMBOL); |
| 1327 | } |
| 1328 | } |
| 1329 | |
Arnaldo Carvalho de Melo | 2f525d0 | 2011-02-04 13:43:24 -0200 | [diff] [blame] | 1330 | int hist_entry__inc_addr_samples(struct hist_entry *he, int evidx, u64 ip) |
Arnaldo Carvalho de Melo | ef7b93a | 2010-05-11 23:18:06 -0300 | [diff] [blame] | 1331 | { |
Arnaldo Carvalho de Melo | 2f525d0 | 2011-02-04 13:43:24 -0200 | [diff] [blame] | 1332 | return symbol__inc_addr_samples(he->ms.sym, he->ms.map, evidx, ip); |
Arnaldo Carvalho de Melo | ef7b93a | 2010-05-11 23:18:06 -0300 | [diff] [blame] | 1333 | } |
| 1334 | |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 1335 | int hist_entry__annotate(struct hist_entry *he, size_t privsize) |
Arnaldo Carvalho de Melo | ef7b93a | 2010-05-11 23:18:06 -0300 | [diff] [blame] | 1336 | { |
Arnaldo Carvalho de Melo | ce6f4fa | 2011-02-08 13:27:39 -0200 | [diff] [blame] | 1337 | return symbol__annotate(he->ms.sym, he->ms.map, privsize); |
Arnaldo Carvalho de Melo | ef7b93a | 2010-05-11 23:18:06 -0300 | [diff] [blame] | 1338 | } |
Arnaldo Carvalho de Melo | c8446b9 | 2010-05-14 10:36:42 -0300 | [diff] [blame] | 1339 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1340 | void hists__inc_nr_events(struct hists *hists, u32 type) |
Arnaldo Carvalho de Melo | c8446b9 | 2010-05-14 10:36:42 -0300 | [diff] [blame] | 1341 | { |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1342 | ++hists->stats.nr_events[0]; |
| 1343 | ++hists->stats.nr_events[type]; |
Arnaldo Carvalho de Melo | c8446b9 | 2010-05-14 10:36:42 -0300 | [diff] [blame] | 1344 | } |
| 1345 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1346 | size_t hists__fprintf_nr_events(struct hists *hists, FILE *fp) |
Arnaldo Carvalho de Melo | c8446b9 | 2010-05-14 10:36:42 -0300 | [diff] [blame] | 1347 | { |
| 1348 | int i; |
| 1349 | size_t ret = 0; |
| 1350 | |
| 1351 | for (i = 0; i < PERF_RECORD_HEADER_MAX; ++i) { |
Arnaldo Carvalho de Melo | e248de3 | 2011-03-05 21:40:06 -0300 | [diff] [blame] | 1352 | const char *name; |
Thomas Gleixner | 3835bc0 | 2010-12-07 12:48:42 +0000 | [diff] [blame] | 1353 | |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1354 | if (hists->stats.nr_events[i] == 0) |
Arnaldo Carvalho de Melo | e248de3 | 2011-03-05 21:40:06 -0300 | [diff] [blame] | 1355 | continue; |
| 1356 | |
| 1357 | name = perf_event__name(i); |
Thomas Gleixner | 3835bc0 | 2010-12-07 12:48:42 +0000 | [diff] [blame] | 1358 | if (!strcmp(name, "UNKNOWN")) |
Arnaldo Carvalho de Melo | c8446b9 | 2010-05-14 10:36:42 -0300 | [diff] [blame] | 1359 | continue; |
Thomas Gleixner | 3835bc0 | 2010-12-07 12:48:42 +0000 | [diff] [blame] | 1360 | |
| 1361 | ret += fprintf(fp, "%16s events: %10d\n", name, |
Arnaldo Carvalho de Melo | 42b28ac | 2011-09-26 12:33:28 -0300 | [diff] [blame] | 1362 | hists->stats.nr_events[i]); |
Arnaldo Carvalho de Melo | c8446b9 | 2010-05-14 10:36:42 -0300 | [diff] [blame] | 1363 | } |
| 1364 | |
| 1365 | return ret; |
| 1366 | } |