aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorNamhyung Kim <namhyung@kernel.org>2014-03-03 02:16:20 -0500
committerJiri Olsa <jolsa@kernel.org>2014-05-21 05:45:34 -0400
commit26d8b338271a17a8a9b78000ebaec8b4645f5476 (patch)
tree41d1a6c7e3204c005df6a8983ccc519d47a55258 /tools/perf
parent043ca389a3181565b5c19d43a55eae111977d13d (diff)
perf tools: Consolidate output field handling to hpp format routines
Until now the hpp and sort functions do similar jobs different ways. Since the sort functions converted/wrapped to hpp formats it can do the job in a uniform way. The perf_hpp__sort_list has a list of hpp formats to sort entries and the perf_hpp__list has a list of hpp formats to print output result. To have a backward compatibility, it automatically adds 'overhead' field in front of sort list. And then all of fields in sort list added to the output list (if it's not already there). Signed-off-by: Namhyung Kim <namhyung@kernel.org> Acked-by: Ingo Molnar <mingo@kernel.org> Link: http://lkml.kernel.org/n/tip-7g3h86woz2sckg3h1lj42ygj@git.kernel.org Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/ui/browsers/hists.c31
-rw-r--r--tools/perf/ui/gtk/hists.c31
-rw-r--r--tools/perf/ui/hist.c26
-rw-r--r--tools/perf/ui/stdio/hist.c55
-rw-r--r--tools/perf/util/hist.c2
-rw-r--r--tools/perf/util/hist.h1
6 files changed, 63 insertions, 83 deletions
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index b0861e3e50a5..847de116b9ec 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -760,8 +760,8 @@ static int hist_browser__show_entry(struct hist_browser *browser,
760 if (!browser->b.navkeypressed) 760 if (!browser->b.navkeypressed)
761 width += 1; 761 width += 1;
762 762
763 hist_entry__sort_snprintf(entry, s, sizeof(s), browser->hists); 763 slsmg_write_nstring("", width);
764 slsmg_write_nstring(s, width); 764
765 ++row; 765 ++row;
766 ++printed; 766 ++printed;
767 } else 767 } else
@@ -1104,27 +1104,32 @@ static int hist_browser__fprintf_entry(struct hist_browser *browser,
1104 struct hist_entry *he, FILE *fp) 1104 struct hist_entry *he, FILE *fp)
1105{ 1105{
1106 char s[8192]; 1106 char s[8192];
1107 double percent;
1108 int printed = 0; 1107 int printed = 0;
1109 char folded_sign = ' '; 1108 char folded_sign = ' ';
1109 struct perf_hpp hpp = {
1110 .buf = s,
1111 .size = sizeof(s),
1112 };
1113 struct perf_hpp_fmt *fmt;
1114 bool first = true;
1115 int ret;
1110 1116
1111 if (symbol_conf.use_callchain) 1117 if (symbol_conf.use_callchain)
1112 folded_sign = hist_entry__folded(he); 1118 folded_sign = hist_entry__folded(he);
1113 1119
1114 hist_entry__sort_snprintf(he, s, sizeof(s), browser->hists);
1115 percent = (he->stat.period * 100.0) / browser->hists->stats.total_period;
1116
1117 if (symbol_conf.use_callchain) 1120 if (symbol_conf.use_callchain)
1118 printed += fprintf(fp, "%c ", folded_sign); 1121 printed += fprintf(fp, "%c ", folded_sign);
1119 1122
1120 printed += fprintf(fp, " %5.2f%%", percent); 1123 perf_hpp__for_each_format(fmt) {
1121 1124 if (!first) {
1122 if (symbol_conf.show_nr_samples) 1125 ret = scnprintf(hpp.buf, hpp.size, " ");
1123 printed += fprintf(fp, " %11u", he->stat.nr_events); 1126 advance_hpp(&hpp, ret);
1124 1127 } else
1125 if (symbol_conf.show_total_period) 1128 first = false;
1126 printed += fprintf(fp, " %12" PRIu64, he->stat.period);
1127 1129
1130 ret = fmt->entry(fmt, &hpp, he);
1131 advance_hpp(&hpp, ret);
1132 }
1128 printed += fprintf(fp, "%s\n", rtrim(s)); 1133 printed += fprintf(fp, "%s\n", rtrim(s));
1129 1134
1130 if (folded_sign == '-') 1135 if (folded_sign == '-')
diff --git a/tools/perf/ui/gtk/hists.c b/tools/perf/ui/gtk/hists.c
index 91f10f3f6dd1..d5c336e1bb14 100644
--- a/tools/perf/ui/gtk/hists.c
+++ b/tools/perf/ui/gtk/hists.c
@@ -153,7 +153,6 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists,
153 struct perf_hpp_fmt *fmt; 153 struct perf_hpp_fmt *fmt;
154 GType col_types[MAX_COLUMNS]; 154 GType col_types[MAX_COLUMNS];
155 GtkCellRenderer *renderer; 155 GtkCellRenderer *renderer;
156 struct sort_entry *se;
157 GtkTreeStore *store; 156 GtkTreeStore *store;
158 struct rb_node *nd; 157 struct rb_node *nd;
159 GtkWidget *view; 158 GtkWidget *view;
@@ -172,16 +171,6 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists,
172 perf_hpp__for_each_format(fmt) 171 perf_hpp__for_each_format(fmt)
173 col_types[nr_cols++] = G_TYPE_STRING; 172 col_types[nr_cols++] = G_TYPE_STRING;
174 173
175 list_for_each_entry(se, &hist_entry__sort_list, list) {
176 if (se->elide)
177 continue;
178
179 if (se == &sort_sym)
180 sym_col = nr_cols;
181
182 col_types[nr_cols++] = G_TYPE_STRING;
183 }
184
185 store = gtk_tree_store_newv(nr_cols, col_types); 174 store = gtk_tree_store_newv(nr_cols, col_types);
186 175
187 view = gtk_tree_view_new(); 176 view = gtk_tree_view_new();
@@ -199,16 +188,6 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists,
199 col_idx++, NULL); 188 col_idx++, NULL);
200 } 189 }
201 190
202 list_for_each_entry(se, &hist_entry__sort_list, list) {
203 if (se->elide)
204 continue;
205
206 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
207 -1, se->se_header,
208 renderer, "text",
209 col_idx++, NULL);
210 }
211
212 for (col_idx = 0; col_idx < nr_cols; col_idx++) { 191 for (col_idx = 0; col_idx < nr_cols; col_idx++) {
213 GtkTreeViewColumn *column; 192 GtkTreeViewColumn *column;
214 193
@@ -253,16 +232,6 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists,
253 gtk_tree_store_set(store, &iter, col_idx++, s, -1); 232 gtk_tree_store_set(store, &iter, col_idx++, s, -1);
254 } 233 }
255 234
256 list_for_each_entry(se, &hist_entry__sort_list, list) {
257 if (se->elide)
258 continue;
259
260 se->se_snprintf(h, s, ARRAY_SIZE(s),
261 hists__col_len(hists, se->se_width_idx));
262
263 gtk_tree_store_set(store, &iter, col_idx++, s, -1);
264 }
265
266 if (symbol_conf.use_callchain && sort__has_sym) { 235 if (symbol_conf.use_callchain && sort__has_sym) {
267 if (callchain_param.mode == CHAIN_GRAPH_REL) 236 if (callchain_param.mode == CHAIN_GRAPH_REL)
268 total = h->stat.period; 237 total = h->stat.period;
diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c
index 0299385284fd..400437ee60b1 100644
--- a/tools/perf/ui/hist.c
+++ b/tools/perf/ui/hist.c
@@ -354,6 +354,14 @@ LIST_HEAD(perf_hpp__sort_list);
354 354
355void perf_hpp__init(void) 355void perf_hpp__init(void)
356{ 356{
357 struct list_head *list;
358 int i;
359
360 for (i = 0; i < PERF_HPP__MAX_INDEX; i++) {
361 INIT_LIST_HEAD(&perf_hpp__format[i].list);
362 INIT_LIST_HEAD(&perf_hpp__format[i].sort_list);
363 }
364
357 perf_hpp__column_enable(PERF_HPP__OVERHEAD); 365 perf_hpp__column_enable(PERF_HPP__OVERHEAD);
358 366
359 if (symbol_conf.show_cpu_utilization) { 367 if (symbol_conf.show_cpu_utilization) {
@@ -371,6 +379,13 @@ void perf_hpp__init(void)
371 379
372 if (symbol_conf.show_total_period) 380 if (symbol_conf.show_total_period)
373 perf_hpp__column_enable(PERF_HPP__PERIOD); 381 perf_hpp__column_enable(PERF_HPP__PERIOD);
382
383 /* prepend overhead field for backward compatiblity. */
384 list = &perf_hpp__format[PERF_HPP__OVERHEAD].sort_list;
385 if (list_empty(list))
386 list_add(list, &perf_hpp__sort_list);
387
388 perf_hpp__setup_output_field();
374} 389}
375 390
376void perf_hpp__column_register(struct perf_hpp_fmt *format) 391void perf_hpp__column_register(struct perf_hpp_fmt *format)
@@ -389,6 +404,17 @@ void perf_hpp__column_enable(unsigned col)
389 perf_hpp__column_register(&perf_hpp__format[col]); 404 perf_hpp__column_register(&perf_hpp__format[col]);
390} 405}
391 406
407void perf_hpp__setup_output_field(void)
408{
409 struct perf_hpp_fmt *fmt;
410
411 /* append sort keys to output field */
412 perf_hpp__for_each_sort_list(fmt) {
413 if (list_empty(&fmt->list))
414 perf_hpp__column_register(fmt);
415 }
416}
417
392int hist_entry__sort_snprintf(struct hist_entry *he, char *s, size_t size, 418int hist_entry__sort_snprintf(struct hist_entry *he, char *s, size_t size,
393 struct hists *hists) 419 struct hists *hists)
394{ 420{
diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c
index 9eccf7f4f367..49e2e4a7346a 100644
--- a/tools/perf/ui/stdio/hist.c
+++ b/tools/perf/ui/stdio/hist.c
@@ -306,8 +306,7 @@ static size_t hist_entry__callchain_fprintf(struct hist_entry *he,
306 return hist_entry_callchain__fprintf(he, total_period, left_margin, fp); 306 return hist_entry_callchain__fprintf(he, total_period, left_margin, fp);
307} 307}
308 308
309static int hist_entry__period_snprintf(struct perf_hpp *hpp, 309static int hist_entry__snprintf(struct hist_entry *he, struct perf_hpp *hpp)
310 struct hist_entry *he)
311{ 310{
312 const char *sep = symbol_conf.field_sep; 311 const char *sep = symbol_conf.field_sep;
313 struct perf_hpp_fmt *fmt; 312 struct perf_hpp_fmt *fmt;
@@ -353,8 +352,7 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size,
353 if (size == 0 || size > bfsz) 352 if (size == 0 || size > bfsz)
354 size = hpp.size = bfsz; 353 size = hpp.size = bfsz;
355 354
356 ret = hist_entry__period_snprintf(&hpp, he); 355 hist_entry__snprintf(he, &hpp);
357 hist_entry__sort_snprintf(he, bf + ret, size - ret, hists);
358 356
359 ret = fprintf(fp, "%s\n", bf); 357 ret = fprintf(fp, "%s\n", bf);
360 358
@@ -386,28 +384,9 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
386 384
387 init_rem_hits(); 385 init_rem_hits();
388 386
389 if (!show_header)
390 goto print_entries;
391
392 fprintf(fp, "# ");
393
394 perf_hpp__for_each_format(fmt) {
395 if (!first)
396 fprintf(fp, "%s", sep ?: " ");
397 else
398 first = false;
399
400 fmt->header(fmt, &dummy_hpp, hists_to_evsel(hists));
401 fprintf(fp, "%s", bf);
402 }
403
404 list_for_each_entry(se, &hist_entry__sort_list, list) { 387 list_for_each_entry(se, &hist_entry__sort_list, list) {
405 if (se->elide) 388 if (se->elide)
406 continue; 389 continue;
407 if (sep) {
408 fprintf(fp, "%c%s", *sep, se->se_header);
409 continue;
410 }
411 width = strlen(se->se_header); 390 width = strlen(se->se_header);
412 if (symbol_conf.col_width_list_str) { 391 if (symbol_conf.col_width_list_str) {
413 if (col_width) { 392 if (col_width) {
@@ -420,7 +399,21 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
420 } 399 }
421 if (!hists__new_col_len(hists, se->se_width_idx, width)) 400 if (!hists__new_col_len(hists, se->se_width_idx, width))
422 width = hists__col_len(hists, se->se_width_idx); 401 width = hists__col_len(hists, se->se_width_idx);
423 fprintf(fp, " %*s", width, se->se_header); 402 }
403
404 if (!show_header)
405 goto print_entries;
406
407 fprintf(fp, "# ");
408
409 perf_hpp__for_each_format(fmt) {
410 if (!first)
411 fprintf(fp, "%s", sep ?: " ");
412 else
413 first = false;
414
415 fmt->header(fmt, &dummy_hpp, hists_to_evsel(hists));
416 fprintf(fp, "%s", bf);
424 } 417 }
425 418
426 fprintf(fp, "\n"); 419 fprintf(fp, "\n");
@@ -447,20 +440,6 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
447 fprintf(fp, "."); 440 fprintf(fp, ".");
448 } 441 }
449 442
450 list_for_each_entry(se, &hist_entry__sort_list, list) {
451 unsigned int i;
452
453 if (se->elide)
454 continue;
455
456 fprintf(fp, " ");
457 width = hists__col_len(hists, se->se_width_idx);
458 if (width == 0)
459 width = strlen(se->se_header);
460 for (i = 0; i < width; i++)
461 fprintf(fp, ".");
462 }
463
464 fprintf(fp, "\n"); 443 fprintf(fp, "\n");
465 if (max_rows && ++nr_rows >= max_rows) 444 if (max_rows && ++nr_rows >= max_rows)
466 goto out; 445 goto out;
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index c99ae4dd973e..ae13c2dbd27a 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -569,7 +569,7 @@ static int hist_entry__sort(struct hist_entry *a, struct hist_entry *b)
569 struct perf_hpp_fmt *fmt; 569 struct perf_hpp_fmt *fmt;
570 int64_t cmp = 0; 570 int64_t cmp = 0;
571 571
572 perf_hpp__for_each_format(fmt) { 572 perf_hpp__for_each_sort_list(fmt) {
573 cmp = fmt->sort(a, b); 573 cmp = fmt->sort(a, b);
574 if (cmp) 574 if (cmp)
575 break; 575 break;
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index eee154a41723..e76d3232672c 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -196,6 +196,7 @@ void perf_hpp__init(void);
196void perf_hpp__column_register(struct perf_hpp_fmt *format); 196void perf_hpp__column_register(struct perf_hpp_fmt *format);
197void perf_hpp__column_enable(unsigned col); 197void perf_hpp__column_enable(unsigned col);
198void perf_hpp__register_sort_field(struct perf_hpp_fmt *format); 198void perf_hpp__register_sort_field(struct perf_hpp_fmt *format);
199void perf_hpp__setup_output_field(void);
199 200
200typedef u64 (*hpp_field_fn)(struct hist_entry *he); 201typedef u64 (*hpp_field_fn)(struct hist_entry *he);
201typedef int (*hpp_callback_fn)(struct perf_hpp *hpp, bool front); 202typedef int (*hpp_callback_fn)(struct perf_hpp *hpp, bool front);