From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751739AbdGZRU2 (ORCPT ); Wed, 26 Jul 2017 13:20:28 -0400 Received: from terminus.zytor.com ([65.50.211.136]:58347 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751678AbdGZRU0 (ORCPT ); Wed, 26 Jul 2017 13:20:26 -0400 Date: Wed, 26 Jul 2017 10:18:14 -0700 From: tip-bot for Arnaldo Carvalho de Melo Message-ID: Cc: dsahern@gmail.com, mingo@kernel.org, namhyung@kernel.org, hpa@zytor.com, tglx@linutronix.de, wangnan0@huawei.com, acme@redhat.com, jolsa@kernel.org, linux-kernel@vger.kernel.org, adrian.hunter@intel.com Reply-To: mingo@kernel.org, dsahern@gmail.com, namhyung@kernel.org, tglx@linutronix.de, hpa@zytor.com, acme@redhat.com, wangnan0@huawei.com, adrian.hunter@intel.com, linux-kernel@vger.kernel.org, jolsa@kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf trace: Filter out 'sshd' in the tracer ancestry in syswide tracing Git-Commit-ID: 082ab9a18e532864d1ceecfb50221df62b1d5a92 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 082ab9a18e532864d1ceecfb50221df62b1d5a92 Gitweb: http://git.kernel.org/tip/082ab9a18e532864d1ceecfb50221df62b1d5a92 Author: Arnaldo Carvalho de Melo AuthorDate: Thu, 20 Jul 2017 11:32:05 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Thu, 20 Jul 2017 15:16:25 -0300 perf trace: Filter out 'sshd' in the tracer ancestry in syswide tracing Avoiding a loop, so now its quite convenient to ssh to a machine and then simply do: # perf trace To trace all syscalls without causing a loop. This was possible using --filter-pids, i.e. once you noticed the loop, get the sshd pid and add it to --filter-pids, restarting the 'perf trace'. Now to figure out how to do that in a X terminal, the other common scenario, which is way more involved, as there are multiple processes communicating to process terminal activity... Using --filter-pids + '-e \!syscall,names,you,dont,need' may be a good approximation when having to do syswide tracing on your workstation. Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-68rjeao9wnpylla41htk7xps@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-trace.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 0ba36f0..05d24b6 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -2241,10 +2241,24 @@ out_enomem: static int trace__set_filter_loop_pids(struct trace *trace) { - int nr = 1; + unsigned int nr = 1; pid_t pids[32] = { getpid(), }; + struct thread *thread = machine__find_thread(trace->host, pids[0], pids[0]); + + while (thread && nr < ARRAY_SIZE(pids)) { + struct thread *parent = machine__find_thread(trace->host, thread->ppid, thread->ppid); + + if (parent == NULL) + break; + + if (!strcmp(thread__comm_str(parent), "sshd")) { + pids[nr++] = parent->tid; + break; + } + thread = parent; + } return perf_evlist__set_filter_pids(trace->evlist, nr, pids); }