aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung@kernel.org>2014-03-03 21:01:41 -0500
committerJiri Olsa <jolsa@kernel.org>2014-05-21 05:45:35 -0400
commit202e7a6d16127323d03e912d7844aa0d614c315e (patch)
treecc13d7a1ed019ebf59b21d53a77804f778e45010 /tools/perf
parenta7d945bc91602f916d2d0c794c179d9a784859e7 (diff)
perf tools: Add ->sort() member to struct sort_entry
Currently, what the sort_entry does is just identifying hist entries so that they can be grouped properly. However, with -F option support, it indeed needs to sort entries appropriately to be shown to users. So add ->sort() member to do it. Signed-off-by: Namhyung Kim <namhyung@kernel.org> Acked-by: Ingo Molnar <mingo@kernel.org> Link: http://lkml.kernel.org/r/1400480762-22852-13-git-send-email-namhyung@kernel.org Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/util/sort.c27
-rw-r--r--tools/perf/util/sort.h1
2 files changed, 23 insertions, 5 deletions
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index b748b02fcb78..5414ba541e47 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -99,6 +99,12 @@ sort__comm_collapse(struct hist_entry *left, struct hist_entry *right)
99 return comm__str(right->comm) - comm__str(left->comm); 99 return comm__str(right->comm) - comm__str(left->comm);
100} 100}
101 101
102static int64_t
103sort__comm_sort(struct hist_entry *left, struct hist_entry *right)
104{
105 return strcmp(comm__str(right->comm), comm__str(left->comm));
106}
107
102static int hist_entry__comm_snprintf(struct hist_entry *he, char *bf, 108static int hist_entry__comm_snprintf(struct hist_entry *he, char *bf,
103 size_t size, unsigned int width) 109 size_t size, unsigned int width)
104{ 110{
@@ -109,6 +115,7 @@ struct sort_entry sort_comm = {
109 .se_header = "Command", 115 .se_header = "Command",
110 .se_cmp = sort__comm_cmp, 116 .se_cmp = sort__comm_cmp,
111 .se_collapse = sort__comm_collapse, 117 .se_collapse = sort__comm_collapse,
118 .se_sort = sort__comm_sort,
112 .se_snprintf = hist_entry__comm_snprintf, 119 .se_snprintf = hist_entry__comm_snprintf,
113 .se_width_idx = HISTC_COMM, 120 .se_width_idx = HISTC_COMM,
114}; 121};
@@ -122,7 +129,7 @@ static int64_t _sort__dso_cmp(struct map *map_l, struct map *map_r)
122 const char *dso_name_l, *dso_name_r; 129 const char *dso_name_l, *dso_name_r;
123 130
124 if (!dso_l || !dso_r) 131 if (!dso_l || !dso_r)
125 return cmp_null(dso_l, dso_r); 132 return cmp_null(dso_r, dso_l);
126 133
127 if (verbose) { 134 if (verbose) {
128 dso_name_l = dso_l->long_name; 135 dso_name_l = dso_l->long_name;
@@ -138,7 +145,7 @@ static int64_t _sort__dso_cmp(struct map *map_l, struct map *map_r)
138static int64_t 145static int64_t
139sort__dso_cmp(struct hist_entry *left, struct hist_entry *right) 146sort__dso_cmp(struct hist_entry *left, struct hist_entry *right)
140{ 147{
141 return _sort__dso_cmp(left->ms.map, right->ms.map); 148 return _sort__dso_cmp(right->ms.map, left->ms.map);
142} 149}
143 150
144static int _hist_entry__dso_snprintf(struct map *map, char *bf, 151static int _hist_entry__dso_snprintf(struct map *map, char *bf,
@@ -210,6 +217,15 @@ sort__sym_cmp(struct hist_entry *left, struct hist_entry *right)
210 return _sort__sym_cmp(left->ms.sym, right->ms.sym); 217 return _sort__sym_cmp(left->ms.sym, right->ms.sym);
211} 218}
212 219
220static int64_t
221sort__sym_sort(struct hist_entry *left, struct hist_entry *right)
222{
223 if (!left->ms.sym || !right->ms.sym)
224 return cmp_null(left->ms.sym, right->ms.sym);
225
226 return strcmp(right->ms.sym->name, left->ms.sym->name);
227}
228
213static int _hist_entry__sym_snprintf(struct map *map, struct symbol *sym, 229static int _hist_entry__sym_snprintf(struct map *map, struct symbol *sym,
214 u64 ip, char level, char *bf, size_t size, 230 u64 ip, char level, char *bf, size_t size,
215 unsigned int width) 231 unsigned int width)
@@ -256,6 +272,7 @@ static int hist_entry__sym_snprintf(struct hist_entry *he, char *bf,
256struct sort_entry sort_sym = { 272struct sort_entry sort_sym = {
257 .se_header = "Symbol", 273 .se_header = "Symbol",
258 .se_cmp = sort__sym_cmp, 274 .se_cmp = sort__sym_cmp,
275 .se_sort = sort__sym_sort,
259 .se_snprintf = hist_entry__sym_snprintf, 276 .se_snprintf = hist_entry__sym_snprintf,
260 .se_width_idx = HISTC_SYMBOL, 277 .se_width_idx = HISTC_SYMBOL,
261}; 278};
@@ -283,7 +300,7 @@ sort__srcline_cmp(struct hist_entry *left, struct hist_entry *right)
283 map__rip_2objdump(map, right->ip)); 300 map__rip_2objdump(map, right->ip));
284 } 301 }
285 } 302 }
286 return strcmp(left->srcline, right->srcline); 303 return strcmp(right->srcline, left->srcline);
287} 304}
288 305
289static int hist_entry__srcline_snprintf(struct hist_entry *he, char *bf, 306static int hist_entry__srcline_snprintf(struct hist_entry *he, char *bf,
@@ -311,7 +328,7 @@ sort__parent_cmp(struct hist_entry *left, struct hist_entry *right)
311 if (!sym_l || !sym_r) 328 if (!sym_l || !sym_r)
312 return cmp_null(sym_l, sym_r); 329 return cmp_null(sym_l, sym_r);
313 330
314 return strcmp(sym_l->name, sym_r->name); 331 return strcmp(sym_r->name, sym_l->name);
315} 332}
316 333
317static int hist_entry__parent_snprintf(struct hist_entry *he, char *bf, 334static int hist_entry__parent_snprintf(struct hist_entry *he, char *bf,
@@ -1126,7 +1143,7 @@ __sort_dimension__alloc_hpp(struct sort_dimension *sd)
1126 1143
1127 hse->hpp.cmp = sd->entry->se_cmp; 1144 hse->hpp.cmp = sd->entry->se_cmp;
1128 hse->hpp.collapse = sd->entry->se_collapse ? : sd->entry->se_cmp; 1145 hse->hpp.collapse = sd->entry->se_collapse ? : sd->entry->se_cmp;
1129 hse->hpp.sort = hse->hpp.collapse; 1146 hse->hpp.sort = sd->entry->se_sort ? : hse->hpp.collapse;
1130 1147
1131 INIT_LIST_HEAD(&hse->hpp.list); 1148 INIT_LIST_HEAD(&hse->hpp.list);
1132 INIT_LIST_HEAD(&hse->hpp.sort_list); 1149 INIT_LIST_HEAD(&hse->hpp.sort_list);
diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h
index 89e5057ca378..f5a831c3d0fb 100644
--- a/tools/perf/util/sort.h
+++ b/tools/perf/util/sort.h
@@ -182,6 +182,7 @@ struct sort_entry {
182 182
183 int64_t (*se_cmp)(struct hist_entry *, struct hist_entry *); 183 int64_t (*se_cmp)(struct hist_entry *, struct hist_entry *);
184 int64_t (*se_collapse)(struct hist_entry *, struct hist_entry *); 184 int64_t (*se_collapse)(struct hist_entry *, struct hist_entry *);
185 int64_t (*se_sort)(struct hist_entry *, struct hist_entry *);
185 int (*se_snprintf)(struct hist_entry *he, char *bf, size_t size, 186 int (*se_snprintf)(struct hist_entry *he, char *bf, size_t size,
186 unsigned int width); 187 unsigned int width);
187 u8 se_width_idx; 188 u8 se_width_idx;