-
-static void svg_ps_bars(void)
-{
- struct ps_struct *ps;
- int i = 0;
- int j = 0;
- int w;
- int pid;
-
- svg("<!-- Process graph -->\n");
-
- svg("<text class=\"t2\" x=\"5\" y=\"-15\">Processes</text>\n");
-
- /* surrounding box */
- svg_graph_box(pcount);
-
- /* pass 2 - ps boxes */
- ps = ps_first;
- while ((ps = get_next_ps(ps))) {
- double starttime;
- int t;
-
- if (!ps)
- continue;
-
- /* leave some trace of what we actually filtered etc. */
- svg("<!-- %s [%i] ppid=%i runtime=%.03fs -->\n", ps->name, ps->pid,
- ps->ppid, ps->total);
-
- /* it would be nice if we could use exec_start from /proc/pid/sched,
- * but it's unreliable and gives bogus numbers */
- starttime = sampletime[ps->first];
-
- if (!ps_filter(ps)) {
- /* remember where _to_ our children need to draw a line */
- ps->pos_x = time_to_graph(starttime - graph_start);
- ps->pos_y = ps_to_graph(j+1); /* bottom left corner */
- } else {
- /* hook children to our parent coords instead */
- ps->pos_x = ps->parent->pos_x;
- ps->pos_y = ps->parent->pos_y;
-
- /* if this is the last child, we might still need to draw a connecting line */
- if ((!ps->next) && (ps->parent))
- svg(" <line class=\"dot\" x1=\"%.03f\" y1=\"%.03f\" x2=\"%.03f\" y2=\"%.03f\" />\n",
- ps->parent->pos_x,
- ps_to_graph(j-1) + 10.0, /* whee, use the last value here */
- ps->parent->pos_x,
- ps->parent->pos_y);
- continue;
- }
-
- svg(" <rect class=\"ps\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
- time_to_graph(starttime - graph_start),
- ps_to_graph(j),
- time_to_graph(sampletime[ps->last] - starttime),
- ps_to_graph(1));
-
- /* paint cpu load over these */
- for (t = ps->first + 1; t < ps->last; t++) {
- double rt, prt;
- double wt, wrt;
-
- /* calculate over interval */
- rt = ps->sample[t].runtime - ps->sample[t-1].runtime;
- wt = ps->sample[t].waittime - ps->sample[t-1].waittime;
-
- prt = (rt / 1000000000) / (sampletime[t] - sampletime[t-1]);
- wrt = (wt / 1000000000) / (sampletime[t] - sampletime[t-1]);
-
- /* this can happen if timekeeping isn't accurate enough */
- if (prt > 1.0)
- prt = 1.0;
- if (wrt > 1.0)
- wrt = 1.0;
-
- if ((prt < 0.1) && (wrt < 0.1)) /* =~ 26 (color threshold) */
- continue;
-
- svg(" <rect class=\"wait\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
- time_to_graph(sampletime[t - 1] - graph_start),
- ps_to_graph(j),
- time_to_graph(sampletime[t] - sampletime[t - 1]),
- ps_to_graph(wrt));
-
- /* draw cpu over wait - TODO figure out how/why run + wait > interval */
- svg(" <rect class=\"cpu\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
- time_to_graph(sampletime[t - 1] - graph_start),
- ps_to_graph(j + (1.0 - prt)),
- time_to_graph(sampletime[t] - sampletime[t - 1]),
- ps_to_graph(prt));
- }
-
- /* determine where to display the process name */
- if (sampletime[ps->last] - sampletime[ps->first] < 1.5)
- /* too small to fit label inside the box */
- w = ps->last;
- else
- w = ps->first;
-
- /* text label of process name */
- svg(" <text x=\"%.03f\" y=\"%.03f\">%s [%i] <tspan class=\"run\">%.03fs</tspan></text>\n",
- time_to_graph(sampletime[w] - graph_start) + 5.0,
- ps_to_graph(j) + 14.0,
- ps->name,
- ps->pid,
- (ps->sample[ps->last].runtime - ps->sample[ps->first].runtime) / 1000000000.0);
- /* paint lines to the parent process */
- if (ps->parent) {
- /* horizontal part */
- svg(" <line class=\"dot\" x1=\"%.03f\" y1=\"%.03f\" x2=\"%.03f\" y2=\"%.03f\" />\n",
- time_to_graph(starttime - graph_start),
- ps_to_graph(j) + 10.0,
- ps->parent->pos_x,
- ps_to_graph(j) + 10.0);
-
- /* one vertical line connecting all the horizontal ones up */
- if (!ps->next)
- svg(" <line class=\"dot\" x1=\"%.03f\" y1=\"%.03f\" x2=\"%.03f\" y2=\"%.03f\" />\n",
- ps->parent->pos_x,
- ps_to_graph(j) + 10.0,
- ps->parent->pos_x,
- ps->parent->pos_y);
- }
-
- j++; /* count boxes */
-
- svg("\n");
- }
-
- /* last pass - determine when idle */
- pid = getpid();
- /* make sure we start counting from the point where we actually have
- * data: assume that bootchart's first sample is when data started
- */
- ps = ps_first;
- while (ps->next_ps) {
- ps = ps->next_ps;
- if (ps->pid == pid)
- break;
- }
-
- for (i = ps->first; i < samples - (hz / 2); i++) {
- double crt;
- double brt;
- int c;
-
- /* subtract bootchart cpu utilization from total */
- crt = 0.0;
- for (c = 0; c < cpus; c++)
- crt += cpustat[c].sample[i + ((int)hz / 2)].runtime - cpustat[c].sample[i].runtime;
- brt = ps->sample[i + ((int)hz / 2)].runtime - ps->sample[i].runtime;
-
- /*
- * our definition of "idle":
- *
- * if for (hz / 2) we've used less CPU than (interval / 2) ...
- * defaults to 4.0%, which experimentally, is where atom idles
- */
- if ((crt - brt) < (interval / 2.0)) {
- idletime = sampletime[i] - graph_start;
- svg("\n<!-- idle detected at %.03f seconds -->\n",
- idletime);
- svg("<line class=\"idle\" x1=\"%.03f\" y1=\"%.03f\" x2=\"%.03f\" y2=\"%.03f\" />\n",
- time_to_graph(idletime),
- -scale_y,
- time_to_graph(idletime),
- ps_to_graph(pcount) + scale_y);
- svg("<text class=\"idle\" x=\"%.03f\" y=\"%.03f\">%.01fs</text>\n",
- time_to_graph(idletime) + 5.0,
- ps_to_graph(pcount) + scale_y,
- idletime);
- break;
- }
- }
+static void svg_ps_bars(void) {
+ struct ps_struct *ps;
+ int i = 0;
+ int j = 0;
+ int w;
+ int pid;
+
+ svg("<!-- Process graph -->\n");
+
+ svg("<text class=\"t2\" x=\"5\" y=\"-15\">Processes</text>\n");
+
+ /* surrounding box */
+ svg_graph_box(pcount);
+
+ /* pass 2 - ps boxes */
+ ps = ps_first;
+ while ((ps = get_next_ps(ps))) {
+ char _cleanup_free_ *enc_name = NULL;
+
+ double starttime;
+ int t;
+
+ enc_name = xml_comment_encode(ps->name);
+ if(!enc_name)
+ continue;
+
+ /* leave some trace of what we actually filtered etc. */
+ svg("<!-- %s [%i] ppid=%i runtime=%.03fs -->\n", enc_name, ps->pid,
+ ps->ppid, ps->total);
+
+ /* it would be nice if we could use exec_start from /proc/pid/sched,
+ * but it's unreliable and gives bogus numbers */
+ starttime = sampletime[ps->first];
+
+ if (!ps_filter(ps)) {
+ /* remember where _to_ our children need to draw a line */
+ ps->pos_x = time_to_graph(starttime - graph_start);
+ ps->pos_y = ps_to_graph(j+1); /* bottom left corner */
+ } else {
+ /* hook children to our parent coords instead */
+ ps->pos_x = ps->parent->pos_x;
+ ps->pos_y = ps->parent->pos_y;
+
+ /* if this is the last child, we might still need to draw a connecting line */
+ if ((!ps->next) && (ps->parent))
+ svg(" <line class=\"dot\" x1=\"%.03f\" y1=\"%.03f\" x2=\"%.03f\" y2=\"%.03f\" />\n",
+ ps->parent->pos_x,
+ ps_to_graph(j-1) + 10.0, /* whee, use the last value here */
+ ps->parent->pos_x,
+ ps->parent->pos_y);
+ continue;
+ }
+
+ svg(" <rect class=\"ps\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
+ time_to_graph(starttime - graph_start),
+ ps_to_graph(j),
+ time_to_graph(sampletime[ps->last] - starttime),
+ ps_to_graph(1));
+
+ /* paint cpu load over these */
+ for (t = ps->first + 1; t < ps->last; t++) {
+ double rt, prt;
+ double wt, wrt;
+
+ /* calculate over interval */
+ rt = ps->sample[t].runtime - ps->sample[t-1].runtime;
+ wt = ps->sample[t].waittime - ps->sample[t-1].waittime;
+
+ prt = (rt / 1000000000) / (sampletime[t] - sampletime[t-1]);
+ wrt = (wt / 1000000000) / (sampletime[t] - sampletime[t-1]);
+
+ /* this can happen if timekeeping isn't accurate enough */
+ if (prt > 1.0)
+ prt = 1.0;
+ if (wrt > 1.0)
+ wrt = 1.0;
+
+ if ((prt < 0.1) && (wrt < 0.1)) /* =~ 26 (color threshold) */
+ continue;
+
+ svg(" <rect class=\"wait\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
+ time_to_graph(sampletime[t - 1] - graph_start),
+ ps_to_graph(j),
+ time_to_graph(sampletime[t] - sampletime[t - 1]),
+ ps_to_graph(wrt));
+
+ /* draw cpu over wait - TODO figure out how/why run + wait > interval */
+ svg(" <rect class=\"cpu\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
+ time_to_graph(sampletime[t - 1] - graph_start),
+ ps_to_graph(j + (1.0 - prt)),
+ time_to_graph(sampletime[t] - sampletime[t - 1]),
+ ps_to_graph(prt));
+ }
+
+ /* determine where to display the process name */
+ if (sampletime[ps->last] - sampletime[ps->first] < 1.5)
+ /* too small to fit label inside the box */
+ w = ps->last;
+ else
+ w = ps->first;
+
+ /* text label of process name */
+ svg(" <text x=\"%.03f\" y=\"%.03f\"><![CDATA[%s]]> [%i]<tspan class=\"run\">%.03fs</tspan></text>\n",
+ time_to_graph(sampletime[w] - graph_start) + 5.0,
+ ps_to_graph(j) + 14.0,
+ ps->name,
+ ps->pid,
+ (ps->sample[ps->last].runtime - ps->sample[ps->first].runtime) / 1000000000.0);
+ /* paint lines to the parent process */
+ if (ps->parent) {
+ /* horizontal part */
+ svg(" <line class=\"dot\" x1=\"%.03f\" y1=\"%.03f\" x2=\"%.03f\" y2=\"%.03f\" />\n",
+ time_to_graph(starttime - graph_start),
+ ps_to_graph(j) + 10.0,
+ ps->parent->pos_x,
+ ps_to_graph(j) + 10.0);
+
+ /* one vertical line connecting all the horizontal ones up */
+ if (!ps->next)
+ svg(" <line class=\"dot\" x1=\"%.03f\" y1=\"%.03f\" x2=\"%.03f\" y2=\"%.03f\" />\n",
+ ps->parent->pos_x,
+ ps_to_graph(j) + 10.0,
+ ps->parent->pos_x,
+ ps->parent->pos_y);
+ }
+
+ j++; /* count boxes */
+
+ svg("\n");
+ }
+
+ /* last pass - determine when idle */
+ pid = getpid();
+ /* make sure we start counting from the point where we actually have
+ * data: assume that bootchart's first sample is when data started
+ */
+ ps = ps_first;
+ while (ps->next_ps) {
+ ps = ps->next_ps;
+ if (ps->pid == pid)
+ break;
+ }
+
+ for (i = ps->first; i < samples - (arg_hz / 2); i++) {
+ double crt;
+ double brt;
+ int c;
+
+ /* subtract bootchart cpu utilization from total */
+ crt = 0.0;
+ for (c = 0; c < cpus; c++)
+ crt += cpustat[c].sample[i + ((int)arg_hz / 2)].runtime - cpustat[c].sample[i].runtime;
+ brt = ps->sample[i + ((int)arg_hz / 2)].runtime - ps->sample[i].runtime;
+
+ /*
+ * our definition of "idle":
+ *
+ * if for (hz / 2) we've used less CPU than (interval / 2) ...
+ * defaults to 4.0%, which experimentally, is where atom idles
+ */
+ if ((crt - brt) < (interval / 2.0)) {
+ idletime = sampletime[i] - graph_start;
+ svg("\n<!-- idle detected at %.03f seconds -->\n",
+ idletime);
+ svg("<line class=\"idle\" x1=\"%.03f\" y1=\"%.03f\" x2=\"%.03f\" y2=\"%.03f\" />\n",
+ time_to_graph(idletime),
+ -arg_scale_y,
+ time_to_graph(idletime),
+ ps_to_graph(pcount) + arg_scale_y);
+ svg("<text class=\"idle\" x=\"%.03f\" y=\"%.03f\">%.01fs</text>\n",
+ time_to_graph(idletime) + 5.0,
+ ps_to_graph(pcount) + arg_scale_y,
+ idletime);
+ break;
+ }
+ }