blob: e97cd476d336f2a9cad2a1eeb9daba34d08ed3a4 [file] [log] [blame]
John Kacurdd68ada2009-09-24 18:02:49 +02001#ifndef __PERF_SORT_H
2#define __PERF_SORT_H
3#include "../builtin.h"
4
5#include "util.h"
6
7#include "color.h"
8#include <linux/list.h>
9#include "cache.h"
10#include <linux/rbtree.h>
11#include "symbol.h"
12#include "string.h"
13#include "callchain.h"
14#include "strlist.h"
15#include "values.h"
16
17#include "../perf.h"
18#include "debug.h"
19#include "header.h"
20
21#include "parse-options.h"
22#include "parse-events.h"
Namhyung Kim14135662013-10-31 10:17:39 +090023#include "hist.h"
John Kacurdd68ada2009-09-24 18:02:49 +020024#include "thread.h"
John Kacurdd68ada2009-09-24 18:02:49 +020025
26extern regex_t parent_regex;
Arnaldo Carvalho de Meloedb7c602010-05-17 16:22:41 -030027extern const char *sort_order;
Namhyung Kima7d945b2014-03-04 10:46:34 +090028extern const char *field_order;
Arnaldo Carvalho de Meloedb7c602010-05-17 16:22:41 -030029extern const char default_parent_pattern[];
30extern const char *parent_pattern;
31extern const char default_sort_order[];
Greg Priceb21484f2012-12-06 21:48:05 -080032extern regex_t ignore_callees_regex;
33extern int have_ignore_callees;
John Kacurdd68ada2009-09-24 18:02:49 +020034extern int sort__need_collapse;
35extern int sort__has_parent;
Namhyung Kim1af556402012-09-14 17:35:27 +090036extern int sort__has_sym;
Namhyung Kim55369fc2013-04-01 20:35:20 +090037extern enum sort_mode sort__mode;
John Kacurdd68ada2009-09-24 18:02:49 +020038extern struct sort_entry sort_comm;
39extern struct sort_entry sort_dso;
40extern struct sort_entry sort_sym;
41extern struct sort_entry sort_parent;
Stephane Eraniana68c2c52012-03-08 23:47:48 +010042extern struct sort_entry sort_dso_from;
43extern struct sort_entry sort_dso_to;
44extern struct sort_entry sort_sym_from;
45extern struct sort_entry sort_sym_to;
Frederic Weisbeckera4fb5812009-10-22 23:23:23 +020046extern enum sort_type sort__first_dimension;
Yunlong Song228f14f2015-03-23 11:50:05 +080047extern const char default_mem_sort_order[];
John Kacurdd68ada2009-09-24 18:02:49 +020048
Namhyung Kimb24c28f2012-10-04 21:49:41 +090049struct he_stat {
50 u64 period;
51 u64 period_sys;
52 u64 period_us;
53 u64 period_guest_sys;
54 u64 period_guest_us;
Andi Kleen05484292013-01-24 16:10:29 +010055 u64 weight;
Namhyung Kimb24c28f2012-10-04 21:49:41 +090056 u32 nr_events;
57};
58
Jiri Olsa96c47f12012-10-05 16:44:42 +020059struct hist_entry_diff {
60 bool computed;
Namhyung Kima0b404f2015-04-19 13:04:10 +090061 union {
62 /* PERF_HPP__DELTA */
63 double period_ratio_delta;
Jiri Olsa96c47f12012-10-05 16:44:42 +020064
Namhyung Kima0b404f2015-04-19 13:04:10 +090065 /* PERF_HPP__RATIO */
66 double period_ratio;
Jiri Olsa96c47f12012-10-05 16:44:42 +020067
Namhyung Kima0b404f2015-04-19 13:04:10 +090068 /* HISTC_WEIGHTED_DIFF */
69 s64 wdiff;
70 };
Jiri Olsa96c47f12012-10-05 16:44:42 +020071};
72
Arnaldo Carvalho de Melo0f0cbf72010-07-26 17:13:40 -030073/**
74 * struct hist_entry - histogram entry
75 *
76 * @row_offset - offset from the first callchain expanded to appear on screen
77 * @nr_rows - rows expanded in callchain, recalculated on folding/unfolding
78 */
John Kacurdd68ada2009-09-24 18:02:49 +020079struct hist_entry {
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -030080 struct rb_node rb_node_in;
John Kacurdd68ada2009-09-24 18:02:49 +020081 struct rb_node rb_node;
Arnaldo Carvalho de Melob821c732012-10-25 14:42:45 -020082 union {
83 struct list_head node;
84 struct list_head head;
85 } pairs;
Namhyung Kimb24c28f2012-10-04 21:49:41 +090086 struct he_stat stat;
Namhyung Kimf8be1c82012-09-11 13:15:07 +090087 struct he_stat *stat_acc;
Arnaldo Carvalho de Melo59fd5302010-03-24 16:40:17 -030088 struct map_symbol ms;
Arnaldo Carvalho de Meloa5e29ac2010-04-03 22:44:37 -030089 struct thread *thread;
Namhyung Kim4dfced32013-09-13 16:28:57 +090090 struct comm *comm;
John Kacurdd68ada2009-09-24 18:02:49 +020091 u64 ip;
Andi Kleen475eeab2013-09-20 07:40:43 -070092 u64 transaction;
Arun Sharmaf60f3592010-06-04 11:27:10 -030093 s32 cpu;
Don Zickus7365be52014-05-27 12:28:05 -040094 u8 cpumode;
Arnaldo Carvalho de Melo0f0cbf72010-07-26 17:13:40 -030095
Jiri Olsae0af43d2012-12-01 21:18:20 +010096 /* We are added by hists__add_dummy_entry. */
97 bool dummy;
98
John Kacurdd68ada2009-09-24 18:02:49 +020099 char level;
Arnaldo Carvalho de Meloa5e29ac2010-04-03 22:44:37 -0300100 u8 filtered;
Namhyung Kim29750822015-04-22 16:18:12 +0900101 union {
102 /*
103 * Since perf diff only supports the stdio output, TUI
104 * fields are only accessed from perf report (or perf
105 * top). So make it an union to reduce memory usage.
106 */
107 struct hist_entry_diff diff;
108 struct /* for TUI */ {
109 u16 row_offset;
110 u16 nr_rows;
Namhyung Kimd8a0f802015-04-22 16:18:13 +0900111 bool init_have_children;
Namhyung Kim3698dab2015-05-05 23:55:46 +0900112 bool unfolded;
113 bool has_children;
Namhyung Kim29750822015-04-22 16:18:12 +0900114 };
115 };
Arnaldo Carvalho de Melo409a8be2012-05-30 10:33:24 -0300116 char *srcline;
Arnaldo Carvalho de Melo83753192010-04-03 16:30:44 -0300117 struct symbol *parent;
Arnaldo Carvalho de Melob821c732012-10-25 14:42:45 -0200118 struct rb_root sorted_chain;
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +0100119 struct branch_info *branch_info;
Jiri Olsaae359f12012-10-04 21:49:35 +0900120 struct hists *hists;
Stephane Eranian98a3b322013-01-24 16:10:35 +0100121 struct mem_info *mem_info;
122 struct callchain_root callchain[0]; /* must be last member */
John Kacurdd68ada2009-09-24 18:02:49 +0200123};
124
Arnaldo Carvalho de Melob821c732012-10-25 14:42:45 -0200125static inline bool hist_entry__has_pairs(struct hist_entry *he)
126{
127 return !list_empty(&he->pairs.node);
128}
129
130static inline struct hist_entry *hist_entry__next_pair(struct hist_entry *he)
131{
132 if (hist_entry__has_pairs(he))
133 return list_entry(he->pairs.node.next, struct hist_entry, pairs.node);
134 return NULL;
135}
136
Jiri Olsa4d233222012-12-13 14:09:00 +0100137static inline void hist_entry__add_pair(struct hist_entry *pair,
138 struct hist_entry *he)
Arnaldo Carvalho de Melob821c732012-10-25 14:42:45 -0200139{
Jiri Olsa4d233222012-12-13 14:09:00 +0100140 list_add_tail(&pair->pairs.node, &he->pairs.head);
Arnaldo Carvalho de Melob821c732012-10-25 14:42:45 -0200141}
142
Namhyung Kim14135662013-10-31 10:17:39 +0900143static inline float hist_entry__get_percent_limit(struct hist_entry *he)
144{
145 u64 period = he->stat.period;
146 u64 total_period = hists__total_period(he->hists);
147
148 if (unlikely(total_period == 0))
149 return 0;
150
151 if (symbol_conf.cumulate_callchain)
152 period = he->stat_acc->period;
153
154 return period * 100.0 / total_period;
155}
156
157
Namhyung Kim55369fc2013-04-01 20:35:20 +0900158enum sort_mode {
159 SORT_MODE__NORMAL,
160 SORT_MODE__BRANCH,
161 SORT_MODE__MEMORY,
Namhyung Kim512ae1b2014-03-18 11:31:39 +0900162 SORT_MODE__TOP,
163 SORT_MODE__DIFF,
Namhyung Kim55369fc2013-04-01 20:35:20 +0900164};
165
Frederic Weisbeckera4fb5812009-10-22 23:23:23 +0200166enum sort_type {
Namhyung Kimfc5871e2012-12-27 18:11:46 +0900167 /* common sort keys */
Frederic Weisbeckera4fb5812009-10-22 23:23:23 +0200168 SORT_PID,
169 SORT_COMM,
170 SORT_DSO,
171 SORT_SYM,
Arun Sharmaf60f3592010-06-04 11:27:10 -0300172 SORT_PARENT,
173 SORT_CPU,
Namhyung Kimfc5871e2012-12-27 18:11:46 +0900174 SORT_SRCLINE,
Andi Kleenf9ea55d2013-07-18 15:58:53 -0700175 SORT_LOCAL_WEIGHT,
176 SORT_GLOBAL_WEIGHT,
Andi Kleen475eeab2013-09-20 07:40:43 -0700177 SORT_TRANSACTION,
Namhyung Kimfc5871e2012-12-27 18:11:46 +0900178
179 /* branch stack specific sort keys */
180 __SORT_BRANCH_STACK,
181 SORT_DSO_FROM = __SORT_BRANCH_STACK,
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +0100182 SORT_DSO_TO,
183 SORT_SYM_FROM,
184 SORT_SYM_TO,
185 SORT_MISPREDICT,
Andi Kleenf5d05bc2013-09-20 07:40:41 -0700186 SORT_ABORT,
187 SORT_IN_TX,
Namhyung Kimafab87b2013-04-03 21:26:11 +0900188
189 /* memory mode specific sort keys */
190 __SORT_MEMORY_MODE,
Andi Kleenf9ea55d2013-07-18 15:58:53 -0700191 SORT_MEM_DADDR_SYMBOL = __SORT_MEMORY_MODE,
Namhyung Kimafab87b2013-04-03 21:26:11 +0900192 SORT_MEM_DADDR_DSO,
193 SORT_MEM_LOCKED,
194 SORT_MEM_TLB,
195 SORT_MEM_LVL,
196 SORT_MEM_SNOOP,
Don Zickus9b32ba72014-06-01 15:38:29 +0200197 SORT_MEM_DCACHELINE,
Frederic Weisbeckera4fb5812009-10-22 23:23:23 +0200198};
199
John Kacurdd68ada2009-09-24 18:02:49 +0200200/*
201 * configurable sorting bits
202 */
203
204struct sort_entry {
205 struct list_head list;
206
Frederic Weisbeckerfcd14982010-04-14 19:11:29 +0200207 const char *se_header;
John Kacurdd68ada2009-09-24 18:02:49 +0200208
Frederic Weisbeckerfcd14982010-04-14 19:11:29 +0200209 int64_t (*se_cmp)(struct hist_entry *, struct hist_entry *);
210 int64_t (*se_collapse)(struct hist_entry *, struct hist_entry *);
Namhyung Kim202e7a62014-03-04 11:01:41 +0900211 int64_t (*se_sort)(struct hist_entry *, struct hist_entry *);
Arnaldo Carvalho de Melo316c7132013-11-05 15:32:36 -0300212 int (*se_snprintf)(struct hist_entry *he, char *bf, size_t size,
Frederic Weisbeckerfcd14982010-04-14 19:11:29 +0200213 unsigned int width);
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -0300214 u8 se_width_idx;
John Kacurdd68ada2009-09-24 18:02:49 +0200215};
216
217extern struct sort_entry sort_thread;
218extern struct list_head hist_entry__sort_list;
219
Namhyung Kim55309982013-02-06 14:57:16 +0900220int setup_sorting(void);
Namhyung Kima7d945b2014-03-04 10:46:34 +0900221int setup_output_field(void);
Namhyung Kim1c89fe92014-05-07 18:42:24 +0900222void reset_output_field(void);
John Kacurdd68ada2009-09-24 18:02:49 +0200223extern int sort_dimension__add(const char *);
Namhyung Kim08e71542013-04-03 21:26:19 +0900224void sort__setup_elide(FILE *fp);
Jiri Olsaf2998422014-05-23 17:15:47 +0200225void perf_hpp__set_elide(int idx, bool elide);
John Kacurdd68ada2009-09-24 18:02:49 +0200226
Greg Priceb21484f2012-12-06 21:48:05 -0800227int report_parse_ignore_callees_opt(const struct option *opt, const char *arg, int unset);
228
Jiri Olsa2f3f9bc2014-08-22 15:58:38 +0200229bool is_strict_order(const char *order);
John Kacurdd68ada2009-09-24 18:02:49 +0200230#endif /* __PERF_SORT_H */