Re: [PATCH 2/5] perf bench uprobe: Print diff to baseline

From: Google
Date: Fri Jul 21 2023 - 10:44:11 EST


On Wed, 19 Jul 2023 17:49:07 -0300
Arnaldo Carvalho de Melo <acme@xxxxxxxxxx> wrote:

> From: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
>
> This is just prep work to show the diff to the unmodified workload.

Looks good to me, just one comment below.

Reviewed-by: Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>

>
> Cc: Adrian Hunter <adrian.hunter@xxxxxxxxx>
> Cc: Andre Fredette <anfredet@xxxxxxxxxx>
> Cc: Clark Williams <williams@xxxxxxxxxx>
> Cc: Dave Tucker <datucker@xxxxxxxxxx>
> Cc: Derek Barbosa <debarbos@xxxxxxxxxx>
> Cc: Ian Rogers <irogers@xxxxxxxxxx>
> Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
> Cc: Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>
> Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
> Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
> ---
> tools/perf/bench/uprobe.c | 27 ++++++++++++++++++++++++---
> 1 file changed, 24 insertions(+), 3 deletions(-)
>
> diff --git a/tools/perf/bench/uprobe.c b/tools/perf/bench/uprobe.c
> index 707174220a76701f..60e7c43298d8cf56 100644
> --- a/tools/perf/bench/uprobe.c
> +++ b/tools/perf/bench/uprobe.c
> @@ -34,6 +34,29 @@ static const char * const bench_uprobe_usage[] = {
> NULL
> };
>
> +static int bench_uprobe_format__default_fprintf(const char *name, const char *unit, u64 diff, FILE *fp)
> +{
> + static u64 baseline;
> + s64 diff_to_baseline = diff - baseline;
> + int printed = fprintf(fp, "# Executed %'d %s calls\n", loops, name);
> +
> + printed += fprintf(fp, " %14s: %'" PRIu64 " %ss", "Total time", diff, unit);
> +
> + if (baseline)
> + printed += fprintf(fp, " %s%'" PRId64 " to baseline", diff_to_baseline > 0 ? "+" : "", diff_to_baseline);
> +
> + printed += fprintf(fp, "\n\n %'.3f %ss/op", (double)diff / (double)loops, unit);

Just a nit, do we need to repeat (double) cast on the denominator side too?

> +
> + if (baseline)
> + printed += fprintf(fp, " %'.3f %ss/op to baseline", (double)diff_to_baseline / (double)loops, unit);
> + else
> + baseline = diff;
> +
> + fputc('\n', fp);
> +
> + return printed + 1;
> +}
> +
> static int bench_uprobe(int argc, const char **argv)
> {
> const char *name = "usleep(1000)", *unit = "usec";
> @@ -56,9 +79,7 @@ static int bench_uprobe(int argc, const char **argv)
>
> switch (bench_format) {
> case BENCH_FORMAT_DEFAULT:
> - printf("# Executed %'d %s calls\n", loops, name);
> - printf(" %14s: %'" PRIu64 " %ss\n\n", "Total time", diff, unit);
> - printf(" %'.3f %ss/op\n", (double)diff / (double)loops, unit);
> + bench_uprobe_format__default_fprintf(name, unit, diff, stdout);
> break;
>
> case BENCH_FORMAT_SIMPLE:
> --
> 2.41.0
>


--
Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>