summaryrefslogtreecommitdiffstats
path: root/tools/perf/bench/uprobe.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2023-06-02 15:18:27 -0300
committerArnaldo Carvalho de Melo <acme@redhat.com>2023-07-20 11:31:19 -0300
commit2df270716447a1024a6c955eed8fa579333dca85 (patch)
tree5e389e2bfa86a8bf35ef45dd966cf8da4e939eb6 /tools/perf/bench/uprobe.c
parentfaa4e0da1cbab97aa18bb6562ab32d9f0fc32e82 (diff)
downloadlinux-stable-2df270716447a1024a6c955eed8fa579333dca85.tar.gz
linux-stable-2df270716447a1024a6c955eed8fa579333dca85.tar.bz2
linux-stable-2df270716447a1024a6c955eed8fa579333dca85.zip
perf bench uprobe: Add benchmark to test uprobe overhead
This just adds the initial "workload", a call to libc's usleep(1000us) function: $ perf stat --null perf bench uprobe all # Running uprobe/baseline benchmark... # Executed 1000 usleep(1000) calls Total time: 1053533 usecs 1053.533 usecs/op Performance counter stats for 'perf bench uprobe all': 1.061042896 seconds time elapsed 0.001079000 seconds user 0.006499000 seconds sys $ More entries will be added using a BPF skel to add various uprobes to the usleep() function. Acked-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Andre Fredette <anfredet@redhat.com> Cc: Clark Williams <williams@redhat.com> Cc: Dave Tucker <datucker@redhat.com> Cc: Derek Barbosa <debarbos@redhat.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Masami Hiramatsu (Google) <mhiramat@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Link: https://lore.kernel.org/lkml/20230719204910.539044-2-acme@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/bench/uprobe.c')
-rw-r--r--tools/perf/bench/uprobe.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/tools/perf/bench/uprobe.c b/tools/perf/bench/uprobe.c
new file mode 100644
index 000000000000..707174220a76
--- /dev/null
+++ b/tools/perf/bench/uprobe.c
@@ -0,0 +1,80 @@
+// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+/*
+ * uprobe.c
+ *
+ * uprobe benchmarks
+ *
+ * Copyright (C) 2023, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
+ */
+#include "../perf.h"
+#include "../util/util.h"
+#include <subcmd/parse-options.h>
+#include "../builtin.h"
+#include "bench.h"
+#include <linux/time64.h>
+
+#include <inttypes.h>
+#include <stdio.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <time.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#define LOOPS_DEFAULT 1000
+static int loops = LOOPS_DEFAULT;
+
+static const struct option options[] = {
+ OPT_INTEGER('l', "loop", &loops, "Specify number of loops"),
+ OPT_END()
+};
+
+static const char * const bench_uprobe_usage[] = {
+ "perf bench uprobe <options>",
+ NULL
+};
+
+static int bench_uprobe(int argc, const char **argv)
+{
+ const char *name = "usleep(1000)", *unit = "usec";
+ struct timespec start, end;
+ u64 diff;
+ int i;
+
+ argc = parse_options(argc, argv, options, bench_uprobe_usage, 0);
+
+ clock_gettime(CLOCK_REALTIME, &start);
+
+ for (i = 0; i < loops; i++) {
+ usleep(USEC_PER_MSEC);
+ }
+
+ clock_gettime(CLOCK_REALTIME, &end);
+
+ diff = end.tv_sec * NSEC_PER_SEC + end.tv_nsec - (start.tv_sec * NSEC_PER_SEC + start.tv_nsec);
+ diff /= NSEC_PER_USEC;
+
+ 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);
+ break;
+
+ case BENCH_FORMAT_SIMPLE:
+ printf("%" PRIu64 "\n", diff);
+ break;
+
+ default:
+ /* reaching here is something of a disaster */
+ fprintf(stderr, "Unknown format:%d\n", bench_format);
+ exit(1);
+ }
+
+ return 0;
+}
+
+int bench_uprobe_baseline(int argc, const char **argv)
+{
+ return bench_uprobe(argc, argv);
+}