From: tip-bot for Namhyung Kim <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: acme@redhat.com, linux-kernel@vger.kernel.org,
eranian@google.com, paulus@samba.org, hpa@zytor.com,
mingo@kernel.org, a.p.zijlstra@chello.nl, namhyung.kim@lge.com,
namhyung@kernel.org, jolsa@redhat.com, dsahern@gmail.com,
tglx@linutronix.de
Subject: [tip:perf/core] perf top: Fix percent output when no samples collected
Date: Fri, 31 May 2013 04:35:46 -0700 [thread overview]
Message-ID: <tip-6f29097f45f6c375f2f6a76c589577575c7feb52@git.kernel.org> (raw)
In-Reply-To: <1368497347-9628-3-git-send-email-namhyung@kernel.org>
Commit-ID: 6f29097f45f6c375f2f6a76c589577575c7feb52
Gitweb: http://git.kernel.org/tip/6f29097f45f6c375f2f6a76c589577575c7feb52
Author: Namhyung Kim <namhyung.kim@lge.com>
AuthorDate: Tue, 14 May 2013 11:09:00 +0900
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 28 May 2013 16:23:59 +0300
perf top: Fix percent output when no samples collected
If there's no sample, kernel and exact percent output at the header
looked like "-nan%".
Tested-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1368497347-9628-3-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/top.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/tools/perf/util/top.c b/tools/perf/util/top.c
index 54d37a4..f857b51 100644
--- a/tools/perf/util/top.c
+++ b/tools/perf/util/top.c
@@ -23,20 +23,31 @@
size_t perf_top__header_snprintf(struct perf_top *top, char *bf, size_t size)
{
- float samples_per_sec = top->samples / top->delay_secs;
- float ksamples_per_sec = top->kernel_samples / top->delay_secs;
- float esamples_percent = (100.0 * top->exact_samples) / top->samples;
+ float samples_per_sec;
+ float ksamples_per_sec;
+ float esamples_percent;
struct perf_record_opts *opts = &top->record_opts;
struct perf_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;
+ } else {
+ samples_per_sec = ksamples_per_sec = esamples_percent = 0.0;
+ }
+
if (!perf_guest) {
+ float ksamples_percent = 0.0;
+
+ if (samples_per_sec)
+ ksamples_percent = (100.0 * ksamples_per_sec) /
+ samples_per_sec;
ret = SNPRINTF(bf, size,
" PerfTop:%8.0f irqs/sec kernel:%4.1f%%"
" exact: %4.1f%% [", samples_per_sec,
- 100.0 - (100.0 * ((samples_per_sec - ksamples_per_sec) /
- samples_per_sec)),
- esamples_percent);
+ 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;
next prev parent reply other threads:[~2013-05-31 11:36 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-14 2:08 [PATCHSET 0/9] perf tools: Assorted fixes and changes on perf top/report Namhyung Kim
2013-05-14 2:08 ` [PATCH 1/9] perf top: Fix -E option behavior Namhyung Kim
2013-05-17 14:21 ` Jiri Olsa
2013-05-31 11:34 ` [tip:perf/core] " tip-bot for Namhyung Kim
2013-05-14 2:09 ` [PATCH 2/9] perf top: Fix percent output when no samples collected Namhyung Kim
2013-05-17 14:22 ` Jiri Olsa
2013-05-31 11:35 ` tip-bot for Namhyung Kim [this message]
2013-05-14 2:09 ` [PATCH 3/9] perf top: Get rid of *_threaded() functions Namhyung Kim
2013-05-17 14:28 ` Jiri Olsa
2013-05-31 11:37 ` [tip:perf/core] " tip-bot for Namhyung Kim
2013-05-14 2:09 ` [PATCH 4/9] perf hists: Move locking to its call-sites Namhyung Kim
2013-05-17 14:39 ` Jiri Olsa
2013-05-31 11:38 ` [tip:perf/core] " tip-bot for Namhyung Kim
2013-05-14 2:09 ` [PATCH 5/9] perf report: Don't be bothered with locking when adding hist entries Namhyung Kim
2013-05-17 14:39 ` Jiri Olsa
2013-05-31 11:39 ` [tip:perf/core] perf report: Don' t bother " tip-bot for Namhyung Kim
2013-05-14 2:09 ` [PATCH 6/9] perf report: Add --percent-limit option Namhyung Kim
2013-05-31 11:40 ` [tip:perf/core] " tip-bot for Namhyung Kim
2013-05-14 2:09 ` [PATCH 7/9] perf top: " Namhyung Kim
2013-05-31 11:42 ` [tip:perf/core] " tip-bot for Namhyung Kim
2013-05-14 2:09 ` [PATCH 8/9] perf report: Add report.percent-limit config variable Namhyung Kim
2013-05-14 11:05 ` Pekka Enberg
2013-05-15 10:08 ` Namhyung Kim
2013-05-16 7:34 ` Pekka Enberg
2013-05-31 11:43 ` [tip:perf/core] " tip-bot for Namhyung Kim
2013-05-14 2:09 ` [PATCH 9/9] perf top: Reuse " Namhyung Kim
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=tip-6f29097f45f6c375f2f6a76c589577575c7feb52@git.kernel.org \
--to=tipbot@zytor.com \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@redhat.com \
--cc=dsahern@gmail.com \
--cc=eranian@google.com \
--cc=hpa@zytor.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung.kim@lge.com \
--cc=namhyung@kernel.org \
--cc=paulus@samba.org \
--cc=tglx@linutronix.de \
/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
Powered by JetHome