From: Sebastien GODARD Date: Sun, 12 Jun 2016 10:10:01 +0000 (+0200) Subject: SVG: Add SVG output for voltage inputs statistics X-Git-Tag: v11.3.5~12 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4e30dc3d554d9af7d101c6776281f80110032386;p=sysstat SVG: Add SVG output for voltage inputs statistics These graphs correspond to the output of "sar -m IN". Signed-off-by: Sebastien GODARD --- diff --git a/activity.c b/activity.c index 881ed3e..36955fe 100644 --- a/activity.c +++ b/activity.c @@ -1166,7 +1166,7 @@ struct activity pwr_temp_act = { /* Voltage inputs */ struct activity pwr_in_act = { .id = A_PWR_IN, - .options = AO_NULL, + .options = AO_GRAPH_PER_ITEM, .magic = ACTIVITY_MAGIC_BASE, .group = G_POWER, #ifdef SOURCE_SADC @@ -1182,9 +1182,10 @@ struct activity pwr_in_act = { .f_render = render_pwr_in_stats, .f_xml_print = xml_print_pwr_in_stats, .f_json_print = json_print_pwr_in_stats, + .f_svg_print = svg_print_pwr_in_stats, .hdr_line = "IN;DEVICE;inV;%in", .name = "A_PWR_IN", - .g_nr = 0, + .g_nr = 2, #endif .nr = -1, .nr2 = 1, diff --git a/svg_stats.c b/svg_stats.c index c072728..1fb750a 100644 --- a/svg_stats.c +++ b/svg_stats.c @@ -3500,6 +3500,104 @@ __print_funct_t svg_print_pwr_temp_stats(struct activity *a, int curr, int actio } } +/* + *************************************************************************** + * Display voltage inputs statistics in SVG. + * + * IN: + * @a Activity structure with statistics. + * @curr Index in array for current sample statistics. + * @action Action expected from current function. + * @svg_p SVG specific parameters: Current graph number (.@graph_no), + * flag indicating that a restart record has been previously + * found (.@restart) and time used for the X axis origin + * (@ust_time_ref). + * @itv Interval of time in jiffies (only with F_MAIN action). + * @record_hdr Pointer on record header of current stats sample. + *************************************************************************** + */ +__print_funct_t svg_print_pwr_in_stats(struct activity *a, int curr, int action, struct svg_parm *svg_p, + unsigned long long g_itv, struct record_header *record_hdr) +{ + struct stats_pwr_in *spc; + int group[] = {1}; + char *title1[] = {"Voltage inputs (1)"}; + char *title2[] = {"Voltage inputs (2)"}; + char *g1_title[] = {"inV"}; + char *g2_title[] = {"%in"}; + static double *spmin, *spmax; + static char **out; + static int *outsize; + char item_name[MAX_SENSORS_DEV_LEN + 8]; + int i; + double tval; + + if (action & F_BEGIN) { + /* + * Allocate arrays that will contain the graphs data + * and the min/max values. + */ + out = allocate_graph_lines(2 * a->nr, &outsize, &spmin, &spmax); + } + + if (action & F_MAIN) { + /* For each temperature sensor */ + for (i = 0; i < a->nr; i++) { + + spc = (struct stats_pwr_in *) ((char *) a->buf[curr] + i * a->msize); + + /* Look for min/max values */ + if (spc->in < *(spmin + 2 * i)) { + *(spmin + 2 * i) = spc->in; + } + if (spc->in > *(spmax + 2 * i)) { + *(spmax + 2 * i) = spc->in; + } + tval = (spc->in_max - spc->in_min) ? + (spc->in - spc->in_min) / (spc->in_max - spc->in_min) * 100 : + 0.0; + if (tval < *(spmin + 2 * i + 1)) { + *(spmin + 2 * i + 1) = tval; + } + if (tval > *(spmax + 2 * i + 1)) { + *(spmax + 2 * i + 1) = tval; + } + + /* inV */ + lnappend(record_hdr->ust_time - svg_p->ust_time_ref, + (double) spc->in, + out + 2 * i, outsize + 2 * i, svg_p->restart); + /* %in */ + brappend(record_hdr->ust_time - svg_p->ust_time_ref, + 0.0, tval, + out + 2 * i + 1, outsize + 2 * i + 1, svg_p->dt); + } + } + + if (action & F_END) { + for (i = 0; i < a->nr; i++) { + + spc = (struct stats_pwr_in *) ((char *) a->buf[curr] + i * a->msize); + + snprintf(item_name, MAX_SENSORS_DEV_LEN + 8, "%d: %s", i + 1, spc->device); + item_name[MAX_SENSORS_DEV_LEN + 7] = '\0'; + + draw_activity_graphs(1, SVG_LINE_GRAPH, + title1, g1_title, item_name, group, + spmin + 2 * i, spmax + 2 * i, out + 2 * i, outsize + 2 * i, + svg_p, record_hdr); + draw_activity_graphs(1, SVG_BAR_GRAPH, + title2, g2_title, item_name, group, + spmin + 2 * i + 1, spmax + 2 * i + 1, + out + 2 * i + 1, outsize + 2 * i + 1, + svg_p, record_hdr); + } + + /* Free remaining structures */ + free_graphs(out, outsize, spmin, spmax); + } +} + /* *************************************************************************** * Display huge pages statistics in SVG. diff --git a/svg_stats.h b/svg_stats.h index b04fd21..994699b 100644 --- a/svg_stats.h +++ b/svg_stats.h @@ -92,6 +92,9 @@ __print_funct_t svg_print_pwr_fan_stats __print_funct_t svg_print_pwr_temp_stats (struct activity *, int, int, struct svg_parm *, unsigned long long, struct record_header *); +__print_funct_t svg_print_pwr_in_stats + (struct activity *, int, int, struct svg_parm *, unsigned long long, + struct record_header *); __print_funct_t svg_print_huge_stats (struct activity *, int, int, struct svg_parm *, unsigned long long, struct record_header *);