1 /* SPDX-License-Identifier: GPL-2.0 */
4 #include "../builtin.h"
9 #include <linux/list.h>
11 #include <linux/rbtree.h>
12 #include "map_symbol.h"
13 #include "symbol_conf.h"
15 #include "callchain.h"
22 #include <subcmd/parse-options.h>
23 #include "parse-events.h"
29 extern regex_t parent_regex
;
30 extern const char *sort_order
;
31 extern const char *field_order
;
32 extern const char default_parent_pattern
[];
33 extern const char *parent_pattern
;
34 extern const char *default_sort_order
;
35 extern regex_t ignore_callees_regex
;
36 extern int have_ignore_callees
;
37 extern enum sort_mode sort__mode
;
38 extern struct sort_entry sort_comm
;
39 extern struct sort_entry sort_dso
;
40 extern struct sort_entry sort_sym
;
41 extern struct sort_entry sort_parent
;
42 extern struct sort_entry sort_dso_from
;
43 extern struct sort_entry sort_dso_to
;
44 extern struct sort_entry sort_sym_from
;
45 extern struct sort_entry sort_sym_to
;
46 extern struct sort_entry sort_srcline
;
47 extern enum sort_type sort__first_dimension
;
48 extern const char default_mem_sort_order
[];
71 struct hist_entry_diff
{
75 double period_ratio_delta
;
80 /* HISTC_WEIGHTED_DIFF */
85 struct hist_entry_ops
{
86 void *(*new)(size_t size
);
87 void (*free
)(void *ptr
);
91 * struct hist_entry - histogram entry
93 * @row_offset - offset from the first callchain expanded to appear on screen
94 * @nr_rows - rows expanded in callchain, recalculated on folding/unfolding
97 struct rb_node rb_node_in
;
98 struct rb_node rb_node
;
100 struct list_head node
;
101 struct list_head head
;
104 struct he_stat
*stat_acc
;
105 struct map_symbol ms
;
106 struct thread
*thread
;
108 struct namespace_id cgroup_id
;
116 /* We are added by hists__add_dummy_entry. */
126 * Since perf diff only supports the stdio output, TUI
127 * fields are only accessed from perf report (or perf
128 * top). So make it a union to reduce memory usage.
130 struct hist_entry_diff diff
;
131 struct /* for TUI */ {
134 bool init_have_children
;
142 struct symbol
*parent
;
143 struct branch_info
*branch_info
;
146 struct mem_info
*mem_info
;
150 struct res_sample
*res_samples
;
152 struct perf_hpp_list
*hpp_list
;
153 struct hist_entry
*parent_he
;
154 struct hist_entry_ops
*ops
;
156 /* this is for hierarchical entry structure */
158 struct rb_root_cached hroot_in
;
159 struct rb_root_cached hroot_out
;
160 }; /* non-leaf entries */
161 struct rb_root sorted_chain
; /* leaf entry has callchains */
163 struct callchain_root callchain
[0]; /* must be last member */
166 static __pure
inline bool hist_entry__has_callchains(struct hist_entry
*he
)
168 return he
->callchain_size
!= 0;
171 static inline bool hist_entry__has_pairs(struct hist_entry
*he
)
173 return !list_empty(&he
->pairs
.node
);
176 static inline struct hist_entry
*hist_entry__next_pair(struct hist_entry
*he
)
178 if (hist_entry__has_pairs(he
))
179 return list_entry(he
->pairs
.node
.next
, struct hist_entry
, pairs
.node
);
183 static inline void hist_entry__add_pair(struct hist_entry
*pair
,
184 struct hist_entry
*he
)
186 list_add_tail(&pair
->pairs
.node
, &he
->pairs
.head
);
189 static inline float hist_entry__get_percent_limit(struct hist_entry
*he
)
191 u64 period
= he
->stat
.period
;
192 u64 total_period
= hists__total_period(he
->hists
);
194 if (unlikely(total_period
== 0))
197 if (symbol_conf
.cumulate_callchain
)
198 period
= he
->stat_acc
->period
;
200 return period
* 100.0 / total_period
;
203 static inline u64
cl_address(u64 address
)
205 /* return the cacheline of the address */
206 return (address
& ~(cacheline_size() - 1));
209 static inline u64
cl_offset(u64 address
)
211 /* return the cacheline of the address */
212 return (address
& (cacheline_size() - 1));
221 SORT_MODE__TRACEPOINT
,
225 /* common sort keys */
245 /* branch stack specific sort keys */
247 SORT_DSO_FROM
= __SORT_BRANCH_STACK
,
259 /* memory mode specific sort keys */
261 SORT_MEM_DADDR_SYMBOL
= __SORT_MEMORY_MODE
,
268 SORT_MEM_IADDR_SYMBOL
,
273 * configurable sorting bits
277 const char *se_header
;
279 int64_t (*se_cmp
)(struct hist_entry
*, struct hist_entry
*);
280 int64_t (*se_collapse
)(struct hist_entry
*, struct hist_entry
*);
281 int64_t (*se_sort
)(struct hist_entry
*, struct hist_entry
*);
282 int (*se_snprintf
)(struct hist_entry
*he
, char *bf
, size_t size
,
284 int (*se_filter
)(struct hist_entry
*he
, int type
, const void *arg
);
288 extern struct sort_entry sort_thread
;
289 extern struct list_head hist_entry__sort_list
;
293 int setup_sorting(struct perf_evlist
*evlist
);
294 int setup_output_field(void);
295 void reset_output_field(void);
296 void sort__setup_elide(FILE *fp
);
297 void perf_hpp__set_elide(int idx
, bool elide
);
299 const char *sort_help(const char *prefix
);
301 int report_parse_ignore_callees_opt(const struct option
*opt
, const char *arg
, int unset
);
303 bool is_strict_order(const char *order
);
305 int hpp_dimension__add_output(unsigned col
);
306 void reset_dimensions(void);
307 int sort_dimension__add(struct perf_hpp_list
*list
, const char *tok
,
308 struct perf_evlist
*evlist
,
310 int output_field_add(struct perf_hpp_list
*list
, char *tok
);
312 sort__iaddr_cmp(struct hist_entry
*left
, struct hist_entry
*right
);
314 sort__daddr_cmp(struct hist_entry
*left
, struct hist_entry
*right
);
316 sort__dcacheline_cmp(struct hist_entry
*left
, struct hist_entry
*right
);
317 char *hist_entry__srcline(struct hist_entry
*he
);
318 #endif /* __PERF_SORT_H */