aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tools/perf/builtin-diff.c4
-rw-r--r--tools/perf/builtin-report.c18
-rw-r--r--tools/perf/builtin-top.c3
-rw-r--r--tools/perf/util/sort.c28
-rw-r--r--tools/perf/util/sort.h2
5 files changed, 31 insertions, 24 deletions
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index b60c711d4e72..8bff543acaab 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -60,7 +60,6 @@ static int data__files_cnt;
60#define data__for_each_file(i, d) data__for_each_file_start(i, d, 0) 60#define data__for_each_file(i, d) data__for_each_file_start(i, d, 0)
61#define data__for_each_file_new(i, d) data__for_each_file_start(i, d, 1) 61#define data__for_each_file_new(i, d) data__for_each_file_start(i, d, 1)
62 62
63static char diff__default_sort_order[] = "dso,symbol";
64static bool force; 63static bool force;
65static bool show_period; 64static bool show_period;
66static bool show_formula; 65static bool show_formula;
@@ -1142,7 +1141,6 @@ int cmd_diff(int argc, const char **argv, const char *prefix __maybe_unused)
1142{ 1141{
1143 perf_config(perf_default_config, NULL); 1142 perf_config(perf_default_config, NULL);
1144 1143
1145 sort_order = diff__default_sort_order;
1146 argc = parse_options(argc, argv, options, diff_usage, 0); 1144 argc = parse_options(argc, argv, options, diff_usage, 0);
1147 1145
1148 if (symbol__init() < 0) 1146 if (symbol__init() < 0)
@@ -1153,6 +1151,8 @@ int cmd_diff(int argc, const char **argv, const char *prefix __maybe_unused)
1153 1151
1154 ui_init(); 1152 ui_init();
1155 1153
1154 sort__mode = SORT_MODE__DIFF;
1155
1156 if (setup_sorting() < 0) 1156 if (setup_sorting() < 0)
1157 usage_with_options(diff_usage, options); 1157 usage_with_options(diff_usage, options);
1158 1158
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index d0180d5de781..f4d640cfdf16 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -805,30 +805,12 @@ repeat:
805 if (branch_mode == -1 && has_br_stack) 805 if (branch_mode == -1 && has_br_stack)
806 sort__mode = SORT_MODE__BRANCH; 806 sort__mode = SORT_MODE__BRANCH;
807 807
808 /* sort__mode could be NORMAL if --no-branch-stack */
809 if (sort__mode == SORT_MODE__BRANCH) {
810 /*
811 * if no sort_order is provided, then specify
812 * branch-mode specific order
813 */
814 if (sort_order == default_sort_order)
815 sort_order = "comm,dso_from,symbol_from,"
816 "dso_to,symbol_to";
817
818 }
819 if (report.mem_mode) { 808 if (report.mem_mode) {
820 if (sort__mode == SORT_MODE__BRANCH) { 809 if (sort__mode == SORT_MODE__BRANCH) {
821 pr_err("branch and mem mode incompatible\n"); 810 pr_err("branch and mem mode incompatible\n");
822 goto error; 811 goto error;
823 } 812 }
824 sort__mode = SORT_MODE__MEMORY; 813 sort__mode = SORT_MODE__MEMORY;
825
826 /*
827 * if no sort_order is provided, then specify
828 * branch-mode specific order
829 */
830 if (sort_order == default_sort_order)
831 sort_order = "local_weight,mem,sym,dso,symbol_daddr,dso_daddr,snoop,tlb,locked";
832 } 814 }
833 815
834 if (setup_sorting() < 0) { 816 if (setup_sorting() < 0) {
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 4fef1e415129..34764b6eabf9 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -1137,8 +1137,7 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
1137 if (argc) 1137 if (argc)
1138 usage_with_options(top_usage, options); 1138 usage_with_options(top_usage, options);
1139 1139
1140 if (sort_order == default_sort_order) 1140 sort__mode = SORT_MODE__TOP;
1141 sort_order = "dso,symbol";
1142 1141
1143 if (setup_sorting() < 0) { 1142 if (setup_sorting() < 0) {
1144 parse_options_usage(top_usage, options, "s", 1); 1143 parse_options_usage(top_usage, options, "s", 1);
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index 916652af8304..d64c1e58f1b1 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -8,7 +8,11 @@ regex_t parent_regex;
8const char default_parent_pattern[] = "^sys_|^do_page_fault"; 8const char default_parent_pattern[] = "^sys_|^do_page_fault";
9const char *parent_pattern = default_parent_pattern; 9const char *parent_pattern = default_parent_pattern;
10const char default_sort_order[] = "comm,dso,symbol"; 10const char default_sort_order[] = "comm,dso,symbol";
11const char *sort_order = default_sort_order; 11const char default_branch_sort_order[] = "comm,dso_from,symbol_from,dso_to,symbol_to";
12const char default_mem_sort_order[] = "local_weight,mem,sym,dso,symbol_daddr,dso_daddr,snoop,tlb,locked";
13const char default_top_sort_order[] = "dso,symbol";
14const char default_diff_sort_order[] = "dso,symbol";
15const char *sort_order;
12regex_t ignore_callees_regex; 16regex_t ignore_callees_regex;
13int have_ignore_callees = 0; 17int have_ignore_callees = 0;
14int sort__need_collapse = 0; 18int sort__need_collapse = 0;
@@ -1218,11 +1222,31 @@ int sort_dimension__add(const char *tok)
1218 return -ESRCH; 1222 return -ESRCH;
1219} 1223}
1220 1224
1225static const char *get_default_sort_order(void)
1226{
1227 const char *default_sort_orders[] = {
1228 default_sort_order,
1229 default_branch_sort_order,
1230 default_mem_sort_order,
1231 default_top_sort_order,
1232 default_diff_sort_order,
1233 };
1234
1235 BUG_ON(sort__mode >= ARRAY_SIZE(default_sort_orders));
1236
1237 return default_sort_orders[sort__mode];
1238}
1239
1221int setup_sorting(void) 1240int setup_sorting(void)
1222{ 1241{
1223 char *tmp, *tok, *str = strdup(sort_order); 1242 char *tmp, *tok, *str;
1243 const char *sort_keys = sort_order;
1224 int ret = 0; 1244 int ret = 0;
1225 1245
1246 if (sort_keys == NULL)
1247 sort_keys = get_default_sort_order();
1248
1249 str = strdup(sort_keys);
1226 if (str == NULL) { 1250 if (str == NULL) {
1227 error("Not enough memory to setup sort keys"); 1251 error("Not enough memory to setup sort keys");
1228 return -ENOMEM; 1252 return -ENOMEM;
diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h
index 43e5ff42a609..1a7295255dc9 100644
--- a/tools/perf/util/sort.h
+++ b/tools/perf/util/sort.h
@@ -133,6 +133,8 @@ enum sort_mode {
133 SORT_MODE__NORMAL, 133 SORT_MODE__NORMAL,
134 SORT_MODE__BRANCH, 134 SORT_MODE__BRANCH,
135 SORT_MODE__MEMORY, 135 SORT_MODE__MEMORY,
136 SORT_MODE__TOP,
137 SORT_MODE__DIFF,
136}; 138};
137 139
138enum sort_type { 140enum sort_type {