diff options
Diffstat (limited to 'src/util/benchmark.c')
-rw-r--r-- | src/util/benchmark.c | 260 |
1 files changed, 133 insertions, 127 deletions
diff --git a/src/util/benchmark.c b/src/util/benchmark.c index c01b7a515..497b3cde3 100644 --- a/src/util/benchmark.c +++ b/src/util/benchmark.c | |||
@@ -47,109 +47,114 @@ static pthread_once_t key_once = PTHREAD_ONCE_INIT; | |||
47 | * @param bd the benchmark data | 47 | * @param bd the benchmark data |
48 | */ | 48 | */ |
49 | static void | 49 | static void |
50 | write_benchmark_data(struct BenchmarkData *bd) | 50 | write_benchmark_data (struct BenchmarkData *bd) |
51 | { | 51 | { |
52 | struct GNUNET_DISK_FileHandle *fh; | 52 | struct GNUNET_DISK_FileHandle *fh; |
53 | pid_t pid = getpid(); | 53 | pid_t pid = getpid (); |
54 | pid_t tid = syscall(SYS_gettid); | 54 | pid_t tid = syscall (SYS_gettid); |
55 | char *benchmark_dir; | 55 | char *benchmark_dir; |
56 | char *s; | 56 | char *s; |
57 | 57 | ||
58 | benchmark_dir = getenv("GNUNET_BENCHMARK_DIR"); | 58 | benchmark_dir = getenv ("GNUNET_BENCHMARK_DIR"); |
59 | 59 | ||
60 | if (NULL == benchmark_dir) | 60 | if (NULL == benchmark_dir) |
61 | return; | 61 | return; |
62 | 62 | ||
63 | if (GNUNET_OK != GNUNET_DISK_directory_create(benchmark_dir)) | 63 | if (GNUNET_OK != GNUNET_DISK_directory_create (benchmark_dir)) |
64 | { | 64 | { |
65 | GNUNET_break(0); | 65 | GNUNET_break (0); |
66 | return; | 66 | return; |
67 | } | 67 | } |
68 | 68 | ||
69 | GNUNET_asprintf(&s, "%s/gnunet-benchmark-ops-%s-%llu-%llu.txt", | 69 | GNUNET_asprintf (&s, "%s/gnunet-benchmark-ops-%s-%llu-%llu.txt", |
70 | benchmark_dir, | 70 | benchmark_dir, |
71 | (pid == tid) ? "main" : "thread", | 71 | (pid == tid) ? "main" : "thread", |
72 | (unsigned long long)pid, | 72 | (unsigned long long) pid, |
73 | (unsigned long long)tid); | 73 | (unsigned long long) tid); |
74 | 74 | ||
75 | fh = GNUNET_DISK_file_open(s, | 75 | fh = GNUNET_DISK_file_open (s, |
76 | (GNUNET_DISK_OPEN_WRITE | | 76 | (GNUNET_DISK_OPEN_WRITE |
77 | GNUNET_DISK_OPEN_TRUNCATE | | 77 | | GNUNET_DISK_OPEN_TRUNCATE |
78 | GNUNET_DISK_OPEN_CREATE), | 78 | | GNUNET_DISK_OPEN_CREATE), |
79 | (GNUNET_DISK_PERM_USER_READ | | 79 | (GNUNET_DISK_PERM_USER_READ |
80 | GNUNET_DISK_PERM_USER_WRITE)); | 80 | | GNUNET_DISK_PERM_USER_WRITE)); |
81 | GNUNET_assert(NULL != fh); | 81 | GNUNET_assert (NULL != fh); |
82 | GNUNET_free(s); | 82 | GNUNET_free (s); |
83 | 83 | ||
84 | #define WRITE_BENCHMARK_OP(opname) do { \ | 84 | #define WRITE_BENCHMARK_OP(opname) do { \ |
85 | GNUNET_asprintf(&s, "op " #opname " count %llu time_us %llu\n", \ | 85 | GNUNET_asprintf (&s, "op " #opname " count %llu time_us %llu\n", \ |
86 | (unsigned long long)bd->opname ## _count, \ | 86 | (unsigned long long) bd->opname ## _count, \ |
87 | (unsigned long long)bd->opname ## _time.rel_value_us); \ | 87 | (unsigned long long) bd->opname ## _time.rel_value_us); \ |
88 | GNUNET_assert(GNUNET_SYSERR != GNUNET_DISK_file_write_blocking(fh, s, strlen(s))); \ | 88 | GNUNET_assert (GNUNET_SYSERR != GNUNET_DISK_file_write_blocking (fh, s, \ |
89 | GNUNET_free(s); \ | 89 | strlen ( \ |
90 | } while (0) | 90 | s))); \ |
91 | 91 | GNUNET_free (s); \ | |
92 | WRITE_BENCHMARK_OP(ecc_ecdh); | 92 | } while (0) |
93 | WRITE_BENCHMARK_OP(ecdh_eddsa); | 93 | |
94 | WRITE_BENCHMARK_OP(ecdhe_key_create); | 94 | WRITE_BENCHMARK_OP (ecc_ecdh); |
95 | WRITE_BENCHMARK_OP(ecdhe_key_get_public); | 95 | WRITE_BENCHMARK_OP (ecdh_eddsa); |
96 | WRITE_BENCHMARK_OP(ecdsa_ecdh); | 96 | WRITE_BENCHMARK_OP (ecdhe_key_create); |
97 | WRITE_BENCHMARK_OP(ecdsa_key_create); | 97 | WRITE_BENCHMARK_OP (ecdhe_key_get_public); |
98 | WRITE_BENCHMARK_OP(ecdsa_key_get_public); | 98 | WRITE_BENCHMARK_OP (ecdsa_ecdh); |
99 | WRITE_BENCHMARK_OP(ecdsa_sign); | 99 | WRITE_BENCHMARK_OP (ecdsa_key_create); |
100 | WRITE_BENCHMARK_OP(ecdsa_verify); | 100 | WRITE_BENCHMARK_OP (ecdsa_key_get_public); |
101 | WRITE_BENCHMARK_OP(eddsa_ecdh); | 101 | WRITE_BENCHMARK_OP (ecdsa_sign); |
102 | WRITE_BENCHMARK_OP(eddsa_key_create); | 102 | WRITE_BENCHMARK_OP (ecdsa_verify); |
103 | WRITE_BENCHMARK_OP(eddsa_key_get_public); | 103 | WRITE_BENCHMARK_OP (eddsa_ecdh); |
104 | WRITE_BENCHMARK_OP(eddsa_sign); | 104 | WRITE_BENCHMARK_OP (eddsa_key_create); |
105 | WRITE_BENCHMARK_OP(eddsa_verify); | 105 | WRITE_BENCHMARK_OP (eddsa_key_get_public); |
106 | WRITE_BENCHMARK_OP(hash); | 106 | WRITE_BENCHMARK_OP (eddsa_sign); |
107 | WRITE_BENCHMARK_OP(hash_context_finish); | 107 | WRITE_BENCHMARK_OP (eddsa_verify); |
108 | WRITE_BENCHMARK_OP(hash_context_read); | 108 | WRITE_BENCHMARK_OP (hash); |
109 | WRITE_BENCHMARK_OP(hash_context_start); | 109 | WRITE_BENCHMARK_OP (hash_context_finish); |
110 | WRITE_BENCHMARK_OP(hkdf); | 110 | WRITE_BENCHMARK_OP (hash_context_read); |
111 | WRITE_BENCHMARK_OP(rsa_blind); | 111 | WRITE_BENCHMARK_OP (hash_context_start); |
112 | WRITE_BENCHMARK_OP(rsa_private_key_create); | 112 | WRITE_BENCHMARK_OP (hkdf); |
113 | WRITE_BENCHMARK_OP(rsa_private_key_get_public); | 113 | WRITE_BENCHMARK_OP (rsa_blind); |
114 | WRITE_BENCHMARK_OP(rsa_sign_blinded); | 114 | WRITE_BENCHMARK_OP (rsa_private_key_create); |
115 | WRITE_BENCHMARK_OP(rsa_unblind); | 115 | WRITE_BENCHMARK_OP (rsa_private_key_get_public); |
116 | WRITE_BENCHMARK_OP(rsa_verify); | 116 | WRITE_BENCHMARK_OP (rsa_sign_blinded); |
117 | WRITE_BENCHMARK_OP (rsa_unblind); | ||
118 | WRITE_BENCHMARK_OP (rsa_verify); | ||
117 | 119 | ||
118 | #undef WRITE_BENCHMARK_OP | 120 | #undef WRITE_BENCHMARK_OP |
119 | 121 | ||
120 | GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fh)); | 122 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh)); |
121 | 123 | ||
122 | GNUNET_asprintf(&s, "%s/gnunet-benchmark-urls-%s-%llu-%llu.txt", | 124 | GNUNET_asprintf (&s, "%s/gnunet-benchmark-urls-%s-%llu-%llu.txt", |
123 | benchmark_dir, | 125 | benchmark_dir, |
124 | (pid == tid) ? "main" : "thread", | 126 | (pid == tid) ? "main" : "thread", |
125 | (unsigned long long)pid, | 127 | (unsigned long long) pid, |
126 | (unsigned long long)tid); | 128 | (unsigned long long) tid); |
127 | 129 | ||
128 | fh = GNUNET_DISK_file_open(s, | 130 | fh = GNUNET_DISK_file_open (s, |
129 | (GNUNET_DISK_OPEN_WRITE | | 131 | (GNUNET_DISK_OPEN_WRITE |
130 | GNUNET_DISK_OPEN_TRUNCATE | | 132 | | GNUNET_DISK_OPEN_TRUNCATE |
131 | GNUNET_DISK_OPEN_CREATE), | 133 | | GNUNET_DISK_OPEN_CREATE), |
132 | (GNUNET_DISK_PERM_USER_READ | | 134 | (GNUNET_DISK_PERM_USER_READ |
133 | GNUNET_DISK_PERM_USER_WRITE)); | 135 | | GNUNET_DISK_PERM_USER_WRITE)); |
134 | GNUNET_assert(NULL != fh); | 136 | GNUNET_assert (NULL != fh); |
135 | GNUNET_free(s); | 137 | GNUNET_free (s); |
136 | 138 | ||
137 | for (unsigned int i = 0; i < bd->urd_len; i++) | 139 | for (unsigned int i = 0; i < bd->urd_len; i++) |
138 | { | 140 | { |
139 | struct UrlRequestData *urd = &bd->urd[i]; | 141 | struct UrlRequestData *urd = &bd->urd[i]; |
140 | GNUNET_asprintf(&s, "url %s status %u count %llu time_us %llu time_us_max %llu bytes_sent %llu bytes_received %llu\n", | 142 | GNUNET_asprintf (&s, |
141 | urd->request_url, | 143 | "url %s status %u count %llu time_us %llu time_us_max %llu bytes_sent %llu bytes_received %llu\n", |
142 | urd->status, | 144 | urd->request_url, |
143 | (unsigned long long)urd->count, | 145 | urd->status, |
144 | (unsigned long long)urd->time.rel_value_us, | 146 | (unsigned long long) urd->count, |
145 | (unsigned long long)urd->time_max.rel_value_us, | 147 | (unsigned long long) urd->time.rel_value_us, |
146 | (unsigned long long)urd->bytes_sent, | 148 | (unsigned long long) urd->time_max.rel_value_us, |
147 | (unsigned long long)urd->bytes_received); | 149 | (unsigned long long) urd->bytes_sent, |
148 | GNUNET_assert(GNUNET_SYSERR != GNUNET_DISK_file_write_blocking(fh, s, strlen(s))); | 150 | (unsigned long long) urd->bytes_received); |
149 | GNUNET_free(s); | 151 | GNUNET_assert (GNUNET_SYSERR != GNUNET_DISK_file_write_blocking (fh, s, |
150 | } | 152 | strlen ( |
153 | s))); | ||
154 | GNUNET_free (s); | ||
155 | } | ||
151 | 156 | ||
152 | GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fh)); | 157 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh)); |
153 | } | 158 | } |
154 | 159 | ||
155 | 160 | ||
@@ -157,13 +162,13 @@ write_benchmark_data(struct BenchmarkData *bd) | |||
157 | * Called when the main thread exits and benchmark data for it was created. | 162 | * Called when the main thread exits and benchmark data for it was created. |
158 | */ | 163 | */ |
159 | static void | 164 | static void |
160 | main_thread_destructor() | 165 | main_thread_destructor () |
161 | { | 166 | { |
162 | struct BenchmarkData *bd; | 167 | struct BenchmarkData *bd; |
163 | 168 | ||
164 | bd = pthread_getspecific(key); | 169 | bd = pthread_getspecific (key); |
165 | if (NULL != bd) | 170 | if (NULL != bd) |
166 | write_benchmark_data(bd); | 171 | write_benchmark_data (bd); |
167 | } | 172 | } |
168 | 173 | ||
169 | 174 | ||
@@ -173,16 +178,16 @@ main_thread_destructor() | |||
173 | * @param cls closure | 178 | * @param cls closure |
174 | */ | 179 | */ |
175 | static void | 180 | static void |
176 | thread_destructor(void *cls) | 181 | thread_destructor (void *cls) |
177 | { | 182 | { |
178 | struct BenchmarkData *bd = cls; | 183 | struct BenchmarkData *bd = cls; |
179 | 184 | ||
180 | // main thread will be handled by atexit | 185 | // main thread will be handled by atexit |
181 | if (getpid() == (pid_t)syscall(SYS_gettid)) | 186 | if (getpid () == (pid_t) syscall (SYS_gettid)) |
182 | return; | 187 | return; |
183 | 188 | ||
184 | GNUNET_assert(NULL != bd); | 189 | GNUNET_assert (NULL != bd); |
185 | write_benchmark_data(bd); | 190 | write_benchmark_data (bd); |
186 | } | 191 | } |
187 | 192 | ||
188 | 193 | ||
@@ -190,9 +195,9 @@ thread_destructor(void *cls) | |||
190 | * Initialize the thread-local variable key for benchmark data. | 195 | * Initialize the thread-local variable key for benchmark data. |
191 | */ | 196 | */ |
192 | static void | 197 | static void |
193 | make_key() | 198 | make_key () |
194 | { | 199 | { |
195 | (void)pthread_key_create(&key, &thread_destructor); | 200 | (void) pthread_key_create (&key, &thread_destructor); |
196 | } | 201 | } |
197 | 202 | ||
198 | 203 | ||
@@ -203,22 +208,22 @@ make_key() | |||
203 | * @return benchmark data for the current thread | 208 | * @return benchmark data for the current thread |
204 | */ | 209 | */ |
205 | struct BenchmarkData * | 210 | struct BenchmarkData * |
206 | get_benchmark_data(void) | 211 | get_benchmark_data (void) |
207 | { | 212 | { |
208 | struct BenchmarkData *bd; | 213 | struct BenchmarkData *bd; |
209 | 214 | ||
210 | (void)pthread_once(&key_once, &make_key); | 215 | (void) pthread_once (&key_once, &make_key); |
211 | 216 | ||
212 | if (NULL == (bd = pthread_getspecific(key))) | 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)) | ||
213 | { | 222 | { |
214 | bd = GNUNET_new(struct BenchmarkData); | 223 | // We're the main thread! |
215 | (void)pthread_setspecific(key, bd); | 224 | atexit (main_thread_destructor); |
216 | if (getpid() == (pid_t)syscall(SYS_gettid)) | ||
217 | { | ||
218 | // We're the main thread! | ||
219 | atexit(main_thread_destructor); | ||
220 | } | ||
221 | } | 225 | } |
226 | } | ||
222 | return bd; | 227 | return bd; |
223 | } | 228 | } |
224 | 229 | ||
@@ -233,53 +238,54 @@ get_benchmark_data(void) | |||
233 | * @param status http status code | 238 | * @param status http status code |
234 | */ | 239 | */ |
235 | struct UrlRequestData * | 240 | struct UrlRequestData * |
236 | get_url_benchmark_data(char *url, unsigned int status) | 241 | get_url_benchmark_data (char *url, unsigned int status) |
237 | { | 242 | { |
238 | char trunc[MAX_BENCHMARK_URL_LEN]; | 243 | char trunc[MAX_BENCHMARK_URL_LEN]; |
239 | struct BenchmarkData *bd; | 244 | struct BenchmarkData *bd; |
240 | 245 | ||
241 | if (NULL == url) | 246 | if (NULL == url) |
242 | { | 247 | { |
243 | /* Should not happen unless curl barfs */ | 248 | /* Should not happen unless curl barfs */ |
244 | GNUNET_break(0); | 249 | GNUNET_break (0); |
245 | url = "<empty>"; | 250 | url = "<empty>"; |
246 | } | 251 | } |
247 | 252 | ||
248 | memcpy(trunc, url, MAX_BENCHMARK_URL_LEN); | 253 | memcpy (trunc, url, MAX_BENCHMARK_URL_LEN); |
249 | trunc[MAX_BENCHMARK_URL_LEN - 1] = 0; | 254 | trunc[MAX_BENCHMARK_URL_LEN - 1] = 0; |
250 | 255 | ||
251 | /* We're not interested in what's after the query string */ | 256 | /* We're not interested in what's after the query string */ |
252 | for (size_t i = 0; i < strlen(trunc); i++) | 257 | for (size_t i = 0; i < strlen (trunc); i++) |
258 | { | ||
259 | if (trunc[i] == '?') | ||
253 | { | 260 | { |
254 | if (trunc[i] == '?') | 261 | trunc[i] = 0; |
255 | { | 262 | break; |
256 | trunc[i] = 0; | ||
257 | break; | ||
258 | } | ||
259 | } | 263 | } |
264 | } | ||
260 | 265 | ||
261 | bd = get_benchmark_data(); | 266 | bd = get_benchmark_data (); |
262 | 267 | ||
263 | GNUNET_assert(bd->urd_len <= bd->urd_capacity); | 268 | GNUNET_assert (bd->urd_len <= bd->urd_capacity); |
264 | 269 | ||
265 | for (unsigned int i = 0; i < bd->urd_len; i++) | 270 | for (unsigned int i = 0; i < bd->urd_len; i++) |
266 | { | 271 | { |
267 | if ((0 == strcmp(trunc, bd->urd[i].request_url)) && | 272 | if ((0 == strcmp (trunc, bd->urd[i].request_url)) && |
268 | (bd->urd[i].status == status)) | 273 | (bd->urd[i].status == status)) |
269 | return &bd->urd[i]; | 274 | return &bd->urd[i]; |
270 | } | 275 | } |
271 | 276 | ||
272 | { | 277 | { |
273 | struct UrlRequestData urd = { 0 }; | 278 | struct UrlRequestData urd = { 0 }; |
274 | 279 | ||
275 | memcpy(&urd.request_url, trunc, MAX_BENCHMARK_URL_LEN); | 280 | memcpy (&urd.request_url, trunc, MAX_BENCHMARK_URL_LEN); |
276 | urd.status = status; | 281 | urd.status = status; |
277 | 282 | ||
278 | if (bd->urd_len == bd->urd_capacity) | 283 | if (bd->urd_len == bd->urd_capacity) |
279 | { | 284 | { |
280 | bd->urd_capacity = 2 * (bd->urd_capacity + 1); | 285 | bd->urd_capacity = 2 * (bd->urd_capacity + 1); |
281 | bd->urd = GNUNET_realloc(bd->urd, bd->urd_capacity * sizeof(struct UrlRequestData)); | 286 | bd->urd = GNUNET_realloc (bd->urd, bd->urd_capacity * sizeof(struct |
282 | } | 287 | UrlRequestData)); |
288 | } | ||
283 | 289 | ||
284 | bd->urd[bd->urd_len++] = urd; | 290 | bd->urd[bd->urd_len++] = urd; |
285 | return &bd->urd[bd->urd_len - 1]; | 291 | return &bd->urd[bd->urd_len - 1]; |