32#include <sys/syscall.h>
37static pthread_key_t
key;
42static pthread_once_t
key_once = PTHREAD_ONCE_INIT;
54 pid_t
pid = getpid ();
55 pid_t tid = syscall (SYS_gettid);
59 benchmark_dir =
getenv (
"GNUNET_BENCHMARK_DIR");
61 if (NULL == benchmark_dir)
72 (
pid == tid) ?
"main" :
"thread",
73 (
unsigned long long)
pid,
74 (
unsigned long long) tid);
85#define WRITE_BENCHMARK_OP(opname) do { \
86 GNUNET_asprintf (&s, "op " #opname " count %llu time_us %llu\n", \
87 (unsigned long long) bd->opname ## _count, \
88 (unsigned long long) bd->opname ## _time.rel_value_us); \
89 GNUNET_assert (GNUNET_SYSERR != GNUNET_DISK_file_write_blocking (fh, s, \
121#undef WRITE_BENCHMARK_OP
127 (
pid == tid) ?
"main" :
"thread",
128 (
unsigned long long)
pid,
129 (
unsigned long long) tid);
140 for (
unsigned int i = 0; i < bd->
urd_len; i++)
144 "url %s status %u count %llu time_us %llu time_us_max %llu bytes_sent %llu bytes_received %llu\n",
147 (
unsigned long long) urd->
count,
170 bd = pthread_getspecific (
key);
187 if (getpid () == (pid_t) syscall (SYS_gettid))
218 if (NULL == (bd = pthread_getspecific (
key)))
221 (void) pthread_setspecific (
key, bd);
222 if (getpid () == (pid_t) syscall (SYS_gettid))
258 for (
size_t i = 0; i < strlen (trunc); i++)
271 for (
unsigned int i = 0; i < bd->
urd_len; i++)
static void make_key()
Initialize the thread-local variable key for benchmark data.
#define WRITE_BENCHMARK_OP(opname)
struct UrlRequestData * get_url_benchmark_data(char *url, unsigned int status)
Get benchmark data for a URL.
static void thread_destructor(void *cls)
Called when a thread exits and benchmark data for it was created.
static pthread_once_t key_once
One-time initialization marker for key.
static void main_thread_destructor()
Called when the main thread exits and benchmark data for it was created.
struct BenchmarkData * get_benchmark_data(void)
Acquire the benchmark data for the current thread, allocate if necessary.
static pthread_key_t key
Thread-local storage key for the benchmark data.
static void write_benchmark_data(struct BenchmarkData *bd)
Write benchmark data to a file.
benchmarking for various operations
#define MAX_BENCHMARK_URL_LEN
Maximum length of URLs considered for benchmarking.
static int status
The program status; 0 for success.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
ssize_t GNUNET_DISK_file_write_blocking(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file, blocking, if necessary.
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create(const char *dir)
Implementation of "mkdir -p".
@ GNUNET_DISK_OPEN_WRITE
Open the file for writing.
@ GNUNET_DISK_OPEN_TRUNCATE
Truncate file if it exists.
@ GNUNET_DISK_OPEN_CREATE
Create file if it doesn't exist.
@ GNUNET_DISK_PERM_USER_READ
Owner can read.
@ GNUNET_DISK_PERM_USER_WRITE
Owner can write.
#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.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_realloc(ptr, size)
Wrapper around realloc.
#define GNUNET_free(ptr)
Wrapper around free.
Thread-local struct for benchmarking data.
unsigned int urd_capacity
struct UrlRequestData * urd
Handle used to access files (and pipes).
uint64_t rel_value_us
The actual value.
Struct for benchmark data for one URL.
struct GNUNET_TIME_Relative time
Total time spent requesting this URL.
char request_url[128]
Request URL, truncated (but 0-terminated).
unsigned int status
HTTP status code.
uint64_t bytes_received
How many bytes were received in total as response to requesting this URL.
struct GNUNET_TIME_Relative time_max
Slowest time to response.
uint64_t bytes_sent
How many bytes were sent in total to request the URL.
uint64_t count
How often was the URL requested?