diff options
| author | cheloha <> | 2018-08-11 16:07:36 +0000 |
|---|---|---|
| committer | cheloha <> | 2018-08-11 16:07:36 +0000 |
| commit | 3bdf42f49f445f33cfe8ce9261d1504d89474682 (patch) | |
| tree | b38d04b397a5aacb6260a8e443994c0d5a4c60b0 /src | |
| parent | 510a5bb350e3d31f34b392a9252d98f6c54efa01 (diff) | |
| download | openbsd-3bdf42f49f445f33cfe8ce9261d1504d89474682.tar.gz openbsd-3bdf42f49f445f33cfe8ce9261d1504d89474682.tar.bz2 openbsd-3bdf42f49f445f33cfe8ce9261d1504d89474682.zip | |
Refactor the nearly identical benchmark loops into a single loop.
Move all of the benchmark code -- loop initialization, the loops, and
the report printing -- into a new function, benchmark(). Eliminates
lots of duplicate code.
Regressions to 1.20 caught by tb@ and inoguchi@. Tweaked by tb@.
ok tb@, jsing@
Diffstat (limited to 'src')
| -rw-r--r-- | src/usr.bin/openssl/s_time.c | 247 |
1 files changed, 108 insertions, 139 deletions
diff --git a/src/usr.bin/openssl/s_time.c b/src/usr.bin/openssl/s_time.c index 0d0b771281..c5d2ede9bb 100644 --- a/src/usr.bin/openssl/s_time.c +++ b/src/usr.bin/openssl/s_time.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: s_time.c,v 1.24 2018/07/13 18:36:56 cheloha Exp $ */ | 1 | /* $OpenBSD: s_time.c,v 1.25 2018/08/11 16:07:36 cheloha Exp $ */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -91,6 +91,7 @@ extern int verify_depth; | |||
| 91 | 91 | ||
| 92 | static void s_time_usage(void); | 92 | static void s_time_usage(void); |
| 93 | static SSL *doConnection(SSL * scon); | 93 | static SSL *doConnection(SSL * scon); |
| 94 | static int benchmark(int); | ||
| 94 | 95 | ||
| 95 | static SSL_CTX *tm_ctx = NULL; | 96 | static SSL_CTX *tm_ctx = NULL; |
| 96 | static const SSL_METHOD *s_time_meth = NULL; | 97 | static const SSL_METHOD *s_time_meth = NULL; |
| @@ -244,13 +245,7 @@ tm_Time_F(int op) | |||
| 244 | int | 245 | int |
| 245 | s_time_main(int argc, char **argv) | 246 | s_time_main(int argc, char **argv) |
| 246 | { | 247 | { |
| 247 | double totalTime = 0.0; | ||
| 248 | int nConn = 0; | ||
| 249 | SSL *scon = NULL; | ||
| 250 | time_t finishtime; | ||
| 251 | int ret = 1; | 248 | int ret = 1; |
| 252 | char buf[1024 * 8]; | ||
| 253 | int ver; | ||
| 254 | 249 | ||
| 255 | if (single_execution) { | 250 | if (single_execution) { |
| 256 | if (pledge("stdio rpath inet dns", NULL) == -1) { | 251 | if (pledge("stdio rpath inet dns", NULL) == -1) { |
| @@ -328,60 +323,8 @@ s_time_main(int argc, char **argv) | |||
| 328 | 323 | ||
| 329 | /* Loop and time how long it takes to make connections */ | 324 | /* Loop and time how long it takes to make connections */ |
| 330 | 325 | ||
| 331 | bytes_read = 0; | 326 | if (benchmark(0)) |
| 332 | finishtime = time(NULL) + s_time_config.maxtime; | 327 | goto end; |
| 333 | tm_Time_F(START); | ||
| 334 | for (;;) { | ||
| 335 | if (finishtime < time(NULL)) | ||
| 336 | break; | ||
| 337 | if ((scon = doConnection(NULL)) == NULL) | ||
| 338 | goto end; | ||
| 339 | |||
| 340 | if (s_time_config.www_path != NULL) { | ||
| 341 | int i, retval = snprintf(buf, sizeof buf, | ||
| 342 | "GET %s HTTP/1.0\r\n\r\n", s_time_config.www_path); | ||
| 343 | if ((size_t)retval >= sizeof buf) { | ||
| 344 | fprintf(stderr, "URL too long\n"); | ||
| 345 | goto end; | ||
| 346 | } | ||
| 347 | SSL_write(scon, buf, strlen(buf)); | ||
| 348 | while ((i = SSL_read(scon, buf, sizeof(buf))) > 0) | ||
| 349 | bytes_read += i; | ||
| 350 | } | ||
| 351 | if (s_time_config.no_shutdown) | ||
| 352 | SSL_set_shutdown(scon, SSL_SENT_SHUTDOWN | | ||
| 353 | SSL_RECEIVED_SHUTDOWN); | ||
| 354 | else | ||
| 355 | SSL_shutdown(scon); | ||
| 356 | |||
| 357 | nConn += 1; | ||
| 358 | if (SSL_session_reused(scon)) | ||
| 359 | ver = 'r'; | ||
| 360 | else { | ||
| 361 | ver = SSL_version(scon); | ||
| 362 | if (ver == TLS1_VERSION) | ||
| 363 | ver = 't'; | ||
| 364 | else if (ver == SSL3_VERSION) | ||
| 365 | ver = '3'; | ||
| 366 | else if (ver == SSL2_VERSION) | ||
| 367 | ver = '2'; | ||
| 368 | else | ||
| 369 | ver = '*'; | ||
| 370 | } | ||
| 371 | fputc(ver, stdout); | ||
| 372 | fflush(stdout); | ||
| 373 | |||
| 374 | SSL_free(scon); | ||
| 375 | scon = NULL; | ||
| 376 | } | ||
| 377 | totalTime += tm_Time_F(STOP); /* Add the time for this iteration */ | ||
| 378 | |||
| 379 | printf("\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n", | ||
| 380 | nConn, totalTime, ((double) nConn / totalTime), bytes_read); | ||
| 381 | printf("%d connections in %lld real seconds, %ld bytes read per connection\n", | ||
| 382 | nConn, | ||
| 383 | (long long)(time(NULL) - finishtime + s_time_config.maxtime), | ||
| 384 | bytes_read / nConn); | ||
| 385 | 328 | ||
| 386 | /* | 329 | /* |
| 387 | * Now loop and time connections using the same session id over and | 330 | * Now loop and time connections using the same session id over and |
| @@ -393,88 +336,11 @@ s_time_main(int argc, char **argv) | |||
| 393 | goto end; | 336 | goto end; |
| 394 | printf("\n\nNow timing with session id reuse.\n"); | 337 | printf("\n\nNow timing with session id reuse.\n"); |
| 395 | 338 | ||
| 396 | /* Get an SSL object so we can reuse the session id */ | 339 | if (benchmark(1)) |
| 397 | if ((scon = doConnection(NULL)) == NULL) { | ||
| 398 | fprintf(stderr, "Unable to get connection\n"); | ||
| 399 | goto end; | 340 | goto end; |
| 400 | } | ||
| 401 | if (s_time_config.www_path != NULL) { | ||
| 402 | int retval = snprintf(buf, sizeof buf, | ||
| 403 | "GET %s HTTP/1.0\r\n\r\n", s_time_config.www_path); | ||
| 404 | if ((size_t)retval >= sizeof buf) { | ||
| 405 | fprintf(stderr, "URL too long\n"); | ||
| 406 | goto end; | ||
| 407 | } | ||
| 408 | SSL_write(scon, buf, strlen(buf)); | ||
| 409 | while (SSL_read(scon, buf, sizeof(buf)) > 0); | ||
| 410 | } | ||
| 411 | if (s_time_config.no_shutdown) | ||
| 412 | SSL_set_shutdown(scon, SSL_SENT_SHUTDOWN | | ||
| 413 | SSL_RECEIVED_SHUTDOWN); | ||
| 414 | else | ||
| 415 | SSL_shutdown(scon); | ||
| 416 | |||
| 417 | nConn = 0; | ||
| 418 | totalTime = 0.0; | ||
| 419 | |||
| 420 | finishtime = time(NULL) + s_time_config.maxtime; | ||
| 421 | |||
| 422 | printf("starting\n"); | ||
| 423 | bytes_read = 0; | ||
| 424 | tm_Time_F(START); | ||
| 425 | |||
| 426 | for (;;) { | ||
| 427 | if (finishtime < time(NULL)) | ||
| 428 | break; | ||
| 429 | if ((doConnection(scon)) == NULL) | ||
| 430 | goto end; | ||
| 431 | |||
| 432 | if (s_time_config.www_path) { | ||
| 433 | int i, retval = snprintf(buf, sizeof buf, | ||
| 434 | "GET %s HTTP/1.0\r\n\r\n", s_time_config.www_path); | ||
| 435 | if ((size_t)retval >= sizeof buf) { | ||
| 436 | fprintf(stderr, "URL too long\n"); | ||
| 437 | goto end; | ||
| 438 | } | ||
| 439 | SSL_write(scon, buf, strlen(buf)); | ||
| 440 | while ((i = SSL_read(scon, buf, sizeof(buf))) > 0) | ||
| 441 | bytes_read += i; | ||
| 442 | } | ||
| 443 | if (s_time_config.no_shutdown) | ||
| 444 | SSL_set_shutdown(scon, SSL_SENT_SHUTDOWN | | ||
| 445 | SSL_RECEIVED_SHUTDOWN); | ||
| 446 | else | ||
| 447 | SSL_shutdown(scon); | ||
| 448 | |||
| 449 | nConn += 1; | ||
| 450 | if (SSL_session_reused(scon)) | ||
| 451 | ver = 'r'; | ||
| 452 | else { | ||
| 453 | ver = SSL_version(scon); | ||
| 454 | if (ver == TLS1_VERSION) | ||
| 455 | ver = 't'; | ||
| 456 | else if (ver == SSL3_VERSION) | ||
| 457 | ver = '3'; | ||
| 458 | else if (ver == SSL2_VERSION) | ||
| 459 | ver = '2'; | ||
| 460 | else | ||
| 461 | ver = '*'; | ||
| 462 | } | ||
| 463 | fputc(ver, stdout); | ||
| 464 | fflush(stdout); | ||
| 465 | } | ||
| 466 | totalTime += tm_Time_F(STOP); /* Add the time for this iteration */ | ||
| 467 | |||
| 468 | printf("\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n", nConn, totalTime, ((double) nConn / totalTime), bytes_read); | ||
| 469 | printf("%d connections in %lld real seconds, %ld bytes read per connection\n", | ||
| 470 | nConn, | ||
| 471 | (long long)(time(NULL) - finishtime + s_time_config.maxtime), | ||
| 472 | bytes_read / nConn); | ||
| 473 | 341 | ||
| 474 | ret = 0; | 342 | ret = 0; |
| 475 | end: | 343 | end: |
| 476 | SSL_free(scon); | ||
| 477 | |||
| 478 | if (tm_ctx != NULL) { | 344 | if (tm_ctx != NULL) { |
| 479 | SSL_CTX_free(tm_ctx); | 345 | SSL_CTX_free(tm_ctx); |
| 480 | tm_ctx = NULL; | 346 | tm_ctx = NULL; |
| @@ -542,3 +408,106 @@ doConnection(SSL * scon) | |||
| 542 | } | 408 | } |
| 543 | return serverCon; | 409 | return serverCon; |
| 544 | } | 410 | } |
| 411 | |||
| 412 | static int | ||
| 413 | benchmark(int reuse_session) | ||
| 414 | { | ||
| 415 | double totalTime = 0.0; | ||
| 416 | int nConn = 0; | ||
| 417 | SSL *scon = NULL; | ||
| 418 | time_t finishtime; | ||
| 419 | int ret = 1; | ||
| 420 | char buf[1024 * 8]; | ||
| 421 | int ver; | ||
| 422 | |||
| 423 | if (reuse_session) { | ||
| 424 | /* Get an SSL object so we can reuse the session id */ | ||
| 425 | if ((scon = doConnection(NULL)) == NULL) { | ||
| 426 | fprintf(stderr, "Unable to get connection\n"); | ||
| 427 | goto end; | ||
| 428 | } | ||
| 429 | if (s_time_config.www_path != NULL) { | ||
| 430 | int retval = snprintf(buf, sizeof buf, | ||
| 431 | "GET %s HTTP/1.0\r\n\r\n", s_time_config.www_path); | ||
| 432 | if ((size_t)retval >= sizeof buf) { | ||
| 433 | fprintf(stderr, "URL too long\n"); | ||
| 434 | goto end; | ||
| 435 | } | ||
| 436 | SSL_write(scon, buf, strlen(buf)); | ||
| 437 | while (SSL_read(scon, buf, sizeof(buf)) > 0); | ||
| 438 | } | ||
| 439 | if (s_time_config.no_shutdown) | ||
| 440 | SSL_set_shutdown(scon, SSL_SENT_SHUTDOWN | | ||
| 441 | SSL_RECEIVED_SHUTDOWN); | ||
| 442 | else | ||
| 443 | SSL_shutdown(scon); | ||
| 444 | printf("starting\n"); | ||
| 445 | } | ||
| 446 | |||
| 447 | nConn = 0; | ||
| 448 | totalTime = 0.0; | ||
| 449 | |||
| 450 | finishtime = time(NULL) + s_time_config.maxtime; | ||
| 451 | |||
| 452 | bytes_read = 0; | ||
| 453 | tm_Time_F(START); | ||
| 454 | |||
| 455 | for (;;) { | ||
| 456 | if (finishtime < time(NULL)) | ||
| 457 | break; | ||
| 458 | if ((scon = doConnection(reuse_session ? scon : NULL)) == NULL) | ||
| 459 | goto end; | ||
| 460 | |||
| 461 | if (s_time_config.www_path != NULL) { | ||
| 462 | int i, retval = snprintf(buf, sizeof buf, | ||
| 463 | "GET %s HTTP/1.0\r\n\r\n", s_time_config.www_path); | ||
| 464 | if ((size_t)retval >= sizeof buf) { | ||
| 465 | fprintf(stderr, "URL too long\n"); | ||
| 466 | goto end; | ||
| 467 | } | ||
| 468 | SSL_write(scon, buf, strlen(buf)); | ||
| 469 | while ((i = SSL_read(scon, buf, sizeof(buf))) > 0) | ||
| 470 | bytes_read += i; | ||
| 471 | } | ||
| 472 | if (s_time_config.no_shutdown) | ||
| 473 | SSL_set_shutdown(scon, SSL_SENT_SHUTDOWN | | ||
| 474 | SSL_RECEIVED_SHUTDOWN); | ||
| 475 | else | ||
| 476 | SSL_shutdown(scon); | ||
| 477 | |||
| 478 | nConn += 1; | ||
| 479 | if (SSL_session_reused(scon)) | ||
| 480 | ver = 'r'; | ||
| 481 | else { | ||
| 482 | ver = SSL_version(scon); | ||
| 483 | if (ver == TLS1_VERSION) | ||
| 484 | ver = 't'; | ||
| 485 | else if (ver == SSL3_VERSION) | ||
| 486 | ver = '3'; | ||
| 487 | else if (ver == SSL2_VERSION) | ||
| 488 | ver = '2'; | ||
| 489 | else | ||
| 490 | ver = '*'; | ||
| 491 | } | ||
| 492 | fputc(ver, stdout); | ||
| 493 | fflush(stdout); | ||
| 494 | |||
| 495 | if (!reuse_session) { | ||
| 496 | SSL_free(scon); | ||
| 497 | scon = NULL; | ||
| 498 | } | ||
| 499 | } | ||
| 500 | totalTime += tm_Time_F(STOP); /* Add the time for this iteration */ | ||
| 501 | |||
| 502 | printf("\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n", | ||
| 503 | nConn, totalTime, ((double) nConn / totalTime), bytes_read); | ||
| 504 | printf("%d connections in %lld real seconds, %ld bytes read per connection\n", | ||
| 505 | nConn, | ||
| 506 | (long long)(time(NULL) - finishtime + s_time_config.maxtime), | ||
| 507 | bytes_read / nConn); | ||
| 508 | |||
| 509 | ret = 0; | ||
| 510 | end: | ||
| 511 | SSL_free(scon); | ||
| 512 | return ret; | ||
| 513 | } | ||
