***/
#include <stdio.h>
-#include <stdarg.h>
-#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <limits.h>
#include <unistd.h>
#include <sys/utsname.h>
-#include <sys/stat.h>
#include <fcntl.h>
#include "util.h"
#include "svg.h"
#include "bootchart.h"
#include "list.h"
+#include "utf8.h"
#define time_to_graph(t) ((t) * arg_scale_x)
#define ps_to_graph(n) ((n) * arg_scale_y)
static int pfiltered = 0;
static int pcount = 0;
static int kcount = 0;
-static float psize = 0;
-static float ksize = 0;
-static float esize = 0;
+static double psize = 0;
+static double ksize = 0;
+static double esize = 0;
static struct list_sample_data *sampledata;
static struct list_sample_data *prev_sampledata;
extern struct list_sample_data *head;
static void svg_header(void) {
- float w;
- float h;
+ double w;
+ double h;
struct list_sample_data *sampledata_last;
+ assert(head);
+
sampledata = head;
- LIST_FIND_TAIL(struct list_sample_data, link, sampledata, head);
+ LIST_FIND_TAIL(link, sampledata, head);
sampledata_last = head;
LIST_FOREACH_BEFORE(link, sampledata, head) {
sampledata_last = sampledata;
svg("<defs>\n <style type=\"text/css\">\n <![CDATA[\n");
svg(" rect { stroke-width: 1; }\n");
+ svg(" rect.bg { fill: rgb(255,255,255); }\n");
svg(" rect.cpu { fill: rgb(64,64,240); stroke-width: 0; fill-opacity: 0.7; }\n");
svg(" rect.wait { fill: rgb(240,240,0); stroke-width: 0; fill-opacity: 0.7; }\n");
svg(" rect.bi { fill: rgb(240,128,128); stroke-width: 0; fill-opacity: 0.7; }\n");
char *c;
FILE *f;
time_t t;
- int fd;
+ int fd, r;
struct utsname uts;
/* grab /proc/cmdline */
/* date */
t = time(NULL);
- strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", localtime(&t));
+ r = strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", localtime(&t));
+ assert_se(r > 0);
/* CPU type */
fd = openat(procfd, "cpuinfo", O_RDONLY);
continue;
enc_name = xml_comment_encode(ps->name);
- if(!enc_name)
+ if (!enc_name)
continue;
svg("<!-- %s [%d] pss=", enc_name, ps->pid);
double tot;
double pbo;
- tot = 0;
pbo = 0;
start = MAX(i - ((range / 2) - 1), 0);
}
}
-static void svg_cpu_bar(void) {
+static void svg_cpu_bar(int cpu_num) {
svg("<!-- CPU utilization graph -->\n");
- svg("<text class=\"t2\" x=\"5\" y=\"-15\">CPU utilization</text>\n");
+ if (cpu_num < 0)
+ svg("<text class=\"t2\" x=\"5\" y=\"-15\">CPU[overall] utilization</text>\n");
+ else
+ svg("<text class=\"t2\" x=\"5\" y=\"-15\">CPU[%d] utilization</text>\n", cpu_num);
/* surrounding box */
svg_graph_box(5);
ptrt = trt = 0.0;
- for (c = 0; c < cpus; c++)
- trt += sampledata->runtime[c] - prev_sampledata->runtime[c];
+ if (cpu_num < 0)
+ for (c = 0; c < cpus; c++)
+ trt += sampledata->runtime[c] - prev_sampledata->runtime[c];
+ else
+ trt = sampledata->runtime[cpu_num] - prev_sampledata->runtime[cpu_num];
trt = trt / 1000000000.0;
- trt = trt / (double)cpus;
+ if (cpu_num < 0)
+ trt = trt / (double)cpus;
if (trt > 0.0)
ptrt = trt / (sampledata->sampletime - prev_sampledata->sampletime);
}
}
-static void svg_wait_bar(void) {
+static void svg_wait_bar(int cpu_num) {
svg("<!-- Wait time aggregation box -->\n");
- svg("<text class=\"t2\" x=\"5\" y=\"-15\">CPU wait</text>\n");
+ if (cpu_num < 0)
+ svg("<text class=\"t2\" x=\"5\" y=\"-15\">CPU[overall] wait</text>\n");
+ else
+ svg("<text class=\"t2\" x=\"5\" y=\"-15\">CPU[%d] wait</text>\n", cpu_num);
/* surrounding box */
svg_graph_box(5);
ptwt = twt = 0.0;
- for (c = 0; c < cpus; c++)
- twt += sampledata->waittime[c] - prev_sampledata->waittime[c];
+ if (cpu_num < 0)
+ for (c = 0; c < cpus; c++)
+ twt += sampledata->waittime[c] - prev_sampledata->waittime[c];
+ else
+ twt = sampledata->waittime[cpu_num] - prev_sampledata->waittime[cpu_num];
twt = twt / 1000000000.0;
- twt = twt / (double)cpus;
+ if (cpu_num < 0)
+ twt = twt / (double)cpus;
if (twt > 0.0)
ptwt = twt / (sampledata->sampletime - prev_sampledata->sampletime);
}
}
-
static void svg_entropy_bar(void) {
svg("<!-- entropy pool graph -->\n");
return NULL;
}
-static int ps_filter(struct ps_struct *ps) {
+static bool ps_filter(struct ps_struct *ps) {
if (!arg_filter)
- return 0;
+ return false;
/* can't draw data when there is only 1 sample (need start + stop) */
if (ps->first == ps->last)
- return -1;
+ return true;
/* don't filter kthreadd */
if (ps->pid == 2)
- return 0;
+ return false;
/* drop stuff that doesn't use any real CPU time */
if (ps->total <= 0.001)
- return -1;
+ return true;
return 0;
}
/* pass 2 - ps boxes */
ps = ps_first;
while ((ps = get_next_ps(ps))) {
- _cleanup_free_ char *enc_name = NULL;
+ _cleanup_free_ char *enc_name = NULL, *escaped = NULL;
double endtime;
double starttime;
int t;
- enc_name = xml_comment_encode(ps->name);
- if(!enc_name)
+ if (!utf8_is_printable(ps->name, strlen(ps->name)))
+ escaped = utf8_escape_non_printable(ps->name);
+
+ enc_name = xml_comment_encode(escaped ? escaped : ps->name);
+ if (!enc_name)
continue;
/* leave some trace of what we actually filtered etc. */
w = starttime;
/* text label of process name */
- svg(" <text x=\"%.03f\" y=\"%.03f\"><![CDATA[%s]]> [%i]<tspan class=\"run\">%.03fs</tspan></text>\n",
+ svg(" <text x=\"%.03f\" y=\"%.03f\"><![CDATA[%s]]> [%i]<tspan class=\"run\">%.03fs</tspan> %s</text>\n",
time_to_graph(w - graph_start) + 5.0,
ps_to_graph(j) + 14.0,
- ps->name,
+ escaped ? escaped : ps->name,
ps->pid,
- (ps->last->runtime - ps->first->runtime) / 1000000000.0);
+ (ps->last->runtime - ps->first->runtime) / 1000000000.0,
+ arg_show_cgroup ? ps->cgroup : "");
/* paint lines to the parent process */
if (ps->parent) {
/* horizontal part */
ps->sample = ps->sample->next;
sample_hz = ps->sample;
- for (ii=0;((ii<(int)arg_hz/2)&&(ps->sample->next));ii++)
+ for (ii=0;((ii<(int)arg_hz/2)&&(sample_hz->next));ii++)
sample_hz = sample_hz->next;
/* subtract bootchart cpu utilization from total */
void svg_do(const char *build) {
struct ps_struct *ps;
+ double offset = 7;
+ int c;
- memset(&str, 0, sizeof(str));
+ memzero(&str, sizeof(str));
ps = ps_first;
/* after this, we can draw the header with proper sizing */
svg_header();
+ svg("<rect class=\"bg\" width=\"100%%\" height=\"100%%\" />\n\n");
svg("<g transform=\"translate(10,400)\">\n");
svg_io_bi_bar();
svg("</g>\n\n");
- svg("<g transform=\"translate(10,%.03f)\">\n", 400.0 + (arg_scale_y * 7.0));
+ svg("<g transform=\"translate(10,%.03f)\">\n", 400.0 + (arg_scale_y * offset));
svg_io_bo_bar();
svg("</g>\n\n");
- svg("<g transform=\"translate(10,%.03f)\">\n", 400.0 + (arg_scale_y * 14.0));
- svg_cpu_bar();
- svg("</g>\n\n");
+ for (c = -1; c < (arg_percpu ? cpus : 0); c++) {
+ offset += 7;
+ svg("<g transform=\"translate(10,%.03f)\">\n", 400.0 + (arg_scale_y * offset));
+ svg_cpu_bar(c);
+ svg("</g>\n\n");
- svg("<g transform=\"translate(10,%.03f)\">\n", 400.0 + (arg_scale_y * 21.0));
- svg_wait_bar();
- svg("</g>\n\n");
+ offset += 7;
+ svg("<g transform=\"translate(10,%.03f)\">\n", 400.0 + (arg_scale_y * offset));
+ svg_wait_bar(c);
+ svg("</g>\n\n");
+ }
if (kcount) {
- svg("<g transform=\"translate(10,%.03f)\">\n", 400.0 + (arg_scale_y * 28.0));
+ offset += 7;
+ svg("<g transform=\"translate(10,%.03f)\">\n", 400.0 + (arg_scale_y * offset));
svg_do_initcall(0);
svg("</g>\n\n");
}
- svg("<g transform=\"translate(10,%.03f)\">\n", 400.0 + (arg_scale_y * 28.0) + ksize);
+ offset += 7;
+ svg("<g transform=\"translate(10,%.03f)\">\n", 400.0 + (arg_scale_y * offset) + ksize);
svg_ps_bars();
svg("</g>\n\n");
svg("</g>\n\n");
if (arg_entropy) {
- svg("<g transform=\"translate(10,%.03f)\">\n", 400.0 + (arg_scale_y * 28.0) + ksize + psize);
+ svg("<g transform=\"translate(10,%.03f)\">\n", 400.0 + (arg_scale_y * offset) + ksize + psize);
svg_entropy_bar();
svg("</g>\n\n");
}
if (arg_pss) {
- svg("<g transform=\"translate(10,%.03f)\">\n", 400.0 + (arg_scale_y * 28.0) + ksize + psize + esize);
+ svg("<g transform=\"translate(10,%.03f)\">\n", 400.0 + (arg_scale_y * offset) + ksize + psize + esize);
svg_pss_graph();
svg("</g>\n\n");