From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Jiri Olsa <jolsa@redhat.com>, LKML <linux-kernel@vger.kernel.org>,
David Ahern <dsahern@gmail.com>,
Frederic Weisbecker <fweisbec@gmail.com>,
Andi Kleen <andi@firstfloor.org>,
Stephane Eranian <eranian@google.com>,
Adrian Hunter <adrian.hunter@intel.com>
Subject: [PATCH/RFC 14/16] perf top: Separate struct perf_top_stats
Date: Thu, 10 Dec 2015 16:53:33 +0900 [thread overview]
Message-ID: <1449734015-9148-15-git-send-email-namhyung@kernel.org> (raw)
In-Reply-To: <1449734015-9148-1-git-send-email-namhyung@kernel.org>
The perf top maintains various stats regarding samples. Separate out
those stats so that it can be updated concurrently.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/builtin-top.c | 36 ++++++++++++++++++++++++++++--------
tools/perf/util/top.c | 18 ++++++++----------
tools/perf/util/top.h | 12 ++++++++----
3 files changed, 44 insertions(+), 22 deletions(-)
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 5987986b5203..f3ab46b234b6 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -902,8 +902,26 @@ struct reader_arg {
int idx;
struct perf_top *top;
struct hists *hists;
+ struct perf_top_stats stats;
};
+static void perf_top_stats__add(struct perf_top_stats *dst,
+ struct perf_top_stats *src)
+{
+ static pthread_mutex_t stats_lock = PTHREAD_MUTEX_INITIALIZER;
+
+ pthread_mutex_lock(&stats_lock);
+
+ dst->samples += src->samples;
+ dst->exact_samples += src->exact_samples;
+ dst->kernel_samples += src->kernel_samples;
+ dst->us_samples += src->us_samples;
+ dst->guest_kernel_samples += src->guest_kernel_samples;
+ dst->guest_us_samples += src->guest_us_samples;
+
+ pthread_mutex_unlock(&stats_lock);
+}
+
static void perf_event__process_sample(struct reader_arg *rarg,
const union perf_event *event,
struct perf_evsel *evsel,
@@ -938,7 +956,7 @@ static void perf_event__process_sample(struct reader_arg *rarg,
}
if (event->header.misc & PERF_RECORD_MISC_EXACT_IP)
- top->exact_samples++;
+ rarg->stats.exact_samples++;
if (perf_event__preprocess_sample(event, machine, &al, sample) < 0)
return;
@@ -1000,28 +1018,28 @@ static void perf_top__mmap_read(struct reader_arg *rarg)
origin = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
if (event->header.type == PERF_RECORD_SAMPLE)
- ++top->samples;
+ ++rarg->stats.samples;
switch (origin) {
case PERF_RECORD_MISC_USER:
- ++top->us_samples;
+ ++rarg->stats.us_samples;
if (top->hide_user_symbols)
goto next_event;
machine = &session->machines.host;
break;
case PERF_RECORD_MISC_KERNEL:
- ++top->kernel_samples;
+ ++rarg->stats.kernel_samples;
if (top->hide_kernel_symbols)
goto next_event;
machine = &session->machines.host;
break;
case PERF_RECORD_MISC_GUEST_KERNEL:
- ++top->guest_kernel_samples;
+ ++rarg->stats.guest_kernel_samples;
machine = perf_session__find_machine(session,
sample.pid);
break;
case PERF_RECORD_MISC_GUEST_USER:
- ++top->guest_us_samples;
+ ++rarg->stats.guest_us_samples;
/*
* TODO: we don't process guest user from host side
* except simple counting.
@@ -1065,12 +1083,14 @@ static void *mmap_read_worker(void *arg)
}
while (!done) {
- u64 hits = top->samples;
+ u64 hits = rarg->stats.samples;
perf_top__mmap_read(rarg);
- if (hits == top->samples)
+ if (hits == rarg->stats.samples)
perf_evlist__poll(top->evlist, 100);
+ else
+ perf_top_stats__add(&top->stats, &rarg->stats);
}
return NULL;
}
diff --git a/tools/perf/util/top.c b/tools/perf/util/top.c
index 8e517def925b..95d6bba1a2a0 100644
--- a/tools/perf/util/top.c
+++ b/tools/perf/util/top.c
@@ -30,10 +30,10 @@ size_t perf_top__header_snprintf(struct perf_top *top, char *bf, size_t size)
struct target *target = &opts->target;
size_t ret = 0;
- if (top->samples) {
- samples_per_sec = top->samples / top->delay_secs;
- ksamples_per_sec = top->kernel_samples / top->delay_secs;
- esamples_percent = (100.0 * top->exact_samples) / top->samples;
+ if (top->stats.samples) {
+ samples_per_sec = top->stats.samples / top->delay_secs;
+ ksamples_per_sec = top->stats.kernel_samples / top->delay_secs;
+ esamples_percent = (100.0 * top->stats.exact_samples) / top->stats.samples;
} else {
samples_per_sec = ksamples_per_sec = esamples_percent = 0.0;
}
@@ -49,9 +49,9 @@ size_t perf_top__header_snprintf(struct perf_top *top, char *bf, size_t size)
" exact: %4.1f%% [", samples_per_sec,
ksamples_percent, esamples_percent);
} else {
- float us_samples_per_sec = top->us_samples / top->delay_secs;
- float guest_kernel_samples_per_sec = top->guest_kernel_samples / top->delay_secs;
- float guest_us_samples_per_sec = top->guest_us_samples / top->delay_secs;
+ float us_samples_per_sec = top->stats.us_samples / top->delay_secs;
+ float guest_kernel_samples_per_sec = top->stats.guest_kernel_samples / top->delay_secs;
+ float guest_us_samples_per_sec = top->stats.guest_us_samples / top->delay_secs;
ret = SNPRINTF(bf, size,
" PerfTop:%8.0f irqs/sec kernel:%4.1f%% us:%4.1f%%"
@@ -111,7 +111,5 @@ size_t perf_top__header_snprintf(struct perf_top *top, char *bf, size_t size)
void perf_top__reset_sample_counters(struct perf_top *top)
{
- top->samples = top->us_samples = top->kernel_samples =
- top->exact_samples = top->guest_kernel_samples =
- top->guest_us_samples = 0;
+ memset(&top->stats, 0, sizeof(top->stats));
}
diff --git a/tools/perf/util/top.h b/tools/perf/util/top.h
index c56a00cff5b4..55eb5aebae59 100644
--- a/tools/perf/util/top.h
+++ b/tools/perf/util/top.h
@@ -11,18 +11,22 @@ struct perf_evlist;
struct perf_evsel;
struct perf_session;
+struct perf_top_stats {
+ u64 samples;
+ u64 exact_samples;
+ u64 kernel_samples, us_samples;
+ u64 guest_kernel_samples, guest_us_samples;
+};
+
struct perf_top {
struct perf_tool tool;
struct perf_evlist *evlist;
struct record_opts record_opts;
+ struct perf_top_stats stats;
/*
* Symbols will be added here in perf_event__process_sample and will
* get out after decayed.
*/
- u64 samples;
- u64 kernel_samples, us_samples;
- u64 exact_samples;
- u64 guest_us_samples, guest_kernel_samples;
int print_entries, count_filter, delay_secs;
int max_stack;
bool hide_kernel_symbols, hide_user_symbols, zero;
--
2.6.2
next prev parent reply other threads:[~2015-12-10 7:54 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-10 7:53 [PATCHSET 00/16] perf top: Add multi-thread support (v1) Namhyung Kim
2015-12-10 7:53 ` [PATCH/RFC 01/16] perf top: Delete half-processed hist entries when exit Namhyung Kim
2015-12-10 9:55 ` 平松雅巳 / HIRAMATU,MASAMI
2015-12-10 18:57 ` Arnaldo Carvalho de Melo
2015-12-14 8:15 ` [tip:perf/core] " tip-bot for Namhyung Kim
2015-12-10 7:53 ` [PATCH/RFC 02/16] perf top: Fix and cleanup perf_top__record_precise_ip() Namhyung Kim
2015-12-10 19:04 ` Arnaldo Carvalho de Melo
2015-12-11 2:27 ` Namhyung Kim
2015-12-10 7:53 ` [PATCH/RFC 03/16] perf top: Factor out warnings about kernel addresses and symbols Namhyung Kim
2015-12-10 19:07 ` Arnaldo Carvalho de Melo
2015-12-14 1:44 ` Namhyung Kim
2015-12-14 2:02 ` Namhyung Kim
2015-12-10 7:53 ` [PATCH/RFC 04/16] perf top: Factor out warnings in perf_top__record_precise_ip() Namhyung Kim
2015-12-10 7:53 ` [PATCH/RFC 05/16] perf top: Show warning messages in the display thread Namhyung Kim
2015-12-10 7:53 ` [PATCH/RFC 06/16] perf top: Get rid of access to hists->lock in perf_top__record_precise_ip() Namhyung Kim
2015-12-10 7:53 ` [PATCH/RFC 07/16] perf hists: Pass hists struct to hist_entry_iter struct Namhyung Kim
2015-12-13 23:15 ` Jiri Olsa
2015-12-14 1:45 ` Namhyung Kim
2015-12-10 7:53 ` [PATCH/RFC 08/16] perf tools: Export a couple of hist functions Namhyung Kim
2015-12-13 23:17 ` Jiri Olsa
2015-12-10 7:53 ` [PATCH/RFC 09/16] perf tools: Update hist entry's hists pointer Namhyung Kim
2015-12-13 23:23 ` Jiri Olsa
2015-12-13 23:28 ` Jiri Olsa
2015-12-14 1:51 ` Namhyung Kim
2015-12-10 7:53 ` [PATCH/RFC 10/16] perf hist: Add events_stats__add() and hists__add_stats() Namhyung Kim
2015-12-10 7:53 ` [PATCH/RFC 11/16] perf top: Implement basic parallel processing Namhyung Kim
2015-12-14 9:23 ` Jiri Olsa
2015-12-14 9:35 ` Jiri Olsa
2015-12-15 2:08 ` Namhyung Kim
2015-12-10 7:53 ` [PATCH/RFC 12/16] perf tools: Reduce lock contention when processing events Namhyung Kim
2015-12-14 8:43 ` Jiri Olsa
2015-12-15 2:03 ` Namhyung Kim
2015-12-10 7:53 ` [PATCH/RFC 13/16] perf top: Protect the seen list using mutex Namhyung Kim
2015-12-10 7:53 ` Namhyung Kim [this message]
2015-12-10 7:53 ` [PATCH/RFC 15/16] perf top: Add --num-thread option Namhyung Kim
2015-12-10 7:53 ` [PATCH/RFC 16/16] perf tools: Skip dso front cache for multi-threaded lookup Namhyung Kim
2015-12-10 8:01 ` [PATCHSET 00/16] perf top: Add multi-thread support (v1) Ingo Molnar
2015-12-10 8:49 ` Namhyung Kim
2015-12-11 8:11 ` Ingo Molnar
2015-12-11 15:01 ` David Ahern
2015-12-14 1:12 ` Namhyung Kim
2015-12-14 9:26 ` Peter Zijlstra
2015-12-14 9:38 ` Ingo Molnar
2015-12-14 14:55 ` David Ahern
2015-12-14 16:26 ` Arnaldo Carvalho de Melo
2015-12-14 16:41 ` Peter Zijlstra
2015-12-14 17:52 ` Arnaldo Carvalho de Melo
2015-12-14 16:38 ` Namhyung Kim
2015-12-14 16:56 ` Peter Zijlstra
2015-12-14 17:11 ` Namhyung Kim
2015-12-14 14:46 ` David Ahern
2015-12-14 17:06 ` Namhyung Kim
2015-12-14 17:54 ` Arnaldo Carvalho de Melo
2015-12-14 16:25 ` Namhyung Kim
2015-12-14 16:44 ` 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=1449734015-9148-15-git-send-email-namhyung@kernel.org \
--to=namhyung@kernel.org \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=andi@firstfloor.org \
--cc=dsahern@gmail.com \
--cc=eranian@google.com \
--cc=fweisbec@gmail.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@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;
as well as URLs for NNTP newsgroup(s).