From: Adrian Hunter <adrian.hunter@intel.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Andi Kleen <ak@linux.intel.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Ingo Molnar <mingo@kernel.org>,
linux-kernel@vger.kernel.org, Jiri Olsa <jolsa@redhat.com>,
Stephane Eranian <eranian@google.com>,
mathieu.poirier@linaro.org, Pawel Moll <pawel.moll@arm.com>
Subject: [PATCH V3 3/4] perf record: Add option --switch-events to select PERF_RECORD_SWITCH events
Date: Tue, 7 Jul 2015 11:36:41 +0300 [thread overview]
Message-ID: <1436258202-6540-4-git-send-email-adrian.hunter@intel.com> (raw)
In-Reply-To: <1436258202-6540-1-git-send-email-adrian.hunter@intel.com>
Add an option to select PERF_RECORD_SWITCH events.
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
tools/perf/Documentation/perf-record.txt | 3 +++
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, 25 insertions(+)
diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt
index 9b9d9d086680..92d098c5123b 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -276,6 +276,9 @@ 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.
+
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 283fe96bdfc1..a20ad2191a92 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1072,6 +1072,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()
};
@@ -1099,6 +1101,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 937b16aa0300..cf459f89fc9b 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 037633c1da9d..c2fb15768d79 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 67d2b43dd500..c63f96dba0d2 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -737,6 +737,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 1f7becbe5e18..0d228a29526d 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;
--
1.9.1
next prev parent reply other threads:[~2015-07-07 8:40 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-07 8:36 [PATCH V3 0/4] perf: Add PERF_RECORD_SWITCH to indicate context switches Adrian Hunter
2015-07-07 8:36 ` [PATCH V3 1/4] " Adrian Hunter
2015-07-07 13:25 ` Arnaldo Carvalho de Melo
2015-07-07 13:44 ` Arnaldo Carvalho de Melo
2015-07-07 15:36 ` Peter Zijlstra
2015-07-07 16:13 ` Arnaldo Carvalho de Melo
2015-07-07 22:52 ` Peter Zijlstra
2015-07-08 13:28 ` Arnaldo Carvalho de Melo
2015-07-08 13:42 ` Adrian Hunter
2015-07-08 14:56 ` Arnaldo Carvalho de Melo
2015-07-07 8:36 ` [PATCH V3 2/4] perf tools: Add new PERF_RECORD_SWITCH event Adrian Hunter
2015-07-07 13:50 ` Arnaldo Carvalho de Melo
2015-07-07 8:36 ` Adrian Hunter [this message]
2015-07-07 13:53 ` [PATCH V3 3/4] perf record: Add option --switch-events to select PERF_RECORD_SWITCH events Arnaldo Carvalho de Melo
2015-07-07 8:36 ` [PATCH V3 4/4] perf script: Add option --show-switch-events Adrian Hunter
2015-07-07 13:54 ` Arnaldo Carvalho de Melo
2015-07-07 9:06 ` [PATCH V3 0/4] perf: Add PERF_RECORD_SWITCH to indicate context switches Peter Zijlstra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1436258202-6540-4-git-send-email-adrian.hunter@intel.com \
--to=adrian.hunter@intel.com \
--cc=acme@kernel.org \
--cc=ak@linux.intel.com \
--cc=eranian@google.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.poirier@linaro.org \
--cc=mingo@kernel.org \
--cc=pawel.moll@arm.com \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome