diff options
| -rw-r--r-- | tools/perf/ui/browsers/hists.c | 83 |
1 files changed, 72 insertions, 11 deletions
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index aef800d97ea1..f98aeac607dd 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include <string.h> | 7 | #include <string.h> |
| 8 | #include <linux/rbtree.h> | 8 | #include <linux/rbtree.h> |
| 9 | #include <sys/ttydefaults.h> | 9 | #include <sys/ttydefaults.h> |
| 10 | #include <linux/time64.h> | ||
| 10 | 11 | ||
| 11 | #include "../../util/callchain.h" | 12 | #include "../../util/callchain.h" |
| 12 | #include "../../util/evsel.h" | 13 | #include "../../util/evsel.h" |
| @@ -30,6 +31,7 @@ | |||
| 30 | #include "srcline.h" | 31 | #include "srcline.h" |
| 31 | #include "string2.h" | 32 | #include "string2.h" |
| 32 | #include "units.h" | 33 | #include "units.h" |
| 34 | #include "time-utils.h" | ||
| 33 | 35 | ||
| 34 | #include "sane_ctype.h" | 36 | #include "sane_ctype.h" |
| 35 | 37 | ||
| @@ -2338,6 +2340,7 @@ close_file_and_continue: | |||
| 2338 | } | 2340 | } |
| 2339 | 2341 | ||
| 2340 | struct popup_action { | 2342 | struct popup_action { |
| 2343 | unsigned long time; | ||
| 2341 | struct thread *thread; | 2344 | struct thread *thread; |
| 2342 | struct map_symbol ms; | 2345 | struct map_symbol ms; |
| 2343 | int socket; | 2346 | int socket; |
| @@ -2527,36 +2530,64 @@ static int | |||
| 2527 | do_run_script(struct hist_browser *browser __maybe_unused, | 2530 | do_run_script(struct hist_browser *browser __maybe_unused, |
| 2528 | struct popup_action *act) | 2531 | struct popup_action *act) |
| 2529 | { | 2532 | { |
| 2530 | char script_opt[64]; | 2533 | char *script_opt; |
| 2531 | memset(script_opt, 0, sizeof(script_opt)); | 2534 | int len; |
| 2535 | int n = 0; | ||
| 2536 | |||
| 2537 | len = 100; | ||
| 2538 | if (act->thread) | ||
| 2539 | len += strlen(thread__comm_str(act->thread)); | ||
| 2540 | else if (act->ms.sym) | ||
| 2541 | len += strlen(act->ms.sym->name); | ||
| 2542 | script_opt = malloc(len); | ||
| 2543 | if (!script_opt) | ||
| 2544 | return -1; | ||
| 2532 | 2545 | ||
| 2546 | script_opt[0] = 0; | ||
| 2533 | if (act->thread) { | 2547 | if (act->thread) { |
| 2534 | scnprintf(script_opt, sizeof(script_opt), " -c %s ", | 2548 | n = scnprintf(script_opt, len, " -c %s ", |
| 2535 | thread__comm_str(act->thread)); | 2549 | thread__comm_str(act->thread)); |
| 2536 | } else if (act->ms.sym) { | 2550 | } else if (act->ms.sym) { |
| 2537 | scnprintf(script_opt, sizeof(script_opt), " -S %s ", | 2551 | n = scnprintf(script_opt, len, " -S %s ", |
| 2538 | act->ms.sym->name); | 2552 | act->ms.sym->name); |
| 2539 | } | 2553 | } |
| 2540 | 2554 | ||
| 2555 | if (act->time) { | ||
| 2556 | char start[32], end[32]; | ||
| 2557 | unsigned long starttime = act->time; | ||
| 2558 | unsigned long endtime = act->time + symbol_conf.time_quantum; | ||
| 2559 | |||
| 2560 | if (starttime == endtime) { /* Display 1ms as fallback */ | ||
| 2561 | starttime -= 1*NSEC_PER_MSEC; | ||
| 2562 | endtime += 1*NSEC_PER_MSEC; | ||
| 2563 | } | ||
| 2564 | timestamp__scnprintf_usec(starttime, start, sizeof start); | ||
| 2565 | timestamp__scnprintf_usec(endtime, end, sizeof end); | ||
| 2566 | n += snprintf(script_opt + n, len - n, " --time %s,%s", start, end); | ||
| 2567 | } | ||
| 2568 | |||
| 2541 | script_browse(script_opt); | 2569 | script_browse(script_opt); |
| 2570 | free(script_opt); | ||
| 2542 | return 0; | 2571 | return 0; |
| 2543 | } | 2572 | } |
| 2544 | 2573 | ||
| 2545 | static int | 2574 | static int |
| 2546 | add_script_opt(struct hist_browser *browser __maybe_unused, | 2575 | add_script_opt_2(struct hist_browser *browser __maybe_unused, |
| 2547 | struct popup_action *act, char **optstr, | 2576 | struct popup_action *act, char **optstr, |
| 2548 | struct thread *thread, struct symbol *sym) | 2577 | struct thread *thread, struct symbol *sym, |
| 2578 | const char *tstr) | ||
| 2549 | { | 2579 | { |
| 2580 | |||
| 2550 | if (thread) { | 2581 | if (thread) { |
| 2551 | if (asprintf(optstr, "Run scripts for samples of thread [%s]", | 2582 | if (asprintf(optstr, "Run scripts for samples of thread [%s]%s", |
| 2552 | thread__comm_str(thread)) < 0) | 2583 | thread__comm_str(thread), tstr) < 0) |
| 2553 | return 0; | 2584 | return 0; |
| 2554 | } else if (sym) { | 2585 | } else if (sym) { |
| 2555 | if (asprintf(optstr, "Run scripts for samples of symbol [%s]", | 2586 | if (asprintf(optstr, "Run scripts for samples of symbol [%s]%s", |
| 2556 | sym->name) < 0) | 2587 | sym->name, tstr) < 0) |
| 2557 | return 0; | 2588 | return 0; |
| 2558 | } else { | 2589 | } else { |
| 2559 | if (asprintf(optstr, "Run scripts for all samples") < 0) | 2590 | if (asprintf(optstr, "Run scripts for all samples%s", tstr) < 0) |
| 2560 | return 0; | 2591 | return 0; |
| 2561 | } | 2592 | } |
| 2562 | 2593 | ||
| @@ -2567,6 +2598,36 @@ add_script_opt(struct hist_browser *browser __maybe_unused, | |||
| 2567 | } | 2598 | } |
| 2568 | 2599 | ||
| 2569 | static int | 2600 | static int |
| 2601 | add_script_opt(struct hist_browser *browser, | ||
| 2602 | struct popup_action *act, char **optstr, | ||
| 2603 | struct thread *thread, struct symbol *sym) | ||
| 2604 | { | ||
| 2605 | int n, j; | ||
| 2606 | struct hist_entry *he; | ||
| 2607 | |||
| 2608 | n = add_script_opt_2(browser, act, optstr, thread, sym, ""); | ||
| 2609 | |||
| 2610 | he = hist_browser__selected_entry(browser); | ||
| 2611 | if (sort_order && strstr(sort_order, "time")) { | ||
| 2612 | char tstr[128]; | ||
| 2613 | |||
| 2614 | optstr++; | ||
| 2615 | act++; | ||
| 2616 | j = sprintf(tstr, " in "); | ||
| 2617 | j += timestamp__scnprintf_usec(he->time, tstr + j, | ||
| 2618 | sizeof tstr - j); | ||
| 2619 | j += sprintf(tstr + j, "-"); | ||
| 2620 | timestamp__scnprintf_usec(he->time + symbol_conf.time_quantum, | ||
| 2621 | tstr + j, | ||
| 2622 | sizeof tstr - j); | ||
| 2623 | n += add_script_opt_2(browser, act, optstr, thread, sym, | ||
| 2624 | tstr); | ||
| 2625 | act->time = he->time; | ||
| 2626 | } | ||
| 2627 | return n; | ||
| 2628 | } | ||
| 2629 | |||
| 2630 | static int | ||
| 2570 | do_switch_data(struct hist_browser *browser __maybe_unused, | 2631 | do_switch_data(struct hist_browser *browser __maybe_unused, |
| 2571 | struct popup_action *act __maybe_unused) | 2632 | struct popup_action *act __maybe_unused) |
| 2572 | { | 2633 | { |
