aboutsummaryrefslogtreecommitdiff
path: root/src/lib/util/benchmark.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/util/benchmark.h')
-rw-r--r--src/lib/util/benchmark.h174
1 files changed, 174 insertions, 0 deletions
diff --git a/src/lib/util/benchmark.h b/src/lib/util/benchmark.h
new file mode 100644
index 000000000..e35fa50bd
--- /dev/null
+++ b/src/lib/util/benchmark.h
@@ -0,0 +1,174 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2018 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file util/benchmark.h
23 * @brief benchmarking for various operations
24 * @author Florian Dold <flo@dold.me>
25 */
26
27#ifndef BENCHMARK_H_
28#define BENCHMARK_H_
29
30#include "gnunet_time_lib.h"
31
32/**
33 * Maximum length of URLs considered for benchmarking.
34 * Shorter URLs are simply truncated.
35 */
36#define MAX_BENCHMARK_URL_LEN 128
37
38#if ENABLE_BENCHMARK
39#define BENCHMARK_START(opname) \
40 struct GNUNET_TIME_Absolute _benchmark_ ## opname ## _start = \
41 GNUNET_TIME_absolute_get ()
42#define BENCHMARK_END(opname) do { \
43 { \
44 struct GNUNET_TIME_Absolute _benchmark_ ## opname ## _end = \
45 GNUNET_TIME_absolute_get (); \
46 struct BenchmarkData *bd = get_benchmark_data (); \
47 bd->opname ## _count++; \
48 bd->opname ## _time = \
49 GNUNET_TIME_relative_add (bd->opname ## _time, \
50 GNUNET_TIME_absolute_get_difference ( \
51 _benchmark_ ## opname ## _start, \
52 _benchmark_ \
53 ## opname ## _end)); \
54 } \
55} while (0)
56#else
57#define BENCHMARK_START(opname) do { } while (0)
58#define BENCHMARK_END(opname) do { } while (0)
59#endif
60
61
62/**
63 * Struct for benchmark data for one URL.
64 */
65struct UrlRequestData
66{
67 /**
68 * Request URL, truncated (but 0-terminated).
69 */
70 char request_url[MAX_BENCHMARK_URL_LEN];
71
72 /**
73 * HTTP status code.
74 */
75 unsigned int status;
76
77 /**
78 * How often was the URL requested?
79 */
80 uint64_t count;
81
82 /**
83 * How many bytes were sent in total to request the URL.
84 */
85 uint64_t bytes_sent;
86
87 /**
88 * How many bytes were received in total as response to requesting this URL.
89 */
90 uint64_t bytes_received;
91
92 /**
93 * Total time spent requesting this URL.
94 */
95 struct GNUNET_TIME_Relative time;
96
97 /**
98 * Slowest time to response.
99 */
100 struct GNUNET_TIME_Relative time_max;
101
102 /**
103 * Fastest time to response.
104 */
105 struct GNUNET_TIME_Relative time_min;
106};
107
108#define GNUNET_DECLARE_BENCHMARK_OP(opname) \
109 uint64_t opname ## _count; \
110 struct GNUNET_TIME_Relative opname ## _time
111
112/**
113 * Thread-local struct for benchmarking data.
114 */
115struct BenchmarkData
116{
117 GNUNET_DECLARE_BENCHMARK_OP (ecc_ecdh);
118 GNUNET_DECLARE_BENCHMARK_OP (ecdh_eddsa);
119 GNUNET_DECLARE_BENCHMARK_OP (ecdhe_key_create);
120 GNUNET_DECLARE_BENCHMARK_OP (ecdhe_key_get_public);
121 GNUNET_DECLARE_BENCHMARK_OP (ecdsa_ecdh);
122 GNUNET_DECLARE_BENCHMARK_OP (ecdsa_key_create);
123 GNUNET_DECLARE_BENCHMARK_OP (ecdsa_key_get_public);
124 GNUNET_DECLARE_BENCHMARK_OP (ecdsa_sign);
125 GNUNET_DECLARE_BENCHMARK_OP (ecdsa_verify);
126 GNUNET_DECLARE_BENCHMARK_OP (eddsa_ecdh);
127 GNUNET_DECLARE_BENCHMARK_OP (eddsa_key_create);
128 GNUNET_DECLARE_BENCHMARK_OP (eddsa_key_get_public);
129 GNUNET_DECLARE_BENCHMARK_OP (eddsa_sign);
130 GNUNET_DECLARE_BENCHMARK_OP (eddsa_verify);
131 GNUNET_DECLARE_BENCHMARK_OP (hash);
132 GNUNET_DECLARE_BENCHMARK_OP (hash_context_finish);
133 GNUNET_DECLARE_BENCHMARK_OP (hash_context_read);
134 GNUNET_DECLARE_BENCHMARK_OP (hash_context_start);
135 GNUNET_DECLARE_BENCHMARK_OP (hkdf);
136 GNUNET_DECLARE_BENCHMARK_OP (rsa_blind);
137 GNUNET_DECLARE_BENCHMARK_OP (rsa_private_key_create);
138 GNUNET_DECLARE_BENCHMARK_OP (rsa_private_key_get_public);
139 GNUNET_DECLARE_BENCHMARK_OP (rsa_sign_blinded);
140 GNUNET_DECLARE_BENCHMARK_OP (rsa_unblind);
141 GNUNET_DECLARE_BENCHMARK_OP (rsa_verify);
142
143 struct UrlRequestData *urd;
144
145 unsigned int urd_len;
146
147 unsigned int urd_capacity;
148};
149
150#undef GNUNET_DECLARE_BENCHMARK_OP
151
152
153/**
154 * Acquire the benchmark data for the current thread, allocate if necessary.
155 * Installs handler to collect the benchmark data on thread termination.
156 *
157 * @return benchmark data for the current thread
158 */
159struct BenchmarkData *
160get_benchmark_data (void);
161
162/**
163 * Get benchmark data for a URL. If the URL is too long, it's truncated
164 * before looking up the corresponding benchmark data.
165 *
166 * Statistics are bucketed by URL and status code.
167 *
168 * @param url url to get request data for
169 * @param status http status code
170 */
171struct UrlRequestData *
172get_url_benchmark_data (char *url, unsigned int status);
173
174#endif /* BENCHMARK_H_ */