From: Sebastien GODARD Date: Sat, 25 Apr 2020 07:31:56 +0000 (+0200) Subject: sadf: Add option "hz=" for datafile conversion X-Git-Tag: v12.3.3~13 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=de54ed37d6fe5ca6ab2086bdb4b3733c7abb72a9;p=sysstat sadf: Add option "hz=" for datafile conversion 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 --- diff --git a/sa.h b/sa.h index 804e0c9..7e6f963 100644 --- a/sa.h +++ b/sa.h @@ -246,6 +246,7 @@ #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" diff --git a/sa_conv.c b/sa_conv.c index d518b81..a61679c 100644 --- 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 dfdca38..22e8a16 100644 --- 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]); }