4 #include <traceevent/event-parse.h>
11 static int comma_fprintf(FILE *fp
, bool *first
, const char *fmt
, ...)
17 ret
+= fprintf(fp
, ",");
19 ret
+= fprintf(fp
, ":");
24 ret
+= vfprintf(fp
, fmt
, args
);
29 static int __print_attr__fprintf(FILE *fp
, const char *name
, const char *val
, void *priv
)
31 return comma_fprintf(fp
, (bool *)priv
, " %s: %s", name
, val
);
34 int perf_evsel__fprintf(struct perf_evsel
*evsel
,
35 struct perf_attr_details
*details
, FILE *fp
)
40 if (details
->event_group
) {
41 struct perf_evsel
*pos
;
43 if (!perf_evsel__is_group_leader(evsel
))
46 if (evsel
->nr_members
> 1)
47 printed
+= fprintf(fp
, "%s{", evsel
->group_name
?: "");
49 printed
+= fprintf(fp
, "%s", perf_evsel__name(evsel
));
50 for_each_group_member(pos
, evsel
)
51 printed
+= fprintf(fp
, ",%s", perf_evsel__name(pos
));
53 if (evsel
->nr_members
> 1)
54 printed
+= fprintf(fp
, "}");
58 printed
+= fprintf(fp
, "%s", perf_evsel__name(evsel
));
60 if (details
->verbose
) {
61 printed
+= perf_event_attr__fprintf(fp
, &evsel
->attr
,
62 __print_attr__fprintf
, &first
);
63 } else if (details
->freq
) {
64 const char *term
= "sample_freq";
66 if (!evsel
->attr
.freq
)
67 term
= "sample_period";
69 printed
+= comma_fprintf(fp
, &first
, " %s=%" PRIu64
,
70 term
, (u64
)evsel
->attr
.sample_freq
);
73 if (details
->trace_fields
) {
74 struct format_field
*field
;
76 if (evsel
->attr
.type
!= PERF_TYPE_TRACEPOINT
) {
77 printed
+= comma_fprintf(fp
, &first
, " (not a tracepoint)");
81 field
= evsel
->tp_format
->format
.fields
;
83 printed
+= comma_fprintf(fp
, &first
, " (no trace field)");
87 printed
+= comma_fprintf(fp
, &first
, " trace_fields: %s", field
->name
);
91 printed
+= comma_fprintf(fp
, &first
, "%s", field
->name
);
100 int sample__fprintf_callchain(struct perf_sample
*sample
, int left_alignment
,
101 unsigned int print_opts
, struct callchain_cursor
*cursor
,
105 struct callchain_cursor_node
*node
;
106 int print_ip
= print_opts
& EVSEL__PRINT_IP
;
107 int print_sym
= print_opts
& EVSEL__PRINT_SYM
;
108 int print_dso
= print_opts
& EVSEL__PRINT_DSO
;
109 int print_symoffset
= print_opts
& EVSEL__PRINT_SYMOFFSET
;
110 int print_oneline
= print_opts
& EVSEL__PRINT_ONELINE
;
111 int print_srcline
= print_opts
& EVSEL__PRINT_SRCLINE
;
112 int print_unknown_as_addr
= print_opts
& EVSEL__PRINT_UNKNOWN_AS_ADDR
;
113 int print_arrow
= print_opts
& EVSEL__PRINT_CALLCHAIN_ARROW
;
114 int print_skip_ignored
= print_opts
& EVSEL__PRINT_SKIP_IGNORED
;
115 char s
= print_oneline
? ' ' : '\t';
118 if (sample
->callchain
) {
119 struct addr_location node_al
;
121 callchain_cursor_commit(cursor
);
126 node
= callchain_cursor_current(cursor
);
130 if (node
->sym
&& node
->sym
->ignore
&& print_skip_ignored
)
133 printed
+= fprintf(fp
, "%-*.*s", left_alignment
, left_alignment
, " ");
135 if (print_arrow
&& !first
)
136 printed
+= fprintf(fp
, " <-");
139 printed
+= fprintf(fp
, "%c%16" PRIx64
, s
, node
->ip
);
142 addr
= node
->map
->map_ip(node
->map
, node
->ip
);
145 printed
+= fprintf(fp
, " ");
147 node_al
.map
= node
->map
;
149 if (print_symoffset
) {
150 printed
+= __symbol__fprintf_symname_offs(node
->sym
, &node_al
,
151 print_unknown_as_addr
,
154 printed
+= __symbol__fprintf_symname(node
->sym
, &node_al
,
155 print_unknown_as_addr
, fp
);
160 printed
+= fprintf(fp
, " (");
161 printed
+= map__fprintf_dsoname(node
->map
, fp
);
162 printed
+= fprintf(fp
, ")");
166 printed
+= map__fprintf_srcline(node
->map
, addr
, "\n ", fp
);
169 printed
+= fprintf(fp
, "\n");
171 if (symbol_conf
.bt_stop_list
&&
173 strlist__has_entry(symbol_conf
.bt_stop_list
,
180 callchain_cursor_advance(cursor
);
187 int sample__fprintf_sym(struct perf_sample
*sample
, struct addr_location
*al
,
188 int left_alignment
, unsigned int print_opts
,
189 struct callchain_cursor
*cursor
, FILE *fp
)
192 int print_ip
= print_opts
& EVSEL__PRINT_IP
;
193 int print_sym
= print_opts
& EVSEL__PRINT_SYM
;
194 int print_dso
= print_opts
& EVSEL__PRINT_DSO
;
195 int print_symoffset
= print_opts
& EVSEL__PRINT_SYMOFFSET
;
196 int print_srcline
= print_opts
& EVSEL__PRINT_SRCLINE
;
197 int print_unknown_as_addr
= print_opts
& EVSEL__PRINT_UNKNOWN_AS_ADDR
;
199 if (cursor
!= NULL
) {
200 printed
+= sample__fprintf_callchain(sample
, left_alignment
,
201 print_opts
, cursor
, fp
);
203 printed
+= fprintf(fp
, "%-*.*s", left_alignment
, left_alignment
, " ");
206 printed
+= fprintf(fp
, "%16" PRIx64
, sample
->ip
);
209 printed
+= fprintf(fp
, " ");
210 if (print_symoffset
) {
211 printed
+= __symbol__fprintf_symname_offs(al
->sym
, al
,
212 print_unknown_as_addr
,
215 printed
+= __symbol__fprintf_symname(al
->sym
, al
,
216 print_unknown_as_addr
, fp
);
221 printed
+= fprintf(fp
, " (");
222 printed
+= map__fprintf_dsoname(al
->map
, fp
);
223 printed
+= fprintf(fp
, ")");
227 printed
+= map__fprintf_srcline(al
->map
, al
->addr
, "\n ", fp
);