Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / tools / perf / util / evsel_fprintf.c
blobfb498a723a006ac1bcbbc0e487f674a5aa11094b
1 // SPDX-License-Identifier: GPL-2.0
2 #include <inttypes.h>
3 #include <stdio.h>
4 #include <stdbool.h>
5 #include <traceevent/event-parse.h>
6 #include "evsel.h"
7 #include "util/evsel_fprintf.h"
8 #include "util/event.h"
9 #include "callchain.h"
10 #include "map.h"
11 #include "strlist.h"
12 #include "symbol.h"
13 #include "srcline.h"
15 static int comma_fprintf(FILE *fp, bool *first, const char *fmt, ...)
17 va_list args;
18 int ret = 0;
20 if (!*first) {
21 ret += fprintf(fp, ",");
22 } else {
23 ret += fprintf(fp, ":");
24 *first = false;
27 va_start(args, fmt);
28 ret += vfprintf(fp, fmt, args);
29 va_end(args);
30 return ret;
33 static int __print_attr__fprintf(FILE *fp, const char *name, const char *val, void *priv)
35 return comma_fprintf(fp, (bool *)priv, " %s: %s", name, val);
38 int evsel__fprintf(struct evsel *evsel, struct perf_attr_details *details, FILE *fp)
40 bool first = true;
41 int printed = 0;
43 if (details->event_group) {
44 struct evsel *pos;
46 if (!evsel__is_group_leader(evsel))
47 return 0;
49 if (evsel->core.nr_members > 1)
50 printed += fprintf(fp, "%s{", evsel->group_name ?: "");
52 printed += fprintf(fp, "%s", evsel__name(evsel));
53 for_each_group_member(pos, evsel)
54 printed += fprintf(fp, ",%s", evsel__name(pos));
56 if (evsel->core.nr_members > 1)
57 printed += fprintf(fp, "}");
58 goto out;
61 printed += fprintf(fp, "%s", evsel__name(evsel));
63 if (details->verbose) {
64 printed += perf_event_attr__fprintf(fp, &evsel->core.attr,
65 __print_attr__fprintf, &first);
66 } else if (details->freq) {
67 const char *term = "sample_freq";
69 if (!evsel->core.attr.freq)
70 term = "sample_period";
72 printed += comma_fprintf(fp, &first, " %s=%" PRIu64,
73 term, (u64)evsel->core.attr.sample_freq);
76 if (details->trace_fields) {
77 struct tep_format_field *field;
79 if (evsel->core.attr.type != PERF_TYPE_TRACEPOINT) {
80 printed += comma_fprintf(fp, &first, " (not a tracepoint)");
81 goto out;
84 field = evsel->tp_format->format.fields;
85 if (field == NULL) {
86 printed += comma_fprintf(fp, &first, " (no trace field)");
87 goto out;
90 printed += comma_fprintf(fp, &first, " trace_fields: %s", field->name);
92 field = field->next;
93 while (field) {
94 printed += comma_fprintf(fp, &first, "%s", field->name);
95 field = field->next;
98 out:
99 fputc('\n', fp);
100 return ++printed;
103 int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,
104 unsigned int print_opts, struct callchain_cursor *cursor,
105 struct strlist *bt_stop_list, FILE *fp)
107 int printed = 0;
108 struct callchain_cursor_node *node;
109 int print_ip = print_opts & EVSEL__PRINT_IP;
110 int print_sym = print_opts & EVSEL__PRINT_SYM;
111 int print_dso = print_opts & EVSEL__PRINT_DSO;
112 int print_symoffset = print_opts & EVSEL__PRINT_SYMOFFSET;
113 int print_oneline = print_opts & EVSEL__PRINT_ONELINE;
114 int print_srcline = print_opts & EVSEL__PRINT_SRCLINE;
115 int print_unknown_as_addr = print_opts & EVSEL__PRINT_UNKNOWN_AS_ADDR;
116 int print_arrow = print_opts & EVSEL__PRINT_CALLCHAIN_ARROW;
117 int print_skip_ignored = print_opts & EVSEL__PRINT_SKIP_IGNORED;
118 char s = print_oneline ? ' ' : '\t';
119 bool first = true;
121 if (sample->callchain) {
122 struct addr_location node_al;
124 callchain_cursor_commit(cursor);
126 while (1) {
127 struct symbol *sym;
128 struct map *map;
129 u64 addr = 0;
131 node = callchain_cursor_current(cursor);
132 if (!node)
133 break;
135 sym = node->ms.sym;
136 map = node->ms.map;
138 if (sym && sym->ignore && print_skip_ignored)
139 goto next;
141 printed += fprintf(fp, "%-*.*s", left_alignment, left_alignment, " ");
143 if (print_arrow && !first)
144 printed += fprintf(fp, " <-");
146 if (print_ip)
147 printed += fprintf(fp, "%c%16" PRIx64, s, node->ip);
149 if (map)
150 addr = map->map_ip(map, node->ip);
152 if (print_sym) {
153 printed += fprintf(fp, " ");
154 node_al.addr = addr;
155 node_al.map = map;
157 if (print_symoffset) {
158 printed += __symbol__fprintf_symname_offs(sym, &node_al,
159 print_unknown_as_addr,
160 true, fp);
161 } else {
162 printed += __symbol__fprintf_symname(sym, &node_al,
163 print_unknown_as_addr, fp);
167 if (print_dso && (!sym || !sym->inlined)) {
168 printed += fprintf(fp, " (");
169 printed += map__fprintf_dsoname(map, fp);
170 printed += fprintf(fp, ")");
173 if (print_srcline)
174 printed += map__fprintf_srcline(map, addr, "\n ", fp);
176 if (sym && sym->inlined)
177 printed += fprintf(fp, " (inlined)");
179 if (!print_oneline)
180 printed += fprintf(fp, "\n");
182 /* Add srccode here too? */
183 if (bt_stop_list && sym &&
184 strlist__has_entry(bt_stop_list, sym->name)) {
185 break;
188 first = false;
189 next:
190 callchain_cursor_advance(cursor);
194 return printed;
197 int sample__fprintf_sym(struct perf_sample *sample, struct addr_location *al,
198 int left_alignment, unsigned int print_opts,
199 struct callchain_cursor *cursor, struct strlist *bt_stop_list, FILE *fp)
201 int printed = 0;
202 int print_ip = print_opts & EVSEL__PRINT_IP;
203 int print_sym = print_opts & EVSEL__PRINT_SYM;
204 int print_dso = print_opts & EVSEL__PRINT_DSO;
205 int print_symoffset = print_opts & EVSEL__PRINT_SYMOFFSET;
206 int print_srcline = print_opts & EVSEL__PRINT_SRCLINE;
207 int print_unknown_as_addr = print_opts & EVSEL__PRINT_UNKNOWN_AS_ADDR;
209 if (cursor != NULL) {
210 printed += sample__fprintf_callchain(sample, left_alignment, print_opts,
211 cursor, bt_stop_list, fp);
212 } else {
213 printed += fprintf(fp, "%-*.*s", left_alignment, left_alignment, " ");
215 if (print_ip)
216 printed += fprintf(fp, "%16" PRIx64, sample->ip);
218 if (print_sym) {
219 printed += fprintf(fp, " ");
220 if (print_symoffset) {
221 printed += __symbol__fprintf_symname_offs(al->sym, al,
222 print_unknown_as_addr,
223 true, fp);
224 } else {
225 printed += __symbol__fprintf_symname(al->sym, al,
226 print_unknown_as_addr, fp);
230 if (print_dso) {
231 printed += fprintf(fp, " (");
232 printed += map__fprintf_dsoname(al->map, fp);
233 printed += fprintf(fp, ")");
236 if (print_srcline)
237 printed += map__fprintf_srcline(al->map, al->addr, "\n ", fp);
240 return printed;