]> granicus.if.org Git - sysstat/commitdiff
SVG: Add new option: "showinfo"
authorSebastien GODARD <sysstat@users.noreply.github.com>
Sun, 26 Mar 2017 09:46:25 +0000 (11:46 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Sun, 26 Mar 2017 09:46:25 +0000 (11:46 +0200)
This option tells sadf to display additional information (for now, these
are the date and the hostname) on each chart.

E.g.: sadf -g -O showinfo -- -A > graph.svg

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
sa.h
sadf.c
svg_stats.c

diff --git a/sa.h b/sa.h
index ddac09acd0af5d2294e405bdd0123163f159fe8c..1e28ad4b06d46bd2d49dd84234bb99aefe97500a 100644 (file)
--- a/sa.h
+++ b/sa.h
 #define S_F_UNIT               0x00100000
 #define S_F_SVG_HEIGHT         0x00200000
 #define S_F_SVG_PACKED         0x00400000
+#define S_F_SVG_SHOW_INFO      0x00800000
 
 #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 AUTOSCALE_ON(m)                        (((m) & S_F_SVG_AUTOSCALE) == S_F_SVG_AUTOSCALE)
 #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_INFO(m)                        (((m) & S_F_SVG_SHOW_INFO) == S_F_SVG_SHOW_INFO)
 #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 PACK_VIEWS(m)                  (((m) & S_F_SVG_PACKED) == S_F_SVG_PACKED)
 #define K_AUTOSCALE    "autoscale"
 #define K_ONEDAY       "oneday"
 #define K_SHOWIDLE     "showidle"
+#define K_SHOWINFO     "showinfo"
 #define K_SHOWHINTS    "showhints"
 #define K_HEIGHT       "height="
 #define K_PACKED       "packed"
@@ -301,6 +304,7 @@ struct svg_parm {
        unsigned long ust_time_first;   /* Time (in seconds since the epoch) for first sample */
        int graph_no;                   /* Total number of views already displayed */
        int restart;                    /* TRUE if we have just met a RESTART record */
+       struct file_header *file_hdr;   /* Pointer on file header structure */
 };
 
 /* Structure used when displaying SVG header */
diff --git a/sadf.c b/sadf.c
index 063293ae65775a3ec530eabac9a1700305ab598b..781d4cbc12b4fe686cee0a2019f675648bbcb79f 100644 (file)
--- a/sadf.c
+++ b/sadf.c
@@ -878,6 +878,7 @@ void display_curr_act_graphs(int ifd, off_t fpos, int *curr, long *cnt, int *eos
        parm.ust_time_ref = get_time_ref();
        parm.ust_time_first = record_hdr[2].ust_time;
        parm.restart = TRUE;
+       parm.file_hdr = &file_hdr;
 
        *cnt  = count;
        reset_cd = 1;
@@ -1534,6 +1535,9 @@ int main(int argc, char **argv)
                                else if (!strcmp(t, K_SHOWIDLE)) {
                                        flags |= S_F_SVG_SHOW_IDLE;
                                }
+                               else if (!strcmp(t, K_SHOWINFO)) {
+                                       flags |= S_F_SVG_SHOW_INFO;
+                               }
                                else if (!strcmp(t, K_SHOWHINTS)) {
                                        flags |= S_F_RAW_SHOW_HINTS;
                                }
index d0d941c028bad4d221ef319118a2ec29b61e3e98..4043f806f439183187442595d9cade70a871b0ba 100644 (file)
@@ -809,7 +809,7 @@ void draw_activity_graphs(int g_nr, int g_type[], char *title[], char *g_title[]
        unsigned int asfactor[16];
        long int xpos;
        double lmax, xfactor, yfactor, ypos, gmin, gmax;
-       char val[32];
+       char val[32], cur_date[TIMESTAMP_LEN];
 
        /* Translate to proper position for current activity */
        printf("<g id=\"g%d\" transform=\"translate(0,%d)\">\n",
@@ -891,6 +891,24 @@ void draw_activity_graphs(int g_nr, int g_type[], char *title[], char *g_title[]
                               !dp * 2, *(spmax + pos + j) * asfactor[j]);
                }
 
+               if (DISPLAY_INFO(flags)) {
+                       /* Display additional info (hostname, date) */
+                       printf("<text x=\"%d\" y=\"%d\" "
+                              "style=\"fill: yellow; text-anchor: end; stroke: none; font-size: 14px\">"
+                              "%s\n",
+                              xv + SVG_V_XSIZE - 5, yv + SVG_M_YSIZE + SVG_G_YSIZE,
+                              svg_p->file_hdr->sa_nodename);
+
+                       /* Get report date */
+                       set_report_date(localtime((const time_t *) &(svg_p->file_hdr->sa_ust_time)),
+                                       cur_date, sizeof(cur_date));
+                       printf("<tspan x=\"%d\" y=\"%d\" "
+                              "style=\"fill: yellow; text-anchor: end; stroke: none; font-size: 14px\">"
+                              "%s</tspan>\n</text>\n",
+                              xv + SVG_V_XSIZE - 5, yv + SVG_M_YSIZE + SVG_G_YSIZE + 14,
+                              cur_date);
+               }
+
                /* Translate to proper position for current graph within current activity */
                printf("<g transform=\"translate(%d,%d)\">\n",
                       xv + SVG_M_XSIZE, yv + SVG_M_YSIZE + SVG_G_YSIZE);