1 // SPDX-License-Identifier: GPL-2.0
5 #include <traceevent/event-parse.h>
7 #include "util/evsel_fprintf.h"
8 #include "util/event.h"
15 static int comma_fprintf(FILE *fp, bool *first, const char *fmt, ...)
21 ret += fprintf(fp, ",");
23 ret += fprintf(fp, ":");
28 ret += vfprintf(fp, fmt, args);
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 perf_evsel__fprintf(struct evsel *evsel,
39 struct perf_attr_details *details, FILE *fp)
44 if (details->event_group) {
47 if (!perf_evsel__is_group_leader(evsel))
50 if (evsel->core.nr_members > 1)
51 printed += fprintf(fp, "%s{", evsel->group_name ?: "");
53 printed += fprintf(fp, "%s", perf_evsel__name(evsel));
54 for_each_group_member(pos, evsel)
55 printed += fprintf(fp, ",%s", perf_evsel__name(pos));
57 if (evsel->core.nr_members > 1)
58 printed += fprintf(fp, "}");
62 printed += fprintf(fp, "%s", perf_evsel__name(evsel));
64 if (details->verbose) {
65 printed += perf_event_attr__fprintf(fp, &evsel->core.attr,
66 __print_attr__fprintf, &first);
67 } else if (details->freq) {
68 const char *term = "sample_freq";
70 if (!evsel->core.attr.freq)
71 term = "sample_period";
73 printed += comma_fprintf(fp, &first, " %s=%" PRIu64,
74 term, (u64)evsel->core.attr.sample_freq);
77 if (details->trace_fields) {
78 struct tep_format_field *field;
80 if (evsel->core.attr.type != PERF_TYPE_TRACEPOINT) {
81 printed += comma_fprintf(fp, &first, " (not a tracepoint)");
85 field = evsel->tp_format->format.fields;
87 printed += comma_fprintf(fp, &first, " (no trace field)");
91 printed += comma_fprintf(fp, &first, " trace_fields: %s", field->name);
95 printed += comma_fprintf(fp, &first, "%s", field->name);
104 int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,
105 unsigned int print_opts, struct callchain_cursor *cursor,
106 struct strlist *bt_stop_list, FILE *fp)
109 struct callchain_cursor_node *node;
110 int print_ip = print_opts & EVSEL__PRINT_IP;
111 int print_sym = print_opts & EVSEL__PRINT_SYM;
112 int print_dso = print_opts & EVSEL__PRINT_DSO;
113 int print_symoffset = print_opts & EVSEL__PRINT_SYMOFFSET;
114 int print_oneline = print_opts & EVSEL__PRINT_ONELINE;
115 int print_srcline = print_opts & EVSEL__PRINT_SRCLINE;
116 int print_unknown_as_addr = print_opts & EVSEL__PRINT_UNKNOWN_AS_ADDR;
117 int print_arrow = print_opts & EVSEL__PRINT_CALLCHAIN_ARROW;
118 int print_skip_ignored = print_opts & EVSEL__PRINT_SKIP_IGNORED;
119 char s = print_oneline ? ' ' : '\t';
122 if (sample->callchain) {
123 struct addr_location node_al;
125 callchain_cursor_commit(cursor);
130 node = callchain_cursor_current(cursor);
134 if (node->sym && node->sym->ignore && print_skip_ignored)
137 printed += fprintf(fp, "%-*.*s", left_alignment, left_alignment, " ");
139 if (print_arrow && !first)
140 printed += fprintf(fp, " <-");
143 printed += fprintf(fp, "%c%16" PRIx64, s, node->ip);
146 addr = node->map->map_ip(node->map, node->ip);
149 printed += fprintf(fp, " ");
151 node_al.map = node->map;
153 if (print_symoffset) {
154 printed += __symbol__fprintf_symname_offs(node->sym, &node_al,
155 print_unknown_as_addr,
158 printed += __symbol__fprintf_symname(node->sym, &node_al,
159 print_unknown_as_addr, fp);
163 if (print_dso && (!node->sym || !node->sym->inlined)) {
164 printed += fprintf(fp, " (");
165 printed += map__fprintf_dsoname(node->map, fp);
166 printed += fprintf(fp, ")");
170 printed += map__fprintf_srcline(node->map, addr, "\n ", fp);
172 if (node->sym && node->sym->inlined)
173 printed += fprintf(fp, " (inlined)");
176 printed += fprintf(fp, "\n");
178 /* Add srccode here too? */
179 if (bt_stop_list && node->sym &&
180 strlist__has_entry(bt_stop_list, node->sym->name)) {
186 callchain_cursor_advance(cursor);
193 int sample__fprintf_sym(struct perf_sample *sample, struct addr_location *al,
194 int left_alignment, unsigned int print_opts,
195 struct callchain_cursor *cursor, struct strlist *bt_stop_list, FILE *fp)
198 int print_ip = print_opts & EVSEL__PRINT_IP;
199 int print_sym = print_opts & EVSEL__PRINT_SYM;
200 int print_dso = print_opts & EVSEL__PRINT_DSO;
201 int print_symoffset = print_opts & EVSEL__PRINT_SYMOFFSET;
202 int print_srcline = print_opts & EVSEL__PRINT_SRCLINE;
203 int print_unknown_as_addr = print_opts & EVSEL__PRINT_UNKNOWN_AS_ADDR;
205 if (cursor != NULL) {
206 printed += sample__fprintf_callchain(sample, left_alignment, print_opts,
207 cursor, bt_stop_list, fp);
209 printed += fprintf(fp, "%-*.*s", left_alignment, left_alignment, " ");
212 printed += fprintf(fp, "%16" PRIx64, sample->ip);
215 printed += fprintf(fp, " ");
216 if (print_symoffset) {
217 printed += __symbol__fprintf_symname_offs(al->sym, al,
218 print_unknown_as_addr,
221 printed += __symbol__fprintf_symname(al->sym, al,
222 print_unknown_as_addr, fp);
227 printed += fprintf(fp, " (");
228 printed += map__fprintf_dsoname(al->map, fp);
229 printed += fprintf(fp, ")");
233 printed += map__fprintf_srcline(al->map, al->addr, "\n ", fp);