1 // SPDX-License-Identifier: GPL-2.0
3 * Benchmark of /proc/kallsyms parsing.
5 * Copyright 2020 Google LLC.
9 #include "../util/stat.h"
10 #include <linux/time64.h>
11 #include <subcmd/parse-options.h>
12 #include <symbol/kallsyms.h>
14 static unsigned int iterations
= 100;
16 static const struct option options
[] = {
17 OPT_UINTEGER('i', "iterations", &iterations
,
18 "Number of iterations used to compute average"),
22 static const char *const bench_usage
[] = {
23 "perf bench internals kallsyms-parse <options>",
27 static int bench_process_symbol(void *arg __maybe_unused
,
28 const char *name __maybe_unused
,
29 char type __maybe_unused
,
30 u64 start __maybe_unused
)
35 static int do_kallsyms_parse(void)
37 struct timeval start
, end
, diff
;
40 double time_average
, time_stddev
;
42 struct stats time_stats
;
44 init_stats(&time_stats
);
46 for (i
= 0; i
< iterations
; i
++) {
47 gettimeofday(&start
, NULL
);
48 err
= kallsyms__parse("/proc/kallsyms", NULL
,
49 bench_process_symbol
);
53 gettimeofday(&end
, NULL
);
54 timersub(&end
, &start
, &diff
);
55 runtime_us
= diff
.tv_sec
* USEC_PER_SEC
+ diff
.tv_usec
;
56 update_stats(&time_stats
, runtime_us
);
59 time_average
= avg_stats(&time_stats
) / USEC_PER_MSEC
;
60 time_stddev
= stddev_stats(&time_stats
) / USEC_PER_MSEC
;
61 printf(" Average kallsyms__parse took: %.3f ms (+- %.3f ms)\n",
62 time_average
, time_stddev
);
66 int bench_kallsyms_parse(int argc
, const char **argv
)
68 argc
= parse_options(argc
, argv
, options
, bench_usage
, 0);
70 usage_with_options(bench_usage
, options
);
74 return do_kallsyms_parse();