From 1276e5d366dddad609d121985270ac1381c5b00b Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Sun, 22 Jan 2017 11:44:25 +0100 Subject: [PATCH] SVG: Add new option: "height=" The user can now explicitly specify canvas height using sadf's switch -O and option "height=" when creating SVG graphs with sadf -g. E.g.: sadf -g -O height=40000 -- -A > graph.svg Signed-off-by: Sebastien GODARD --- sa.h | 3 +++ sadf.c | 27 +++++++++++++++++++++++---- sadf_misc.c | 7 +++++-- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/sa.h b/sa.h index 61602e3..4b0224f 100644 --- a/sa.h +++ b/sa.h @@ -105,6 +105,7 @@ #define S_F_SVG_ONE_DAY 0x00040000 #define S_F_SVG_SHOW_IDLE 0x00080000 #define S_F_UNIT 0x00100000 +#define S_F_SVG_HEIGHT 0x00200000 #define WANT_SINCE_BOOT(m) (((m) & S_F_SINCE_BOOT) == S_F_SINCE_BOOT) #define WANT_SA_ROTAT(m) (((m) & S_F_SA_ROTAT) == S_F_SA_ROTAT) @@ -128,6 +129,7 @@ #define DISPLAY_ONE_DAY(m) (((m) & S_F_SVG_ONE_DAY) == S_F_SVG_ONE_DAY) #define DISPLAY_IDLE(m) (((m) & S_F_SVG_SHOW_IDLE) == S_F_SVG_SHOW_IDLE) #define DISPLAY_UNIT(m) (((m) & S_F_UNIT) == S_F_UNIT) +#define SET_CANVAS_HEIGHT(m) (((m) & S_F_SVG_HEIGHT) == S_F_SVG_HEIGHT) #define AO_F_NULL 0x00000000 @@ -208,6 +210,7 @@ #define K_ONEDAY "oneday" #define K_SHOWIDLE "showidle" #define K_SHOWHINTS "showhints" +#define K_HEIGHT "height=" /* Groups of activities */ #define G_DEFAULT 0x00 diff --git a/sadf.c b/sadf.c index 3680aa7..66ff30c 100644 --- a/sadf.c +++ b/sadf.c @@ -50,6 +50,7 @@ unsigned int flags = 0; 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 */ /* File header */ struct file_header file_hdr; @@ -1274,9 +1275,19 @@ void logic3_display_loop(int ifd, struct file_activity *file_actlst, __nr_t cpu_ /* Use a decimal point to make SVG code locale independent */ setlocale(LC_NUMERIC, "C"); - /* Calculate the number of graphs to display */ - graph_nr = get_svg_graph_nr(ifd, file, file_magic, - file_actlst, rectime, loctime); + if (SET_CANVAS_HEIGHT(flags)) { + /* + * Option "-O height=..." used: This is not a number + * of graphs but the SVG canvas height set on the command line. + */ + graph_nr = canvas_height; + } + else { + /* Calculate the number of graphs to display */ + graph_nr = get_svg_graph_nr(ifd, file, file_magic, + file_actlst, rectime, loctime); + } + if (!graph_nr) /* No graph to display */ return; @@ -1426,7 +1437,7 @@ int main(int argc, char **argv) int day_offset = 0; int i, rc; char dfile[MAX_FILE_LEN]; - char *t; + char *t, *v; /* Get HZ */ get_HZ(); @@ -1504,6 +1515,14 @@ int main(int argc, char **argv) else if (!strcmp(t, K_SHOWHINTS)) { flags |= S_F_RAW_SHOW_HINTS; } + else if (!strncmp(t, K_HEIGHT, strlen(K_HEIGHT))) { + v = t + strlen(K_HEIGHT); + if (!strlen(v) || (strspn(v, DIGITS) != strlen(v))) { + usage(argv[0]); + } + canvas_height = atoi(v); + flags |= S_F_SVG_HEIGHT; + } else { usage(argv[0]); } diff --git a/sadf_misc.c b/sadf_misc.c index 8486e56..4e97841 100644 --- a/sadf_misc.c +++ b/sadf_misc.c @@ -896,7 +896,8 @@ __printf_funct_t print_hdr_header(void *parm, int action, char *dfile, * Display the header of the report (SVG format). * * IN: - * @parm Specific parameter. Here: number of graphs to display. + * @parm Specific parameter. Here: number of graphs to display or + * canvas height entered on the command line. * @action Action expected from current function. * @dfile Name of system activity data file (unused here). * @file_magic System activity file magic header (unused here). @@ -926,7 +927,9 @@ __printf_funct_t print_svg_header(void *parm, int action, char *dfile, if (action & F_MAIN) { printf(" width=\"%d\" height=\"%d\"" " fill=\"black\" stroke=\"gray\" stroke-width=\"1\">\n", - SVG_V_XSIZE, SVG_H_YSIZE + SVG_T_YSIZE * (*graph_nr)); + SVG_V_XSIZE, + SET_CANVAS_HEIGHT(flags) ? *graph_nr + : SVG_H_YSIZE + SVG_T_YSIZE * (*graph_nr)); printf(""); print_gal_header(localtime((const time_t *) &(file_hdr->sa_ust_time)), file_hdr->sa_sysname, file_hdr->sa_release, -- 2.40.0