Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753116AbbH1REl (ORCPT ); Fri, 28 Aug 2015 13:04:41 -0400 Received: from mga02.intel.com ([134.134.136.20]:25548 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752853AbbH1RED (ORCPT ); Fri, 28 Aug 2015 13:04:03 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,425,1437462000"; d="scan'208";a="777614786" From: Kan Liang 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 Subject: [PATCH V7 6/8] perf,tools: Dump per-sample freq/CPU%/CORE_BUSY% in report -D Date: Fri, 28 Aug 2015 05:48:07 -0400 Message-Id: <1440755289-30939-7-git-send-email-kan.liang@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1440755289-30939-1-git-send-email-kan.liang@intel.com> References: <1440755289-30939-1-git-send-email-kan.liang@intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 6351 Lines: 202 From: Kan Liang The group read results from cycles/ref-cycles/TSC/ASTATE/MSTATE event can be used to calculate the frequency, CPU Utilization and percent performance during each sampling period. This patch shows them in report -D. Here is an example: $ perf record -e '{cycles,ref-cycles,msr/tsc/,msr/mperf/,msr/aperf/}:S' ~/tchain_edit Here is one sample from perf report -D 1972044565107 0x3498 [0x88]: PERF_RECORD_SAMPLE(IP, 0x2): 10608/10608: 0x4005fd period: 564686 addr: 0 ... sample_read: .... group nr 5 ..... id 0000000000000012, value 0000000002143901 ..... id 0000000000000052, value 0000000002143896 ..... id 0000000000000094, value 00000000021e443d ..... id 00000000000000d4, value 00000000021db984 ..... id 0000000000000114, value 00000000021db964 ..... Freq 2301 MHz ..... CPU% 98% ..... CORE_BUSY% 99% Signed-off-by: Kan Liang --- tools/perf/util/session.c | 31 ++++++++++++++++++++--- tools/perf/util/session.h | 64 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 8a4537e..215ff73 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -7,7 +7,6 @@ #include #include "evlist.h" -#include "evsel.h" #include "session.h" #include "tool.h" #include "sort.h" @@ -877,8 +876,15 @@ static void perf_evlist__print_tstamp(struct perf_evlist *evlist, printf("%" PRIu64 " ", sample->time); } -static void sample_read__printf(struct perf_sample *sample, u64 read_format) +static void sample_read__printf(struct perf_sample *sample, + struct perf_evsel *evsel) { + u64 read_format = evsel->attr.read_format; + struct perf_evlist *evlist = evsel->evlist; + struct perf_sample_id *sid; + perf_freq_t data = { 0 }; + u64 cpu_max_freq = evlist->env->cpu.max_freq; + printf("... sample_read:\n"); if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) @@ -901,10 +907,26 @@ static void sample_read__printf(struct perf_sample *sample, u64 read_format) printf("..... id %016" PRIx64 ", value %016" PRIx64 "\n", value->id, value->value); + + sid = perf_evlist__id2sid(evlist, value->id); + evsel = sid->evsel; + if (evsel != NULL) + perf_freq__init(evlist->env->msr_pmu_type, + evsel, data, value->value); } } else printf("..... id %016" PRIx64 ", value %016" PRIx64 "\n", sample->read.one.id, sample->read.one.value); + + if (perf_freq__has_freq(data)) + printf("..... Freq %lu MHz\n", + perf_freq__get_freq(data, cpu_max_freq/1000)); + if (perf_freq__has_cpu_util(data)) + printf("..... CPU%% %lu%%\n", + perf_freq__get_cpu_util(data)); + if (perf_freq__has_core_busy(data)) + printf("..... CORE_BUSY%% %lu%%\n", + perf_freq__get_core_busy(data)); } static void dump_event(struct perf_evlist *evlist, union perf_event *event, @@ -964,7 +986,7 @@ static void dump_sample(struct perf_evsel *evsel, union perf_event *event, printf("... transaction: %" PRIx64 "\n", sample->transaction); if (sample_type & PERF_SAMPLE_READ) - sample_read__printf(sample, evsel->attr.read_format); + sample_read__printf(sample, evsel); } static struct machine *machines__find_for_cpumode(struct machines *machines, @@ -1079,11 +1101,12 @@ static int machines__deliver_event(struct machines *machines, switch (event->header.type) { case PERF_RECORD_SAMPLE: - dump_sample(evsel, event, sample); if (evsel == NULL) { ++evlist->stats.nr_unknown_id; return 0; } + dump_sample(evsel, event, sample); + if (machine == NULL) { ++evlist->stats.nr_unprocessable_samples; return 0; diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h index b44afc7..83bf4a9 100644 --- a/tools/perf/util/session.h +++ b/tools/perf/util/session.h @@ -11,6 +11,7 @@ #include "ordered-events.h" #include #include +#include "evsel.h" struct ip_callchain; struct thread; @@ -42,6 +43,69 @@ 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 + +enum perf_freq_perf_index { + FREQ_PERF_TSC = 0, + FREQ_PERF_APERF = 1, + FREQ_PERF_MPERF = 2, + FREQ_PERF_CYCLES = 3, + FREQ_PERF_REF_CYCLES = 4, + + FREQ_PERF_MAX +}; + +typedef u64 perf_freq_t[FREQ_PERF_MAX]; + +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[FREQ_PERF_TSC] = value; + if (evsel->attr.config == PERF_MSR_APERF) + array[FREQ_PERF_APERF] = value; + if (evsel->attr.config == PERF_MSR_MPERF) + array[FREQ_PERF_MPERF] = value; + } + if (evsel->attr.type == PERF_TYPE_HARDWARE) { + if (evsel->attr.config == PERF_COUNT_HW_CPU_CYCLES) + array[FREQ_PERF_CYCLES] = value; + if (evsel->attr.config == PERF_COUNT_HW_REF_CPU_CYCLES) + array[FREQ_PERF_REF_CYCLES] = value; + } +} + +static inline bool perf_freq__has_freq(perf_freq_t array) +{ + return ((array[FREQ_PERF_CYCLES] > 0) && (array[FREQ_PERF_REF_CYCLES] > 0)); +} +static inline u64 perf_freq__get_freq(perf_freq_t array, u64 cpu_max_freq) +{ + return ((array[FREQ_PERF_CYCLES] * cpu_max_freq) / array[FREQ_PERF_REF_CYCLES]); +} +static inline bool perf_freq__has_cpu_util(perf_freq_t array) +{ + return ((array[FREQ_PERF_TSC] > 0) && (array[FREQ_PERF_REF_CYCLES] > 0)); +} +static inline u64 perf_freq__get_cpu_util(perf_freq_t array) +{ + return ((100 * array[FREQ_PERF_REF_CYCLES]) / array[FREQ_PERF_TSC]); +} + +static inline bool perf_freq__has_core_busy(perf_freq_t array) +{ + return ((array[FREQ_PERF_APERF] > 0) && (array[FREQ_PERF_MPERF] > 0)); +} +static inline u64 perf_freq__get_core_busy(perf_freq_t array) +{ + return ((100 * array[FREQ_PERF_APERF]) / array[FREQ_PERF_MPERF]); +} + struct perf_tool; struct perf_session *perf_session__new(struct perf_data_file *file, -- 1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/