]> granicus.if.org Git - sysstat/commitdiff
SVG: Add new option: "height="
authorSebastien GODARD <sysstat@users.noreply.github.com>
Sun, 22 Jan 2017 10:44:25 +0000 (11:44 +0100)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Sun, 22 Jan 2017 10:44:25 +0000 (11:44 +0100)
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 <sysstat@users.noreply.github.com>
sa.h
sadf.c
sadf_misc.c

diff --git a/sa.h b/sa.h
index 61602e3feb9086bccfff7ccc9b79018964677072..4b0224f682fa7e7c0559897de65d73b2f995f271 100644 (file)
--- a/sa.h
+++ b/sa.h
 #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)
 #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
 
 #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 3680aa714f90849d76abf1c215fb9d21c3bccf2a..66ff30c81c81584a8548ec2763ae8315bcbdac9b 100644 (file)
--- 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]);
                                }
index 8486e56fb3f4f7caefb6f610241b7067f02aa8b6..4e9784143a3f236cb8700b828a8e45cb86fa7765 100644 (file)
@@ -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("<text x= \"0\" y=\"30\" text-anchor=\"start\" stroke=\"brown\">");
                print_gal_header(localtime((const time_t *) &(file_hdr->sa_ust_time)),
                                 file_hdr->sa_sysname, file_hdr->sa_release,