From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755894Ab3H2Eao (ORCPT ); Thu, 29 Aug 2013 00:30:44 -0400 Received: from mail-pa0-f54.google.com ([209.85.220.54]:44877 "EHLO mail-pa0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755717Ab3H2EaE (ORCPT ); Thu, 29 Aug 2013 00:30:04 -0400 From: David Ahern To: acme@ghostprotocols.net, linux-kernel@vger.kernel.org Cc: David Ahern , Adrian Hunter , Frederic Weisbecker , Mike Galbraith , Paul Mackerras , Peter Zijlstra , Stephane Eranian Subject: [PATCH 3/3] perf trace: Honor target pid / tid options when analyzing a file Date: Wed, 28 Aug 2013 22:29:53 -0600 Message-Id: <1377750593-48046-4-git-send-email-dsahern@gmail.com> X-Mailer: git-send-email 1.7.10.1 In-Reply-To: <1377750593-48046-1-git-send-email-dsahern@gmail.com> References: <1377750593-48046-1-git-send-email-dsahern@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Allows capture of raw_syscall events for all processes or threads in a task and then analyzing specific ones. Signed-off-by: David Ahern Cc: Adrian Hunter Cc: Frederic Weisbecker Cc: Mike Galbraith Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Stephane Eranian --- tools/perf/builtin-trace.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index a03c777..ec0c7b3 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -8,6 +8,7 @@ #include "util/thread.h" #include "util/parse-options.h" #include "util/strlist.h" +#include "util/intlist.h" #include "util/thread_map.h" #include @@ -259,6 +260,8 @@ struct trace { unsigned long nr_events; struct strlist *ev_qualifier; bool not_ev_qualifier; + struct intlist *tid_list; + struct intlist *pid_list; bool sched; bool multiple_threads; double duration_filter; @@ -649,6 +652,18 @@ out_dump: return 0; } +static bool skip_sample(struct trace *trace, struct perf_sample *sample) +{ + if ((trace->pid_list && intlist__find(trace->pid_list, sample->pid)) || + (trace->tid_list && intlist__find(trace->tid_list, sample->tid))) + return false; + + if (trace->pid_list || trace->tid_list) + return true; + + return false; +} + static int trace__process_sample(struct perf_tool *tool, union perf_event *event __maybe_unused, struct perf_sample *sample, @@ -660,6 +675,9 @@ static int trace__process_sample(struct perf_tool *tool, tracepoint_handler handler = evsel->handler.func; + if (skip_sample(trace, sample)) + return 0; + if (trace->base_time == 0) trace->base_time = sample->time; @@ -679,6 +697,27 @@ perf_session__has_tp(struct perf_session *session, const char *name) return evsel != NULL; } +static int parse_target_str(struct trace *trace) +{ + if (trace->opts.target.pid) { + trace->pid_list = intlist__new(trace->opts.target.pid); + if (trace->pid_list == NULL) { + pr_err("Error parsing process id string\n"); + return -EINVAL; + } + } + + if (trace->opts.target.tid) { + trace->tid_list = intlist__new(trace->opts.target.tid); + if (trace->tid_list == NULL) { + pr_err("Error parsing thread id string\n"); + return -EINVAL; + } + } + + return 0; +} + static int trace__run(struct trace *trace, int argc, const char **argv) { struct perf_evlist *evlist = perf_evlist__new(); @@ -865,6 +904,10 @@ static int trace__replay(struct trace *trace) goto out; } + err = parse_target_str(trace); + if (err != 0) + goto out; + setup_pager(); err = perf_session__process_events(session, &trace->tool); -- 1.7.10.1