hbench: comments
[helenos.git] / uspace / app / hbench / hbench.h
blobee7ea613e6bab70c1c59dcd46aa0c5f23df660da
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 <stdbool.h>
42 #include <perf.h>
44 /** Single run information.
46 * Used to store both performance information (now, only wall-clock
47 * time) as well as information about error.
49 * Use proper access functions when modifying data inside this structure.
51 * Eventually, we could collection of hardware counters etc. without
52 * modifying signatures of any existing benchmark.
54 typedef struct {
55 stopwatch_t stopwatch;
56 char *error_buffer;
57 size_t error_buffer_size;
58 } bench_run_t;
60 /** Benchmark environment configuration.
62 * Use proper access functions when modifying data inside this structure.
64 typedef struct {
65 hash_table_t parameters;
66 } bench_env_t;
68 /** Actual benchmark runner.
70 * The first argument describes the environment, second is used to store
71 * information about the run (performance data or error message) and
72 * third describes workload size (number of iterations).
74 typedef bool (*benchmark_entry_t)(bench_env_t *, bench_run_t *, uint64_t);
76 /** Setup and teardown callback type.
78 * Unlike in benchmark_entry_t, we do not need to pass in number of
79 * iterations to execute (note that we use bench_run_t only to simplify
80 * creation of error messages).
82 typedef bool (*benchmark_helper_t)(bench_env_t *, bench_run_t *);
84 typedef struct {
85 const char *name;
86 const char *desc;
87 benchmark_entry_t entry;
88 benchmark_helper_t setup;
89 benchmark_helper_t teardown;
90 } benchmark_t;
92 extern void bench_run_init(bench_run_t *, char *, size_t);
93 extern bool bench_run_fail(bench_run_t *, const char *, ...);
95 static inline void bench_run_start(bench_run_t *run)
97 stopwatch_start(&run->stopwatch);
100 static inline void bench_run_stop(bench_run_t *run)
102 stopwatch_stop(&run->stopwatch);
105 extern errno_t csv_report_open(const char *);
106 extern void csv_report_add_entry(bench_run_t *, int, benchmark_t *, uint64_t);
107 extern void csv_report_close(void);
109 extern errno_t bench_env_init(bench_env_t *);
110 extern errno_t bench_env_param_set(bench_env_t *, const char *, const char *);
111 extern const char *bench_env_param_get(bench_env_t *, const char *, const char *);
112 extern void bench_env_cleanup(bench_env_t *);
114 extern benchmark_t *benchmarks[];
115 extern size_t benchmark_count;
117 /* Put your benchmark descriptors here (and also to benchlist.c). */
118 extern benchmark_t benchmark_dir_read;
119 extern benchmark_t benchmark_fibril_mutex;
120 extern benchmark_t benchmark_file_read;
121 extern benchmark_t benchmark_malloc1;
122 extern benchmark_t benchmark_malloc2;
123 extern benchmark_t benchmark_ns_ping;
124 extern benchmark_t benchmark_ping_pong;
126 #endif
128 /** @}