4 #include <traceevent/event-parse.h>
12 static int comma_fprintf(FILE *fp
, bool *first
, const char *fmt
, ...)
18 ret
+= fprintf(fp
, ",");
20 ret
+= fprintf(fp
, ":");
25 ret
+= vfprintf(fp
, fmt
, args
);
30 static int __print_attr__fprintf(FILE *fp
, const char *name
, const char *val
, void *priv
)
32 return comma_fprintf(fp
, (bool *)priv
, " %s: %s", name
, val
);
35 int perf_evsel__fprintf(struct perf_evsel
*evsel
,
36 struct perf_attr_details
*details
, FILE *fp
)
41 if (details
->event_group
) {
42 struct perf_evsel
*pos
;
44 if (!perf_evsel__is_group_leader(evsel
))
47 if (evsel
->nr_members
> 1)
48 printed
+= fprintf(fp
, "%s{", evsel
->group_name
?: "");
50 printed
+= fprintf(fp
, "%s", perf_evsel__name(evsel
));
51 for_each_group_member(pos
, evsel
)
52 printed
+= fprintf(fp
, ",%s", perf_evsel__name(pos
));
54 if (evsel
->nr_members
> 1)
55 printed
+= fprintf(fp
, "}");
59 printed
+= fprintf(fp
, "%s", perf_evsel__name(evsel
));
61 if (details
->verbose
) {
62 printed
+= perf_event_attr__fprintf(fp
, &evsel
->attr
,
63 __print_attr__fprintf
, &first
);
64 } else if (details
->freq
) {
65 const char *term
= "sample_freq";
67 if (!evsel
->attr
.freq
)
68 term
= "sample_period";
70 printed
+= comma_fprintf(fp
, &first
, " %s=%" PRIu64
,
71 term
, (u64
)evsel
->attr
.sample_freq
);
74 if (details
->trace_fields
) {
75 struct format_field
*field
;
77 if (evsel
->attr
.type
!= PERF_TYPE_TRACEPOINT
) {
78 printed
+= comma_fprintf(fp
, &first
, " (not a tracepoint)");
82 field
= evsel
->tp_format
->format
.fields
;
84 printed
+= comma_fprintf(fp
, &first
, " (no trace field)");
88 printed
+= comma_fprintf(fp
, &first
, " trace_fields: %s", field
->name
);
92 printed
+= comma_fprintf(fp
, &first
, "%s", field
->name
);
101 int sample__fprintf_callchain(struct perf_sample
*sample
, int left_alignment
,
102 unsigned int print_opts
, struct callchain_cursor
*cursor
,
106 struct callchain_cursor_node
*node
;
107 int print_ip
= print_opts
& EVSEL__PRINT_IP
;
108 int print_sym
= print_opts
& EVSEL__PRINT_SYM
;
109 int print_dso
= print_opts
& EVSEL__PRINT_DSO
;
110 int print_symoffset
= print_opts
& EVSEL__PRINT_SYMOFFSET
;
111 int print_oneline
= print_opts
& EVSEL__PRINT_ONELINE
;
112 int print_srcline
= print_opts
& EVSEL__PRINT_SRCLINE
;
113 int print_unknown_as_addr
= print_opts
& EVSEL__PRINT_UNKNOWN_AS_ADDR
;
114 int print_arrow
= print_opts
& EVSEL__PRINT_CALLCHAIN_ARROW
;
115 int print_skip_ignored
= print_opts
& EVSEL__PRINT_SKIP_IGNORED
;
116 char s
= print_oneline
? ' ' : '\t';
119 if (sample
->callchain
) {
120 struct addr_location node_al
;
122 callchain_cursor_commit(cursor
);
127 node
= callchain_cursor_current(cursor
);
131 if (node
->sym
&& node
->sym
->ignore
&& print_skip_ignored
)
134 printed
+= fprintf(fp
, "%-*.*s", left_alignment
, left_alignment
, " ");
136 if (print_arrow
&& !first
)
137 printed
+= fprintf(fp
, " <-");
140 printed
+= fprintf(fp
, "%c%16" PRIx64
, s
, node
->ip
);
143 addr
= node
->map
->map_ip(node
->map
, node
->ip
);
146 printed
+= fprintf(fp
, " ");
148 node_al
.map
= node
->map
;
150 if (print_symoffset
) {
151 printed
+= __symbol__fprintf_symname_offs(node
->sym
, &node_al
,
152 print_unknown_as_addr
,
155 printed
+= __symbol__fprintf_symname(node
->sym
, &node_al
,
156 print_unknown_as_addr
, fp
);
161 printed
+= fprintf(fp
, " (");
162 printed
+= map__fprintf_dsoname(node
->map
, fp
);
163 printed
+= fprintf(fp
, ")");
167 printed
+= map__fprintf_srcline(node
->map
, addr
, "\n ", fp
);
170 printed
+= fprintf(fp
, "\n");
172 if (symbol_conf
.inline_name
&& node
->map
) {
173 struct inline_node
*inode
;
175 addr
= map__rip_2objdump(node
->map
, node
->ip
),
176 inode
= dso__parse_addr_inlines(node
->map
->dso
, addr
);
179 struct inline_list
*ilist
;
181 list_for_each_entry(ilist
, &inode
->val
, list
) {
183 printed
+= fprintf(fp
, " <-");
185 /* IP is same, just skip it */
187 printed
+= fprintf(fp
, "%c%16s",
190 printed
+= fprintf(fp
, " %s",
193 printed
+= fprintf(fp
, "\n %s:%d",
197 printed
+= fprintf(fp
, "\n");
200 inline_node__delete(inode
);
204 if (symbol_conf
.bt_stop_list
&&
206 strlist__has_entry(symbol_conf
.bt_stop_list
,
213 callchain_cursor_advance(cursor
);
220 int sample__fprintf_sym(struct perf_sample
*sample
, struct addr_location
*al
,
221 int left_alignment
, unsigned int print_opts
,
222 struct callchain_cursor
*cursor
, FILE *fp
)
225 int print_ip
= print_opts
& EVSEL__PRINT_IP
;
226 int print_sym
= print_opts
& EVSEL__PRINT_SYM
;
227 int print_dso
= print_opts
& EVSEL__PRINT_DSO
;
228 int print_symoffset
= print_opts
& EVSEL__PRINT_SYMOFFSET
;
229 int print_srcline
= print_opts
& EVSEL__PRINT_SRCLINE
;
230 int print_unknown_as_addr
= print_opts
& EVSEL__PRINT_UNKNOWN_AS_ADDR
;
232 if (cursor
!= NULL
) {
233 printed
+= sample__fprintf_callchain(sample
, left_alignment
,
234 print_opts
, cursor
, fp
);
236 printed
+= fprintf(fp
, "%-*.*s", left_alignment
, left_alignment
, " ");
239 printed
+= fprintf(fp
, "%16" PRIx64
, sample
->ip
);
242 printed
+= fprintf(fp
, " ");
243 if (print_symoffset
) {
244 printed
+= __symbol__fprintf_symname_offs(al
->sym
, al
,
245 print_unknown_as_addr
,
248 printed
+= __symbol__fprintf_symname(al
->sym
, al
,
249 print_unknown_as_addr
, fp
);
254 printed
+= fprintf(fp
, " (");
255 printed
+= map__fprintf_dsoname(al
->map
, fp
);
256 printed
+= fprintf(fp
, ")");
260 printed
+= map__fprintf_srcline(al
->map
, al
->addr
, "\n ", fp
);