Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tools: Introduce struct hist_browser_timer

Currently various hist browser functions receive 3 arguments for
refreshing histogram but only used from a few places. Also it's only
for perf top command so that it can be NULL for other (and probably
most) cases. Pack them into a struct in order to reduce number of those
unused arguments.

This is a mechanical change and does not intend a functional change.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Tested-by: David Ahern <dsahern@gmail.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Irina Tirdea <irina.tirdea@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1351835406-15208-2-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Namhyung Kim and committed by
Arnaldo Carvalho de Melo
9783adf7 48ed0ece

+58 -67
+1 -1
tools/perf/builtin-annotate.c
··· 139 139 } 140 140 141 141 if (use_browser > 0) { 142 - key = hist_entry__tui_annotate(he, evidx, NULL, NULL, 0); 142 + key = hist_entry__tui_annotate(he, evidx, NULL); 143 143 switch (key) { 144 144 case K_RIGHT: 145 145 next = rb_next(nd);
+2 -2
tools/perf/builtin-report.c
··· 428 428 if (use_browser > 0) { 429 429 if (use_browser == 1) { 430 430 perf_evlist__tui_browse_hists(session->evlist, help, 431 - NULL, NULL, 0); 431 + NULL); 432 432 } else if (use_browser == 2) { 433 433 perf_evlist__gtk_browse_hists(session->evlist, help, 434 - NULL, NULL, 0); 434 + NULL); 435 435 } 436 436 } else 437 437 perf_evlist__tty_browse_hists(session->evlist, rep, help);
+6 -3
tools/perf/builtin-top.c
··· 582 582 struct perf_evsel *pos; 583 583 struct perf_top *top = arg; 584 584 const char *help = "For a higher level overview, try: perf top --sort comm,dso"; 585 + struct hist_browser_timer hbt = { 586 + .timer = perf_top__sort_new_samples, 587 + .arg = top, 588 + .refresh = top->delay_secs, 589 + }; 585 590 586 591 perf_top__sort_new_samples(top); 587 592 ··· 598 593 list_for_each_entry(pos, &top->evlist->entries, node) 599 594 pos->hists.uid_filter_str = top->target.uid_str; 600 595 601 - perf_evlist__tui_browse_hists(top->evlist, help, 602 - perf_top__sort_new_samples, 603 - top, top->delay_secs); 596 + perf_evlist__tui_browse_hists(top->evlist, help, &hbt); 604 597 605 598 exit_browser(0); 606 599 exit(0);
+12 -15
tools/perf/ui/browsers/annotate.c
··· 386 386 browser->b.nr_entries = browser->nr_asm_entries; 387 387 } 388 388 389 - static bool annotate_browser__callq(struct annotate_browser *browser, 390 - int evidx, void (*timer)(void *arg), 391 - void *arg, int delay_secs) 389 + static bool annotate_browser__callq(struct annotate_browser *browser, int evidx, 390 + struct hist_browser_timer *hbt) 392 391 { 393 392 struct map_symbol *ms = browser->b.priv; 394 393 struct disasm_line *dl = browser->selection; ··· 417 418 } 418 419 419 420 pthread_mutex_unlock(&notes->lock); 420 - symbol__tui_annotate(target, ms->map, evidx, timer, arg, delay_secs); 421 + symbol__tui_annotate(target, ms->map, evidx, hbt); 421 422 ui_browser__show_title(&browser->b, sym->name); 422 423 return true; 423 424 } ··· 601 602 } 602 603 603 604 static int annotate_browser__run(struct annotate_browser *browser, int evidx, 604 - void(*timer)(void *arg), 605 - void *arg, int delay_secs) 605 + struct hist_browser_timer *hbt) 606 606 { 607 607 struct rb_node *nd = NULL; 608 608 struct map_symbol *ms = browser->b.priv; 609 609 struct symbol *sym = ms->sym; 610 610 const char *help = "Press 'h' for help on key bindings"; 611 + int delay_secs = hbt ? hbt->refresh : 0; 611 612 int key; 612 613 613 614 if (ui_browser__show(&browser->b, sym->name, help) < 0) ··· 638 639 639 640 switch (key) { 640 641 case K_TIMER: 641 - if (timer != NULL) 642 - timer(arg); 642 + if (hbt) 643 + hbt->timer(hbt->arg); 643 644 644 645 if (delay_secs != 0) 645 646 symbol__annotate_decay_histogram(sym, evidx); ··· 739 740 goto show_sup_ins; 740 741 goto out; 741 742 } else if (!(annotate_browser__jump(browser) || 742 - annotate_browser__callq(browser, evidx, timer, arg, delay_secs))) { 743 + annotate_browser__callq(browser, evidx, hbt))) { 743 744 show_sup_ins: 744 745 ui_helpline__puts("Actions are only available for 'callq', 'retq' & jump instructions."); 745 746 } ··· 762 763 } 763 764 764 765 int hist_entry__tui_annotate(struct hist_entry *he, int evidx, 765 - void(*timer)(void *arg), void *arg, int delay_secs) 766 + struct hist_browser_timer *hbt) 766 767 { 767 - return symbol__tui_annotate(he->ms.sym, he->ms.map, evidx, 768 - timer, arg, delay_secs); 768 + return symbol__tui_annotate(he->ms.sym, he->ms.map, evidx, hbt); 769 769 } 770 770 771 771 static void annotate_browser__mark_jump_targets(struct annotate_browser *browser, ··· 814 816 } 815 817 816 818 int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx, 817 - void(*timer)(void *arg), void *arg, 818 - int delay_secs) 819 + struct hist_browser_timer *hbt) 819 820 { 820 821 struct disasm_line *pos, *n; 821 822 struct annotation *notes; ··· 896 899 897 900 annotate_browser__update_addr_width(&browser); 898 901 899 - ret = annotate_browser__run(&browser, evidx, timer, arg, delay_secs); 902 + ret = annotate_browser__run(&browser, evidx, hbt); 900 903 list_for_each_entry_safe(pos, n, &notes->src->source, node) { 901 904 list_del(&pos->node); 902 905 disasm_line__free(pos);
+19 -24
tools/perf/ui/browsers/hists.c
··· 310 310 } 311 311 312 312 static int hist_browser__run(struct hist_browser *browser, const char *ev_name, 313 - void(*timer)(void *arg), void *arg, int delay_secs) 313 + struct hist_browser_timer *hbt) 314 314 { 315 315 int key; 316 316 char title[160]; 317 + int delay_secs = hbt ? hbt->refresh : 0; 317 318 318 319 browser->b.entries = &browser->hists->entries; 319 320 browser->b.nr_entries = browser->hists->nr_entries; ··· 331 330 332 331 switch (key) { 333 332 case K_TIMER: 334 - timer(arg); 333 + hbt->timer(hbt->arg); 335 334 ui_browser__update_nr_entries(&browser->b, browser->hists->nr_entries); 336 335 337 336 if (browser->hists->stats.nr_lost_warned != ··· 1137 1136 static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, 1138 1137 const char *helpline, const char *ev_name, 1139 1138 bool left_exits, 1140 - void(*timer)(void *arg), void *arg, 1141 - int delay_secs) 1139 + struct hist_browser_timer *hbt) 1142 1140 { 1143 1141 struct hists *hists = &evsel->hists; 1144 1142 struct hist_browser *browser = hist_browser__new(hists); ··· 1148 1148 int key = -1; 1149 1149 char buf[64]; 1150 1150 char script_opt[64]; 1151 + int delay_secs = hbt ? hbt->refresh : 0; 1151 1152 1152 1153 if (browser == NULL) 1153 1154 return -1; ··· 1171 1170 1172 1171 nr_options = 0; 1173 1172 1174 - key = hist_browser__run(browser, ev_name, timer, arg, delay_secs); 1173 + key = hist_browser__run(browser, ev_name, hbt); 1175 1174 1176 1175 if (browser->he_selection != NULL) { 1177 1176 thread = hist_browser__selected_thread(browser); ··· 1221 1220 } 1222 1221 continue; 1223 1222 case 'r': 1224 - if (is_report_browser(timer)) 1223 + if (is_report_browser(hbt)) 1225 1224 goto do_scripts; 1226 1225 continue; 1227 1226 case K_F1: ··· 1389 1388 * Don't let this be freed, say, by hists__decay_entry. 1390 1389 */ 1391 1390 he->used = true; 1392 - err = hist_entry__tui_annotate(he, evsel->idx, 1393 - timer, arg, delay_secs); 1391 + err = hist_entry__tui_annotate(he, evsel->idx, hbt); 1394 1392 he->used = false; 1395 1393 /* 1396 1394 * offer option to annotate the other branch source or target ··· 1512 1512 1513 1513 static int perf_evsel_menu__run(struct perf_evsel_menu *menu, 1514 1514 int nr_events, const char *help, 1515 - void(*timer)(void *arg), void *arg, int delay_secs) 1515 + struct hist_browser_timer *hbt) 1516 1516 { 1517 1517 struct perf_evlist *evlist = menu->b.priv; 1518 1518 struct perf_evsel *pos; 1519 1519 const char *ev_name, *title = "Available samples"; 1520 + int delay_secs = hbt ? hbt->refresh : 0; 1520 1521 int key; 1521 1522 1522 1523 if (ui_browser__show(&menu->b, title, ··· 1529 1528 1530 1529 switch (key) { 1531 1530 case K_TIMER: 1532 - timer(arg); 1531 + hbt->timer(hbt->arg); 1533 1532 1534 1533 if (!menu->lost_events_warned && menu->lost_events) { 1535 1534 ui_browser__warn_lost_events(&menu->b); ··· 1547 1546 * Give the calling tool a chance to populate the non 1548 1547 * default evsel resorted hists tree. 1549 1548 */ 1550 - if (timer) 1551 - timer(arg); 1549 + if (hbt) 1550 + hbt->timer(hbt->arg); 1552 1551 ev_name = perf_evsel__name(pos); 1553 1552 key = perf_evsel__hists_browse(pos, nr_events, help, 1554 - ev_name, true, timer, 1555 - arg, delay_secs); 1553 + ev_name, true, hbt); 1556 1554 ui_browser__show_title(&menu->b, title); 1557 1555 switch (key) { 1558 1556 case K_TAB: ··· 1599 1599 1600 1600 static int __perf_evlist__tui_browse_hists(struct perf_evlist *evlist, 1601 1601 const char *help, 1602 - void(*timer)(void *arg), void *arg, 1603 - int delay_secs) 1602 + struct hist_browser_timer *hbt) 1604 1603 { 1605 1604 struct perf_evsel *pos; 1606 1605 struct perf_evsel_menu menu = { ··· 1623 1624 menu.b.width = line_len; 1624 1625 } 1625 1626 1626 - return perf_evsel_menu__run(&menu, evlist->nr_entries, help, timer, 1627 - arg, delay_secs); 1627 + return perf_evsel_menu__run(&menu, evlist->nr_entries, help, hbt); 1628 1628 } 1629 1629 1630 1630 int perf_evlist__tui_browse_hists(struct perf_evlist *evlist, const char *help, 1631 - void(*timer)(void *arg), void *arg, 1632 - int delay_secs) 1631 + struct hist_browser_timer *hbt) 1633 1632 { 1634 1633 if (evlist->nr_entries == 1) { 1635 1634 struct perf_evsel *first = list_entry(evlist->entries.next, 1636 1635 struct perf_evsel, node); 1637 1636 const char *ev_name = perf_evsel__name(first); 1638 1637 return perf_evsel__hists_browse(first, evlist->nr_entries, help, 1639 - ev_name, false, timer, arg, 1640 - delay_secs); 1638 + ev_name, false, hbt); 1641 1639 } 1642 1640 1643 - return __perf_evlist__tui_browse_hists(evlist, help, 1644 - timer, arg, delay_secs); 1641 + return __perf_evlist__tui_browse_hists(evlist, help, hbt); 1645 1642 }
+1 -3
tools/perf/ui/gtk/browser.c
··· 237 237 238 238 int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist, 239 239 const char *help, 240 - void (*timer) (void *arg)__maybe_unused, 241 - void *arg __maybe_unused, 242 - int delay_secs __maybe_unused) 240 + struct hist_browser_timer *hbt __maybe_unused) 243 241 { 244 242 struct perf_evsel *pos; 245 243 GtkWidget *vbox;
+4 -4
tools/perf/util/annotate.h
··· 5 5 #include <stdint.h> 6 6 #include "types.h" 7 7 #include "symbol.h" 8 + #include "hist.h" 8 9 #include <linux/list.h> 9 10 #include <linux/rbtree.h> 10 11 #include <pthread.h> ··· 141 140 142 141 #ifdef NEWT_SUPPORT 143 142 int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx, 144 - void(*timer)(void *arg), void *arg, int delay_secs); 143 + struct hist_browser_timer *hbt); 145 144 #else 146 145 static inline int symbol__tui_annotate(struct symbol *sym __maybe_unused, 147 146 struct map *map __maybe_unused, 148 147 int evidx __maybe_unused, 149 - void(*timer)(void *arg) __maybe_unused, 150 - void *arg __maybe_unused, 151 - int delay_secs __maybe_unused) 148 + struct hist_browser_timer *hbt 149 + __maybe_unused) 152 150 { 153 151 return 0; 154 152 }
+13 -15
tools/perf/util/hist.h
··· 157 157 158 158 struct perf_evlist; 159 159 160 + struct hist_browser_timer { 161 + void (*timer)(void *arg); 162 + void *arg; 163 + int refresh; 164 + }; 165 + 160 166 #ifdef NEWT_SUPPORT 161 167 #include "../ui/keysyms.h" 162 168 int hist_entry__tui_annotate(struct hist_entry *he, int evidx, 163 - void(*timer)(void *arg), void *arg, int delay_secs); 169 + struct hist_browser_timer *hbt); 164 170 165 171 int perf_evlist__tui_browse_hists(struct perf_evlist *evlist, const char *help, 166 - void(*timer)(void *arg), void *arg, 167 - int refresh); 172 + struct hist_browser_timer *hbt); 168 173 int script_browse(const char *script_opt); 169 174 #else 170 175 static inline 171 176 int perf_evlist__tui_browse_hists(struct perf_evlist *evlist __maybe_unused, 172 177 const char *help __maybe_unused, 173 - void(*timer)(void *arg) __maybe_unused, 174 - void *arg __maybe_unused, 175 - int refresh __maybe_unused) 178 + struct hist_browser_timer *hbt __maybe_unused) 176 179 { 177 180 return 0; 178 181 } ··· 183 180 static inline int hist_entry__tui_annotate(struct hist_entry *self 184 181 __maybe_unused, 185 182 int evidx __maybe_unused, 186 - void(*timer)(void *arg) 187 - __maybe_unused, 188 - void *arg __maybe_unused, 189 - int delay_secs __maybe_unused) 183 + struct hist_browser_timer *hbt 184 + __maybe_unused) 190 185 { 191 186 return 0; 192 187 } ··· 200 199 201 200 #ifdef GTK2_SUPPORT 202 201 int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist, const char *help, 203 - void(*timer)(void *arg), void *arg, 204 - int refresh); 202 + struct hist_browser_timer *hbt __maybe_unused); 205 203 #else 206 204 static inline 207 205 int perf_evlist__gtk_browse_hists(struct perf_evlist *evlist __maybe_unused, 208 206 const char *help __maybe_unused, 209 - void(*timer)(void *arg) __maybe_unused, 210 - void *arg __maybe_unused, 211 - int refresh __maybe_unused) 207 + struct hist_browser_timer *hbt __maybe_unused) 212 208 { 213 209 return 0; 214 210 }