2 * Copyright (c) 2018 Jiri Svoboda
3 * Copyright (c) 2019 Vojtech Horky
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 /** @addtogroup hbench
39 #include <adt/hash_table.h>
46 /** Single run information.
48 * Used to store both performance information (now, only wall-clock
49 * time) as well as information about error.
51 * Use proper access functions when modifying data inside this structure.
53 * Eventually, we could collection of hardware counters etc. without
54 * modifying signatures of any existing benchmark.
57 stopwatch_t stopwatch
;
59 size_t error_buffer_size
;
62 /** Benchmark environment configuration.
64 * Use proper access functions when modifying data inside this structure.
67 hash_table_t parameters
;
70 typedef bool (*benchmark_entry_t
)(bench_env_t
*, bench_run_t
*, uint64_t);
71 typedef bool (*benchmark_helper_t
)(bench_env_t
*, bench_run_t
*);
76 benchmark_entry_t entry
;
77 benchmark_helper_t setup
;
78 benchmark_helper_t teardown
;
81 static inline void bench_run_init(bench_run_t
*run
, char *error_buffer
,
82 size_t error_buffer_size
)
84 stopwatch_init(&run
->stopwatch
);
85 run
->error_buffer
= error_buffer
;
86 run
->error_buffer_size
= error_buffer_size
;
89 static inline void bench_run_start(bench_run_t
*run
)
91 stopwatch_start(&run
->stopwatch
);
94 static inline void bench_run_stop(bench_run_t
*run
)
96 stopwatch_stop(&run
->stopwatch
);
99 static inline bool bench_run_fail(bench_run_t
*run
, const char *fmt
, ...)
103 vsnprintf(run
->error_buffer
, run
->error_buffer_size
, fmt
, args
);
109 extern benchmark_t
*benchmarks
[];
110 extern size_t benchmark_count
;
112 extern errno_t
csv_report_open(const char *);
113 extern void csv_report_add_entry(bench_run_t
*, int, benchmark_t
*, uint64_t);
114 extern void csv_report_close(void);
116 extern errno_t
bench_env_init(bench_env_t
*);
117 extern errno_t
bench_env_param_set(bench_env_t
*, const char *, const char *);
118 extern const char *bench_env_param_get(bench_env_t
*, const char *, const char *);
119 extern void bench_env_cleanup(bench_env_t
*);
121 /* Put your benchmark descriptors here (and also to benchlist.c). */
122 extern benchmark_t benchmark_dir_read
;
123 extern benchmark_t benchmark_fibril_mutex
;
124 extern benchmark_t benchmark_file_read
;
125 extern benchmark_t benchmark_malloc1
;
126 extern benchmark_t benchmark_malloc2
;
127 extern benchmark_t benchmark_ns_ping
;
128 extern benchmark_t benchmark_ping_pong
;