perf report: Add parallelism sort key
authorDmitry Vyukov <dvyukov@google.com>
Thu, 13 Feb 2025 09:08:15 +0000 (10:08 +0100)
committerNamhyung Kim <namhyung@kernel.org>
Tue, 18 Feb 2025 06:00:50 +0000 (22:00 -0800)
Show parallelism level in profiles if requested by user.

Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
Reviewed-by: Andi Kleen <ak@linux.intel.com>
Link: https://lore.kernel.org/r/7f7bb87cbaa51bf1fb008a0d68b687423ce4bad4.1739437531.git.dvyukov@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/builtin-report.c
tools/perf/util/hist.c
tools/perf/util/hist.h
tools/perf/util/session.c
tools/perf/util/session.h
tools/perf/util/sort.c
tools/perf/util/sort.h

index 0d9bd090eda71f15ad79333a55b4e75cc4af5836..14d49f062588131eb616e72f1bfeb6b323ee3bf2 100644 (file)
@@ -1720,6 +1720,17 @@ repeat:
                symbol_conf.annotate_data_sample = true;
        }
 
+       if (report.disable_order || !perf_session__has_switch_events(session)) {
+               if ((sort_order && strstr(sort_order, "parallelism")) ||
+                               (field_order && strstr(field_order, "parallelism"))) {
+                       if (report.disable_order)
+                               ui__error("Use of parallelism is incompatible with --disable-order.\n");
+                       else
+                               ui__error("Use of parallelism requires --switch-events during record.\n");
+                       return -1;
+               }
+       }
+
        if (sort_order && strstr(sort_order, "ipc")) {
                parse_options_usage(report_usage, options, "s", 1);
                goto error;
index 0f30f843c566d2e18913c5bedf2631d67fcff3ed..cafd693568189eb97b0f0cbca306a7602079190e 100644 (file)
@@ -207,6 +207,7 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
 
        hists__new_col_len(hists, HISTC_CGROUP, 6);
        hists__new_col_len(hists, HISTC_CGROUP_ID, 20);
+       hists__new_col_len(hists, HISTC_PARALLELISM, 11);
        hists__new_col_len(hists, HISTC_CPU, 3);
        hists__new_col_len(hists, HISTC_SOCKET, 6);
        hists__new_col_len(hists, HISTC_MEM_LOCKED, 6);
@@ -741,6 +742,7 @@ __hists__add_entry(struct hists *hists,
                .ip      = al->addr,
                .level   = al->level,
                .code_page_size = sample->code_page_size,
+               .parallelism    = al->parallelism,
                .stat = {
                        .nr_events = 1,
                        .period = sample->period,
index 46c8373e314657fae96141acc3df6bb72ed14209..a6e662d77dc2456124b28d98a6b437394e1a5ef6 100644 (file)
@@ -42,6 +42,7 @@ enum hist_column {
        HISTC_CGROUP_ID,
        HISTC_CGROUP,
        HISTC_PARENT,
+       HISTC_PARALLELISM,
        HISTC_CPU,
        HISTC_SOCKET,
        HISTC_SRCLINE,
@@ -228,6 +229,7 @@ struct hist_entry {
        u64                     transaction;
        s32                     socket;
        s32                     cpu;
+       int                     parallelism;
        u64                     code_page_size;
        u64                     weight;
        u64                     ins_lat;
@@ -580,6 +582,7 @@ bool perf_hpp__is_thread_entry(struct perf_hpp_fmt *fmt);
 bool perf_hpp__is_comm_entry(struct perf_hpp_fmt *fmt);
 bool perf_hpp__is_dso_entry(struct perf_hpp_fmt *fmt);
 bool perf_hpp__is_sym_entry(struct perf_hpp_fmt *fmt);
+bool perf_hpp__is_parallelism_entry(struct perf_hpp_fmt *fmt);
 
 struct perf_hpp_fmt *perf_hpp_fmt__dup(struct perf_hpp_fmt *fmt);
 
index c35b7e8ad51f35332030001e9d69f68b6271ad13..60fb9997ea0d11ceb9f98e5e153e72e84f97c148 100644 (file)
@@ -2439,6 +2439,18 @@ bool perf_session__has_traces(struct perf_session *session, const char *msg)
        return false;
 }
 
+bool perf_session__has_switch_events(struct perf_session *session)
+{
+       struct evsel *evsel;
+
+       evlist__for_each_entry(session->evlist, evsel) {
+               if (evsel->core.attr.context_switch)
+                       return true;
+       }
+
+       return false;
+}
+
 int map__set_kallsyms_ref_reloc_sym(struct map *map, const char *symbol_name, u64 addr)
 {
        char *bracket;
index bcf1bcf06959baf43778c2d32c3eaadf63d9681b..db1c120a9e67f77ad1ee474eb82424ae348bf430 100644 (file)
@@ -141,6 +141,7 @@ int perf_session__resolve_callchain(struct perf_session *session,
                                    struct symbol **parent);
 
 bool perf_session__has_traces(struct perf_session *session, const char *msg);
+bool perf_session__has_switch_events(struct perf_session *session);
 
 void perf_event__attr_swap(struct perf_event_attr *attr);
 
index 3dd33721823f365deaaafafbe87c5388391d5eab..7eef43f5be3604b51ff41e7ed6e26e145679f9ec 100644 (file)
@@ -892,6 +892,27 @@ struct sort_entry sort_cpu = {
        .se_width_idx   = HISTC_CPU,
 };
 
+/* --sort parallelism */
+
+static int64_t
+sort__parallelism_cmp(struct hist_entry *left, struct hist_entry *right)
+{
+       return right->parallelism - left->parallelism;
+}
+
+static int hist_entry__parallelism_snprintf(struct hist_entry *he, char *bf,
+                                   size_t size, unsigned int width)
+{
+       return repsep_snprintf(bf, size, "%*d", width, he->parallelism);
+}
+
+struct sort_entry sort_parallelism = {
+       .se_header      = "Parallelism",
+       .se_cmp         = sort__parallelism_cmp,
+       .se_snprintf    = hist_entry__parallelism_snprintf,
+       .se_width_idx   = HISTC_PARALLELISM,
+};
+
 /* --sort cgroup_id */
 
 static int64_t _sort__cgroup_dev_cmp(u64 left_dev, u64 right_dev)
@@ -2534,6 +2555,7 @@ static struct sort_dimension common_sort_dimensions[] = {
        DIM(SORT_ANNOTATE_DATA_TYPE_OFFSET, "typeoff", sort_type_offset),
        DIM(SORT_SYM_OFFSET, "symoff", sort_sym_offset),
        DIM(SORT_ANNOTATE_DATA_TYPE_CACHELINE, "typecln", sort_type_cacheline),
+       DIM(SORT_PARALLELISM, "parallelism", sort_parallelism),
 };
 
 #undef DIM
@@ -2735,6 +2757,7 @@ MK_SORT_ENTRY_CHK(thread)
 MK_SORT_ENTRY_CHK(comm)
 MK_SORT_ENTRY_CHK(dso)
 MK_SORT_ENTRY_CHK(sym)
+MK_SORT_ENTRY_CHK(parallelism)
 
 
 static bool __sort__hpp_equal(struct perf_hpp_fmt *a, struct perf_hpp_fmt *b)
index a8572574e1686be6233ef4d11284caebe196825c..11fb15f91409358296e19e28a6f52c2fd13b91ee 100644 (file)
@@ -72,6 +72,7 @@ enum sort_type {
        SORT_ANNOTATE_DATA_TYPE_OFFSET,
        SORT_SYM_OFFSET,
        SORT_ANNOTATE_DATA_TYPE_CACHELINE,
+       SORT_PARALLELISM,
 
        /* branch stack specific sort keys */
        __SORT_BRANCH_STACK,