aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung@kernel.org>2014-03-02 21:46:55 -0500
committerJiri Olsa <jolsa@kernel.org>2014-05-21 05:45:34 -0400
commit8b536999cd75e565125c74b2cf2a746d4f053a92 (patch)
tree46a4a0d3d64885c8503d0adb4896e85c7d86d014 /tools
parentbc18b7f2e3ca09b360b26c25a7541ba6f170111b (diff)
perf tools: Convert sort entries to hpp formats
This is a preparation of consolidating management of output field and sort keys. Signed-off-by: Namhyung Kim <namhyung@kernel.org> Acked-by: Ingo Molnar <mingo@kernel.org> Link: http://lkml.kernel.org/r/1400480762-22852-3-git-send-email-namhyung@kernel.org Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/ui/hist.c6
-rw-r--r--tools/perf/util/hist.h6
-rw-r--r--tools/perf/util/sort.c80
3 files changed, 88 insertions, 4 deletions
diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c
index d4a4f2e7eb43..a6eea666b443 100644
--- a/tools/perf/ui/hist.c
+++ b/tools/perf/ui/hist.c
@@ -284,6 +284,7 @@ struct perf_hpp_fmt perf_hpp__format[] = {
284}; 284};
285 285
286LIST_HEAD(perf_hpp__list); 286LIST_HEAD(perf_hpp__list);
287LIST_HEAD(perf_hpp__sort_list);
287 288
288 289
289#undef HPP__COLOR_PRINT_FNS 290#undef HPP__COLOR_PRINT_FNS
@@ -325,6 +326,11 @@ void perf_hpp__column_register(struct perf_hpp_fmt *format)
325 list_add_tail(&format->list, &perf_hpp__list); 326 list_add_tail(&format->list, &perf_hpp__list);
326} 327}
327 328
329void perf_hpp__register_sort_field(struct perf_hpp_fmt *format)
330{
331 list_add_tail(&format->sort_list, &perf_hpp__sort_list);
332}
333
328void perf_hpp__column_enable(unsigned col) 334void perf_hpp__column_enable(unsigned col)
329{ 335{
330 BUG_ON(col >= PERF_HPP__MAX_INDEX); 336 BUG_ON(col >= PERF_HPP__MAX_INDEX);
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index 36dbe00e3cc8..eee154a41723 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -165,13 +165,18 @@ struct perf_hpp_fmt {
165 int64_t (*sort)(struct hist_entry *a, struct hist_entry *b); 165 int64_t (*sort)(struct hist_entry *a, struct hist_entry *b);
166 166
167 struct list_head list; 167 struct list_head list;
168 struct list_head sort_list;
168}; 169};
169 170
170extern struct list_head perf_hpp__list; 171extern struct list_head perf_hpp__list;
172extern struct list_head perf_hpp__sort_list;
171 173
172#define perf_hpp__for_each_format(format) \ 174#define perf_hpp__for_each_format(format) \
173 list_for_each_entry(format, &perf_hpp__list, list) 175 list_for_each_entry(format, &perf_hpp__list, list)
174 176
177#define perf_hpp__for_each_sort_list(format) \
178 list_for_each_entry(format, &perf_hpp__sort_list, sort_list)
179
175extern struct perf_hpp_fmt perf_hpp__format[]; 180extern struct perf_hpp_fmt perf_hpp__format[];
176 181
177enum { 182enum {
@@ -190,6 +195,7 @@ enum {
190void perf_hpp__init(void); 195void perf_hpp__init(void);
191void perf_hpp__column_register(struct perf_hpp_fmt *format); 196void perf_hpp__column_register(struct perf_hpp_fmt *format);
192void perf_hpp__column_enable(unsigned col); 197void perf_hpp__column_enable(unsigned col);
198void perf_hpp__register_sort_field(struct perf_hpp_fmt *format);
193 199
194typedef u64 (*hpp_field_fn)(struct hist_entry *he); 200typedef u64 (*hpp_field_fn)(struct hist_entry *he);
195typedef int (*hpp_callback_fn)(struct perf_hpp *hpp, bool front); 201typedef int (*hpp_callback_fn)(struct perf_hpp *hpp, bool front);
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index 635cd8f8b22e..b2829f947053 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -2,6 +2,7 @@
2#include "hist.h" 2#include "hist.h"
3#include "comm.h" 3#include "comm.h"
4#include "symbol.h" 4#include "symbol.h"
5#include "evsel.h"
5 6
6regex_t parent_regex; 7regex_t parent_regex;
7const char default_parent_pattern[] = "^sys_|^do_page_fault"; 8const char default_parent_pattern[] = "^sys_|^do_page_fault";
@@ -1027,10 +1028,80 @@ static struct sort_dimension memory_sort_dimensions[] = {
1027 1028
1028#undef DIM 1029#undef DIM
1029 1030
1030static void __sort_dimension__add(struct sort_dimension *sd, enum sort_type idx) 1031struct hpp_sort_entry {
1032 struct perf_hpp_fmt hpp;
1033 struct sort_entry *se;
1034};
1035
1036static int __sort__hpp_header(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
1037 struct perf_evsel *evsel)
1038{
1039 struct hpp_sort_entry *hse;
1040 size_t len;
1041
1042 hse = container_of(fmt, struct hpp_sort_entry, hpp);
1043 len = hists__col_len(&evsel->hists, hse->se->se_width_idx);
1044
1045 return scnprintf(hpp->buf, hpp->size, "%*s", len, hse->se->se_header);
1046}
1047
1048static int __sort__hpp_width(struct perf_hpp_fmt *fmt,
1049 struct perf_hpp *hpp __maybe_unused,
1050 struct perf_evsel *evsel)
1051{
1052 struct hpp_sort_entry *hse;
1053
1054 hse = container_of(fmt, struct hpp_sort_entry, hpp);
1055
1056 return hists__col_len(&evsel->hists, hse->se->se_width_idx);
1057}
1058
1059static int __sort__hpp_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
1060 struct hist_entry *he)
1061{
1062 struct hpp_sort_entry *hse;
1063 size_t len;
1064
1065 hse = container_of(fmt, struct hpp_sort_entry, hpp);
1066 len = hists__col_len(he->hists, hse->se->se_width_idx);
1067
1068 return hse->se->se_snprintf(he, hpp->buf, hpp->size, len);
1069}
1070
1071static int __sort_dimension__add_hpp(struct sort_dimension *sd)
1072{
1073 struct hpp_sort_entry *hse;
1074
1075 hse = malloc(sizeof(*hse));
1076 if (hse == NULL) {
1077 pr_err("Memory allocation failed\n");
1078 return -1;
1079 }
1080
1081 hse->se = sd->entry;
1082 hse->hpp.header = __sort__hpp_header;
1083 hse->hpp.width = __sort__hpp_width;
1084 hse->hpp.entry = __sort__hpp_entry;
1085 hse->hpp.color = NULL;
1086
1087 hse->hpp.cmp = sd->entry->se_cmp;
1088 hse->hpp.collapse = sd->entry->se_collapse ? : sd->entry->se_cmp;
1089 hse->hpp.sort = hse->hpp.collapse;
1090
1091 INIT_LIST_HEAD(&hse->hpp.list);
1092 INIT_LIST_HEAD(&hse->hpp.sort_list);
1093
1094 perf_hpp__register_sort_field(&hse->hpp);
1095 return 0;
1096}
1097
1098static int __sort_dimension__add(struct sort_dimension *sd, enum sort_type idx)
1031{ 1099{
1032 if (sd->taken) 1100 if (sd->taken)
1033 return; 1101 return 0;
1102
1103 if (__sort_dimension__add_hpp(sd) < 0)
1104 return -1;
1034 1105
1035 if (sd->entry->se_collapse) 1106 if (sd->entry->se_collapse)
1036 sort__need_collapse = 1; 1107 sort__need_collapse = 1;
@@ -1040,6 +1111,8 @@ static void __sort_dimension__add(struct sort_dimension *sd, enum sort_type idx)
1040 1111
1041 list_add_tail(&sd->entry->list, &hist_entry__sort_list); 1112 list_add_tail(&sd->entry->list, &hist_entry__sort_list);
1042 sd->taken = 1; 1113 sd->taken = 1;
1114
1115 return 0;
1043} 1116}
1044 1117
1045int sort_dimension__add(const char *tok) 1118int sort_dimension__add(const char *tok)
@@ -1068,8 +1141,7 @@ int sort_dimension__add(const char *tok)
1068 sort__has_dso = 1; 1141 sort__has_dso = 1;
1069 } 1142 }
1070 1143
1071 __sort_dimension__add(sd, i); 1144 return __sort_dimension__add(sd, i);
1072 return 0;
1073 } 1145 }
1074 1146
1075 for (i = 0; i < ARRAY_SIZE(bstack_sort_dimensions); i++) { 1147 for (i = 0; i < ARRAY_SIZE(bstack_sort_dimensions); i++) {