GNUnet  0.10.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 103 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 206 of file benchmark.c.

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

Referenced by get_url_benchmark_data().

207 {
208  struct BenchmarkData *bd;
209 
210  (void)pthread_once(&key_once, &make_key);
211 
212  if (NULL == (bd = pthread_getspecific(key)))
213  {
214  bd = GNUNET_new(struct BenchmarkData);
215  (void)pthread_setspecific(key, bd);
216  if (getpid() == (pid_t)syscall(SYS_gettid))
217  {
218  // We're the main thread!
219  atexit(main_thread_destructor);
220  }
221  }
222  return bd;
223 }
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:110
static void main_thread_destructor()
Called when the main thread exits and benchmark data for it was created.
Definition: benchmark.c:160
static void make_key()
Initialize the thread-local variable key for benchmark data.
Definition: benchmark.c:193
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 236 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().

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