From: Andi Kleen <andi@firstfloor.org>
To: acme@kernel.org
Cc: jolsa@kernel.org, eranian@google.com,
linux-kernel@vger.kernel.org, Andi Kleen <ak@linux.intel.com>
Subject: [PATCH 3/4] perf, tools, stat: Add support for metrics in interval mode
Date: Wed, 29 Jul 2015 17:21:39 -0700 [thread overview]
Message-ID: <1438215700-5530-4-git-send-email-andi@firstfloor.org> (raw)
In-Reply-To: <1438215700-5530-1-git-send-email-andi@firstfloor.org>
From: Andi Kleen <ak@linux.intel.com>
Now that we can modify the metrics printout functions easily,
it's straight forward to support metric printing for interval mode.
All that is needed is to print the time stamp on every new line.
Pass the prefix into the context and print it out.
Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
tools/perf/builtin-stat.c | 62 ++++++++++++++++++++++++++++++-----------------
1 file changed, 40 insertions(+), 22 deletions(-)
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index e6386f1..372e719 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -619,6 +619,9 @@ static void aggr_printout(struct perf_evsel *evsel, int id, int nr)
struct outstate {
FILE *fh;
+ const char *prefix;
+ int nfields;
+ u64 run, ena;
};
#define BASE_INDENT 41
@@ -629,13 +632,13 @@ struct outstate {
static void new_line_no_aggr_std(void *ctx)
{
struct outstate *os = ctx;
- fprintf(os->fh, "\n%*s", BASE_INDENT + NA_INDENT, "");
+ fprintf(os->fh, "\n%s%-*s", os->prefix, BASE_INDENT + NA_INDENT, "");
}
static void new_line_std(void *ctx)
{
struct outstate *os = ctx;
- fprintf(os->fh, "\n%-*s", BASE_INDENT + AGGR_INDENT, "");
+ fprintf(os->fh, "\n%s%-*s", os->prefix, BASE_INDENT + AGGR_INDENT, "");
}
static void print_metric_std(void *ctx, const char *color, const char *fmt,
@@ -662,6 +665,7 @@ static void nsec_printout(int id, int nr, struct perf_evsel *evsel, double avg,
void *ctx, print_metric_t print_metric)
{
double msecs = avg / 1e6;
+ double ratio;
const char *fmt_v, *fmt_n;
char name[25];
@@ -685,12 +689,13 @@ static void nsec_printout(int id, int nr, struct perf_evsel *evsel, double avg,
if (evsel->cgrp)
fprintf(output, "%s%s", csv_sep, evsel->cgrp->name);
- if (csv_output || interval)
+ if (csv_output)
return;
- if (perf_evsel__match(evsel, SOFTWARE, SW_TASK_CLOCK))
+ ratio = avg_stats(&walltime_nsecs_stats);
+ if (perf_evsel__match(evsel, SOFTWARE, SW_TASK_CLOCK) && ratio)
print_metric(ctx, NULL, "%8.3f", "CPUs utilized",
- avg / avg_stats(&walltime_nsecs_stats));
+ avg / ratio);
else
print_metric(ctx, NULL, NULL, NULL, 0);
}
@@ -730,7 +735,7 @@ static void abs_printout(int id, int nr, struct perf_evsel *evsel, double avg,
if (evsel->cgrp)
fprintf(output, "%s%s", csv_sep, evsel->cgrp->name);
- if (csv_output || interval)
+ if (csv_output)
return;
perf_stat__print_shadow_stats(evsel, avg, cpu,
@@ -739,17 +744,25 @@ static void abs_printout(int id, int nr, struct perf_evsel *evsel, double avg,
ctx);
}
-static void printout(int id, int nr, struct perf_evsel *counter, double uval)
+static void printout(int id, int nr, struct perf_evsel *counter, double uval,
+ char *prefix)
{
- struct outstate os = { .fh = output };
+ struct outstate os = {
+ .fh = output,
+ .prefix = prefix ? prefix : ""
+ };
+ print_metric_t pm = print_metric_std;
+ void (*nl)(void *);
+
+ if (aggr_mode == AGGR_NONE)
+ nl = new_line_no_aggr_std;
+ else
+ nl = new_line_std;
if (nsec_counter(counter))
- nsec_printout(id, nr, counter, uval, &os, print_metric_std);
+ nsec_printout(id, nr, counter, uval, &os, pm);
else
- abs_printout(id, nr, counter, uval, &os,
- print_metric_std,
- aggr_mode == AGGR_NONE ?
- new_line_no_aggr_std : new_line_std);
+ abs_printout(id, nr, counter, uval, &os, pm, nl);
}
static void print_aggr(char *prefix)
@@ -805,7 +818,7 @@ static void print_aggr(char *prefix)
continue;
}
uval = val * counter->scale;
- printout(id, nr, counter, uval);
+ printout(id, nr, counter, uval, prefix);
if (!csv_output)
print_noise(counter, 1.0);
@@ -835,7 +848,7 @@ static void print_aggr_thread(struct perf_evsel *counter, char *prefix)
fprintf(output, "%s", prefix);
uval = val * counter->scale;
- printout(thread, 0, counter, uval);
+ printout(thread, 0, counter, uval, prefix);
if (!csv_output)
print_noise(counter, 1.0);
@@ -884,7 +897,7 @@ static void print_counter_aggr(struct perf_evsel *counter, char *prefix)
}
uval = avg * counter->scale;
- printout(-1, 0, counter, uval);
+ printout(-1, 0, counter, uval, prefix);
print_noise(counter, avg);
@@ -936,7 +949,7 @@ static void print_counter(struct perf_evsel *counter, char *prefix)
}
uval = val * counter->scale;
- printout(cpu, 0, counter, uval);
+ printout(cpu, 0, counter, uval, prefix);
if (!csv_output)
print_noise(counter, 1.0);
@@ -955,20 +968,25 @@ static void print_interval(char *prefix, struct timespec *ts)
if (num_print_interval == 0 && !csv_output) {
switch (aggr_mode) {
case AGGR_SOCKET:
- fprintf(output, "# time socket cpus counts %*s events\n", unit_width, "unit");
+ fprintf(output, "# time socket cpus counts %*s events metric multiplex\n",
+ unit_width, "unit");
break;
case AGGR_CORE:
- fprintf(output, "# time core cpus counts %*s events\n", unit_width, "unit");
+ fprintf(output, "# time core cpus counts %*s events metric multiplex\n",
+ unit_width, "unit");
break;
case AGGR_NONE:
- fprintf(output, "# time CPU counts %*s events\n", unit_width, "unit");
+ fprintf(output, "# time CPU counts %*s events metric multiplex\n",
+ unit_width, "unit");
break;
case AGGR_THREAD:
- fprintf(output, "# time comm-pid counts %*s events\n", unit_width, "unit");
+ fprintf(output, "# time comm-pid counts %*s events metric\n",
+ unit_width, "unit");
break;
case AGGR_GLOBAL:
default:
- fprintf(output, "# time counts %*s events\n", unit_width, "unit");
+ fprintf(output, "# time counts %*s events metric multiplex\n",
+ unit_width, "unit");
}
}
--
2.4.3
next prev parent reply other threads:[~2015-07-30 0:36 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-30 0:21 perf, tools: Refactor and support interval and CSV metrics Andi Kleen
2015-07-30 0:21 ` [PATCH 1/4] perf, tools: Do not include escape sequences in color_vfprintf return Andi Kleen
2015-07-30 12:35 ` [PATCH] perf tools: Remove color_fprintf_ln function Jiri Olsa
2015-07-30 0:21 ` [PATCH 2/4] perf, tools, stat: Abstract stat metrics printing Andi Kleen
2015-07-30 13:42 ` Jiri Olsa
2015-07-30 13:47 ` Jiri Olsa
2015-08-04 0:41 ` Andi Kleen
2015-08-08 17:40 ` Jiri Olsa
2015-07-30 0:21 ` Andi Kleen [this message]
2015-07-30 13:53 ` [PATCH 3/4] perf, tools, stat: Add support for metrics in interval mode Jiri Olsa
2015-07-30 0:21 ` [PATCH 4/4] perf, tools, stat: Implement CSV metrics output Andi Kleen
2015-07-30 14:06 ` Jiri Olsa
2015-07-30 14:08 ` Jiri Olsa
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=1438215700-5530-4-git-send-email-andi@firstfloor.org \
--to=andi@firstfloor.org \
--cc=acme@kernel.org \
--cc=ak@linux.intel.com \
--cc=eranian@google.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.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