Add a --terse option
authorMatt Caswell <matt@openssl.org>
Mon, 22 May 2023 15:34:40 +0000 (16:34 +0100)
committerMatt Caswell <matt@openssl.org>
Mon, 29 May 2023 10:43:59 +0000 (11:43 +0100)
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/tools/pull/146)

perf/README
perf/handshake.c
perf/randbytes.c

index d1bc7afe91414a211ec81e01207ae75f1ca35d4e..aa5865a95b77ba56b3c6e689b0c59339c78faa5a 100644 (file)
@@ -14,16 +14,16 @@ is to be tested. Typically we would expect the apps to be built multiple times
 To build the tests we assume that the target OpenSSL has already been built.
 Two environment variables are required:
 
-TARGET_SSL_INCLUDE_PATH: Points to a directory where the OpenSSL include files
+TARGET_OSSL_INCLUDE_PATH: Points to a directory where the OpenSSL include files
 are held (e.g. typically "include" under the build directory).
 
-TARGET_SSL_LIBRARY_PATH: Points to a directory where libcrypto.so and libssl.so
+TARGET_OSSL_LIBRARY_PATH: Points to a directory where libcrypto.so and libssl.so
 are contained.
 
 To build:
 
-export TARGET_SSL_INCLUDE_PATH=/path/to/openssl/include
-export TARGET_SSL_LIBRARY_PATH=/path/to/openssl
+export TARGET_OSSL_INCLUDE_PATH=/path/to/openssl/include
+export TARGET_OSSL_LIBRARY_PATH=/path/to/openssl
 make
 
 The performance testing apps must be run ensuring that libcrypto.so and
index 358d95ed055d58cb456f8432b3760c985547d363..e18f34965dfe955e315b8cf69ba2342c89c10ee2 100644 (file)
@@ -9,6 +9,7 @@
 
 #include <stdlib.h>
 #include <stdio.h>
+#include <string.h>
 #include <openssl/ssl.h>
 #include "perflib/perflib.h"
 
@@ -56,25 +57,35 @@ int main(int argc, char *argv[])
     char *privkey;
     int ret = EXIT_FAILURE;
     int i;
+    int argnext;
+    int terse = 0;
 
-    if (argc != 3) {
-        printf("Usage: handshake certsdir threadcount\n");
+    if ((argc != 3 && argc != 4)
+            || (argc == 4 && strcmp("--terse", argv[1]) != 0)) {
+        printf("Usage: handshake [--terse] certsdir threadcount\n");
         return EXIT_FAILURE;
     }
 
-    threadcount = atoi(argv[2]);
-    if (threadcount < 1) {
-        printf("threadcount must be > 0\n");
-        return EXIT_FAILURE;
+    if (argc == 4) {
+        terse = 1;
+        argnext = 2;
+    } else {
+        argnext = 1;
     }
 
-    cert = perflib_mk_file_path(argv[1], "servercert.pem");
-    privkey = perflib_mk_file_path(argv[1], "serverkey.pem");
+    cert = perflib_mk_file_path(argv[argnext], "servercert.pem");
+    privkey = perflib_mk_file_path(argv[argnext], "serverkey.pem");
     if (cert == NULL || privkey == NULL) {
         printf("Failed to allocate cert/privkey\n");
         goto err;
     }
 
+    threadcount = atoi(argv[++argnext]);
+    if (threadcount < 1) {
+        printf("threadcount must be > 0\n");
+        goto err;
+    }
+
     times = OPENSSL_malloc(sizeof(OSSL_TIME) * threadcount);
     if (times == NULL) {
         printf("Failed to create times array\n");
@@ -105,8 +116,13 @@ int main(int argc, char *argv[])
     persec = ((NUM_HANDSHAKES_PER_THREAD * threadcount * OSSL_TIME_SECOND)
              / (double)ossl_time2ticks(duration));
 
-    printf("Average time per handshake: %ldus\n", ossl_time2us(av));
-    printf("Handshakes per second: %lf\n", persec);
+    if (terse) {
+        printf("%ld\n", ossl_time2us(av));
+        printf("%lf\n", persec);
+    } else {
+        printf("Average time per handshake: %ldus\n", ossl_time2us(av));
+        printf("Handshakes per second: %lf\n", persec);
+    }
 
     ret = EXIT_SUCCESS;
  err:
index 09b8f0a6b768ade4f6bc6af997e65b89e3ddae1c..6357bf00b6741d6dfb49a8dcbad702f2e709d217 100644 (file)
@@ -9,6 +9,7 @@
 
 #include <stdlib.h>
 #include <stdio.h>
+#include <string.h>
 #include <openssl/rand.h>
 #include <openssl/crypto.h>
 #include "perflib/perflib.h"
@@ -35,13 +36,23 @@ int main(int argc, char *argv[])
     OSSL_TIME duration;
     uint64_t us;
     double avcalltime;
+    int terse = 0;
+    int argnext;
 
-    if (argc != 2) {
-        printf("Usage: randbytes threadcount\n");
+    if ((argc != 2 && argc != 3)
+                || (argc == 3 && strcmp("--terse", argv[1]) != 0)) {
+        printf("Usage: randbytes [--terse] threadcount\n");
         return EXIT_FAILURE;
     }
 
-    threadcount = atoi(argv[1]);
+    if (argc == 3) {
+        terse = 1;
+        argnext = 2;
+    } else {
+        argnext = 1;
+    }
+
+    threadcount = atoi(argv[argnext]);
     if (threadcount < 1) {
         printf("threadcount must be > 0\n");
         return EXIT_FAILURE;
@@ -61,8 +72,11 @@ int main(int argc, char *argv[])
 
     avcalltime = (double)us / (NUM_CALL_BLOCKS_PER_THREAD * threadcount);
 
-    printf("Average time per %d RAND_bytes() calls: %lfus\n",
-           NUM_CALLS_PER_BLOCK, avcalltime);
+    if (terse)
+        printf("%lf\n", avcalltime);
+    else
+        printf("Average time per %d RAND_bytes() calls: %lfus\n",
+            NUM_CALLS_PER_BLOCK, avcalltime);
 
     return EXIT_SUCCESS;
 }