mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>,
	Ian Rogers <irogers@google.com>,
	Kan Liang <kan.liang@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	linux-perf-users@vger.kernel.org
Subject: [PATCH] perf mem: Add -H/--hierarchy option for report subcommand
Date: Mon, 28 Oct 2024 13:23:36 -0700	[thread overview]
Message-ID: <20241028202336.1478570-1-namhyung@kernel.org> (raw)

Like in perf report, the -H/--hierarchy mode supports hierarchical
output using the given sort key.  But with -T/--type-profile option it
would be better to have the 'type' sort key in the beginning so that
users can see something like following:

  $ perf mem report -T -H
  ...
  #
  #          Overhead       Samples  Data Type / Memory access / Snoop / TLB access
  # ...............................  ..............................................
  #
      97.96%          4099           (unknown)
         97.05%          4089           L1 hit
            97.05%          4089           None
               97.05%          4089           L1 or L2 hit
          0.71%             6           RAM hit
             0.71%             6           Hit
                0.71%             6           L1 or L2 hit
          0.16%             2           L2 hit
             0.16%             2           None
                0.16%             2           L1 or L2 hit
          0.04%             2           LFB/MAB hit
             0.04%             2           None
                0.04%             2           L1 or L2 hit
       0.98%            12           struct folio
          0.61%             9           L1 hit
             0.61%             9           None
                0.61%             9           L1 or L2 hit
          0.37%             3           LFB/MAB hit
             0.37%             3           None
                0.37%             3           L1 or L2 hit
       0.45%             5           unsigned char
          0.45%             5           LFB/MAB hit
             0.45%             5           None

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/Documentation/perf-mem.txt |  6 ++++++
 tools/perf/builtin-mem.c              | 10 +++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/tools/perf/Documentation/perf-mem.txt b/tools/perf/Documentation/perf-mem.txt
index 8a1bd9ff0f86dfb8..ac16c1b276e3912c 100644
--- a/tools/perf/Documentation/perf-mem.txt
+++ b/tools/perf/Documentation/perf-mem.txt
@@ -125,6 +125,12 @@ REPORT OPTIONS
 	Specify the field separator used when dump raw samples (-D option). By default,
 	The separator is the space character.
 
+-H::
+--hierarchy::
+	Enable hierarchical output.  In the hierarchy mode, each sort key groups
+	samples based on the criteria and then sub-divide it using the lower
+	level sort key.  See linkperf:perf-report[1] for details.
+
 In addition, for report all perf report options are valid, and for record
 all perf record options.
 
diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c
index 651188c1d8259842..2efa01947cf17aa0 100644
--- a/tools/perf/builtin-mem.c
+++ b/tools/perf/builtin-mem.c
@@ -39,6 +39,7 @@ struct perf_mem {
 	bool			all_kernel;
 	bool			all_user;
 	bool			data_type;
+	bool			report_hierarchy;
 	int			operation;
 	const char		*cpu_list;
 	DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
@@ -329,6 +330,8 @@ static char *get_sort_order(struct perf_mem *mem)
 
 	if (mem->sort_key)
 		scnprintf(sort, sizeof(sort), "--sort=%s", mem->sort_key);
+	else if (mem->report_hierarchy && mem->data_type)
+		strcpy(sort, "--sort=type,mem,snoop,tlb");
 	else if (mem->data_type)
 		strcpy(sort, "--sort=mem,snoop,tlb,type");
 	/*
@@ -374,7 +377,7 @@ static int __cmd_report(int argc, const char **argv, struct perf_mem *mem,
 	if (mem->dump_raw)
 		return report_raw_events(mem);
 
-	rep_argc = argc + 3;
+	rep_argc = argc + 5;
 	rep_argv = calloc(rep_argc + 1, sizeof(char *));
 	if (!rep_argv)
 		return -1;
@@ -387,6 +390,9 @@ static int __cmd_report(int argc, const char **argv, struct perf_mem *mem,
 	if (new_sort_order)
 		rep_argv[i++] = new_sort_order;
 
+	if (mem->report_hierarchy)
+		rep_argv[i++] = "-H";
+
 	for (j = 0; j < argc; j++, i++)
 		rep_argv[i] = argv[j];
 
@@ -513,6 +519,8 @@ int cmd_mem(int argc, const char **argv)
 		   sort_order_help),
 	OPT_BOOLEAN('T', "type-profile", &mem.data_type,
 		    "Show data-type profile result"),
+	OPT_BOOLEAN('H', "hierarchy", &mem.report_hierarchy,
+		    "Show entries in a hierarchy"),
 	OPT_PARENT(mem_options)
 	};
 	const char *const mem_subcommands[] = { "record", "report", NULL };
-- 
2.47.0.163.g1226f6d8fa-goog


                 reply	other threads:[~2024-10-28 20:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241028202336.1478570-1-namhyung@kernel.org \
    --to=namhyung@kernel.org \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®