Blame view
tools/perf/util/evsel_fprintf.c
5.71 KB
fd20e8111
|
1 |
#include <inttypes.h> |
25da4fab5
|
2 3 4 5 6 7 |
#include <stdio.h> #include <stdbool.h> #include <traceevent/event-parse.h> #include "evsel.h" #include "callchain.h" #include "map.h" |
8ec20b176
|
8 |
#include "strlist.h" |
25da4fab5
|
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
#include "symbol.h" static int comma_fprintf(FILE *fp, bool *first, const char *fmt, ...) { va_list args; int ret = 0; if (!*first) { ret += fprintf(fp, ","); } else { ret += fprintf(fp, ":"); *first = false; } va_start(args, fmt); ret += vfprintf(fp, fmt, args); va_end(args); return ret; } static int __print_attr__fprintf(FILE *fp, const char *name, const char *val, void *priv) { return comma_fprintf(fp, (bool *)priv, " %s: %s", name, val); } int perf_evsel__fprintf(struct perf_evsel *evsel, struct perf_attr_details *details, FILE *fp) { bool first = true; int printed = 0; if (details->event_group) { struct perf_evsel *pos; if (!perf_evsel__is_group_leader(evsel)) return 0; if (evsel->nr_members > 1) printed += fprintf(fp, "%s{", evsel->group_name ?: ""); printed += fprintf(fp, "%s", perf_evsel__name(evsel)); for_each_group_member(pos, evsel) printed += fprintf(fp, ",%s", perf_evsel__name(pos)); if (evsel->nr_members > 1) printed += fprintf(fp, "}"); goto out; } printed += fprintf(fp, "%s", perf_evsel__name(evsel)); if (details->verbose) { printed += perf_event_attr__fprintf(fp, &evsel->attr, __print_attr__fprintf, &first); } else if (details->freq) { const char *term = "sample_freq"; if (!evsel->attr.freq) term = "sample_period"; printed += comma_fprintf(fp, &first, " %s=%" PRIu64, term, (u64)evsel->attr.sample_freq); } if (details->trace_fields) { struct format_field *field; if (evsel->attr.type != PERF_TYPE_TRACEPOINT) { printed += comma_fprintf(fp, &first, " (not a tracepoint)"); goto out; } field = evsel->tp_format->format.fields; if (field == NULL) { printed += comma_fprintf(fp, &first, " (no trace field)"); goto out; } printed += comma_fprintf(fp, &first, " trace_fields: %s", field->name); field = field->next; while (field) { printed += comma_fprintf(fp, &first, "%s", field->name); field = field->next; } } out: fputc(' ', fp); return ++printed; } int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment, unsigned int print_opts, struct callchain_cursor *cursor, FILE *fp) { int printed = 0; struct callchain_cursor_node *node; int print_ip = print_opts & EVSEL__PRINT_IP; int print_sym = print_opts & EVSEL__PRINT_SYM; int print_dso = print_opts & EVSEL__PRINT_DSO; int print_symoffset = print_opts & EVSEL__PRINT_SYMOFFSET; int print_oneline = print_opts & EVSEL__PRINT_ONELINE; int print_srcline = print_opts & EVSEL__PRINT_SRCLINE; int print_unknown_as_addr = print_opts & EVSEL__PRINT_UNKNOWN_AS_ADDR; |
69b7e4807
|
114 |
int print_arrow = print_opts & EVSEL__PRINT_CALLCHAIN_ARROW; |
2d9bbf6eb
|
115 |
int print_skip_ignored = print_opts & EVSEL__PRINT_SKIP_IGNORED; |
25da4fab5
|
116 |
char s = print_oneline ? ' ' : '\t'; |
69b7e4807
|
117 |
bool first = true; |
25da4fab5
|
118 119 120 121 122 123 124 125 126 127 128 129 |
if (sample->callchain) { struct addr_location node_al; callchain_cursor_commit(cursor); while (1) { u64 addr = 0; node = callchain_cursor_current(cursor); if (!node) break; |
2d9bbf6eb
|
130 131 |
if (node->sym && node->sym->ignore && print_skip_ignored) goto next; |
25da4fab5
|
132 |
printed += fprintf(fp, "%-*.*s", left_alignment, left_alignment, " "); |
69b7e4807
|
133 134 |
if (print_arrow && !first) printed += fprintf(fp, " <-"); |
25da4fab5
|
135 136 137 138 139 140 141 142 143 144 145 146 147 |
if (print_ip) printed += fprintf(fp, "%c%16" PRIx64, s, node->ip); if (node->map) addr = node->map->map_ip(node->map, node->ip); if (print_sym) { printed += fprintf(fp, " "); node_al.addr = addr; node_al.map = node->map; if (print_symoffset) { printed += __symbol__fprintf_symname_offs(node->sym, &node_al, |
a8763445f
|
148 149 |
print_unknown_as_addr, true, fp); |
25da4fab5
|
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
} else { printed += __symbol__fprintf_symname(node->sym, &node_al, print_unknown_as_addr, fp); } } if (print_dso) { printed += fprintf(fp, " ("); printed += map__fprintf_dsoname(node->map, fp); printed += fprintf(fp, ")"); } if (print_srcline) printed += map__fprintf_srcline(node->map, addr, " ", fp); if (!print_oneline) printed += fprintf(fp, " "); |
e7a06a535
|
169 |
|
64eff7d9c
|
170 171 |
if (symbol_conf.bt_stop_list && node->sym && |
64eff7d9c
|
172 173 174 175 |
strlist__has_entry(symbol_conf.bt_stop_list, node->sym->name)) { break; } |
69b7e4807
|
176 |
first = false; |
2d9bbf6eb
|
177 178 |
next: callchain_cursor_advance(cursor); |
25da4fab5
|
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
} } return printed; } int sample__fprintf_sym(struct perf_sample *sample, struct addr_location *al, int left_alignment, unsigned int print_opts, struct callchain_cursor *cursor, FILE *fp) { int printed = 0; int print_ip = print_opts & EVSEL__PRINT_IP; int print_sym = print_opts & EVSEL__PRINT_SYM; int print_dso = print_opts & EVSEL__PRINT_DSO; int print_symoffset = print_opts & EVSEL__PRINT_SYMOFFSET; int print_srcline = print_opts & EVSEL__PRINT_SRCLINE; int print_unknown_as_addr = print_opts & EVSEL__PRINT_UNKNOWN_AS_ADDR; if (cursor != NULL) { printed += sample__fprintf_callchain(sample, left_alignment, print_opts, cursor, fp); |
e7a06a535
|
200 |
} else { |
25da4fab5
|
201 202 203 204 205 206 207 208 209 |
printed += fprintf(fp, "%-*.*s", left_alignment, left_alignment, " "); if (print_ip) printed += fprintf(fp, "%16" PRIx64, sample->ip); if (print_sym) { printed += fprintf(fp, " "); if (print_symoffset) { printed += __symbol__fprintf_symname_offs(al->sym, al, |
a8763445f
|
210 211 |
print_unknown_as_addr, true, fp); |
25da4fab5
|
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
} else { printed += __symbol__fprintf_symname(al->sym, al, print_unknown_as_addr, fp); } } if (print_dso) { printed += fprintf(fp, " ("); printed += map__fprintf_dsoname(al->map, fp); printed += fprintf(fp, ")"); } if (print_srcline) printed += map__fprintf_srcline(al->map, al->addr, " ", fp); } return printed; } |