aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@redhat.com>2012-10-12 18:06:16 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2012-12-09 06:46:05 -0500
commit1240005e0d3a7e03c2fd05603fb01676e5a004f7 (patch)
tree055fb08fabe4c5d09c339dc2fb4ac63e741127a8
parent35d48ddfc0627443bd7ad2750a3f65d42cb742a0 (diff)
perf hists: Introduce perf_hpp__list for period related columns
Adding perf_hpp__list list to register and contain all period related columns the command is interested in. This way we get rid of static array holding all possible columns and enable commands to register their own columns. It'll be handy for diff command in future to process and display data for multiple files. Signed-off-by: Jiri Olsa <jolsa@redhat.com> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Ingo Molnar <mingo@elte.hu> Cc: Paul Mackerras <paulus@samba.org> Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Namhyung Kim <namhyung@kernel.org> Link: http://lkml.kernel.org/n/tip-kiykge4igrcl7etmpmveto1h@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/builtin-diff.c21
-rw-r--r--tools/perf/builtin-report.c1
-rw-r--r--tools/perf/ui/browsers/hists.c20
-rw-r--r--tools/perf/ui/gtk/browser.c30
-rw-r--r--tools/perf/ui/hist.c96
-rw-r--r--tools/perf/ui/setup.c1
-rw-r--r--tools/perf/ui/stdio/hist.c17
-rw-r--r--tools/perf/util/hist.h11
8 files changed, 101 insertions, 96 deletions
diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c
index 93b852f8a5d5..9fbbc01c5ad7 100644
--- a/tools/perf/builtin-diff.c
+++ b/tools/perf/builtin-diff.c
@@ -597,40 +597,35 @@ static const struct option options[] = {
597 597
598static void ui_init(void) 598static void ui_init(void)
599{ 599{
600 perf_hpp__init();
601
602 /* No overhead column. */
603 perf_hpp__column_enable(PERF_HPP__OVERHEAD, false);
604
605 /* 600 /*
606 * Display baseline/delta/ratio/displacement/ 601 * Display baseline/delta/ratio/displacement/
607 * formula/periods columns. 602 * formula/periods columns.
608 */ 603 */
609 perf_hpp__column_enable(PERF_HPP__BASELINE, true); 604 perf_hpp__column_enable(PERF_HPP__BASELINE);
610 605
611 switch (compute) { 606 switch (compute) {
612 case COMPUTE_DELTA: 607 case COMPUTE_DELTA:
613 perf_hpp__column_enable(PERF_HPP__DELTA, true); 608 perf_hpp__column_enable(PERF_HPP__DELTA);
614 break; 609 break;
615 case COMPUTE_RATIO: 610 case COMPUTE_RATIO:
616 perf_hpp__column_enable(PERF_HPP__RATIO, true); 611 perf_hpp__column_enable(PERF_HPP__RATIO);
617 break; 612 break;
618 case COMPUTE_WEIGHTED_DIFF: 613 case COMPUTE_WEIGHTED_DIFF:
619 perf_hpp__column_enable(PERF_HPP__WEIGHTED_DIFF, true); 614 perf_hpp__column_enable(PERF_HPP__WEIGHTED_DIFF);
620 break; 615 break;
621 default: 616 default:
622 BUG_ON(1); 617 BUG_ON(1);
623 }; 618 };
624 619
625 if (show_displacement) 620 if (show_displacement)
626 perf_hpp__column_enable(PERF_HPP__DISPL, true); 621 perf_hpp__column_enable(PERF_HPP__DISPL);
627 622
628 if (show_formula) 623 if (show_formula)
629 perf_hpp__column_enable(PERF_HPP__FORMULA, true); 624 perf_hpp__column_enable(PERF_HPP__FORMULA);
630 625
631 if (show_period) { 626 if (show_period) {
632 perf_hpp__column_enable(PERF_HPP__PERIOD, true); 627 perf_hpp__column_enable(PERF_HPP__PERIOD);
633 perf_hpp__column_enable(PERF_HPP__PERIOD_BASELINE, true); 628 perf_hpp__column_enable(PERF_HPP__PERIOD_BASELINE);
634 } 629 }
635} 630}
636 631
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index fc251005dd3d..5134acf1c39a 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -692,6 +692,7 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
692 setup_browser(true); 692 setup_browser(true);
693 else { 693 else {
694 use_browser = 0; 694 use_browser = 0;
695 perf_hpp__column_enable(PERF_HPP__OVERHEAD);
695 perf_hpp__init(); 696 perf_hpp__init();
696 } 697 }
697 698
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index ccc4bd161420..57b82c26cd05 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -587,6 +587,8 @@ HPP__COLOR_FN(overhead_guest_us, period_guest_us)
587 587
588void hist_browser__init_hpp(void) 588void hist_browser__init_hpp(void)
589{ 589{
590 perf_hpp__column_enable(PERF_HPP__OVERHEAD);
591
590 perf_hpp__init(); 592 perf_hpp__init();
591 593
592 perf_hpp__format[PERF_HPP__OVERHEAD].color = 594 perf_hpp__format[PERF_HPP__OVERHEAD].color =
@@ -607,12 +609,13 @@ static int hist_browser__show_entry(struct hist_browser *browser,
607{ 609{
608 char s[256]; 610 char s[256];
609 double percent; 611 double percent;
610 int i, printed = 0; 612 int printed = 0;
611 int width = browser->b.width; 613 int width = browser->b.width;
612 char folded_sign = ' '; 614 char folded_sign = ' ';
613 bool current_entry = ui_browser__is_current_entry(&browser->b, row); 615 bool current_entry = ui_browser__is_current_entry(&browser->b, row);
614 off_t row_offset = entry->row_offset; 616 off_t row_offset = entry->row_offset;
615 bool first = true; 617 bool first = true;
618 struct perf_hpp_fmt *fmt;
616 619
617 if (current_entry) { 620 if (current_entry) {
618 browser->he_selection = entry; 621 browser->he_selection = entry;
@@ -629,12 +632,11 @@ static int hist_browser__show_entry(struct hist_browser *browser,
629 .buf = s, 632 .buf = s,
630 .size = sizeof(s), 633 .size = sizeof(s),
631 }; 634 };
635 int i = 0;
632 636
633 ui_browser__gotorc(&browser->b, row, 0); 637 ui_browser__gotorc(&browser->b, row, 0);
634 638
635 for (i = 0; i < PERF_HPP__MAX_INDEX; i++) { 639 perf_hpp__for_each_format(fmt) {
636 if (!perf_hpp__format[i].cond)
637 continue;
638 640
639 if (!first) { 641 if (!first) {
640 slsmg_printf(" "); 642 slsmg_printf(" ");
@@ -642,14 +644,14 @@ static int hist_browser__show_entry(struct hist_browser *browser,
642 } 644 }
643 first = false; 645 first = false;
644 646
645 if (perf_hpp__format[i].color) { 647 if (fmt->color) {
646 hpp.ptr = &percent; 648 hpp.ptr = &percent;
647 /* It will set percent for us. See HPP__COLOR_FN above. */ 649 /* It will set percent for us. See HPP__COLOR_FN above. */
648 width -= perf_hpp__format[i].color(&hpp, entry); 650 width -= fmt->color(&hpp, entry);
649 651
650 ui_browser__set_percent_color(&browser->b, percent, current_entry); 652 ui_browser__set_percent_color(&browser->b, percent, current_entry);
651 653
652 if (i == PERF_HPP__OVERHEAD && symbol_conf.use_callchain) { 654 if (!i && symbol_conf.use_callchain) {
653 slsmg_printf("%c ", folded_sign); 655 slsmg_printf("%c ", folded_sign);
654 width -= 2; 656 width -= 2;
655 } 657 }
@@ -659,9 +661,11 @@ static int hist_browser__show_entry(struct hist_browser *browser,
659 if (!current_entry || !browser->b.navkeypressed) 661 if (!current_entry || !browser->b.navkeypressed)
660 ui_browser__set_color(&browser->b, HE_COLORSET_NORMAL); 662 ui_browser__set_color(&browser->b, HE_COLORSET_NORMAL);
661 } else { 663 } else {
662 width -= perf_hpp__format[i].entry(&hpp, entry); 664 width -= fmt->entry(&hpp, entry);
663 slsmg_printf("%s", s); 665 slsmg_printf("%s", s);
664 } 666 }
667
668 i++;
665 } 669 }
666 670
667 /* The scroll bar isn't being used */ 671 /* The scroll bar isn't being used */
diff --git a/tools/perf/ui/gtk/browser.c b/tools/perf/ui/gtk/browser.c
index 253b6219a39e..e59ba337f494 100644
--- a/tools/perf/ui/gtk/browser.c
+++ b/tools/perf/ui/gtk/browser.c
@@ -74,6 +74,8 @@ HPP__COLOR_FN(overhead_guest_us, period_guest_us)
74 74
75void perf_gtk__init_hpp(void) 75void perf_gtk__init_hpp(void)
76{ 76{
77 perf_hpp__column_enable(PERF_HPP__OVERHEAD);
78
77 perf_hpp__init(); 79 perf_hpp__init();
78 80
79 perf_hpp__format[PERF_HPP__OVERHEAD].color = 81 perf_hpp__format[PERF_HPP__OVERHEAD].color =
@@ -90,13 +92,14 @@ void perf_gtk__init_hpp(void)
90 92
91static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists) 93static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists)
92{ 94{
95 struct perf_hpp_fmt *fmt;
93 GType col_types[MAX_COLUMNS]; 96 GType col_types[MAX_COLUMNS];
94 GtkCellRenderer *renderer; 97 GtkCellRenderer *renderer;
95 struct sort_entry *se; 98 struct sort_entry *se;
96 GtkListStore *store; 99 GtkListStore *store;
97 struct rb_node *nd; 100 struct rb_node *nd;
98 GtkWidget *view; 101 GtkWidget *view;
99 int i, col_idx; 102 int col_idx;
100 int nr_cols; 103 int nr_cols;
101 char s[512]; 104 char s[512];
102 105
@@ -107,12 +110,8 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists)
107 110
108 nr_cols = 0; 111 nr_cols = 0;
109 112
110 for (i = 0; i < PERF_HPP__MAX_INDEX; i++) { 113 perf_hpp__for_each_format(fmt)
111 if (!perf_hpp__format[i].cond)
112 continue;
113
114 col_types[nr_cols++] = G_TYPE_STRING; 114 col_types[nr_cols++] = G_TYPE_STRING;
115 }
116 115
117 list_for_each_entry(se, &hist_entry__sort_list, list) { 116 list_for_each_entry(se, &hist_entry__sort_list, list) {
118 if (se->elide) 117 if (se->elide)
@@ -129,12 +128,8 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists)
129 128
130 col_idx = 0; 129 col_idx = 0;
131 130
132 for (i = 0; i < PERF_HPP__MAX_INDEX; i++) { 131 perf_hpp__for_each_format(fmt) {
133 if (!perf_hpp__format[i].cond) 132 fmt->header(&hpp);
134 continue;
135
136 perf_hpp__format[i].header(&hpp);
137
138 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view), 133 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
139 -1, s, 134 -1, s,
140 renderer, "markup", 135 renderer, "markup",
@@ -166,14 +161,11 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists)
166 161
167 col_idx = 0; 162 col_idx = 0;
168 163
169 for (i = 0; i < PERF_HPP__MAX_INDEX; i++) { 164 perf_hpp__for_each_format(fmt) {
170 if (!perf_hpp__format[i].cond) 165 if (fmt->color)
171 continue; 166 fmt->color(&hpp, h);
172
173 if (perf_hpp__format[i].color)
174 perf_hpp__format[i].color(&hpp, h);
175 else 167 else
176 perf_hpp__format[i].entry(&hpp, h); 168 fmt->entry(&hpp, h);
177 169
178 gtk_list_store_set(store, &iter, col_idx++, s, -1); 170 gtk_list_store_set(store, &iter, col_idx++, s, -1);
179 } 171 }
diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c
index aa84130024d5..0a5281fe41d6 100644
--- a/tools/perf/ui/hist.c
+++ b/tools/perf/ui/hist.c
@@ -386,60 +386,71 @@ static int hpp__entry_formula(struct perf_hpp *hpp, struct hist_entry *he)
386 return scnprintf(hpp->buf, hpp->size, fmt, buf); 386 return scnprintf(hpp->buf, hpp->size, fmt, buf);
387} 387}
388 388
389#define HPP__COLOR_PRINT_FNS(_name) \ 389#define HPP__COLOR_PRINT_FNS(_name) \
390 .header = hpp__header_ ## _name, \ 390 { \
391 .width = hpp__width_ ## _name, \ 391 .header = hpp__header_ ## _name, \
392 .color = hpp__color_ ## _name, \ 392 .width = hpp__width_ ## _name, \
393 .entry = hpp__entry_ ## _name 393 .color = hpp__color_ ## _name, \
394 .entry = hpp__entry_ ## _name \
395 }
394 396
395#define HPP__PRINT_FNS(_name) \ 397#define HPP__PRINT_FNS(_name) \
396 .header = hpp__header_ ## _name, \ 398 { \
397 .width = hpp__width_ ## _name, \ 399 .header = hpp__header_ ## _name, \
398 .entry = hpp__entry_ ## _name 400 .width = hpp__width_ ## _name, \
401 .entry = hpp__entry_ ## _name \
402 }
399 403
400struct perf_hpp_fmt perf_hpp__format[] = { 404struct perf_hpp_fmt perf_hpp__format[] = {
401 { .cond = false, HPP__COLOR_PRINT_FNS(baseline) }, 405 HPP__COLOR_PRINT_FNS(baseline),
402 { .cond = true, HPP__COLOR_PRINT_FNS(overhead) }, 406 HPP__COLOR_PRINT_FNS(overhead),
403 { .cond = false, HPP__COLOR_PRINT_FNS(overhead_sys) }, 407 HPP__COLOR_PRINT_FNS(overhead_sys),
404 { .cond = false, HPP__COLOR_PRINT_FNS(overhead_us) }, 408 HPP__COLOR_PRINT_FNS(overhead_us),
405 { .cond = false, HPP__COLOR_PRINT_FNS(overhead_guest_sys) }, 409 HPP__COLOR_PRINT_FNS(overhead_guest_sys),
406 { .cond = false, HPP__COLOR_PRINT_FNS(overhead_guest_us) }, 410 HPP__COLOR_PRINT_FNS(overhead_guest_us),
407 { .cond = false, HPP__PRINT_FNS(samples) }, 411 HPP__PRINT_FNS(samples),
408 { .cond = false, HPP__PRINT_FNS(period) }, 412 HPP__PRINT_FNS(period),
409 { .cond = false, HPP__PRINT_FNS(period_baseline) }, 413 HPP__PRINT_FNS(period_baseline),
410 { .cond = false, HPP__PRINT_FNS(delta) }, 414 HPP__PRINT_FNS(delta),
411 { .cond = false, HPP__PRINT_FNS(ratio) }, 415 HPP__PRINT_FNS(ratio),
412 { .cond = false, HPP__PRINT_FNS(wdiff) }, 416 HPP__PRINT_FNS(wdiff),
413 { .cond = false, HPP__PRINT_FNS(displ) }, 417 HPP__PRINT_FNS(displ),
414 { .cond = false, HPP__PRINT_FNS(formula) } 418 HPP__PRINT_FNS(formula)
415}; 419};
416 420
421LIST_HEAD(perf_hpp__list);
422
417#undef HPP__COLOR_PRINT_FNS 423#undef HPP__COLOR_PRINT_FNS
418#undef HPP__PRINT_FNS 424#undef HPP__PRINT_FNS
419 425
420void perf_hpp__init(void) 426void perf_hpp__init(void)
421{ 427{
422 if (symbol_conf.show_cpu_utilization) { 428 if (symbol_conf.show_cpu_utilization) {
423 perf_hpp__format[PERF_HPP__OVERHEAD_SYS].cond = true; 429 perf_hpp__column_enable(PERF_HPP__OVERHEAD_SYS);
424 perf_hpp__format[PERF_HPP__OVERHEAD_US].cond = true; 430 perf_hpp__column_enable(PERF_HPP__OVERHEAD_US);
425 431
426 if (perf_guest) { 432 if (perf_guest) {
427 perf_hpp__format[PERF_HPP__OVERHEAD_GUEST_SYS].cond = true; 433 perf_hpp__column_enable(PERF_HPP__OVERHEAD_GUEST_SYS);
428 perf_hpp__format[PERF_HPP__OVERHEAD_GUEST_US].cond = true; 434 perf_hpp__column_enable(PERF_HPP__OVERHEAD_GUEST_US);
429 } 435 }
430 } 436 }
431 437
432 if (symbol_conf.show_nr_samples) 438 if (symbol_conf.show_nr_samples)
433 perf_hpp__format[PERF_HPP__SAMPLES].cond = true; 439 perf_hpp__column_enable(PERF_HPP__SAMPLES);
434 440
435 if (symbol_conf.show_total_period) 441 if (symbol_conf.show_total_period)
436 perf_hpp__format[PERF_HPP__PERIOD].cond = true; 442 perf_hpp__column_enable(PERF_HPP__PERIOD);
437} 443}
438 444
439void perf_hpp__column_enable(unsigned col, bool enable) 445void perf_hpp__column_register(struct perf_hpp_fmt *format)
446{
447 list_add_tail(&format->list, &perf_hpp__list);
448}
449
450void perf_hpp__column_enable(unsigned col)
440{ 451{
441 BUG_ON(col >= PERF_HPP__MAX_INDEX); 452 BUG_ON(col >= PERF_HPP__MAX_INDEX);
442 perf_hpp__format[col].cond = enable; 453 perf_hpp__column_register(&perf_hpp__format[col]);
443} 454}
444 455
445static inline void advance_hpp(struct perf_hpp *hpp, int inc) 456static inline void advance_hpp(struct perf_hpp *hpp, int inc)
@@ -452,27 +463,25 @@ int hist_entry__period_snprintf(struct perf_hpp *hpp, struct hist_entry *he,
452 bool color) 463 bool color)
453{ 464{
454 const char *sep = symbol_conf.field_sep; 465 const char *sep = symbol_conf.field_sep;
466 struct perf_hpp_fmt *fmt;
455 char *start = hpp->buf; 467 char *start = hpp->buf;
456 int i, ret; 468 int ret;
457 bool first = true; 469 bool first = true;
458 470
459 if (symbol_conf.exclude_other && !he->parent) 471 if (symbol_conf.exclude_other && !he->parent)
460 return 0; 472 return 0;
461 473
462 for (i = 0; i < PERF_HPP__MAX_INDEX; i++) { 474 perf_hpp__for_each_format(fmt) {
463 if (!perf_hpp__format[i].cond)
464 continue;
465
466 if (!sep || !first) { 475 if (!sep || !first) {
467 ret = scnprintf(hpp->buf, hpp->size, "%s", sep ?: " "); 476 ret = scnprintf(hpp->buf, hpp->size, "%s", sep ?: " ");
468 advance_hpp(hpp, ret); 477 advance_hpp(hpp, ret);
469 first = false; 478 first = false;
470 } 479 }
471 480
472 if (color && perf_hpp__format[i].color) 481 if (color && fmt->color)
473 ret = perf_hpp__format[i].color(hpp, he); 482 ret = fmt->color(hpp, he);
474 else 483 else
475 ret = perf_hpp__format[i].entry(hpp, he); 484 ret = fmt->entry(hpp, he);
476 485
477 advance_hpp(hpp, ret); 486 advance_hpp(hpp, ret);
478 } 487 }
@@ -504,16 +513,15 @@ int hist_entry__sort_snprintf(struct hist_entry *he, char *s, size_t size,
504 */ 513 */
505unsigned int hists__sort_list_width(struct hists *hists) 514unsigned int hists__sort_list_width(struct hists *hists)
506{ 515{
516 struct perf_hpp_fmt *fmt;
507 struct sort_entry *se; 517 struct sort_entry *se;
508 int i, ret = 0; 518 int i = 0, ret = 0;
509 519
510 for (i = 0; i < PERF_HPP__MAX_INDEX; i++) { 520 perf_hpp__for_each_format(fmt) {
511 if (!perf_hpp__format[i].cond)
512 continue;
513 if (i) 521 if (i)
514 ret += 2; 522 ret += 2;
515 523
516 ret += perf_hpp__format[i].width(NULL); 524 ret += fmt->width(NULL);
517 } 525 }
518 526
519 list_for_each_entry(se, &hist_entry__sort_list, list) 527 list_for_each_entry(se, &hist_entry__sort_list, list)
diff --git a/tools/perf/ui/setup.c b/tools/perf/ui/setup.c
index ebb4cc107876..166f13df3134 100644
--- a/tools/perf/ui/setup.c
+++ b/tools/perf/ui/setup.c
@@ -30,6 +30,7 @@ void setup_browser(bool fallback_to_pager)
30 if (fallback_to_pager) 30 if (fallback_to_pager)
31 setup_pager(); 31 setup_pager();
32 32
33 perf_hpp__column_enable(PERF_HPP__OVERHEAD);
33 perf_hpp__init(); 34 perf_hpp__init();
34 break; 35 break;
35 } 36 }
diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c
index f0ee204f99bb..0eae3b2c32f2 100644
--- a/tools/perf/ui/stdio/hist.c
+++ b/tools/perf/ui/stdio/hist.c
@@ -335,13 +335,14 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size,
335size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows, 335size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
336 int max_cols, FILE *fp) 336 int max_cols, FILE *fp)
337{ 337{
338 struct perf_hpp_fmt *fmt;
338 struct sort_entry *se; 339 struct sort_entry *se;
339 struct rb_node *nd; 340 struct rb_node *nd;
340 size_t ret = 0; 341 size_t ret = 0;
341 unsigned int width; 342 unsigned int width;
342 const char *sep = symbol_conf.field_sep; 343 const char *sep = symbol_conf.field_sep;
343 const char *col_width = symbol_conf.col_width_list_str; 344 const char *col_width = symbol_conf.col_width_list_str;
344 int idx, nr_rows = 0; 345 int nr_rows = 0;
345 char bf[96]; 346 char bf[96];
346 struct perf_hpp dummy_hpp = { 347 struct perf_hpp dummy_hpp = {
347 .buf = bf, 348 .buf = bf,
@@ -355,16 +356,14 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
355 goto print_entries; 356 goto print_entries;
356 357
357 fprintf(fp, "# "); 358 fprintf(fp, "# ");
358 for (idx = 0; idx < PERF_HPP__MAX_INDEX; idx++) {
359 if (!perf_hpp__format[idx].cond)
360 continue;
361 359
360 perf_hpp__for_each_format(fmt) {
362 if (!first) 361 if (!first)
363 fprintf(fp, "%s", sep ?: " "); 362 fprintf(fp, "%s", sep ?: " ");
364 else 363 else
365 first = false; 364 first = false;
366 365
367 perf_hpp__format[idx].header(&dummy_hpp); 366 fmt->header(&dummy_hpp);
368 fprintf(fp, "%s", bf); 367 fprintf(fp, "%s", bf);
369 } 368 }
370 369
@@ -400,18 +399,16 @@ size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
400 first = true; 399 first = true;
401 400
402 fprintf(fp, "# "); 401 fprintf(fp, "# ");
403 for (idx = 0; idx < PERF_HPP__MAX_INDEX; idx++) {
404 unsigned int i;
405 402
406 if (!perf_hpp__format[idx].cond) 403 perf_hpp__for_each_format(fmt) {
407 continue; 404 unsigned int i;
408 405
409 if (!first) 406 if (!first)
410 fprintf(fp, "%s", sep ?: " "); 407 fprintf(fp, "%s", sep ?: " ");
411 else 408 else
412 first = false; 409 first = false;
413 410
414 width = perf_hpp__format[idx].width(&dummy_hpp); 411 width = fmt->width(&dummy_hpp);
415 for (i = 0; i < width; i++) 412 for (i = 0; i < width; i++)
416 fprintf(fp, "."); 413 fprintf(fp, ".");
417 } 414 }
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index 8b091a51e4a2..a935a60d521c 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -126,13 +126,19 @@ struct perf_hpp {
126}; 126};
127 127
128struct perf_hpp_fmt { 128struct perf_hpp_fmt {
129 bool cond;
130 int (*header)(struct perf_hpp *hpp); 129 int (*header)(struct perf_hpp *hpp);
131 int (*width)(struct perf_hpp *hpp); 130 int (*width)(struct perf_hpp *hpp);
132 int (*color)(struct perf_hpp *hpp, struct hist_entry *he); 131 int (*color)(struct perf_hpp *hpp, struct hist_entry *he);
133 int (*entry)(struct perf_hpp *hpp, struct hist_entry *he); 132 int (*entry)(struct perf_hpp *hpp, struct hist_entry *he);
133
134 struct list_head list;
134}; 135};
135 136
137extern struct list_head perf_hpp__list;
138
139#define perf_hpp__for_each_format(format) \
140 list_for_each_entry(format, &perf_hpp__list, list)
141
136extern struct perf_hpp_fmt perf_hpp__format[]; 142extern struct perf_hpp_fmt perf_hpp__format[];
137 143
138enum { 144enum {
@@ -155,7 +161,8 @@ enum {
155}; 161};
156 162
157void perf_hpp__init(void); 163void perf_hpp__init(void);
158void perf_hpp__column_enable(unsigned col, bool enable); 164void perf_hpp__column_register(struct perf_hpp_fmt *format);
165void perf_hpp__column_enable(unsigned col);
159int hist_entry__period_snprintf(struct perf_hpp *hpp, struct hist_entry *he, 166int hist_entry__period_snprintf(struct perf_hpp *hpp, struct hist_entry *he,
160 bool color); 167 bool color);
161 168