GNUnet  0.11.x
Data Structures | Macros | Functions
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. More...
 
#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. More...
 
struct UrlRequestDataget_url_benchmark_data (char *url, unsigned int status)
 Get benchmark data for a URL. More...
 

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.

Referenced by get_url_benchmark_data().

◆ BENCHMARK_START

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

◆ BENCHMARK_END

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

◆ 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.

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 211 of file benchmark.c.

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

Referenced by get_url_benchmark_data().

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

Statistics are bucketed by URL and status code.

Parameters
urlurl to get request data for
statushttp status code

Definition at line 241 of file benchmark.c.

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

Referenced by GNUNET_CURL_perform2().

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