From: kan.liang@intel.com
To: acme@kernel.org, jolsa@kernel.org
Cc: a.p.zijlstra@chello.nl, luto@kernel.org, mingo@redhat.com,
eranian@google.com, ak@linux.intel.com, mark.rutland@arm.com,
adrian.hunter@intel.com, namhyung@kernel.org,
linux-kernel@vger.kernel.org, Kan Liang <kan.liang@intel.com>
Subject: [PATCH V10 2/8] perf, record: introduce --perf-freq option
Date: Wed, 16 Sep 2015 10:21:50 -0400 [thread overview]
Message-ID: <1442413316-33518-3-git-send-email-kan.liang@intel.com> (raw)
In-Reply-To: <1442413316-33518-1-git-send-email-kan.liang@intel.com>
From: Kan Liang <kan.liang@intel.com>
To generate the frequency and performance output, perf must sample read
special events like cycles, ref-cycles, msr/tsc/, msr/aperf/ or
msr/mperf/.
With the --perf-freq option, perf record can automatically check and add
those event into evlist as group for sampling read.
Signed-off-by: Kan Liang <kan.liang@intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
---
tools/perf/Documentation/perf-record.txt | 8 +++++++
tools/perf/builtin-record.c | 39 +++++++++++++++++++++++++++++++-
tools/perf/util/event.h | 10 ++++++++
3 files changed, 56 insertions(+), 1 deletion(-)
diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt
index 2e9ce77..8a65f37 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -308,6 +308,14 @@ This option sets the time out limit. The default value is 500 ms.
Record context switch events i.e. events of type PERF_RECORD_SWITCH or
PERF_RECORD_SWITCH_CPU_WIDE.
+--perf-freq::
+Collect CPU frequency and performance result per sample. It includes frequency,
+CPU utilization and actual percent performance (APERF/MPERF%).
+To generate the frequency and performance output, special events cycles,
+ref-cycles, msr/tsc/, msr/aperf/ or msr/mperf/ must be read by group.
+This option can automatically probe available special events on system, and
+read their sample value by group.
+
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 142eeb3..8c4da18 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -13,7 +13,7 @@
#include "util/util.h"
#include "util/parse-options.h"
#include "util/parse-events.h"
-
+#include "util/pmu.h"
#include "util/callchain.h"
#include "util/cgroup.h"
#include "util/header.h"
@@ -50,6 +50,7 @@ struct record {
bool no_buildid;
bool no_buildid_cache;
long samples;
+ bool perf_freq;
};
static int record__write(struct record *rec, void *bf, size_t size)
@@ -948,6 +949,35 @@ out_free:
return ret;
}
+const char *perf_freq_events[PERF_FREQ_MAX][3] = {
+ { "msr", "tsc", "msr/tsc/" },
+ { "msr", "aperf", "msr/aperf/" },
+ { "msr", "mperf", "msr/mperf/" },
+ { NULL, "cycles", "cycles" },
+ { NULL, "ref-cycles", "ref-cycles" },
+};
+
+static int
+record_add_perf_freq_events(struct perf_evlist *evlist)
+{
+ int i;
+ char perf_freq_attrs[100];
+
+ strcpy(perf_freq_attrs, "{cycles,ref-cycles");
+ for (i = 0; i < PERF_FREQ_MAX; i++) {
+ if ((i == PERF_FREQ_CYCLES) ||
+ (i == PERF_FREQ_REF_CYCLES))
+ continue;
+ if (pmu_have_event(perf_freq_events[i][0], perf_freq_events[i][1])) {
+ strcat(perf_freq_attrs, ",");
+ strcat(perf_freq_attrs, perf_freq_events[i][2]);
+ }
+ }
+ strcat(perf_freq_attrs, "}:S");
+
+ return parse_events(evlist, perf_freq_attrs, NULL);
+}
+
static const char * const __record_usage[] = {
"perf record [<options>] [<command>]",
"perf record [<options>] -- <command> [<options>]",
@@ -1096,6 +1126,8 @@ struct option __record_options[] = {
"per thread proc mmap processing timeout in ms"),
OPT_BOOLEAN(0, "switch-events", &record.opts.record_switch_events,
"Record context switch events"),
+ OPT_BOOLEAN(0, "perf-freq", &record.perf_freq,
+ "Collect CPU frequency and performance result per sample"),
OPT_END()
};
@@ -1157,6 +1189,11 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)
if (rec->no_buildid_cache || rec->no_buildid)
disable_buildid_cache();
+ if (rec->perf_freq && record_add_perf_freq_events(rec->evlist)) {
+ pr_err("Cannot set up freq and performance events\n");
+ goto out_symbol_exit;
+ }
+
if (rec->evlist->nr_entries == 0 &&
perf_evlist__add_default(rec->evlist) < 0) {
pr_err("Not enough memory for event selector list\n");
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index f729df5..3439462 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -177,6 +177,16 @@ enum {
PERF_IP_FLAG_TRACE_BEGIN |\
PERF_IP_FLAG_TRACE_END)
+enum perf_freqs {
+ PERF_FREQ_TSC = 0,
+ PERF_FREQ_APERF = 1,
+ PERF_FREQ_MPERF = 2,
+ PERF_FREQ_CYCLES = 3,
+ PERF_FREQ_REF_CYCLES = 4,
+
+ PERF_FREQ_MAX
+};
+
struct perf_sample {
u64 ip;
u32 pid, tid;
--
1.8.3.1
next prev parent reply other threads:[~2015-09-16 21:39 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-16 14:21 [PATCH V10 0/8] Freq/CPU%/CORE_BUSY% support kan.liang
2015-09-16 14:21 ` [PATCH V10 1/8] perf,tools: introduce generic FEAT for CPU attributes kan.liang
2015-09-16 14:21 ` kan.liang [this message]
2015-09-16 14:21 ` [PATCH V10 3/8] perf,tools: caculate freq per sample kan.liang
2015-09-16 14:21 ` [PATCH V10 4/8] perf,tools: Dump per-sample freq/CPU%/CORE_BUSY% in report -D kan.liang
2015-09-16 14:21 ` [PATCH V10 5/8] perf,tools: caculate and save freq/CPU%/CORE_BUSY% in he_stat kan.liang
2015-09-16 14:21 ` [PATCH V10 6/8] perf,tools: only show leader's value in hpp__fmt kan.liang
2015-09-16 14:21 ` [PATCH V10 7/8] perf,tools: Introduce HPP__SINGLE_PRINT_FNS support kan.liang
2015-09-16 14:21 ` [PATCH V10 8/8] perf,tools: Show freq/CPU%/CORE_BUSY% in perf report by --perf-freq kan.liang
2015-09-28 20:05 ` [PATCH V10 0/8] Freq/CPU%/CORE_BUSY% support Liang, Kan
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=1442413316-33518-3-git-send-email-kan.liang@intel.com \
--to=kan.liang@intel.com \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=ak@linux.intel.com \
--cc=eranian@google.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.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