From d5b14e0199d0ab025dde113b1173ba6b0aead669 Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Sun, 31 Dec 2017 09:13:09 +0100 Subject: [PATCH] sadf -H: Display all the activities in file Make sadf -H display all the activities present in file, whether known or unknown. Signed-off-by: Sebastien GODARD --- sa.h | 2 +- sadf.c | 10 +++++----- sadf.h | 8 ++++---- sadf_misc.c | 44 ++++++++++++++++++++++++++++---------------- 4 files changed, 38 insertions(+), 26 deletions(-) diff --git a/sa.h b/sa.h index b9eb411..6b4c2ad 100644 --- a/sa.h +++ b/sa.h @@ -957,7 +957,7 @@ struct report_format { * (data displayed once at the beginning of the report). */ __printf_funct_t (*f_header) (void *, int, char *, struct file_magic *, struct file_header *, - struct activity * [], unsigned int []); + struct activity * [], unsigned int [], struct file_activity *); /* * This function defines the statistics part of the report. * Used only with textual (XML-like) reports. diff --git a/sadf.c b/sadf.c index be25da1..6f3ae03 100644 --- a/sadf.c +++ b/sadf.c @@ -940,7 +940,7 @@ void logic1_display_loop(int ifd, struct file_activity *file_actlst, char *file, /* Print header (eg. XML file header) */ if (*fmt[f_position]->f_header) { (*fmt[f_position]->f_header)(&tab, F_BEGIN, file, file_magic, - &file_hdr, act, id_seq); + &file_hdr, act, id_seq, file_actlst); } /* Process activities */ @@ -1059,7 +1059,7 @@ void logic1_display_loop(int ifd, struct file_activity *file_actlst, char *file, /* Print header trailer */ if (*fmt[f_position]->f_header) { (*fmt[f_position]->f_header)(&tab, F_END, file, file_magic, - &file_hdr, act, id_seq); + &file_hdr, act, id_seq, file_actlst); } } @@ -1243,7 +1243,7 @@ void logic3_display_loop(int ifd, struct file_activity *file_actlst, /* Print SVG header */ if (*fmt[f_position]->f_header) { (*fmt[f_position]->f_header)(&parm, F_BEGIN + F_MAIN, file, file_magic, - &file_hdr, act, id_seq); + &file_hdr, act, id_seq, file_actlst); } /* @@ -1311,7 +1311,7 @@ close_svg: /* Print SVG trailer */ if (*fmt[f_position]->f_header) { (*fmt[f_position]->f_header)(&parm, F_END, file, file_magic, - &file_hdr, act, id_seq); + &file_hdr, act, id_seq, file_actlst); } } @@ -1341,7 +1341,7 @@ void read_stats_from_file(char dfile[]) if (*fmt[f_position]->f_header) { /* Display only data file header then exit */ (*fmt[f_position]->f_header)(&tab, F_BEGIN + F_END, dfile, &file_magic, - &file_hdr, act, id_seq); + &file_hdr, act, id_seq, file_actlst); } exit(0); } diff --git a/sadf.h b/sadf.h index 7be036d..c3d99f6 100644 --- a/sadf.h +++ b/sadf.h @@ -183,15 +183,15 @@ __tm_funct_t print_raw_timestamp */ __printf_funct_t print_xml_header (void *, int, char *, struct file_magic *, struct file_header *, - struct activity * [], unsigned int []); + struct activity * [], unsigned int [], struct file_activity *); __printf_funct_t print_json_header (void *, int, char *, struct file_magic *, struct file_header *, - struct activity * [], unsigned int []); + struct activity * [], unsigned int [], struct file_activity *); __printf_funct_t print_hdr_header (void *, int, char *, struct file_magic *, struct file_header *, - struct activity * [], unsigned int []); + struct activity * [], unsigned int [], struct file_activity *); __printf_funct_t print_svg_header (void *, int, char *, struct file_magic *, struct file_header *, - struct activity * [], unsigned int []); + struct activity * [], unsigned int [], struct file_activity *); #endif /* _SADF_H */ diff --git a/sadf_misc.c b/sadf_misc.c index b64fd75..5f837ee 100644 --- a/sadf_misc.c +++ b/sadf_misc.c @@ -682,6 +682,7 @@ __tm_funct_t print_raw_timestamp(void *parm, int action, char *cur_date, * @file_hdr System activity file standard header. * @act Array of activities (unused here). * @id_seq Activity sequence (unused here). + * @file_actlst List of (known or unknown) activities in file (unused here). * * OUT: * @parm Number of tabulations. @@ -690,7 +691,8 @@ __tm_funct_t print_raw_timestamp(void *parm, int action, char *cur_date, __printf_funct_t print_xml_header(void *parm, int action, char *dfile, struct file_magic *file_magic, struct file_header *file_hdr, - struct activity *act[], unsigned int id_seq[]) + struct activity *act[], unsigned int id_seq[], + struct file_activity *file_actlst) { struct tm rectime, *loc_t; char cur_time[TIMESTAMP_LEN]; @@ -748,6 +750,7 @@ __printf_funct_t print_xml_header(void *parm, int action, char *dfile, * @file_hdr System activity file standard header. * @act Array of activities (unused here). * @id_seq Activity sequence (unused here). + * @file_actlst List of (known or unknown) activities in file (unused here). * * OUT: * @parm Number of tabulations. @@ -756,7 +759,8 @@ __printf_funct_t print_xml_header(void *parm, int action, char *dfile, __printf_funct_t print_json_header(void *parm, int action, char *dfile, struct file_magic *file_magic, struct file_header *file_hdr, - struct activity *act[], unsigned int id_seq[]) + struct activity *act[], unsigned int id_seq[], + struct file_activity *file_actlst) { struct tm rectime, *loc_t; char cur_time[TIMESTAMP_LEN]; @@ -807,15 +811,18 @@ __printf_funct_t print_json_header(void *parm, int action, char *dfile, * @file_hdr System activity file standard header. * @act Array of activities. * @id_seq Activity sequence. + * @file_actlst List of (known or unknown) activities in file. *************************************************************************** */ __printf_funct_t print_hdr_header(void *parm, int action, char *dfile, struct file_magic *file_magic, struct file_header *file_hdr, - struct activity *act[], unsigned int id_seq[]) + struct activity *act[], unsigned int id_seq[], + struct file_activity *file_actlst) { int i, p; struct tm rectime, *loc_t; + struct file_activity *fal; char cur_time[TIMESTAMP_LEN]; /* Actions F_MAIN and F_END ignored */ @@ -853,24 +860,27 @@ __printf_funct_t print_hdr_header(void *parm, int action, char *dfile, printf(_("Size of a long int: %d\n"), file_hdr->sa_sizeof_long); printf("HZ = %lu\n", file_hdr->sa_hz); - - /* Number of activities in file */ - printf("sa_act_nr: %u\n", + printf(_("Number of activities in file: %u\n"), file_hdr->sa_act_nr); printf(_("List of activities:\n")); + fal = file_actlst; + for (i = 0; i < file_hdr->sa_act_nr; i++, fal++) { - for (i = 0; i < NR_ACT; i++) { - if (!id_seq[i]) - continue; - - p = get_activity_position(act, id_seq[i], EXIT_IF_NOT_FOUND); + p = get_activity_position(act, fal->id, RESUME_IF_NOT_FOUND); - printf("%02d: %s\t(x%d)", act[p]->id, act[p]->name, act[p]->nr_ini); - if (IS_MATRIX(act[p]->options)) { - printf("\t(x%d)", act[p]->nr2); + printf("%02d: ", fal->id); + if (p >= 0) { + printf("%-15s", act[p]->name); + } + else { + printf(_("Unknown activity")); + } + printf("\t(x%d)", fal->nr); + if (fal->nr2 > 1) { + printf("\t(x%d)", fal->nr2); } - if (act[p]->magic == ACTIVITY_MAGIC_UNKNOWN) { + if ((p >= 0) && (act[p]->magic == ACTIVITY_MAGIC_UNKNOWN)) { printf(_("\t[Unknown activity format]")); } printf("\n"); @@ -892,12 +902,14 @@ __printf_funct_t print_hdr_header(void *parm, int action, char *dfile, * @file_hdr System activity file standard header. * @act Array of activities (unused here). * @id_seq Activity sequence (unused here). + * @file_actlst List of (known or unknown) activities in file (unused here). *************************************************************************** */ __printf_funct_t print_svg_header(void *parm, int action, char *dfile, struct file_magic *file_magic, struct file_header *file_hdr, - struct activity *act[], unsigned int id_seq[]) + struct activity *act[], unsigned int id_seq[], + struct file_activity *file_actlst) { struct svg_hdr_parm *hdr_parm = (struct svg_hdr_parm *) parm; -- 2.40.0