Skip to content

Commit

Permalink
perf lock: Add -t/--thread option for report
Browse files Browse the repository at this point in the history
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
  ...

Committer notes:

Add that option to the 'perf lock report' man page.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20220521010811.932703-2-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Namhyung Kim authored and Arnaldo Carvalho de Melo committed May 23, 2022
1 parent 79d9333 commit 7c3bcbd
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
21 changes: 21 additions & 0 deletions tools/perf/Documentation/perf-lock.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------

Expand Down
28 changes: 27 additions & 1 deletion tools/perf/builtin-lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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] = '.';
Expand Down Expand Up @@ -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)
};

Expand Down

0 comments on commit 7c3bcbd

Please sign in to comment.