From 5a786ba8a635f619b49ec3f9ee664a232e3de59f Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Wed, 17 Aug 2022 09:55:20 +0200 Subject: [PATCH] Add support for option -t with sadf's SVG output (#331) When sadf was used to display SVG graphs, it was not possible to display the timestamps (on the X axis) in the same locale as that of the file creator. This was because option -t was not supported by sadf in SVG output format. This patch fixes that. Signed-off-by: Sebastien GODARD --- format.c | 2 +- sa.h | 3 +++ sadf.c | 3 +++ svg_stats.c | 38 ++++++++++++++++++++++++++++++++++++-- 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/format.c b/format.c index 6fa3d27..2a391c4 100644 --- a/format.c +++ b/format.c @@ -126,7 +126,7 @@ struct report_format conv_fmt = { */ struct report_format svg_fmt = { .id = F_SVG_OUTPUT, - .options = FO_HEADER_ONLY + FO_LOCAL_TIME + FO_NO_TRUE_TIME + + .options = FO_HEADER_ONLY + FO_LOCAL_TIME + FO_LC_NUMERIC_C, .f_header = print_svg_header, .f_statistics = NULL, diff --git a/sa.h b/sa.h index 86b857f..cfaeeed 100644 --- a/sa.h +++ b/sa.h @@ -365,6 +365,9 @@ struct svg_parm { int graph_no; /* Total number of views already displayed */ int restart; /* TRUE if we have just met a RESTART record */ int nr_act_dispd; /* Number of activities that will be displayed */ + char hour; /* Hour, minute and second (expressed in the */ + char minute; /* locale of the datafile creator) for first */ + char second; /* sample */ struct file_header *file_hdr; /* Pointer on file header structure */ }; diff --git a/sadf.c b/sadf.c index 18a4d97..b6b39b5 100644 --- a/sadf.c +++ b/sadf.c @@ -927,6 +927,9 @@ void display_curr_act_graphs(int ifd, int *curr, long *cnt, int *eosaf, parm.restart = TRUE; parm.file_hdr = &file_hdr; parm.nr_act_dispd = nr_act_dispd; + parm.hour = record_hdr[2].hour; + parm.minute = record_hdr[2].minute; + parm.second = record_hdr[2].second; *cnt = count; reset_cd = 1; diff --git a/svg_stats.c b/svg_stats.c index 403f084..7265c77 100644 --- a/svg_stats.c +++ b/svg_stats.c @@ -548,6 +548,34 @@ unsigned int pwr10(int n) return e; } +/* + *************************************************************************** + * Compute timestamp for next graduation on the X axis. + * + * IN: + * @stamp Record header with timestamp for current graduation. + * @xpos Number of seconds between two consecutive graduations. + * + * OUT: + * @stamp Record header with timestamp for next graduation that will + * be displayed on the X axis of the graph. + *************************************************************************** + */ +void compute_next_graduation_timestamp(struct record_header *stamp, long int xpos) +{ + stamp->ust_time += xpos; + + if (PRINT_TRUE_TIME(flags)) { + /* Lines below useful only when option -t used */ + stamp->second += xpos; + stamp->minute += stamp->second / 60; + stamp->second %= 60; + stamp->hour += stamp->minute / 60; + stamp->minute %= 60; + stamp->hour %= 24; + } +} + /* *************************************************************************** * Autoscale graphs of a given view. @@ -655,7 +683,11 @@ void display_vgrid(long int xpos, double xfactor, int v_gridnr, struct svg_parm char cur_time[TIMESTAMP_LEN]; int j; - stamp.ust_time = svg_p->ust_time_ref; /* Only ust_time field needs to be set. TRUE_TIME not allowed */ + stamp.ust_time = svg_p->ust_time_ref; + /* Also set hour, minute and second in case TRUE_TIME (option -t) requested by user */ + stamp.hour = svg_p->hour; + stamp.minute = svg_p->minute; + stamp.second = svg_p->second; /* Print marker in debug mode */ if (DISPLAY_DEBUG_MODE(flags)) { @@ -701,7 +733,9 @@ void display_vgrid(long int xpos, double xfactor, int v_gridnr, struct svg_parm svg_colors[palette][SVG_COL_AXIS_IDX], (long) (xpos * j * xfactor), cur_time); } - stamp.ust_time += xpos; + + /* Compute timestamp for next graduation */ + compute_next_graduation_timestamp(&stamp, xpos); } if (!PRINT_LOCAL_TIME(flags)) { -- 2.40.0