0001
0002
0003
0004
0005
0006
0007 #include <stdlib.h>
0008 #include "bench.h"
0009 #include "../util/stat.h"
0010 #include <linux/time64.h>
0011 #include <subcmd/parse-options.h>
0012 #include <symbol/kallsyms.h>
0013
0014 static unsigned int iterations = 100;
0015
0016 static const struct option options[] = {
0017 OPT_UINTEGER('i', "iterations", &iterations,
0018 "Number of iterations used to compute average"),
0019 OPT_END()
0020 };
0021
0022 static const char *const bench_usage[] = {
0023 "perf bench internals kallsyms-parse <options>",
0024 NULL
0025 };
0026
0027 static int bench_process_symbol(void *arg __maybe_unused,
0028 const char *name __maybe_unused,
0029 char type __maybe_unused,
0030 u64 start __maybe_unused)
0031 {
0032 return 0;
0033 }
0034
0035 static int do_kallsyms_parse(void)
0036 {
0037 struct timeval start, end, diff;
0038 u64 runtime_us;
0039 unsigned int i;
0040 double time_average, time_stddev;
0041 int err;
0042 struct stats time_stats;
0043
0044 init_stats(&time_stats);
0045
0046 for (i = 0; i < iterations; i++) {
0047 gettimeofday(&start, NULL);
0048 err = kallsyms__parse("/proc/kallsyms", NULL,
0049 bench_process_symbol);
0050 if (err)
0051 return err;
0052
0053 gettimeofday(&end, NULL);
0054 timersub(&end, &start, &diff);
0055 runtime_us = diff.tv_sec * USEC_PER_SEC + diff.tv_usec;
0056 update_stats(&time_stats, runtime_us);
0057 }
0058
0059 time_average = avg_stats(&time_stats) / USEC_PER_MSEC;
0060 time_stddev = stddev_stats(&time_stats) / USEC_PER_MSEC;
0061 printf(" Average kallsyms__parse took: %.3f ms (+- %.3f ms)\n",
0062 time_average, time_stddev);
0063 return 0;
0064 }
0065
0066 int bench_kallsyms_parse(int argc, const char **argv)
0067 {
0068 argc = parse_options(argc, argv, options, bench_usage, 0);
0069 if (argc) {
0070 usage_with_options(bench_usage, options);
0071 exit(EXIT_FAILURE);
0072 }
0073
0074 return do_kallsyms_parse();
0075 }