2 This file is part of GNUnet.
3 Copyright (C) 2018 GNUnet e.V.
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.
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.
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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
22 * @file util/benchmark.h
23 * @brief benchmarking for various operations
24 * @author Florian Dold <flo@dold.me>
30 #include "gnunet_time_lib.h"
33 * Maximum length of URLs considered for benchmarking.
34 * Shorter URLs are simply truncated.
36 #define MAX_BENCHMARK_URL_LEN 128
39 #define BENCHMARK_START(opname) \
40 struct GNUNET_TIME_Absolute _benchmark_##opname##_start = GNUNET_TIME_absolute_get ()
41 #define BENCHMARK_END(opname) do { \
43 struct GNUNET_TIME_Absolute _benchmark_##opname##_end = GNUNET_TIME_absolute_get (); \
44 struct BenchmarkData *bd = get_benchmark_data (); \
45 bd->opname##_count++; \
47 GNUNET_TIME_relative_add (bd->opname##_time, \
48 GNUNET_TIME_absolute_get_difference (_benchmark_##opname##_start, \
49 _benchmark_##opname##_end)); \
53 #define BENCHMARK_START(opname) do { } while (0)
54 #define BENCHMARK_END(opname) do { } while (0)
59 * Struct for benchmark data for one URL.
64 * Request URL, truncated (but 0-terminated).
66 char request_url[MAX_BENCHMARK_URL_LEN];
74 * How often was the URL requested?
79 * Total time spent requesting this URL.
81 struct GNUNET_TIME_Relative time;
84 * Slowest time to response.
86 struct GNUNET_TIME_Relative time_max;
89 * Fastest time to response.
91 struct GNUNET_TIME_Relative time_min;
94 #define GNUNET_DECLARE_BENCHMARK_OP(opname) \
95 uint64_t opname##_count; \
96 struct GNUNET_TIME_Relative opname##_time
99 * Thread-local struct for benchmarking data.
103 GNUNET_DECLARE_BENCHMARK_OP (ecc_ecdh);
104 GNUNET_DECLARE_BENCHMARK_OP (ecdh_eddsa);
105 GNUNET_DECLARE_BENCHMARK_OP (ecdhe_key_create);
106 GNUNET_DECLARE_BENCHMARK_OP (ecdhe_key_get_public);
107 GNUNET_DECLARE_BENCHMARK_OP (ecdsa_ecdh);
108 GNUNET_DECLARE_BENCHMARK_OP (ecdsa_key_create);
109 GNUNET_DECLARE_BENCHMARK_OP (ecdsa_key_get_public);
110 GNUNET_DECLARE_BENCHMARK_OP (ecdsa_sign);
111 GNUNET_DECLARE_BENCHMARK_OP (ecdsa_verify);
112 GNUNET_DECLARE_BENCHMARK_OP (eddsa_ecdh);
113 GNUNET_DECLARE_BENCHMARK_OP (eddsa_key_create);
114 GNUNET_DECLARE_BENCHMARK_OP (eddsa_key_get_public);
115 GNUNET_DECLARE_BENCHMARK_OP (eddsa_sign);
116 GNUNET_DECLARE_BENCHMARK_OP (eddsa_verify);
117 GNUNET_DECLARE_BENCHMARK_OP (hash);
118 GNUNET_DECLARE_BENCHMARK_OP (hash_context_finish);
119 GNUNET_DECLARE_BENCHMARK_OP (hash_context_read);
120 GNUNET_DECLARE_BENCHMARK_OP (hash_context_start);
121 GNUNET_DECLARE_BENCHMARK_OP (hkdf);
122 GNUNET_DECLARE_BENCHMARK_OP (rsa_blind);
123 GNUNET_DECLARE_BENCHMARK_OP (rsa_private_key_create);
124 GNUNET_DECLARE_BENCHMARK_OP (rsa_private_key_get_public);
125 GNUNET_DECLARE_BENCHMARK_OP (rsa_sign_blinded);
126 GNUNET_DECLARE_BENCHMARK_OP (rsa_unblind);
127 GNUNET_DECLARE_BENCHMARK_OP (rsa_verify);
129 struct UrlRequestData *urd;
131 unsigned int urd_len;
133 unsigned int urd_capacity;
136 #undef GNUNET_DECLARE_BENCHMARK_OP
140 * Acquire the benchmark data for the current thread, allocate if necessary.
141 * Installs handler to collect the benchmark data on thread termination.
143 * @return benchmark data for the current thread
145 struct BenchmarkData *
146 get_benchmark_data (void);
149 * Get benchmark data for a URL. If the URL is too long, it's truncated
150 * before looking up the correspoding benchmark data.
152 * Statistics are bucketed by URL and status code.
154 * @param url url to get request data for
155 * @param status http status code
157 struct UrlRequestData *
158 get_url_benchmark_data (char *url, unsigned int status);
160 #endif /* BENCHMARK_H_ */