Add simple time and performance measurement in verbose mode master
authorSteve McIntyre <steve@einval.com>
Fri, 17 Jan 2020 18:00:54 +0000 (18:00 +0000)
committerSteve McIntyre <steve@einval.com>
Fri, 17 Jan 2020 18:25:39 +0000 (18:25 +0000)
mkimage.c

index d82dec4..de3ae2d 100644 (file)
--- a/mkimage.c
+++ b/mkimage.c
@@ -22,6 +22,8 @@
 #include <unistd.h>
 #include <sys/mman.h>
 #include <stdint.h>
+#include <time.h>
+#include <sys/time.h>
 #include "endian.h"
 #include "jig-base64.h"
 #include "md5.h"
@@ -959,6 +961,18 @@ static int parse_file_block_sha256(INT64 offset, INT64 data_size, INT64 file_siz
     return ENOENT;
 }
 
+static void get_time(double *newtime)
+{
+    struct timeval tv;
+    struct timezone tz;
+
+    tz.tz_minuteswest = 0;
+    tz.tz_dsttime = 0;
+
+    gettimeofday(&tv, &tz);
+    *newtime = (double)tv.tv_sec + ((double)tv.tv_usec / 1000000);
+}
+
 static int parse_template_file(char *filename, int sizeonly, char *missing, char *output_name)
 {
     INT64 template_offset = 0;
@@ -980,6 +994,8 @@ static int parse_template_file(char *filename, int sizeonly, char *missing, char
     unsigned char image_sha256sum[SHA256_BYTES];
     unsigned char image_md5sum_from_tmpl[MD5_BYTES];
     unsigned char image_sha256sum_from_tmpl[SHA256_BYTES];
+    double start_time;
+    double end_time;
 
     zip_state.total_offset = 0;
     
@@ -998,6 +1014,8 @@ static int parse_template_file(char *filename, int sizeonly, char *missing, char
         return ENOMEM;
     }
 
+    get_time(&start_time);
+
     /* Find the beginning of the desc block */
     file_size = get_file_size(filename);
     fseek(file, file_size - 6, SEEK_SET);
@@ -1281,6 +1299,14 @@ static int parse_template_file(char *filename, int sizeonly, char *missing, char
             }
         }
         fprintf(logfile, "Output image length is %lld bytes\n", written_length);
+
+        if (verbose)
+        {
+            get_time(&end_time);
+            end_time -= start_time;
+            fprintf(logfile, "  Image creation iook %.2f seconds, (%.2f MB/s)\n",
+                    end_time, (written_length / 1000000 / end_time));
+        }
     }
     
     return 0;