Merge tag 'ntb-5.11' of git://github.com/jonmason/ntb
[linux/fpc-iii.git] / tools / perf / bench / kallsyms-parse.c
blob2b0d0f980ae96eca14682aaebac45f65c052c980
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Benchmark of /proc/kallsyms parsing.
5 * Copyright 2020 Google LLC.
6 */
7 #include <stdlib.h>
8 #include "bench.h"
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"),
19 OPT_END()
22 static const char *const bench_usage[] = {
23 "perf bench internals kallsyms-parse <options>",
24 NULL
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)
32 return 0;
35 static int do_kallsyms_parse(void)
37 struct timeval start, end, diff;
38 u64 runtime_us;
39 unsigned int i;
40 double time_average, time_stddev;
41 int err;
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);
50 if (err)
51 return err;
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);
63 return 0;
66 int bench_kallsyms_parse(int argc, const char **argv)
68 argc = parse_options(argc, argv, options, bench_usage, 0);
69 if (argc) {
70 usage_with_options(bench_usage, options);
71 exit(EXIT_FAILURE);
74 return do_kallsyms_parse();