GNUnet debian-0.24.3-29-g453fda2cf
 
Loading...
Searching...
No Matches
benchmark.h File Reference

benchmarking for various operations More...

#include "gnunet_time_lib.h"
Include dependency graph for benchmark.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  UrlRequestData
 Struct for benchmark data for one URL. More...
 
struct  BenchmarkData
 Thread-local struct for benchmarking data. More...
 

Macros

#define MAX_BENCHMARK_URL_LEN   128
 Maximum length of URLs considered for benchmarking.
 
#define BENCHMARK_START(opname)   do { } while (0)
 
#define BENCHMARK_END(opname)   do { } while (0)
 
#define GNUNET_DECLARE_BENCHMARK_OP(opname)
 

Functions

struct BenchmarkDataget_benchmark_data (void)
 Acquire the benchmark data for the current thread, allocate if necessary.
 
struct UrlRequestDataget_url_benchmark_data (char *url, unsigned int status)
 Get benchmark data for a URL.
 

Detailed Description

benchmarking for various operations

Author
Florian Dold flo@d.nosp@m.old..nosp@m.me

Definition in file benchmark.h.

Macro Definition Documentation

◆ MAX_BENCHMARK_URL_LEN

#define MAX_BENCHMARK_URL_LEN   128

Maximum length of URLs considered for benchmarking.

Shorter URLs are simply truncated.

Definition at line 36 of file benchmark.h.

◆ BENCHMARK_START

#define BENCHMARK_START (   opname)    do { } while (0)

Definition at line 57 of file benchmark.h.

◆ BENCHMARK_END

#define BENCHMARK_END (   opname)    do { } while (0)

Definition at line 58 of file benchmark.h.

◆ GNUNET_DECLARE_BENCHMARK_OP

#define GNUNET_DECLARE_BENCHMARK_OP (   opname)
Value:
uint64_t opname ## _count; \
struct GNUNET_TIME_Relative opname ## _time
Time for relative time used by GNUnet, in microseconds.

Definition at line 108 of file benchmark.h.

115{
117 GNUNET_DECLARE_BENCHMARK_OP (ecdh_eddsa);
118 GNUNET_DECLARE_BENCHMARK_OP (ecdhe_key_create);
119 GNUNET_DECLARE_BENCHMARK_OP (ecdhe_key_get_public);
120 GNUNET_DECLARE_BENCHMARK_OP (ecdsa_ecdh);
121 GNUNET_DECLARE_BENCHMARK_OP (ecdsa_key_create);
122 GNUNET_DECLARE_BENCHMARK_OP (ecdsa_key_get_public);
123 GNUNET_DECLARE_BENCHMARK_OP (ecdsa_sign);
124 GNUNET_DECLARE_BENCHMARK_OP (ecdsa_verify);
125 GNUNET_DECLARE_BENCHMARK_OP (eddsa_ecdh);
126 GNUNET_DECLARE_BENCHMARK_OP (eddsa_key_create);
127 GNUNET_DECLARE_BENCHMARK_OP (eddsa_key_get_public);
128 GNUNET_DECLARE_BENCHMARK_OP (eddsa_sign);
129 GNUNET_DECLARE_BENCHMARK_OP (eddsa_verify);
131 GNUNET_DECLARE_BENCHMARK_OP (hash_context_finish);
132 GNUNET_DECLARE_BENCHMARK_OP (hash_context_read);
133 GNUNET_DECLARE_BENCHMARK_OP (hash_context_start);
135 GNUNET_DECLARE_BENCHMARK_OP (rsa_blind);
136 GNUNET_DECLARE_BENCHMARK_OP (rsa_private_key_create);
137 GNUNET_DECLARE_BENCHMARK_OP (rsa_private_key_get_public);
138 GNUNET_DECLARE_BENCHMARK_OP (rsa_sign_blinded);
139 GNUNET_DECLARE_BENCHMARK_OP (rsa_unblind);
140 GNUNET_DECLARE_BENCHMARK_OP (rsa_verify);
141
142 struct UrlRequestData *urd;
143
144 unsigned int urd_len;
145
146 unsigned int urd_capacity;
147};
148
149#undef GNUNET_DECLARE_BENCHMARK_OP
150
151
158struct BenchmarkData *
159get_benchmark_data (void);
160
170struct UrlRequestData *
171get_url_benchmark_data (char *url, unsigned int status);
172
173#endif /* BENCHMARK_H_ */
struct UrlRequestData * get_url_benchmark_data(char *url, unsigned int status)
Get benchmark data for a URL.
Definition benchmark.c:242
struct BenchmarkData * get_benchmark_data(void)
Acquire the benchmark data for the current thread, allocate if necessary.
Definition benchmark.c:212
#define GNUNET_DECLARE_BENCHMARK_OP(opname)
Definition benchmark.h:108
static int status
The program status; 0 for success.
Definition gnunet-nse.c:39
Thread-local struct for benchmarking data.
Definition benchmark.h:116
Struct for benchmark data for one URL.
Definition benchmark.h:66

Function Documentation

◆ get_benchmark_data()

struct BenchmarkData * get_benchmark_data ( void  )

Acquire the benchmark data for the current thread, allocate if necessary.

Installs handler to collect the benchmark data on thread termination.

Returns
benchmark data for the current thread

Definition at line 212 of file benchmark.c.

213{
214 struct BenchmarkData *bd;
215
216 (void) pthread_once (&key_once, &make_key);
217
218 if (NULL == (bd = pthread_getspecific (key)))
219 {
220 bd = GNUNET_new (struct BenchmarkData);
221 (void) pthread_setspecific (key, bd);
222 if (getpid () == (pid_t) syscall (SYS_gettid))
223 {
224 // We're the main thread!
225 atexit (main_thread_destructor);
226 }
227 }
228 return bd;
229}
static void make_key()
Initialize the thread-local variable key for benchmark data.
Definition benchmark.c:199
static pthread_once_t key_once
One-time initialization marker for key.
Definition benchmark.c:42
static void main_thread_destructor()
Called when the main thread exits and benchmark data for it was created.
Definition benchmark.c:166
static pthread_key_t key
Thread-local storage key for the benchmark data.
Definition benchmark.c:37
#define GNUNET_new(type)
Allocate a struct or union of the given type.

References GNUNET_new, key, key_once, main_thread_destructor(), and make_key().

Referenced by get_url_benchmark_data().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_url_benchmark_data()

struct UrlRequestData * get_url_benchmark_data ( char *  url,
unsigned int  status 
)

Get benchmark data for a URL.

If the URL is too long, it's truncated before looking up the corresponding benchmark data.

Statistics are bucketed by URL and status code.

Parameters
urlurl to get request data for
statushttp status code

Definition at line 242 of file benchmark.c.

243{
244 char trunc[MAX_BENCHMARK_URL_LEN];
245 struct BenchmarkData *bd;
246
247 if (NULL == url)
248 {
249 /* Should not happen unless curl barfs */
250 GNUNET_break (0);
251 url = "<empty>";
252 }
253
254 memcpy (trunc, url, MAX_BENCHMARK_URL_LEN);
255 trunc[MAX_BENCHMARK_URL_LEN - 1] = 0;
256
257 /* We're not interested in what's after the query string */
258 for (size_t i = 0; i < strlen (trunc); i++)
259 {
260 if (trunc[i] == '?')
261 {
262 trunc[i] = 0;
263 break;
264 }
265 }
266
267 bd = get_benchmark_data ();
268
270
271 for (unsigned int i = 0; i < bd->urd_len; i++)
272 {
273 if ((0 == strcmp (trunc, bd->urd[i].request_url)) &&
274 (bd->urd[i].status == status))
275 return &bd->urd[i];
276 }
277
278 {
279 struct UrlRequestData urd = { 0 };
280
281 memcpy (&urd.request_url, trunc, MAX_BENCHMARK_URL_LEN);
282 urd.status = status;
283
284 if (bd->urd_len == bd->urd_capacity)
285 {
286 bd->urd_capacity = 2 * (bd->urd_capacity + 1);
287 bd->urd = GNUNET_realloc (bd->urd, bd->urd_capacity * sizeof(struct
289 }
290
291 bd->urd[bd->urd_len++] = urd;
292 return &bd->urd[bd->urd_len - 1];
293 }
294}
struct BenchmarkData * get_benchmark_data(void)
Acquire the benchmark data for the current thread, allocate if necessary.
Definition benchmark.c:212
#define MAX_BENCHMARK_URL_LEN
Maximum length of URLs considered for benchmarking.
Definition benchmark.h:36
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_realloc(ptr, size)
Wrapper around realloc.
unsigned int urd_capacity
Definition benchmark.h:147
struct UrlRequestData * urd
Definition benchmark.h:143
unsigned int urd_len
Definition benchmark.h:145
char request_url[128]
Request URL, truncated (but 0-terminated).
Definition benchmark.h:70
unsigned int status
HTTP status code.
Definition benchmark.h:75

References get_benchmark_data(), GNUNET_assert, GNUNET_break, GNUNET_realloc, MAX_BENCHMARK_URL_LEN, UrlRequestData::request_url, status, UrlRequestData::status, BenchmarkData::urd, BenchmarkData::urd_capacity, and BenchmarkData::urd_len.

Here is the call graph for this function: