From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>, Ingo Molnar <mingo@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
LKML <linux-kernel@vger.kernel.org>,
Ian Rogers <irogers@google.com>,
linux-perf-users@vger.kernel.org
Subject: Re: [PATCH 2/2] perf lock: Add -t/--thread option for report
Date: Mon, 23 May 2022 09:50:37 -0300 [thread overview]
Message-ID: <YouDHRXZYqZSEutp@kernel.org> (raw)
In-Reply-To: <20220521010811.932703-2-namhyung@kernel.org>
Em Fri, May 20, 2022 at 06:08:11PM -0700, Namhyung Kim escreveu:
> The -t option is to show per-thread lock stat like below:
>
> $ perf lock report -t -F acquired,contended,avg_wait
>
> Name acquired contended avg wait (ns)
>
> perf 240569 9 5784
> swapper 106610 19 543
> :15789 17370 2 14538
> ContainerMgr 8981 6 874
> sleep 5275 1 11281
> ContainerThread 4416 4 944
> RootPressureThr 3215 5 1215
> rcu_preempt 2954 0 0
> ContainerMgr 2560 0 0
> unnamed 1873 0 0
> EventManager_De 1845 1 636
> futex-default-S 1609 0 0
> ...
Applied both and added this:
⬢[acme@toolbox perf]$ git diff
diff --git a/tools/perf/Documentation/perf-lock.txt b/tools/perf/Documentation/perf-lock.txt
index b43222229807672c..656b537b2fba078f 100644
--- a/tools/perf/Documentation/perf-lock.txt
+++ b/tools/perf/Documentation/perf-lock.txt
@@ -64,6 +64,27 @@ REPORT OPTIONS
--combine-locks::
Merge lock instances in the same class (based on name).
+-t::
+--threads::
+ The -t option is to show per-thread lock stat like below:
+
+ $ perf lock report -t -F acquired,contended,avg_wait
+
+ Name acquired contended avg wait (ns)
+
+ perf 240569 9 5784
+ swapper 106610 19 543
+ :15789 17370 2 14538
+ ContainerMgr 8981 6 874
+ sleep 5275 1 11281
+ ContainerThread 4416 4 944
+ RootPressureThr 3215 5 1215
+ rcu_preempt 2954 0 0
+ ContainerMgr 2560 0 0
+ unnamed 1873 0 0
+ EventManager_De 1845 1 636
+ futex-default-S 1609 0 0
+
INFO OPTIONS
------------
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
> tools/perf/builtin-lock.c | 28 +++++++++++++++++++++++++++-
> 1 file changed, 27 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
> index 7ceb12e30719..b1200b7340a6 100644
> --- a/tools/perf/builtin-lock.c
> +++ b/tools/perf/builtin-lock.c
> @@ -118,6 +118,7 @@ struct thread_stat {
> static struct rb_root thread_stats;
>
> static bool combine_locks;
> +static bool show_thread_stats;
>
> static struct thread_stat *thread_stat_find(u32 tid)
> {
> @@ -542,6 +543,10 @@ static int report_lock_acquire_event(struct evsel *evsel,
> u64 addr = evsel__intval(evsel, sample, "lockdep_addr");
> int flag = evsel__intval(evsel, sample, "flags");
>
> + /* abuse ls->addr for tid */
> + if (show_thread_stats)
> + addr = sample->tid;
> +
> ls = lock_stat_findnew(addr, name);
> if (!ls)
> return -ENOMEM;
> @@ -611,6 +616,9 @@ static int report_lock_acquired_event(struct evsel *evsel,
> const char *name = evsel__strval(evsel, sample, "name");
> u64 addr = evsel__intval(evsel, sample, "lockdep_addr");
>
> + if (show_thread_stats)
> + addr = sample->tid;
> +
> ls = lock_stat_findnew(addr, name);
> if (!ls)
> return -ENOMEM;
> @@ -670,6 +678,9 @@ static int report_lock_contended_event(struct evsel *evsel,
> const char *name = evsel__strval(evsel, sample, "name");
> u64 addr = evsel__intval(evsel, sample, "lockdep_addr");
>
> + if (show_thread_stats)
> + addr = sample->tid;
> +
> ls = lock_stat_findnew(addr, name);
> if (!ls)
> return -ENOMEM;
> @@ -722,6 +733,9 @@ static int report_lock_release_event(struct evsel *evsel,
> const char *name = evsel__strval(evsel, sample, "name");
> u64 addr = evsel__intval(evsel, sample, "lockdep_addr");
>
> + if (show_thread_stats)
> + addr = sample->tid;
> +
> ls = lock_stat_findnew(addr, name);
> if (!ls)
> return -ENOMEM;
> @@ -848,7 +862,17 @@ static void print_result(void)
>
> if (strlen(st->name) < 20) {
> /* output raw name */
> - pr_info("%20s ", st->name);
> + const char *name = st->name;
> +
> + if (show_thread_stats) {
> + struct thread *t;
> +
> + /* st->addr contains tid of thread */
> + t = perf_session__findnew(session, st->addr);
> + name = thread__comm_str(t);
> + }
> +
> + pr_info("%20s ", name);
> } else {
> strncpy(cut_name, st->name, 16);
> cut_name[16] = '.';
> @@ -1125,6 +1149,8 @@ int cmd_lock(int argc, const char **argv)
> /* TODO: type */
> OPT_BOOLEAN('c', "combine-locks", &combine_locks,
> "combine locks in the same class"),
> + OPT_BOOLEAN('t', "threads", &show_thread_stats,
> + "show per-thread lock stats"),
> OPT_PARENT(lock_options)
> };
>
> --
> 2.36.1.124.g0e6072fb45-goog
--
- Arnaldo
next prev parent reply other threads:[~2022-05-23 12:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-21 1:08 [PATCH 1/2] perf lock: Do not discard broken lock stats Namhyung Kim
2022-05-21 1:08 ` [PATCH 2/2] perf lock: Add -t/--thread option for report Namhyung Kim
2022-05-23 12:50 ` Arnaldo Carvalho de Melo [this message]
2022-05-24 17:31 ` Namhyung Kim
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=YouDHRXZYqZSEutp@kernel.org \
--to=acme@kernel.org \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.