Skip to content

Commit 082ab9a

Browse files
committed
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 <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Wang Nan <wangnan0@huawei.com> Link: http://lkml.kernel.org/n/tip-68rjeao9wnpylla41htk7xps@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent dd1a503 commit 082ab9a

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

tools/perf/builtin-trace.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2241,10 +2241,24 @@ static int trace__set_ev_qualifier_filter(struct trace *trace)
22412241

22422242
static int trace__set_filter_loop_pids(struct trace *trace)
22432243
{
2244-
int nr = 1;
2244+
unsigned int nr = 1;
22452245
pid_t pids[32] = {
22462246
getpid(),
22472247
};
2248+
struct thread *thread = machine__find_thread(trace->host, pids[0], pids[0]);
2249+
2250+
while (thread && nr < ARRAY_SIZE(pids)) {
2251+
struct thread *parent = machine__find_thread(trace->host, thread->ppid, thread->ppid);
2252+
2253+
if (parent == NULL)
2254+
break;
2255+
2256+
if (!strcmp(thread__comm_str(parent), "sshd")) {
2257+
pids[nr++] = parent->tid;
2258+
break;
2259+
}
2260+
thread = parent;
2261+
}
22482262

22492263
return perf_evlist__set_filter_pids(trace->evlist, nr, pids);
22502264
}

0 commit comments

Comments
 (0)