From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757657AbeAIB4N (ORCPT + 1 other); Mon, 8 Jan 2018 20:56:13 -0500 Received: from LGEAMRELO12.lge.com ([156.147.23.52]:57403 "EHLO lgeamrelo12.lge.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757295AbeAIB4M (ORCPT ); Mon, 8 Jan 2018 20:56:12 -0500 X-Original-SENDERIP: 156.147.1.126 X-Original-MAILFROM: namhyung@kernel.org X-Original-SENDERIP: 10.177.227.17 X-Original-MAILFROM: namhyung@kernel.org Date: Tue, 9 Jan 2018 10:56:07 +0900 From: Namhyung Kim To: Jiri Olsa Cc: Arnaldo Carvalho de Melo , Peter Zijlstra , lkml , Ingo Molnar , David Ahern , Andi Kleen , Alexander Shishkin , kernel-team@lge.com Subject: Re: [PATCH 12/12] perf report: Add --task option to display monitored tasks Message-ID: <20180109015607.GA7138@sejong> References: <20180107160356.28203-1-jolsa@kernel.org> <20180107160356.28203-13-jolsa@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20180107160356.28203-13-jolsa@kernel.org> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: Hi Jiri, On Sun, Jan 07, 2018 at 05:03:56PM +0100, Jiri Olsa wrote: > Adding --task option to display monitored tasks stored > in perf.data. Displaying pid/tid/ppid plus the command > string aligned to distinguish parent and child tasks. > > $ perf record -a > ... > $ perf report --task > # pid tid ppid comm > 0 0 -1 |swapper > 2 2 0 | kthreadd > 14080 14080 2 | kworker/u17:1 > 4 4 2 | kworker/0:0H > 6 6 2 | mm_percpu_wq > ... > 1 1 0 | systemd > 23242 23242 1 | firefox > 23242 23298 23242 | Cache2 I/O > 23242 23304 23242 | GMPThread > ... > 1195 1195 1 | login > 1611 1611 1195 | bash > 1639 1639 1611 | startx > 1663 1663 1639 | xinit > 1673 1673 1663 | xmonad-x86_64-l > 23939 23939 1673 | xterm > 23941 23941 23939 | bash > 23963 23963 23941 | mutt > 24954 24954 23963 | offlineimap Nice! :) > > Link: http://lkml.kernel.org/n/tip-ehvadnmg8b3kdhvgsbuesbr7@git.kernel.org > Signed-off-by: Jiri Olsa > --- > tools/perf/Documentation/perf-report.txt | 4 + > tools/perf/builtin-report.c | 136 ++++++++++++++++++++++++++++++- > 2 files changed, 138 insertions(+), 2 deletions(-) > > diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt > index b0d70bf4ddfe..dcf0d154918f 100644 > --- a/tools/perf/Documentation/perf-report.txt > +++ b/tools/perf/Documentation/perf-report.txt > @@ -441,6 +441,10 @@ include::itrace.txt[] > Display overall events statistics without any further processing. > (like the one at the end of the perf report -D command) > > +--task:: > + Display monitored tasks stored in perf data. Displaying pid/tid/ppid > + plus the command string aligned to distinguish parent and child tasks. > + > include::callchain-overhead-calculation.txt[] > > SEE ALSO > diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c > index 11d303494b0c..f2ca2cbe63c1 100644 > --- a/tools/perf/builtin-report.c > +++ b/tools/perf/builtin-report.c > @@ -15,6 +15,7 @@ > #include "util/color.h" > #include > #include > +#include > #include "util/symbol.h" > #include "util/callchain.h" > #include "util/values.h" > @@ -61,6 +62,7 @@ struct report { > bool inverted_callchain; > bool mem_mode; > bool stat_mode; > + bool task_mode; > bool header; > bool header_only; > bool nonany_branch_mode; > @@ -598,6 +600,124 @@ static int stat_print(struct report *rep) > return 0; > } > > +static void task_setup(struct report *rep) > +{ > + memset(&rep->tool, 0, sizeof(rep->tool)); > + rep->tool.comm = perf_event__process_comm; > + rep->tool.exit = perf_event__process_exit; > + rep->tool.fork = perf_event__process_fork; > + rep->tool.no_warn = true; > +} > + > +struct task { > + struct thread *thread; > + struct list_head list; > + struct list_head children; > +}; > + > +static struct task *task_list(struct task *task, struct machine *machine) > +{ > + struct thread *parent_thread, *thread = task->thread; > + struct task *parent_task; > + > + /* Already listed. */ > + if (!list_empty(&task->list)) > + return NULL; > + > + /* Last one in the chain. */ > + if (thread->ppid == -1) > + return task; > + > + parent_thread = machine__findnew_thread(machine, -1, thread->ppid); I think it should be machine__find_thread() since creating a new thread at this stage would lack thread->priv anyway. Thanks, Namhyung > + if (!parent_thread) > + return ERR_PTR(-ENOMEM); > + > + parent_task = thread__priv(parent_thread); > + list_add_tail(&task->list, &parent_task->children); > + return task_list(parent_task, machine); > +}