aboutsummaryrefslogtreecommitdiff
path: root/src/util/benchmark.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/benchmark.c')
-rw-r--r--src/util/benchmark.c260
1 files changed, 130 insertions, 130 deletions
diff --git a/src/util/benchmark.c b/src/util/benchmark.c
index caf6cd64a..c01b7a515 100644
--- a/src/util/benchmark.c
+++ b/src/util/benchmark.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file util/benchmark.c 22 * @file util/benchmark.c
@@ -47,109 +47,109 @@ static pthread_once_t key_once = PTHREAD_ONCE_INIT;
47 * @param bd the benchmark data 47 * @param bd the benchmark data
48 */ 48 */
49static void 49static void
50write_benchmark_data (struct BenchmarkData *bd) 50write_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, strlen(s))); \
89 GNUNET_free (s); \ 89 GNUNET_free(s); \
90} while (0) 90 } while (0)
91 91
92 WRITE_BENCHMARK_OP (ecc_ecdh); 92 WRITE_BENCHMARK_OP(ecc_ecdh);
93 WRITE_BENCHMARK_OP (ecdh_eddsa); 93 WRITE_BENCHMARK_OP(ecdh_eddsa);
94 WRITE_BENCHMARK_OP (ecdhe_key_create); 94 WRITE_BENCHMARK_OP(ecdhe_key_create);
95 WRITE_BENCHMARK_OP (ecdhe_key_get_public); 95 WRITE_BENCHMARK_OP(ecdhe_key_get_public);
96 WRITE_BENCHMARK_OP (ecdsa_ecdh); 96 WRITE_BENCHMARK_OP(ecdsa_ecdh);
97 WRITE_BENCHMARK_OP (ecdsa_key_create); 97 WRITE_BENCHMARK_OP(ecdsa_key_create);
98 WRITE_BENCHMARK_OP (ecdsa_key_get_public); 98 WRITE_BENCHMARK_OP(ecdsa_key_get_public);
99 WRITE_BENCHMARK_OP (ecdsa_sign); 99 WRITE_BENCHMARK_OP(ecdsa_sign);
100 WRITE_BENCHMARK_OP (ecdsa_verify); 100 WRITE_BENCHMARK_OP(ecdsa_verify);
101 WRITE_BENCHMARK_OP (eddsa_ecdh); 101 WRITE_BENCHMARK_OP(eddsa_ecdh);
102 WRITE_BENCHMARK_OP (eddsa_key_create); 102 WRITE_BENCHMARK_OP(eddsa_key_create);
103 WRITE_BENCHMARK_OP (eddsa_key_get_public); 103 WRITE_BENCHMARK_OP(eddsa_key_get_public);
104 WRITE_BENCHMARK_OP (eddsa_sign); 104 WRITE_BENCHMARK_OP(eddsa_sign);
105 WRITE_BENCHMARK_OP (eddsa_verify); 105 WRITE_BENCHMARK_OP(eddsa_verify);
106 WRITE_BENCHMARK_OP (hash); 106 WRITE_BENCHMARK_OP(hash);
107 WRITE_BENCHMARK_OP (hash_context_finish); 107 WRITE_BENCHMARK_OP(hash_context_finish);
108 WRITE_BENCHMARK_OP (hash_context_read); 108 WRITE_BENCHMARK_OP(hash_context_read);
109 WRITE_BENCHMARK_OP (hash_context_start); 109 WRITE_BENCHMARK_OP(hash_context_start);
110 WRITE_BENCHMARK_OP (hkdf); 110 WRITE_BENCHMARK_OP(hkdf);
111 WRITE_BENCHMARK_OP (rsa_blind); 111 WRITE_BENCHMARK_OP(rsa_blind);
112 WRITE_BENCHMARK_OP (rsa_private_key_create); 112 WRITE_BENCHMARK_OP(rsa_private_key_create);
113 WRITE_BENCHMARK_OP (rsa_private_key_get_public); 113 WRITE_BENCHMARK_OP(rsa_private_key_get_public);
114 WRITE_BENCHMARK_OP (rsa_sign_blinded); 114 WRITE_BENCHMARK_OP(rsa_sign_blinded);
115 WRITE_BENCHMARK_OP (rsa_unblind); 115 WRITE_BENCHMARK_OP(rsa_unblind);
116 WRITE_BENCHMARK_OP (rsa_verify); 116 WRITE_BENCHMARK_OP(rsa_verify);
117 117
118#undef WRITE_BENCHMARK_OP 118#undef WRITE_BENCHMARK_OP
119 119
120 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh)); 120 GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fh));
121 121
122 GNUNET_asprintf (&s, "%s/gnunet-benchmark-urls-%s-%llu-%llu.txt", 122 GNUNET_asprintf(&s, "%s/gnunet-benchmark-urls-%s-%llu-%llu.txt",
123 benchmark_dir, 123 benchmark_dir,
124 (pid == tid) ? "main" : "thread", 124 (pid == tid) ? "main" : "thread",
125 (unsigned long long) pid, 125 (unsigned long long)pid,
126 (unsigned long long) tid); 126 (unsigned long long)tid);
127 127
128 fh = GNUNET_DISK_file_open (s, 128 fh = GNUNET_DISK_file_open(s,
129 (GNUNET_DISK_OPEN_WRITE | 129 (GNUNET_DISK_OPEN_WRITE |
130 GNUNET_DISK_OPEN_TRUNCATE | 130 GNUNET_DISK_OPEN_TRUNCATE |
131 GNUNET_DISK_OPEN_CREATE), 131 GNUNET_DISK_OPEN_CREATE),
132 (GNUNET_DISK_PERM_USER_READ | 132 (GNUNET_DISK_PERM_USER_READ |
133 GNUNET_DISK_PERM_USER_WRITE)); 133 GNUNET_DISK_PERM_USER_WRITE));
134 GNUNET_assert (NULL != fh); 134 GNUNET_assert(NULL != fh);
135 GNUNET_free (s); 135 GNUNET_free(s);
136 136
137 for (unsigned int i = 0; i < bd->urd_len; i++) 137 for (unsigned int i = 0; i < bd->urd_len; i++)
138 { 138 {
139 struct UrlRequestData *urd = &bd->urd[i]; 139 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", 140 GNUNET_asprintf(&s, "url %s status %u count %llu time_us %llu time_us_max %llu bytes_sent %llu bytes_received %llu\n",
141 urd->request_url, 141 urd->request_url,
142 urd->status, 142 urd->status,
143 (unsigned long long) urd->count, 143 (unsigned long long)urd->count,
144 (unsigned long long) urd->time.rel_value_us, 144 (unsigned long long)urd->time.rel_value_us,
145 (unsigned long long) urd->time_max.rel_value_us, 145 (unsigned long long)urd->time_max.rel_value_us,
146 (unsigned long long) urd->bytes_sent, 146 (unsigned long long)urd->bytes_sent,
147 (unsigned long long) urd->bytes_received); 147 (unsigned long long)urd->bytes_received);
148 GNUNET_assert (GNUNET_SYSERR != GNUNET_DISK_file_write_blocking (fh, s, strlen (s))); 148 GNUNET_assert(GNUNET_SYSERR != GNUNET_DISK_file_write_blocking(fh, s, strlen(s)));
149 GNUNET_free (s); 149 GNUNET_free(s);
150 } 150 }
151 151
152 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh)); 152 GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fh));
153} 153}
154 154
155 155
@@ -157,13 +157,13 @@ write_benchmark_data (struct BenchmarkData *bd)
157 * Called when the main thread exits and benchmark data for it was created. 157 * Called when the main thread exits and benchmark data for it was created.
158 */ 158 */
159static void 159static void
160main_thread_destructor () 160main_thread_destructor()
161{ 161{
162 struct BenchmarkData *bd; 162 struct BenchmarkData *bd;
163 163
164 bd = pthread_getspecific (key); 164 bd = pthread_getspecific(key);
165 if (NULL != bd) 165 if (NULL != bd)
166 write_benchmark_data (bd); 166 write_benchmark_data(bd);
167} 167}
168 168
169 169
@@ -173,16 +173,16 @@ main_thread_destructor ()
173 * @param cls closure 173 * @param cls closure
174 */ 174 */
175static void 175static void
176thread_destructor (void *cls) 176thread_destructor(void *cls)
177{ 177{
178 struct BenchmarkData *bd = cls; 178 struct BenchmarkData *bd = cls;
179 179
180 // main thread will be handled by atexit 180 // main thread will be handled by atexit
181 if (getpid () == (pid_t) syscall (SYS_gettid)) 181 if (getpid() == (pid_t)syscall(SYS_gettid))
182 return; 182 return;
183 183
184 GNUNET_assert (NULL != bd); 184 GNUNET_assert(NULL != bd);
185 write_benchmark_data (bd); 185 write_benchmark_data(bd);
186} 186}
187 187
188 188
@@ -190,9 +190,9 @@ thread_destructor (void *cls)
190 * Initialize the thread-local variable key for benchmark data. 190 * Initialize the thread-local variable key for benchmark data.
191 */ 191 */
192static void 192static void
193make_key () 193make_key()
194{ 194{
195 (void) pthread_key_create (&key, &thread_destructor); 195 (void)pthread_key_create(&key, &thread_destructor);
196} 196}
197 197
198 198
@@ -203,22 +203,22 @@ make_key ()
203 * @return benchmark data for the current thread 203 * @return benchmark data for the current thread
204 */ 204 */
205struct BenchmarkData * 205struct BenchmarkData *
206get_benchmark_data (void) 206get_benchmark_data(void)
207{ 207{
208 struct BenchmarkData *bd; 208 struct BenchmarkData *bd;
209 209
210 (void) pthread_once (&key_once, &make_key); 210 (void)pthread_once(&key_once, &make_key);
211 211
212 if (NULL == (bd = pthread_getspecific (key))) 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 { 213 {
218 // We're the main thread! 214 bd = GNUNET_new(struct BenchmarkData);
219 atexit (main_thread_destructor); 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 }
220 } 221 }
221 }
222 return bd; 222 return bd;
223} 223}
224 224
@@ -233,53 +233,53 @@ get_benchmark_data (void)
233 * @param status http status code 233 * @param status http status code
234 */ 234 */
235struct UrlRequestData * 235struct UrlRequestData *
236get_url_benchmark_data (char *url, unsigned int status) 236get_url_benchmark_data(char *url, unsigned int status)
237{ 237{
238 char trunc[MAX_BENCHMARK_URL_LEN]; 238 char trunc[MAX_BENCHMARK_URL_LEN];
239 struct BenchmarkData *bd; 239 struct BenchmarkData *bd;
240 240
241 if (NULL == url) 241 if (NULL == url)
242 { 242 {
243 /* Should not happen unless curl barfs */ 243 /* Should not happen unless curl barfs */
244 GNUNET_break (0); 244 GNUNET_break(0);
245 url = "<empty>"; 245 url = "<empty>";
246 } 246 }
247 247
248 memcpy (trunc, url, MAX_BENCHMARK_URL_LEN); 248 memcpy(trunc, url, MAX_BENCHMARK_URL_LEN);
249 trunc[MAX_BENCHMARK_URL_LEN - 1] = 0; 249 trunc[MAX_BENCHMARK_URL_LEN - 1] = 0;
250 250
251 /* We're not interested in what's after the query string */ 251 /* We're not interested in what's after the query string */
252 for (size_t i = 0; i < strlen (trunc); i++) 252 for (size_t i = 0; i < strlen(trunc); i++)
253 {
254 if (trunc[i] == '?')
255 { 253 {
256 trunc[i] = 0; 254 if (trunc[i] == '?')
257 break; 255 {
256 trunc[i] = 0;
257 break;
258 }
258 } 259 }
259 }
260 260
261 bd = get_benchmark_data (); 261 bd = get_benchmark_data();
262 262
263 GNUNET_assert (bd->urd_len <= bd->urd_capacity); 263 GNUNET_assert(bd->urd_len <= bd->urd_capacity);
264 264
265 for (unsigned int i = 0; i < bd->urd_len; i++) 265 for (unsigned int i = 0; i < bd->urd_len; i++)
266 { 266 {
267 if ( (0 == strcmp (trunc, bd->urd[i].request_url)) && 267 if ((0 == strcmp(trunc, bd->urd[i].request_url)) &&
268 (bd->urd[i].status == status) ) 268 (bd->urd[i].status == status))
269 return &bd->urd[i]; 269 return &bd->urd[i];
270 } 270 }
271 271
272 { 272 {
273 struct UrlRequestData urd = { 0 }; 273 struct UrlRequestData urd = { 0 };
274 274
275 memcpy (&urd.request_url, trunc, MAX_BENCHMARK_URL_LEN); 275 memcpy(&urd.request_url, trunc, MAX_BENCHMARK_URL_LEN);
276 urd.status = status; 276 urd.status = status;
277 277
278 if (bd->urd_len == bd->urd_capacity) 278 if (bd->urd_len == bd->urd_capacity)
279 { 279 {
280 bd->urd_capacity = 2 * (bd->urd_capacity + 1); 280 bd->urd_capacity = 2 * (bd->urd_capacity + 1);
281 bd->urd = GNUNET_realloc (bd->urd, bd->urd_capacity * sizeof (struct UrlRequestData)); 281 bd->urd = GNUNET_realloc(bd->urd, bd->urd_capacity * sizeof(struct UrlRequestData));
282 } 282 }
283 283
284 bd->urd[bd->urd_len++] = urd; 284 bd->urd[bd->urd_len++] = urd;
285 return &bd->urd[bd->urd_len - 1]; 285 return &bd->urd[bd->urd_len - 1];