3 #include <traceevent/event-parse.h>
9 static int comma_fprintf(FILE *fp, bool *first, const char *fmt, ...)
15 ret += fprintf(fp, ",");
17 ret += fprintf(fp, ":");
22 ret += vfprintf(fp, fmt, args);
27 static int __print_attr__fprintf(FILE *fp, const char *name, const char *val, void *priv)
29 return comma_fprintf(fp, (bool *)priv, " %s: %s", name, val);
32 int perf_evsel__fprintf(struct perf_evsel *evsel,
33 struct perf_attr_details *details, FILE *fp)
38 if (details->event_group) {
39 struct perf_evsel *pos;
41 if (!perf_evsel__is_group_leader(evsel))
44 if (evsel->nr_members > 1)
45 printed += fprintf(fp, "%s{", evsel->group_name ?: "");
47 printed += fprintf(fp, "%s", perf_evsel__name(evsel));
48 for_each_group_member(pos, evsel)
49 printed += fprintf(fp, ",%s", perf_evsel__name(pos));
51 if (evsel->nr_members > 1)
52 printed += fprintf(fp, "}");
56 printed += fprintf(fp, "%s", perf_evsel__name(evsel));
58 if (details->verbose) {
59 printed += perf_event_attr__fprintf(fp, &evsel->attr,
60 __print_attr__fprintf, &first);
61 } else if (details->freq) {
62 const char *term = "sample_freq";
64 if (!evsel->attr.freq)
65 term = "sample_period";
67 printed += comma_fprintf(fp, &first, " %s=%" PRIu64,
68 term, (u64)evsel->attr.sample_freq);
71 if (details->trace_fields) {
72 struct format_field *field;
74 if (evsel->attr.type != PERF_TYPE_TRACEPOINT) {
75 printed += comma_fprintf(fp, &first, " (not a tracepoint)");
79 field = evsel->tp_format->format.fields;
81 printed += comma_fprintf(fp, &first, " (no trace field)");
85 printed += comma_fprintf(fp, &first, " trace_fields: %s", field->name);
89 printed += comma_fprintf(fp, &first, "%s", field->name);
98 int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,
99 unsigned int print_opts, struct callchain_cursor *cursor,
103 struct callchain_cursor_node *node;
104 int print_ip = print_opts & EVSEL__PRINT_IP;
105 int print_sym = print_opts & EVSEL__PRINT_SYM;
106 int print_dso = print_opts & EVSEL__PRINT_DSO;
107 int print_symoffset = print_opts & EVSEL__PRINT_SYMOFFSET;
108 int print_oneline = print_opts & EVSEL__PRINT_ONELINE;
109 int print_srcline = print_opts & EVSEL__PRINT_SRCLINE;
110 int print_unknown_as_addr = print_opts & EVSEL__PRINT_UNKNOWN_AS_ADDR;
111 int print_arrow = print_opts & EVSEL__PRINT_CALLCHAIN_ARROW;
112 int print_skip_ignored = print_opts & EVSEL__PRINT_SKIP_IGNORED;
113 char s = print_oneline ? ' ' : '\t';
116 if (sample->callchain) {
117 struct addr_location node_al;
119 callchain_cursor_commit(cursor);
124 node = callchain_cursor_current(cursor);
128 if (node->sym && node->sym->ignore && print_skip_ignored)
131 printed += fprintf(fp, "%-*.*s", left_alignment, left_alignment, " ");
133 if (print_arrow && !first)
134 printed += fprintf(fp, " <-");
137 printed += fprintf(fp, "%c%16" PRIx64, s, node->ip);
140 addr = node->map->map_ip(node->map, node->ip);
143 printed += fprintf(fp, " ");
145 node_al.map = node->map;
147 if (print_symoffset) {
148 printed += __symbol__fprintf_symname_offs(node->sym, &node_al,
149 print_unknown_as_addr,
152 printed += __symbol__fprintf_symname(node->sym, &node_al,
153 print_unknown_as_addr, fp);
158 printed += fprintf(fp, " (");
159 printed += map__fprintf_dsoname(node->map, fp);
160 printed += fprintf(fp, ")");
164 printed += map__fprintf_srcline(node->map, addr, "\n ", fp);
167 printed += fprintf(fp, "\n");
169 if (symbol_conf.bt_stop_list &&
172 strlist__has_entry(symbol_conf.bt_stop_list,
179 callchain_cursor_advance(cursor);
186 int sample__fprintf_sym(struct perf_sample *sample, struct addr_location *al,
187 int left_alignment, unsigned int print_opts,
188 struct callchain_cursor *cursor, FILE *fp)
191 int print_ip = print_opts & EVSEL__PRINT_IP;
192 int print_sym = print_opts & EVSEL__PRINT_SYM;
193 int print_dso = print_opts & EVSEL__PRINT_DSO;
194 int print_symoffset = print_opts & EVSEL__PRINT_SYMOFFSET;
195 int print_srcline = print_opts & EVSEL__PRINT_SRCLINE;
196 int print_unknown_as_addr = print_opts & EVSEL__PRINT_UNKNOWN_AS_ADDR;
198 if (cursor != NULL) {
199 printed += sample__fprintf_callchain(sample, left_alignment,
200 print_opts, cursor, fp);
202 printed += fprintf(fp, "%-*.*s", left_alignment, left_alignment, " ");
205 printed += fprintf(fp, "%16" PRIx64, sample->ip);
208 printed += fprintf(fp, " ");
209 if (print_symoffset) {
210 printed += __symbol__fprintf_symname_offs(al->sym, al,
211 print_unknown_as_addr,
214 printed += __symbol__fprintf_symname(al->sym, al,
215 print_unknown_as_addr, fp);
220 printed += fprintf(fp, " (");
221 printed += map__fprintf_dsoname(al->map, fp);
222 printed += fprintf(fp, ")");
226 printed += map__fprintf_srcline(al->map, al->addr, "\n ", fp);