diff options
author | Namhyung Kim <namhyung@kernel.org> | 2016-03-07 14:44:45 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2016-03-08 04:11:19 -0500 |
commit | c3bc0c436899d01c3a09fddb308d487cc032fbd2 (patch) | |
tree | 65257cd7a5097bb29720e737a7d58279944d7c5d | |
parent | f594bae08183fb6b57db55387794ece3e1edf6f6 (diff) |
perf hists: Introduce perf_hpp__setup_hists_formats()
The perf_hpp__setup_hists_formats() is to build hists-specific output
formats (and sort keys). Currently it's only used in order to build the
output format in a hierarchy with same sort keys, but it could be used
with different sort keys in non-hierarchy mode later.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/1457361308-514-2-git-send-email-namhyung@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r-- | tools/perf/ui/hist.c | 63 | ||||
-rw-r--r-- | tools/perf/util/hist.c | 12 | ||||
-rw-r--r-- | tools/perf/util/hist.h | 11 | ||||
-rw-r--r-- | tools/perf/util/sort.c | 32 |
4 files changed, 118 insertions, 0 deletions
diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c index 7c0585c146e1..3a15e844f89a 100644 --- a/tools/perf/ui/hist.c +++ b/tools/perf/ui/hist.c | |||
@@ -5,6 +5,7 @@ | |||
5 | #include "../util/util.h" | 5 | #include "../util/util.h" |
6 | #include "../util/sort.h" | 6 | #include "../util/sort.h" |
7 | #include "../util/evsel.h" | 7 | #include "../util/evsel.h" |
8 | #include "../util/evlist.h" | ||
8 | 9 | ||
9 | /* hist period print (hpp) functions */ | 10 | /* hist period print (hpp) functions */ |
10 | 11 | ||
@@ -715,3 +716,65 @@ void perf_hpp__set_user_width(const char *width_list_str) | |||
715 | break; | 716 | break; |
716 | } | 717 | } |
717 | } | 718 | } |
719 | |||
720 | static int add_hierarchy_fmt(struct hists *hists, struct perf_hpp_fmt *fmt) | ||
721 | { | ||
722 | struct perf_hpp_list_node *node = NULL; | ||
723 | struct perf_hpp_fmt *fmt_copy; | ||
724 | bool found = false; | ||
725 | |||
726 | list_for_each_entry(node, &hists->hpp_formats, list) { | ||
727 | if (node->level == fmt->level) { | ||
728 | found = true; | ||
729 | break; | ||
730 | } | ||
731 | } | ||
732 | |||
733 | if (!found) { | ||
734 | node = malloc(sizeof(*node)); | ||
735 | if (node == NULL) | ||
736 | return -1; | ||
737 | |||
738 | node->level = fmt->level; | ||
739 | perf_hpp_list__init(&node->hpp); | ||
740 | |||
741 | list_add_tail(&node->list, &hists->hpp_formats); | ||
742 | } | ||
743 | |||
744 | fmt_copy = perf_hpp_fmt__dup(fmt); | ||
745 | if (fmt_copy == NULL) | ||
746 | return -1; | ||
747 | |||
748 | list_add_tail(&fmt_copy->list, &node->hpp.fields); | ||
749 | list_add_tail(&fmt_copy->sort_list, &node->hpp.sorts); | ||
750 | |||
751 | return 0; | ||
752 | } | ||
753 | |||
754 | int perf_hpp__setup_hists_formats(struct perf_hpp_list *list, | ||
755 | struct perf_evlist *evlist) | ||
756 | { | ||
757 | struct perf_evsel *evsel; | ||
758 | struct perf_hpp_fmt *fmt; | ||
759 | struct hists *hists; | ||
760 | int ret; | ||
761 | |||
762 | if (!symbol_conf.report_hierarchy) | ||
763 | return 0; | ||
764 | |||
765 | evlist__for_each(evlist, evsel) { | ||
766 | hists = evsel__hists(evsel); | ||
767 | |||
768 | perf_hpp_list__for_each_sort_list(list, fmt) { | ||
769 | if (perf_hpp__is_dynamic_entry(fmt) && | ||
770 | !perf_hpp__defined_dynamic_entry(fmt, hists)) | ||
771 | continue; | ||
772 | |||
773 | ret = add_hierarchy_fmt(hists, fmt); | ||
774 | if (ret < 0) | ||
775 | return ret; | ||
776 | } | ||
777 | } | ||
778 | |||
779 | return 0; | ||
780 | } | ||
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 4b8b67bc0cd8..fea92fcb6903 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c | |||
@@ -2105,6 +2105,7 @@ int __hists__init(struct hists *hists, struct perf_hpp_list *hpp_list) | |||
2105 | pthread_mutex_init(&hists->lock, NULL); | 2105 | pthread_mutex_init(&hists->lock, NULL); |
2106 | hists->socket_filter = -1; | 2106 | hists->socket_filter = -1; |
2107 | hists->hpp_list = hpp_list; | 2107 | hists->hpp_list = hpp_list; |
2108 | INIT_LIST_HEAD(&hists->hpp_formats); | ||
2108 | return 0; | 2109 | return 0; |
2109 | } | 2110 | } |
2110 | 2111 | ||
@@ -2133,8 +2134,19 @@ static void hists__delete_all_entries(struct hists *hists) | |||
2133 | static void hists_evsel__exit(struct perf_evsel *evsel) | 2134 | static void hists_evsel__exit(struct perf_evsel *evsel) |
2134 | { | 2135 | { |
2135 | struct hists *hists = evsel__hists(evsel); | 2136 | struct hists *hists = evsel__hists(evsel); |
2137 | struct perf_hpp_fmt *fmt, *pos; | ||
2138 | struct perf_hpp_list_node *node, *tmp; | ||
2136 | 2139 | ||
2137 | hists__delete_all_entries(hists); | 2140 | hists__delete_all_entries(hists); |
2141 | |||
2142 | list_for_each_entry_safe(node, tmp, &hists->hpp_formats, list) { | ||
2143 | perf_hpp_list__for_each_format_safe(&node->hpp, fmt, pos) { | ||
2144 | list_del(&fmt->list); | ||
2145 | free(fmt); | ||
2146 | } | ||
2147 | list_del(&node->list); | ||
2148 | free(node); | ||
2149 | } | ||
2138 | } | 2150 | } |
2139 | 2151 | ||
2140 | static int hists_evsel__init(struct perf_evsel *evsel) | 2152 | static int hists_evsel__init(struct perf_evsel *evsel) |
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index f4ef513527ba..3cab9dc20822 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h | |||
@@ -78,6 +78,7 @@ struct hists { | |||
78 | u16 col_len[HISTC_NR_COLS]; | 78 | u16 col_len[HISTC_NR_COLS]; |
79 | int socket_filter; | 79 | int socket_filter; |
80 | struct perf_hpp_list *hpp_list; | 80 | struct perf_hpp_list *hpp_list; |
81 | struct list_head hpp_formats; | ||
81 | int nr_sort_keys; | 82 | int nr_sort_keys; |
82 | }; | 83 | }; |
83 | 84 | ||
@@ -244,6 +245,12 @@ struct perf_hpp_list { | |||
244 | 245 | ||
245 | extern struct perf_hpp_list perf_hpp_list; | 246 | extern struct perf_hpp_list perf_hpp_list; |
246 | 247 | ||
248 | struct perf_hpp_list_node { | ||
249 | struct list_head list; | ||
250 | struct perf_hpp_list hpp; | ||
251 | int level; | ||
252 | }; | ||
253 | |||
247 | void perf_hpp_list__column_register(struct perf_hpp_list *list, | 254 | void perf_hpp_list__column_register(struct perf_hpp_list *list, |
248 | struct perf_hpp_fmt *format); | 255 | struct perf_hpp_fmt *format); |
249 | void perf_hpp_list__register_sort_field(struct perf_hpp_list *list, | 256 | void perf_hpp_list__register_sort_field(struct perf_hpp_list *list, |
@@ -299,6 +306,8 @@ void perf_hpp__cancel_cumulate(void); | |||
299 | void perf_hpp__setup_output_field(struct perf_hpp_list *list); | 306 | void perf_hpp__setup_output_field(struct perf_hpp_list *list); |
300 | void perf_hpp__reset_output_field(struct perf_hpp_list *list); | 307 | void perf_hpp__reset_output_field(struct perf_hpp_list *list); |
301 | void perf_hpp__append_sort_keys(struct perf_hpp_list *list); | 308 | void perf_hpp__append_sort_keys(struct perf_hpp_list *list); |
309 | int perf_hpp__setup_hists_formats(struct perf_hpp_list *list, | ||
310 | struct perf_evlist *evlist); | ||
302 | 311 | ||
303 | 312 | ||
304 | bool perf_hpp__is_sort_entry(struct perf_hpp_fmt *format); | 313 | bool perf_hpp__is_sort_entry(struct perf_hpp_fmt *format); |
@@ -308,6 +317,8 @@ bool perf_hpp__is_trace_entry(struct perf_hpp_fmt *fmt); | |||
308 | bool perf_hpp__is_srcline_entry(struct perf_hpp_fmt *fmt); | 317 | bool perf_hpp__is_srcline_entry(struct perf_hpp_fmt *fmt); |
309 | bool perf_hpp__is_srcfile_entry(struct perf_hpp_fmt *fmt); | 318 | bool perf_hpp__is_srcfile_entry(struct perf_hpp_fmt *fmt); |
310 | 319 | ||
320 | struct perf_hpp_fmt *perf_hpp_fmt__dup(struct perf_hpp_fmt *fmt); | ||
321 | |||
311 | int hist_entry__filter(struct hist_entry *he, int type, const void *arg); | 322 | int hist_entry__filter(struct hist_entry *he, int type, const void *arg); |
312 | 323 | ||
313 | static inline bool perf_hpp__should_skip(struct perf_hpp_fmt *format, | 324 | static inline bool perf_hpp__should_skip(struct perf_hpp_fmt *format, |
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c index ab6eb7ca8c60..71d45d147376 100644 --- a/tools/perf/util/sort.c +++ b/tools/perf/util/sort.c | |||
@@ -1908,6 +1908,34 @@ __alloc_dynamic_entry(struct perf_evsel *evsel, struct format_field *field, | |||
1908 | return hde; | 1908 | return hde; |
1909 | } | 1909 | } |
1910 | 1910 | ||
1911 | struct perf_hpp_fmt *perf_hpp_fmt__dup(struct perf_hpp_fmt *fmt) | ||
1912 | { | ||
1913 | struct perf_hpp_fmt *new_fmt = NULL; | ||
1914 | |||
1915 | if (perf_hpp__is_sort_entry(fmt)) { | ||
1916 | struct hpp_sort_entry *hse, *new_hse; | ||
1917 | |||
1918 | hse = container_of(fmt, struct hpp_sort_entry, hpp); | ||
1919 | new_hse = memdup(hse, sizeof(*hse)); | ||
1920 | if (new_hse) | ||
1921 | new_fmt = &new_hse->hpp; | ||
1922 | } else if (perf_hpp__is_dynamic_entry(fmt)) { | ||
1923 | struct hpp_dynamic_entry *hde, *new_hde; | ||
1924 | |||
1925 | hde = container_of(fmt, struct hpp_dynamic_entry, hpp); | ||
1926 | new_hde = memdup(hde, sizeof(*hde)); | ||
1927 | if (new_hde) | ||
1928 | new_fmt = &new_hde->hpp; | ||
1929 | } else { | ||
1930 | new_fmt = memdup(fmt, sizeof(*fmt)); | ||
1931 | } | ||
1932 | |||
1933 | INIT_LIST_HEAD(&new_fmt->list); | ||
1934 | INIT_LIST_HEAD(&new_fmt->sort_list); | ||
1935 | |||
1936 | return new_fmt; | ||
1937 | } | ||
1938 | |||
1911 | static int parse_field_name(char *str, char **event, char **field, char **opt) | 1939 | static int parse_field_name(char *str, char **event, char **field, char **opt) |
1912 | { | 1940 | { |
1913 | char *event_name, *field_name, *opt_name; | 1941 | char *event_name, *field_name, *opt_name; |
@@ -2700,6 +2728,10 @@ int setup_sorting(struct perf_evlist *evlist) | |||
2700 | /* and then copy output fields to sort keys */ | 2728 | /* and then copy output fields to sort keys */ |
2701 | perf_hpp__append_sort_keys(&perf_hpp_list); | 2729 | perf_hpp__append_sort_keys(&perf_hpp_list); |
2702 | 2730 | ||
2731 | /* setup hists-specific output fields */ | ||
2732 | if (perf_hpp__setup_hists_formats(&perf_hpp_list, evlist) < 0) | ||
2733 | return -1; | ||
2734 | |||
2703 | return 0; | 2735 | return 0; |
2704 | } | 2736 | } |
2705 | 2737 | ||