From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753802AbbG2IPp (ORCPT ); Wed, 29 Jul 2015 04:15:45 -0400 Received: from terminus.zytor.com ([198.137.202.10]:57006 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753779AbbG2IPj (ORCPT ); Wed, 29 Jul 2015 04:15:39 -0400 Date: Wed, 29 Jul 2015 01:15:00 -0700 From: tip-bot for Adrian Hunter Message-ID: Cc: ak@linux.intel.com, acme@redhat.com, jolsa@redhat.com, mingo@kernel.org, peterz@infradead.org, pawel.moll@arm.com, linux-kernel@vger.kernel.org, eranian@google.com, hpa@zytor.com, tglx@linutronix.de, adrian.hunter@intel.com, mathieu.poirier@linaro.org Reply-To: tglx@linutronix.de, adrian.hunter@intel.com, mathieu.poirier@linaro.org, eranian@google.com, hpa@zytor.com, peterz@infradead.org, pawel.moll@arm.com, linux-kernel@vger.kernel.org, ak@linux.intel.com, acme@redhat.com, jolsa@redhat.com, mingo@kernel.org In-Reply-To: <1437471846-26995-4-git-send-email-adrian.hunter@intel.com> References: <1437471846-26995-4-git-send-email-adrian.hunter@intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf record: Add option --switch-events to select PERF_RECORD_SWITCH events Git-Commit-ID: b757bb09134f479a087ece08d2cd2a6ba31c9210 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: b757bb09134f479a087ece08d2cd2a6ba31c9210 Gitweb: http://git.kernel.org/tip/b757bb09134f479a087ece08d2cd2a6ba31c9210 Author: Adrian Hunter AuthorDate: Tue, 21 Jul 2015 12:44:04 +0300 Committer: Arnaldo Carvalho de Melo CommitDate: Thu, 23 Jul 2015 22:51:13 -0300 perf record: Add option --switch-events to select PERF_RECORD_SWITCH events Add an option to select PERF_RECORD_SWITCH events. Signed-off-by: Adrian Hunter Acked-by: Peter Zijlstra (Intel) Tested-by: Arnaldo Carvalho de Melo Tested-by: Jiri Olsa Cc: Andi Kleen Cc: Mathieu Poirier Cc: Pawel Moll Cc: Stephane Eranian Link: http://lkml.kernel.org/r/1437471846-26995-4-git-send-email-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/Documentation/perf-record.txt | 4 ++++ tools/perf/builtin-record.c | 7 +++++++ tools/perf/perf.h | 1 + tools/perf/util/evlist.h | 1 + tools/perf/util/evsel.c | 3 +++ tools/perf/util/record.c | 10 ++++++++++ 6 files changed, 26 insertions(+) diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt index 29e5307..63ee040 100644 --- a/tools/perf/Documentation/perf-record.txt +++ b/tools/perf/Documentation/perf-record.txt @@ -293,6 +293,10 @@ When processing pre-existing threads /proc/XXX/mmap, it may take a long time, because the file may be huge. A time out is needed in such cases. This option sets the time out limit. The default value is 500 ms. +--switch-events:: +Record context switch events i.e. events of type PERF_RECORD_SWITCH or +PERF_RECORD_SWITCH_CPU_WIDE. + SEE ALSO -------- linkperf:perf-stat[1], linkperf:perf-list[1] diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 1932e27..445a64d 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -1075,6 +1075,8 @@ struct option __record_options[] = { "opts", "AUX area tracing Snapshot Mode", ""), OPT_UINTEGER(0, "proc-map-timeout", &record.opts.proc_map_timeout, "per thread proc mmap processing timeout in ms"), + OPT_BOOLEAN(0, "switch-events", &record.opts.record_switch_events, + "Record context switch events"), OPT_END() }; @@ -1102,6 +1104,11 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused) " system-wide mode\n"); usage_with_options(record_usage, record_options); } + if (rec->opts.record_switch_events && + !perf_can_record_switch_events()) { + ui__error("kernel does not support recording context switch events (--switch-events option)\n"); + usage_with_options(record_usage, record_options); + } if (!rec->itr) { rec->itr = auxtrace_record__init(rec->evlist, &err); diff --git a/tools/perf/perf.h b/tools/perf/perf.h index 937b16a..cf459f8 100644 --- a/tools/perf/perf.h +++ b/tools/perf/perf.h @@ -57,6 +57,7 @@ struct record_opts { bool running_time; bool full_auxtrace; bool auxtrace_snapshot_mode; + bool record_switch_events; unsigned int freq; unsigned int mmap_pages; unsigned int auxtrace_mmap_pages; diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index 406a821..a8930b6 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -114,6 +114,7 @@ void perf_evlist__close(struct perf_evlist *evlist); void perf_evlist__set_id_pos(struct perf_evlist *evlist); bool perf_can_sample_identifier(void); +bool perf_can_record_switch_events(void); void perf_evlist__config(struct perf_evlist *evlist, struct record_opts *opts); int record_opts__config(struct record_opts *opts); diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 9e6e6f4..71f6905 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -738,6 +738,9 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts) attr->mmap2 = track && !perf_missing_features.mmap2; attr->comm = track; + if (opts->record_switch_events) + attr->context_switch = track; + if (opts->sample_transaction) perf_evsel__set_sample_bit(evsel, TRANSACTION); diff --git a/tools/perf/util/record.c b/tools/perf/util/record.c index 1f7becb..0d228a2 100644 --- a/tools/perf/util/record.c +++ b/tools/perf/util/record.c @@ -85,6 +85,11 @@ static void perf_probe_comm_exec(struct perf_evsel *evsel) evsel->attr.comm_exec = 1; } +static void perf_probe_context_switch(struct perf_evsel *evsel) +{ + evsel->attr.context_switch = 1; +} + bool perf_can_sample_identifier(void) { return perf_probe_api(perf_probe_sample_identifier); @@ -95,6 +100,11 @@ static bool perf_can_comm_exec(void) return perf_probe_api(perf_probe_comm_exec); } +bool perf_can_record_switch_events(void) +{ + return perf_probe_api(perf_probe_context_switch); +} + void perf_evlist__config(struct perf_evlist *evlist, struct record_opts *opts) { struct perf_evsel *evsel;