1 // SPDX-License-Identifier: GPL-2.0
6 #include "util/evsel_fprintf.h"
7 #include "util/event.h"
15 #ifdef HAVE_LIBTRACEEVENT
16 #include <traceevent/event-parse.h>
19 static int comma_fprintf(FILE *fp, bool *first, const char *fmt, ...)
25 ret += fprintf(fp, ",");
27 ret += fprintf(fp, ":");
32 ret += vfprintf(fp, fmt, args);
37 static int __print_attr__fprintf(FILE *fp, const char *name, const char *val, void *priv)
39 return comma_fprintf(fp, (bool *)priv, " %s: %s", name, val);
42 int evsel__fprintf(struct evsel *evsel, struct perf_attr_details *details, FILE *fp)
47 if (details->event_group) {
50 if (!evsel__is_group_leader(evsel))
53 if (evsel->core.nr_members > 1)
54 printed += fprintf(fp, "%s{", evsel->group_name ?: "");
56 printed += fprintf(fp, "%s", evsel__name(evsel));
57 for_each_group_member(pos, evsel)
58 printed += fprintf(fp, ",%s", evsel__name(pos));
60 if (evsel->core.nr_members > 1)
61 printed += fprintf(fp, "}");
65 printed += fprintf(fp, "%s", evsel__name(evsel));
67 if (details->verbose) {
68 printed += perf_event_attr__fprintf(fp, &evsel->core.attr,
69 __print_attr__fprintf, &first);
70 } else if (details->freq) {
71 const char *term = "sample_freq";
73 if (!evsel->core.attr.freq)
74 term = "sample_period";
76 printed += comma_fprintf(fp, &first, " %s=%" PRIu64,
77 term, (u64)evsel->core.attr.sample_freq);
80 #ifdef HAVE_LIBTRACEEVENT
81 if (details->trace_fields) {
82 struct tep_format_field *field;
84 if (evsel->core.attr.type != PERF_TYPE_TRACEPOINT) {
85 printed += comma_fprintf(fp, &first, " (not a tracepoint)");
89 field = evsel->tp_format->format.fields;
91 printed += comma_fprintf(fp, &first, " (no trace field)");
95 printed += comma_fprintf(fp, &first, " trace_fields: %s", field->name);
99 printed += comma_fprintf(fp, &first, "%s", field->name);
110 int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,
111 unsigned int print_opts, struct callchain_cursor *cursor,
112 struct strlist *bt_stop_list, FILE *fp)
115 struct callchain_cursor_node *node;
116 int print_ip = print_opts & EVSEL__PRINT_IP;
117 int print_sym = print_opts & EVSEL__PRINT_SYM;
118 int print_dso = print_opts & EVSEL__PRINT_DSO;
119 int print_symoffset = print_opts & EVSEL__PRINT_SYMOFFSET;
120 int print_oneline = print_opts & EVSEL__PRINT_ONELINE;
121 int print_srcline = print_opts & EVSEL__PRINT_SRCLINE;
122 int print_unknown_as_addr = print_opts & EVSEL__PRINT_UNKNOWN_AS_ADDR;
123 int print_arrow = print_opts & EVSEL__PRINT_CALLCHAIN_ARROW;
124 int print_skip_ignored = print_opts & EVSEL__PRINT_SKIP_IGNORED;
125 char s = print_oneline ? ' ' : '\t';
128 if (sample->callchain) {
129 struct addr_location node_al;
131 callchain_cursor_commit(cursor);
138 node = callchain_cursor_current(cursor);
145 if (sym && sym->ignore && print_skip_ignored)
148 printed += fprintf(fp, "%-*.*s", left_alignment, left_alignment, " ");
150 if (print_arrow && !first)
151 printed += fprintf(fp, " <-");
154 addr = map__map_ip(map, node->ip);
157 printed += fprintf(fp, "%c%16" PRIx64, s, node->ip);
160 printed += fprintf(fp, " ");
164 if (print_symoffset) {
165 printed += __symbol__fprintf_symname_offs(sym, &node_al,
166 print_unknown_as_addr,
169 printed += __symbol__fprintf_symname(sym, &node_al,
170 print_unknown_as_addr, fp);
174 if (print_dso && (!sym || !sym->inlined)) {
175 printed += fprintf(fp, " (");
176 printed += map__fprintf_dsoname(map, fp);
177 printed += fprintf(fp, ")");
181 printed += map__fprintf_srcline(map, addr, "\n ", fp);
183 if (sym && sym->inlined)
184 printed += fprintf(fp, " (inlined)");
187 printed += fprintf(fp, "\n");
189 /* Add srccode here too? */
190 if (bt_stop_list && sym &&
191 strlist__has_entry(bt_stop_list, sym->name)) {
197 callchain_cursor_advance(cursor);
204 int sample__fprintf_sym(struct perf_sample *sample, struct addr_location *al,
205 int left_alignment, unsigned int print_opts,
206 struct callchain_cursor *cursor, struct strlist *bt_stop_list, FILE *fp)
209 int print_ip = print_opts & EVSEL__PRINT_IP;
210 int print_sym = print_opts & EVSEL__PRINT_SYM;
211 int print_dso = print_opts & EVSEL__PRINT_DSO;
212 int print_symoffset = print_opts & EVSEL__PRINT_SYMOFFSET;
213 int print_srcline = print_opts & EVSEL__PRINT_SRCLINE;
214 int print_unknown_as_addr = print_opts & EVSEL__PRINT_UNKNOWN_AS_ADDR;
216 if (cursor != NULL) {
217 printed += sample__fprintf_callchain(sample, left_alignment, print_opts,
218 cursor, bt_stop_list, fp);
220 printed += fprintf(fp, "%-*.*s", left_alignment, left_alignment, " ");
223 printed += fprintf(fp, "%16" PRIx64, sample->ip);
226 printed += fprintf(fp, " ");
227 if (print_symoffset) {
228 printed += __symbol__fprintf_symname_offs(al->sym, al,
229 print_unknown_as_addr,
232 printed += __symbol__fprintf_symname(al->sym, al,
233 print_unknown_as_addr, fp);
238 printed += fprintf(fp, " (");
239 printed += map__fprintf_dsoname(al->map, fp);
240 printed += fprintf(fp, ")");
244 printed += map__fprintf_srcline(al->map, al->addr, "\n ", fp);
249 #endif /* PYTHON_PERF */