diff options
Diffstat (limited to 'tools/perf/util/sort.c')
| -rw-r--r-- | tools/perf/util/sort.c | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c index d2299e912e59..5d2518e89fc4 100644 --- a/tools/perf/util/sort.c +++ b/tools/perf/util/sort.c | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | #include <inttypes.h> | 3 | #include <inttypes.h> |
| 4 | #include <regex.h> | 4 | #include <regex.h> |
| 5 | #include <linux/mman.h> | 5 | #include <linux/mman.h> |
| 6 | #include <linux/time64.h> | ||
| 6 | #include "sort.h" | 7 | #include "sort.h" |
| 7 | #include "hist.h" | 8 | #include "hist.h" |
| 8 | #include "comm.h" | 9 | #include "comm.h" |
| @@ -12,9 +13,11 @@ | |||
| 12 | #include "evsel.h" | 13 | #include "evsel.h" |
| 13 | #include "evlist.h" | 14 | #include "evlist.h" |
| 14 | #include "strlist.h" | 15 | #include "strlist.h" |
| 16 | #include "strbuf.h" | ||
| 15 | #include <traceevent/event-parse.h> | 17 | #include <traceevent/event-parse.h> |
| 16 | #include "mem-events.h" | 18 | #include "mem-events.h" |
| 17 | #include "annotate.h" | 19 | #include "annotate.h" |
| 20 | #include "time-utils.h" | ||
| 18 | #include <linux/kernel.h> | 21 | #include <linux/kernel.h> |
| 19 | 22 | ||
| 20 | regex_t parent_regex; | 23 | regex_t parent_regex; |
| @@ -654,6 +657,42 @@ struct sort_entry sort_socket = { | |||
| 654 | .se_width_idx = HISTC_SOCKET, | 657 | .se_width_idx = HISTC_SOCKET, |
| 655 | }; | 658 | }; |
| 656 | 659 | ||
| 660 | /* --sort time */ | ||
| 661 | |||
| 662 | static int64_t | ||
| 663 | sort__time_cmp(struct hist_entry *left, struct hist_entry *right) | ||
| 664 | { | ||
| 665 | return right->time - left->time; | ||
| 666 | } | ||
| 667 | |||
| 668 | static int hist_entry__time_snprintf(struct hist_entry *he, char *bf, | ||
| 669 | size_t size, unsigned int width) | ||
| 670 | { | ||
| 671 | unsigned long secs; | ||
| 672 | unsigned long long nsecs; | ||
| 673 | char he_time[32]; | ||
| 674 | |||
| 675 | nsecs = he->time; | ||
| 676 | secs = nsecs / NSEC_PER_SEC; | ||
| 677 | nsecs -= secs * NSEC_PER_SEC; | ||
| 678 | |||
| 679 | if (symbol_conf.nanosecs) | ||
| 680 | snprintf(he_time, sizeof he_time, "%5lu.%09llu: ", | ||
| 681 | secs, nsecs); | ||
| 682 | else | ||
| 683 | timestamp__scnprintf_usec(he->time, he_time, | ||
| 684 | sizeof(he_time)); | ||
| 685 | |||
| 686 | return repsep_snprintf(bf, size, "%-.*s", width, he_time); | ||
| 687 | } | ||
| 688 | |||
| 689 | struct sort_entry sort_time = { | ||
| 690 | .se_header = "Time", | ||
| 691 | .se_cmp = sort__time_cmp, | ||
| 692 | .se_snprintf = hist_entry__time_snprintf, | ||
| 693 | .se_width_idx = HISTC_TIME, | ||
| 694 | }; | ||
| 695 | |||
| 657 | /* --sort trace */ | 696 | /* --sort trace */ |
| 658 | 697 | ||
| 659 | static char *get_trace_output(struct hist_entry *he) | 698 | static char *get_trace_output(struct hist_entry *he) |
| @@ -1634,6 +1673,7 @@ static struct sort_dimension common_sort_dimensions[] = { | |||
| 1634 | DIM(SORT_DSO_SIZE, "dso_size", sort_dso_size), | 1673 | DIM(SORT_DSO_SIZE, "dso_size", sort_dso_size), |
| 1635 | DIM(SORT_CGROUP_ID, "cgroup_id", sort_cgroup_id), | 1674 | DIM(SORT_CGROUP_ID, "cgroup_id", sort_cgroup_id), |
| 1636 | DIM(SORT_SYM_IPC_NULL, "ipc_null", sort_sym_ipc_null), | 1675 | DIM(SORT_SYM_IPC_NULL, "ipc_null", sort_sym_ipc_null), |
| 1676 | DIM(SORT_TIME, "time", sort_time), | ||
| 1637 | }; | 1677 | }; |
| 1638 | 1678 | ||
| 1639 | #undef DIM | 1679 | #undef DIM |
| @@ -3068,3 +3108,54 @@ void reset_output_field(void) | |||
| 3068 | reset_dimensions(); | 3108 | reset_dimensions(); |
| 3069 | perf_hpp__reset_output_field(&perf_hpp_list); | 3109 | perf_hpp__reset_output_field(&perf_hpp_list); |
| 3070 | } | 3110 | } |
| 3111 | |||
| 3112 | #define INDENT (3*8 + 1) | ||
| 3113 | |||
| 3114 | static void add_key(struct strbuf *sb, const char *str, int *llen) | ||
| 3115 | { | ||
| 3116 | if (*llen >= 75) { | ||
| 3117 | strbuf_addstr(sb, "\n\t\t\t "); | ||
| 3118 | *llen = INDENT; | ||
| 3119 | } | ||
| 3120 | strbuf_addf(sb, " %s", str); | ||
| 3121 | *llen += strlen(str) + 1; | ||
| 3122 | } | ||
| 3123 | |||
| 3124 | static void add_sort_string(struct strbuf *sb, struct sort_dimension *s, int n, | ||
| 3125 | int *llen) | ||
| 3126 | { | ||
| 3127 | int i; | ||
| 3128 | |||
| 3129 | for (i = 0; i < n; i++) | ||
| 3130 | add_key(sb, s[i].name, llen); | ||
| 3131 | } | ||
| 3132 | |||
| 3133 | static void add_hpp_sort_string(struct strbuf *sb, struct hpp_dimension *s, int n, | ||
| 3134 | int *llen) | ||
| 3135 | { | ||
| 3136 | int i; | ||
| 3137 | |||
| 3138 | for (i = 0; i < n; i++) | ||
| 3139 | add_key(sb, s[i].name, llen); | ||
| 3140 | } | ||
| 3141 | |||
| 3142 | const char *sort_help(const char *prefix) | ||
| 3143 | { | ||
| 3144 | struct strbuf sb; | ||
| 3145 | char *s; | ||
| 3146 | int len = strlen(prefix) + INDENT; | ||
| 3147 | |||
| 3148 | strbuf_init(&sb, 300); | ||
| 3149 | strbuf_addstr(&sb, prefix); | ||
| 3150 | add_hpp_sort_string(&sb, hpp_sort_dimensions, | ||
| 3151 | ARRAY_SIZE(hpp_sort_dimensions), &len); | ||
| 3152 | add_sort_string(&sb, common_sort_dimensions, | ||
| 3153 | ARRAY_SIZE(common_sort_dimensions), &len); | ||
| 3154 | add_sort_string(&sb, bstack_sort_dimensions, | ||
| 3155 | ARRAY_SIZE(bstack_sort_dimensions), &len); | ||
| 3156 | add_sort_string(&sb, memory_sort_dimensions, | ||
| 3157 | ARRAY_SIZE(memory_sort_dimensions), &len); | ||
| 3158 | s = strbuf_detach(&sb, NULL); | ||
| 3159 | strbuf_release(&sb); | ||
| 3160 | return s; | ||
| 3161 | } | ||
