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 3/8] perf,tools: caculate freq per sample
Date: Wed, 16 Sep 2015 10:21:51 -0400 [thread overview]
Message-ID: <1442413316-33518-4-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>
This patch store the vaule for calculating frequency, CPU Utilization
and percent performance in struct perf_sample, when sample group read
is detected and dump_trace is enabled.
Signed-off-by: Kan Liang <kan.liang@intel.com>
---
tools/perf/util/event.h | 3 +++
tools/perf/util/session.c | 26 +++++++++++++++++++++++++-
tools/perf/util/session.h | 25 +++++++++++++++++++++++++
3 files changed, 53 insertions(+), 1 deletion(-)
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index 3439462..edffeca 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -187,6 +187,8 @@ enum perf_freqs {
PERF_FREQ_MAX
};
+typedef u64 perf_freq_t[PERF_FREQ_MAX];
+
struct perf_sample {
u64 ip;
u32 pid, tid;
@@ -202,6 +204,7 @@ struct perf_sample {
u64 data_src;
u32 flags;
u16 insn_len;
+ perf_freq_t freq;
void *raw_data;
struct ip_callchain *callchain;
struct branch_stack *branch_stack;
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index d1a43a3..e8cb98d 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -7,7 +7,6 @@
#include <sys/mman.h>
#include "evlist.h"
-#include "evsel.h"
#include "session.h"
#include "tool.h"
#include "sort.h"
@@ -1047,6 +1046,26 @@ static int
&sample->read.one, machine);
}
+static void perf_caculate_freq(struct perf_sample *sample,
+ struct perf_evsel *evsel)
+{
+ u64 i;
+ struct perf_evlist *evlist = evsel->evlist;
+ struct sample_read_value *value;
+ struct perf_sample_id *sid;
+ struct perf_evsel *event;
+
+ for (i = 0; i < sample->read.group.nr; i++) {
+
+ value = &sample->read.group.values[i];
+ sid = perf_evlist__id2sid(evlist, value->id);
+ event = sid->evsel;
+ if (event != NULL)
+ perf_freq__init(evlist->env->msr_pmu_type,
+ event, sample->freq, value->value);
+ }
+}
+
static int machines__deliver_event(struct machines *machines,
struct perf_evlist *evlist,
union perf_event *event,
@@ -1068,6 +1087,11 @@ static int machines__deliver_event(struct machines *machines,
++evlist->stats.nr_unknown_id;
return 0;
}
+ if (dump_trace &&
+ (evsel->attr.sample_type & PERF_SAMPLE_READ) &&
+ (evsel->attr.read_format & PERF_FORMAT_GROUP))
+ perf_caculate_freq(sample, evsel);
+
dump_sample(evsel, event, sample);
if (machine == NULL) {
++evlist->stats.nr_unprocessable_samples;
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index b44afc7..f70d3a1 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -9,6 +9,7 @@
#include "thread.h"
#include "data.h"
#include "ordered-events.h"
+#include "evsel.h"
#include <linux/rbtree.h>
#include <linux/perf_event.h>
@@ -42,6 +43,30 @@ struct perf_session {
#define PRINT_IP_OPT_ONELINE (1<<4)
#define PRINT_IP_OPT_SRCLINE (1<<5)
+#define PERF_MSR_TSC 0
+#define PERF_MSR_APERF 1
+#define PERF_MSR_MPERF 2
+
+static inline void perf_freq__init(unsigned int msr_pmu_type,
+ struct perf_evsel *evsel,
+ perf_freq_t array,
+ u64 value)
+{
+ if (evsel->attr.type == msr_pmu_type) {
+ if (evsel->attr.config == PERF_MSR_TSC)
+ array[PERF_FREQ_TSC] = value;
+ if (evsel->attr.config == PERF_MSR_APERF)
+ array[PERF_FREQ_APERF] = value;
+ if (evsel->attr.config == PERF_MSR_MPERF)
+ array[PERF_FREQ_MPERF] = value;
+ }
+ if (evsel->attr.type == PERF_TYPE_HARDWARE) {
+ if (evsel->attr.config == PERF_COUNT_HW_CPU_CYCLES)
+ array[PERF_FREQ_CYCLES] = value;
+ if (evsel->attr.config == PERF_COUNT_HW_REF_CPU_CYCLES)
+ array[PERF_FREQ_REF_CYCLES] = value;
+ }
+}
struct perf_tool;
struct perf_session *perf_session__new(struct perf_data_file *file,
--
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 ` [PATCH V10 2/8] perf, record: introduce --perf-freq option kan.liang
2015-09-16 14:21 ` kan.liang [this message]
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-4-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