From: Sebastien GODARD Date: Fri, 12 Apr 2019 15:45:29 +0000 (+0200) Subject: sadf: Add a function prototype to each output format X-Git-Tag: v12.1.4~9 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=76f5ef6a3ae2805170cc76d9cc6c1fb9fa62d8c7;p=sysstat sadf: Add a function prototype to each output format Each outpout format now defines the function used to display its statistics. Signed-off-by: Sebastien GODARD --- diff --git a/format.c b/format.c index 238031d..e2202f1 100644 --- a/format.c +++ b/format.c @@ -45,7 +45,8 @@ struct report_format hdr_fmt = { .f_statistics = NULL, .f_timestamp = NULL, .f_restart = NULL, - .f_comment = NULL + .f_comment = NULL, + .f_display = NULL }; /* @@ -53,13 +54,14 @@ struct report_format hdr_fmt = { */ struct report_format db_fmt = { .id = F_DB_OUTPUT, - .options = FO_GROUPED_STATS + FO_LOCAL_TIME + FO_HORIZONTALLY + + .options = FO_LOCAL_TIME + FO_HORIZONTALLY + FO_SEC_EPOCH + FO_FIELD_LIST, .f_header = NULL, .f_statistics = NULL, .f_timestamp = print_db_timestamp, .f_restart = print_db_restart, - .f_comment = print_db_comment + .f_comment = print_db_comment, + .f_display = logic2_display_loop }; /* @@ -67,12 +69,13 @@ struct report_format db_fmt = { */ struct report_format ppc_fmt = { .id = F_PPC_OUTPUT, - .options = FO_GROUPED_STATS + FO_LOCAL_TIME + FO_SEC_EPOCH, + .options = FO_LOCAL_TIME + FO_SEC_EPOCH, .f_header = NULL, .f_statistics = NULL, .f_timestamp = print_ppc_timestamp, .f_restart = print_ppc_restart, - .f_comment = print_ppc_comment + .f_comment = print_ppc_comment, + .f_display = logic2_display_loop }; /* @@ -85,7 +88,8 @@ struct report_format xml_fmt = { .f_statistics = print_xml_statistics, .f_timestamp = print_xml_timestamp, .f_restart = print_xml_restart, - .f_comment = print_xml_comment + .f_comment = print_xml_comment, + .f_display = logic1_display_loop }; /* @@ -98,7 +102,8 @@ struct report_format json_fmt = { .f_statistics = print_json_statistics, .f_timestamp = print_json_timestamp, .f_restart = print_json_restart, - .f_comment = print_json_comment + .f_comment = print_json_comment, + .f_display = logic1_display_loop }; /* @@ -111,7 +116,8 @@ struct report_format conv_fmt = { .f_statistics = NULL, .f_timestamp = NULL, .f_restart = NULL, - .f_comment = NULL + .f_comment = NULL, + .f_display = NULL }; /* @@ -124,7 +130,8 @@ struct report_format svg_fmt = { .f_statistics = NULL, .f_timestamp = NULL, .f_restart = NULL, - .f_comment = NULL + .f_comment = NULL, + .f_display = svg_display_loop }; /* @@ -132,12 +139,13 @@ struct report_format svg_fmt = { */ struct report_format raw_fmt = { .id = F_RAW_OUTPUT, - .options = FO_GROUPED_STATS + FO_LOCAL_TIME + FO_SEC_EPOCH, + .options = FO_LOCAL_TIME + FO_SEC_EPOCH, .f_header = NULL, .f_statistics = NULL, .f_timestamp = print_raw_timestamp, .f_restart = print_raw_restart, - .f_comment = print_raw_comment + .f_comment = print_raw_comment, + .f_display = logic2_display_loop }; /* @@ -150,7 +158,8 @@ struct report_format pcp_fmt = { .f_statistics = print_pcp_statistics, .f_timestamp = print_pcp_timestamp, .f_restart = NULL, - .f_comment = NULL + .f_comment = NULL, + .f_display = logic1_display_loop }; /* diff --git a/sa.h b/sa.h index 193ecaf..9d6f1b8 100644 --- a/sa.h +++ b/sa.h @@ -1038,6 +1038,11 @@ struct report_format { * This function displays the comments. */ __printf_funct_t (*f_comment) (int *, int, char *, char *, int, char *, struct file_header *); + /* + * This is the main function used to display all the statistics for current format. + */ + void (*f_display) (int, char *, struct file_activity *, struct file_magic *, + struct tm *, struct tm *, void *); }; /* Possible actions for functions used to display reports */ diff --git a/sadf.c b/sadf.c index fbdb8b1..ae08035 100644 --- a/sadf.c +++ b/sadf.c @@ -995,26 +995,35 @@ void display_curr_act_graphs(int ifd, int *curr, long *cnt, int *eosaf, * Logic #1: Grouped by record type. Sorted by timestamp. * Formats: XML, JSON, PCP * + * NB: all statistics data will be sorted by timestamp. + * Example: If stats for activities A and B at time t and t' have been collected, + * the output will be: + * stats for activity A at t + * stats for activity B at t + * stats for activity A at t' + * stats for activity B at t' + * * IN: * @ifd File descriptor of input file. - * @file_actlst List of (known or unknown) activities in file. * @file System activity data file name (name of file being read). - * @pcparchive PCP archive file name. + * @file_actlst List of (known or unknown) activities in file. * @file_magic System activity file magic header. * @rectime Structure where timestamp (expressed in local time or in UTC * depending on whether options -T/-t have been used or not) can * be saved for current record. * @loctime Structure where timestamp (expressed in local time) can be * saved for current record. + * @dparm PCP archive file name. *************************************************************************** */ -void logic1_display_loop(int ifd, struct file_activity *file_actlst, char *file, - char *pcparchive, struct file_magic *file_magic, - struct tm *rectime, struct tm *loctime) +void logic1_display_loop(int ifd, char *file, struct file_activity *file_actlst, + struct file_magic *file_magic, struct tm *rectime, + struct tm *loctime, void *dparm) { int curr, rtype, tab = 0; int eosaf, next, reset = FALSE; long cnt = 1; + char *pcparchive = (char *) dparm; if (format == F_JSON_OUTPUT) { /* Use a decimal point to make JSON code compliant with RFC7159 */ @@ -1162,21 +1171,31 @@ void logic1_display_loop(int ifd, struct file_activity *file_actlst, char *file, * records. * Formats: ppc, CSV, raw * + * NB: All statistics data for one activity will be displayed before + * displaying stats for next activity. This is what sar does in its report. + * Example: If stats for activities A and B at time t and t' have been collected, + * the output will be: + * stats for activity A at t + * stats for activity A at t' + * stats for activity B at t + * stats for activity B at t' + * * IN: * @ifd File descriptor of input file. + * @file Name of file being read. * @file_actlst List of (known or unknown) activities in file. + * @file_magic file_magic structure filled with file magic header data. * @rectime Structure where timestamp (expressed in local time or in UTC * depending on whether options -T/-t have been used or not) can * be saved for current record. * @loctime Structure where timestamp (expressed in local time) can be * saved for current record. - * @file Name of file being read. - * @file_magic file_magic structure filled with file magic header data. + * @dparm Unused here. *************************************************************************** */ -void logic2_display_loop(int ifd, struct file_activity *file_actlst, - struct tm *rectime, struct tm *loctime, char *file, - struct file_magic *file_magic) +void logic2_display_loop(int ifd, char *file, struct file_activity *file_actlst, + struct file_magic *file_magic, struct tm *rectime, + struct tm *loctime, void *dparm) { int i, p; int curr = 1, rtype; @@ -1283,25 +1302,24 @@ void logic2_display_loop(int ifd, struct file_activity *file_actlst, /* *************************************************************************** - * Display file contents in selected format (logic #3). - * Logic #3: Special logic for SVG output format. - * Formats: SVG + * Display file contents in SVG format. * * IN: * @ifd File descriptor of input file. + * @file Name of file being read. * @file_actlst List of (known or unknown) activities in file. + * @file_magic file_magic structure filled with file magic header data. * @rectime Structure where timestamp (expressed in local time or in UTC * depending on whether options -T/-t have been used or not) can * be saved for current record. * @loctime Structure where timestamp (expressed in local time) can be * saved for current record. - * @file Name of file being read. - * @file_magic file_magic structure filled with file magic header data. + * @dparm Unused here. *************************************************************************** */ -void logic3_display_loop(int ifd, struct file_activity *file_actlst, - struct tm *rectime, struct tm *loctime, char *file, - struct file_magic *file_magic) +void svg_display_loop(int ifd, char *file, struct file_activity *file_actlst, + struct file_magic *file_magic, struct tm *rectime, + struct tm *loctime, void *dparm) { struct svg_hdr_parm parm; int i, p; @@ -1451,17 +1469,9 @@ void read_stats_from_file(char dfile[], char pcparchive[]) allocate_structures(act); /* Call function corresponding to selected output format */ - if (format == F_SVG_OUTPUT) { - logic3_display_loop(ifd, file_actlst, - &rectime, &loctime, dfile, &file_magic); - } - else if (DISPLAY_GROUPED_STATS(fmt[f_position]->options)) { - logic2_display_loop(ifd, file_actlst, - &rectime, &loctime, dfile, &file_magic); - } - else { - logic1_display_loop(ifd, file_actlst, dfile, pcparchive, - &file_magic, &rectime, &loctime); + if (*fmt[f_position]->f_display) { + (*fmt[f_position]->f_display)(ifd, dfile, file_actlst, &file_magic, + &rectime, &loctime, pcparchive); } close(ifd); diff --git a/sadf.h b/sadf.h index a83371c..8a18967 100644 --- a/sadf.h +++ b/sadf.h @@ -43,22 +43,7 @@ /* Format options */ -/* - * Indicate that all statistics data for one activity should be displayed before - * displaying stats for next activity. This is what sar does in its report. - * Example: If stats for activities A and B at time t and t' have been collected, - * setting AO_GROUPED_STATS for a format will result in the following output: - * stats for activity A at t - * stats for activity A at t' - * stats for activity B at t - * stats for activity B at t' - * Without this option, output would be: - * stats for activity A at t - * stats for activity B at t - * stats for activity A at t' - * stats for activity B at t' - */ -#define FO_GROUPED_STATS 0x01 +/* Unused 0x01 */ /* * Indicate that output should stop after the header is displayed. @@ -107,7 +92,6 @@ */ #define FO_NO_TRUE_TIME 0x100 -#define DISPLAY_GROUPED_STATS(m) (((m) & FO_GROUPED_STATS) == FO_GROUPED_STATS) #define ACCEPT_HEADER_ONLY(m) (((m) & FO_HEADER_ONLY) == FO_HEADER_ONLY) #define ACCEPT_BAD_FILE_FORMAT(m) (((m) & FO_BAD_FILE_FORMAT) == FO_BAD_FILE_FORMAT) #define ACCEPT_LOCAL_TIME(m) (((m) & FO_LOCAL_TIME) == FO_LOCAL_TIME) @@ -208,4 +192,17 @@ __printf_funct_t print_pcp_header (void *, int, char *, struct file_magic *, struct file_header *, struct activity * [], unsigned int [], struct file_activity *); +/* + * Main display functions + */ +void logic1_display_loop + (int, char *, struct file_activity *, struct file_magic *, + struct tm *, struct tm *, void *); +void logic2_display_loop + (int, char *, struct file_activity *, struct file_magic *, + struct tm *, struct tm *, void *); +void svg_display_loop + (int, char *, struct file_activity *, struct file_magic *, + struct tm *, struct tm *, void *); + #endif /* _SADF_H */