]> granicus.if.org Git - sysstat/commitdiff
SVG: Properly terminate SVG file when no data have been found
authorSebastien GODARD <sysstat@users.noreply.github.com>
Sun, 5 Feb 2017 09:52:09 +0000 (10:52 +0100)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Sun, 5 Feb 2017 09:52:09 +0000 (10:52 +0100)
When a data file contains only a Linux Restart message with no
statistics, trying to create SVG graphs with sadf -g resulted in an
error ("XML Parsing Error: no element found").
This patch fixes that and display "No data!" instead.

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

diff --git a/sadf.c b/sadf.c
index ff9fec3153adc92924bbbe153dc3748a38f2b3f1..7a9a223bd9f653c9b7483f465e1e95e5e5a559da 100644 (file)
--- a/sadf.c
+++ b/sadf.c
@@ -1326,8 +1326,11 @@ void logic3_display_loop(int ifd, struct file_activity *file_actlst, __nr_t cpu_
                if (read_next_sample(ifd, IGNORE_RESTART | IGNORE_COMMENT, 0,
                                     file, &rtype, 0, file_magic, file_actlst,
                                     rectime, loctime))
-                       /* End of sa data file */
-                       return;
+               {
+                       /* End of sa data file: No views displayed */
+                       parm.graph_nr = 0;
+                       goto close_svg;
+               }
        }
        while ((rtype == R_RESTART) || (rtype == R_COMMENT) ||
               (tm_start.use && (datecmp(loctime, &tm_start) < 0)) ||
@@ -1379,11 +1382,12 @@ void logic3_display_loop(int ifd, struct file_activity *file_actlst, __nr_t cpu_
        }
 
        /* Real number of graphs that have been displayed */
-       graph_nr = g_nr;
+       parm.graph_nr = g_nr;
 
+close_svg:
        /* Print SVG trailer */
        if (*fmt[f_position]->f_header) {
-               (*fmt[f_position]->f_header)(&graph_nr, F_END, file, file_magic,
+               (*fmt[f_position]->f_header)(&parm, F_END, file, file_magic,
                                             &file_hdr, cpu_nr, act, id_seq);
        }
 }
index 12e27d49ab66e5b6c40306c7bd70a235844937e5..5a47233f3273551933c0254b7385390692570e7a 100644 (file)
@@ -942,6 +942,11 @@ __printf_funct_t print_svg_header(void *parm, int action, char *dfile,
 
        if (action & F_END) {
                if (!(action & F_BEGIN)) {
+                       if (!hdr_parm->graph_nr) {
+                               /* No views displayed */
+                               printf("<text x= \"0\" y=\"60\" text-anchor=\"start\" stroke=\"red\">");
+                               printf("No data!</text>\n");
+                       }
                        /* Give actual SVG height */
                        printf("<!-- Actual canvas height: %d -->\n",
                               SVG_H_YSIZE + SVG_T_YSIZE * (hdr_parm->graph_nr));