Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754381AbbGWTEg (ORCPT ); Thu, 23 Jul 2015 15:04:36 -0400 Received: from mga02.intel.com ([134.134.136.20]:40612 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754336AbbGWTEb (ORCPT ); Thu, 23 Jul 2015 15:04:31 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,532,1432623600"; d="scan'208";a="768439071" From: kan.liang@intel.com To: a.p.zijlstra@chello.nl, acme@kernel.org Cc: luto@kernel.org, mingo@redhat.com, eranian@google.com, ak@linux.intel.com, mark.rutland@arm.com, adrian.hunter@intel.com, jolsa@kernel.org, namhyung@kernel.org, linux-kernel@vger.kernel.org, Kan Liang Subject: [PATCH 4/5] perf,tools: caculate and save freq/CPU%/CORE_BUSY% in he_stat Date: Thu, 23 Jul 2015 07:49:42 -0400 Message-Id: <1437652183-62080-5-git-send-email-kan.liang@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1437652183-62080-1-git-send-email-kan.liang@intel.com> References: <1437652183-62080-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: 8333 Lines: 242 From: Kan Liang Introduce a new hist_iter ops (hist_iter_freq_perf) to caculate the freq/CPU%/CORE_BUSY% freq when processing samples, and save them in hist_entry. Signed-off-by: Kan Liang --- tools/perf/builtin-annotate.c | 2 +- tools/perf/builtin-diff.c | 2 +- tools/perf/tests/hists_link.c | 4 ++-- tools/perf/util/hist.c | 51 ++++++++++++++++++++++++++++++++++++++----- tools/perf/util/hist.h | 2 ++ tools/perf/util/sort.h | 3 +++ tools/perf/util/symbol.h | 6 +++++ 7 files changed, 60 insertions(+), 10 deletions(-) diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 2c1bec3..06e2f87 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -71,7 +71,7 @@ static int perf_evsel__add_sample(struct perf_evsel *evsel, return 0; } - he = __hists__add_entry(hists, al, NULL, NULL, NULL, 1, 1, 0, true); + he = __hists__add_entry(hists, al, NULL, NULL, NULL, 1, 1, 0, NULL, true); if (he == NULL) return -ENOMEM; diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c index daaa7dc..2fffcc4 100644 --- a/tools/perf/builtin-diff.c +++ b/tools/perf/builtin-diff.c @@ -315,7 +315,7 @@ static int hists__add_entry(struct hists *hists, u64 weight, u64 transaction) { if (__hists__add_entry(hists, al, NULL, NULL, NULL, period, weight, - transaction, true) != NULL) + transaction, NULL, true) != NULL) return 0; return -ENOMEM; } diff --git a/tools/perf/tests/hists_link.c b/tools/perf/tests/hists_link.c index 8c102b0..5d9f9e3 100644 --- a/tools/perf/tests/hists_link.c +++ b/tools/perf/tests/hists_link.c @@ -90,7 +90,7 @@ static int add_hist_entries(struct perf_evlist *evlist, struct machine *machine) goto out; he = __hists__add_entry(hists, &al, NULL, - NULL, NULL, 1, 1, 0, true); + NULL, NULL, 1, 1, 0, NULL, true); if (he == NULL) { addr_location__put(&al); goto out; @@ -116,7 +116,7 @@ static int add_hist_entries(struct perf_evlist *evlist, struct machine *machine) goto out; he = __hists__add_entry(hists, &al, NULL, - NULL, NULL, 1, 1, 0, true); + NULL, NULL, 1, 1, 0, NULL, true); if (he == NULL) { addr_location__put(&al); goto out; diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 6f28d53..26b8eea 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c @@ -436,7 +436,9 @@ struct hist_entry *__hists__add_entry(struct hists *hists, struct symbol *sym_parent, struct branch_info *bi, struct mem_info *mi, - u64 period, u64 weight, u64 transaction, + u64 period, u64 weight, + u64 transaction, + struct freq_perf_info *info, bool sample_self) { struct hist_entry entry = { @@ -454,6 +456,9 @@ struct hist_entry *__hists__add_entry(struct hists *hists, .nr_events = 1, .period = period, .weight = weight, + .freq = (info != NULL) ? info->freq : 0, + .cpu_u = (info != NULL) ? info->cpu_u : 0, + .core_busy = (info != NULL) ? info->core_busy : 0, }, .parent = sym_parent, .filtered = symbol__parent_filter(sym_parent) | al->filtered, @@ -481,6 +486,32 @@ iter_add_next_nop_entry(struct hist_entry_iter *iter __maybe_unused, } static int +iter_add_single_freq_perf_entry(struct hist_entry_iter *iter, struct addr_location *al) +{ + struct perf_evsel *evsel = iter->evsel; + struct perf_sample *sample = iter->sample; + struct hist_entry *he; + struct freq_perf_info info = {0}; + u64 *data = sample->freq_perf_data; + + if (data[FREQ_PERF_REF_CYCLES] > 0) + info.freq = (data[FREQ_PERF_CYCLES] * cpu_max_freq) / data[FREQ_PERF_REF_CYCLES]; + if (data[FREQ_PERF_TSC] > 0) + info.cpu_u = (100 * data[FREQ_PERF_REF_CYCLES]) / data[FREQ_PERF_TSC]; + if (data[FREQ_PERF_MPERF] > 0) + info.core_busy = (100 * data[FREQ_PERF_APERF]) / data[FREQ_PERF_MPERF]; + + he = __hists__add_entry(evsel__hists(evsel), al, iter->parent, NULL, NULL, + sample->period, sample->weight, + sample->transaction, &info, true); + if (he == NULL) + return -ENOMEM; + + iter->he = he; + return 0; +} + +static int iter_prepare_mem_entry(struct hist_entry_iter *iter, struct addr_location *al) { struct perf_sample *sample = iter->sample; @@ -517,7 +548,7 @@ iter_add_single_mem_entry(struct hist_entry_iter *iter, struct addr_location *al * and the he_stat__add_period() function. */ he = __hists__add_entry(hists, al, iter->parent, NULL, mi, - cost, cost, 0, true); + cost, cost, 0, NULL, true); if (!he) return -ENOMEM; @@ -618,7 +649,7 @@ iter_add_next_branch_entry(struct hist_entry_iter *iter, struct addr_location *a * and not events sampled. Thus we use a pseudo period of 1. */ he = __hists__add_entry(hists, al, iter->parent, &bi[i], NULL, - 1, 1, 0, true); + 1, 1, 0, NULL, true); if (he == NULL) return -ENOMEM; @@ -656,7 +687,7 @@ iter_add_single_normal_entry(struct hist_entry_iter *iter, struct addr_location he = __hists__add_entry(evsel__hists(evsel), al, iter->parent, NULL, NULL, sample->period, sample->weight, - sample->transaction, true); + sample->transaction, NULL, true); if (he == NULL) return -ENOMEM; @@ -718,7 +749,7 @@ iter_add_single_cumulative_entry(struct hist_entry_iter *iter, he = __hists__add_entry(hists, al, iter->parent, NULL, NULL, sample->period, sample->weight, - sample->transaction, true); + sample->transaction, NULL, true); if (he == NULL) return -ENOMEM; @@ -791,7 +822,7 @@ iter_add_next_cumulative_entry(struct hist_entry_iter *iter, he = __hists__add_entry(evsel__hists(evsel), al, iter->parent, NULL, NULL, sample->period, sample->weight, - sample->transaction, false); + sample->transaction, NULL, false); if (he == NULL) return -ENOMEM; @@ -813,6 +844,14 @@ iter_finish_cumulative_entry(struct hist_entry_iter *iter, return 0; } +const struct hist_iter_ops hist_iter_freq_perf = { + .prepare_entry = iter_prepare_normal_entry, + .add_single_entry = iter_add_single_freq_perf_entry, + .next_entry = iter_next_nop_entry, + .add_next_entry = iter_add_next_nop_entry, + .finish_entry = iter_finish_normal_entry, +}; + const struct hist_iter_ops hist_iter_mem = { .prepare_entry = iter_prepare_mem_entry, .add_single_entry = iter_add_single_mem_entry, diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h index 5ed8d9c..70bd557 100644 --- a/tools/perf/util/hist.h +++ b/tools/perf/util/hist.h @@ -102,6 +102,7 @@ extern const struct hist_iter_ops hist_iter_normal; extern const struct hist_iter_ops hist_iter_branch; extern const struct hist_iter_ops hist_iter_mem; extern const struct hist_iter_ops hist_iter_cumulative; +extern const struct hist_iter_ops hist_iter_freq_perf; struct hist_entry *__hists__add_entry(struct hists *hists, struct addr_location *al, @@ -109,6 +110,7 @@ struct hist_entry *__hists__add_entry(struct hists *hists, struct branch_info *bi, struct mem_info *mi, u64 period, u64 weight, u64 transaction, + struct freq_perf_info *freq_perf, bool sample_self); int hist_entry_iter__add(struct hist_entry_iter *iter, struct addr_location *al, int max_stack_depth, void *arg); diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h index e97cd47..90422ed 100644 --- a/tools/perf/util/sort.h +++ b/tools/perf/util/sort.h @@ -54,6 +54,9 @@ struct he_stat { u64 period_guest_us; u64 weight; u32 nr_events; + u64 freq; + u64 cpu_u; + u64 core_busy; }; struct hist_entry_diff { diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index b98ce51..fa0ccf3 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h @@ -180,6 +180,12 @@ struct mem_info { union perf_mem_data_src data_src; }; +struct freq_perf_info { + u64 freq; + u64 cpu_u; + u64 core_busy; +}; + struct addr_location { struct machine *machine; struct thread *thread; -- 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/