]> granicus.if.org Git - sysstat/commitdiff
sadf: Add option "hz=" for datafile conversion
authorSebastien GODARD <sysstat@users.noreply.github.com>
Sat, 25 Apr 2020 07:31:56 +0000 (09:31 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Sat, 25 Apr 2020 07:31:56 +0000 (09:31 +0200)
Add a new option to be used with "sadf -c" (datafile conversion).
This option enables the user to specify the number of ticks per second
for the machine where the datafile to be converted was created.
E.g.:
sadf -c old_datafile -O hz=250 > new_datafile

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
sa.h
sa_conv.c
sadf.c

diff --git a/sa.h b/sa.h
index 804e0c9bffc0747648914fad0edcbf231b155fec..7e6f963eded764a9d701d7fc19f90063c2f236fa 100644 (file)
--- a/sa.h
+++ b/sa.h
 #define K_CUSTOMCOL    "customcol"
 #define K_BWCOL                "bwcol"
 #define K_PCPARCHIVE   "pcparchive="
+#define K_HZ           "hz="
 
 /* Environment variables */
 #define ENV_COLORS_PALETTE     "S_COLORS_PALETTE"
index d518b814811ba735044fca557502bfbe152ad9e9..a61679c5b368ec7a71d05756aa168857a0ccf786 100644 (file)
--- a/sa_conv.c
+++ b/sa_conv.c
@@ -38,6 +38,7 @@
 #endif
 
 extern int endian_mismatch;
+extern unsigned int user_hz;
 extern unsigned int act_types_nr[];
 extern unsigned int rec_types_nr[];
 extern unsigned int hdr_types_nr[];
@@ -238,6 +239,11 @@ void upgrade_file_header(void *buffer, struct file_header *file_hdr, int previou
        }
        file_hdr->act_size = FILE_ACTIVITY_SIZE;
        file_hdr->rec_size = RECORD_HEADER_SIZE;
+
+       /*
+        * Note: @extra_next and @sa_tzname[] members are set to zero
+        * because file_hdr has been memset'd to zero.
+        */
 }
 
 /*
@@ -1967,8 +1973,14 @@ void convert_file(char dfile[], struct activity *act[])
                goto success;
        }
 
-       /* Get HZ */
-       get_HZ();
+       if (!user_hz) {
+               /* Get HZ */
+               get_HZ();
+       }
+       else {
+               /* HZ set on the command line with option -O */
+               hz = user_hz;
+       }
        fprintf(stderr, _("HZ: Using current value: %lu\n"), HZ);
 
        /* Upgrade file's header section */
diff --git a/sadf.c b/sadf.c
index dfdca38d7fbf1384a8ddd4b1f5e879ccc3f2b539..22e8a163e35410438deabf2f3281850ab6d51ce7 100644 (file)
--- a/sadf.c
+++ b/sadf.c
@@ -70,6 +70,7 @@ unsigned int dm_major;                /* Device-mapper major number */
 unsigned int format = 0;       /* Output format */
 unsigned int f_position = 0;   /* Output format position in array */
 unsigned int canvas_height = 0; /* SVG canvas height value set with option -O */
+unsigned int user_hz = 0;      /* HZ value set with option -O */
 
 /* File header */
 struct file_header file_hdr;
@@ -1625,6 +1626,13 @@ int main(int argc, char **argv)
                                        strncpy(pcparchive, v, MAX_FILE_LEN);
                                        pcparchive[MAX_FILE_LEN - 1] = '\0';
                                }
+                               else if (!strncmp(t, K_HZ, strlen(K_HZ))) {
+                                       v = t + strlen(K_HZ);
+                                       if (!strlen(v) || (strspn(v, DIGITS) != strlen(v))) {
+                                               usage(argv[0]);
+                                       }
+                                       user_hz = atoi(v);
+                               }
                                else {
                                        usage(argv[0]);
                                }