hbench: remove global state
[helenos.git] / uspace / app / hbench / hbench.h
blobba6626fc4abe3d3554ed52c8fc2e52da5d62edc2
1 /*
2 * Copyright (c) 2018 Jiri Svoboda
3 * Copyright (c) 2019 Vojtech Horky
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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
31 * @{
33 /** @file
36 #ifndef HBENCH_H_
37 #define HBENCH_H_
39 #include <adt/hash_table.h>
40 #include <errno.h>
41 #include <stdarg.h>
42 #include <stdbool.h>
43 #include <stdio.h>
44 #include <perf.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.
56 typedef struct {
57 stopwatch_t stopwatch;
58 char *error_buffer;
59 size_t error_buffer_size;
60 } bench_run_t;
62 /** Benchmark environment configuration.
64 * Use proper access functions when modifying data inside this structure.
66 typedef struct {
67 hash_table_t parameters;
68 } bench_env_t;
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 *);
73 typedef struct {
74 const char *name;
75 const char *desc;
76 benchmark_entry_t entry;
77 benchmark_helper_t setup;
78 benchmark_helper_t teardown;
79 } benchmark_t;
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, ...)
101 va_list args;
102 va_start(args, fmt);
103 vsnprintf(run->error_buffer, run->error_buffer_size, fmt, args);
104 va_end(args);
106 return false;
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;
130 #endif
132 /** @}