4 * Copyright (c) 2009 Intel Coproration
6 * Auke Kok <auke-jan.h.kok@intel.com>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; version 2
21 #include <sys/utsname.h>
23 #include "bootchart.h"
26 #define time_to_graph(t) ((t) * scale_x)
27 #define ps_to_graph(n) ((n) * scale_y)
28 #define kb_to_graph(m) ((m) * scale_y * 0.0001)
29 #define to_color(n) (192.0 - ((n) * 192.0))
31 #define max(x, y) (((x) > (y)) ? (x) : (y))
32 #define min(x, y) (((x) < (y)) ? (x) : (y))
34 static char str[8092];
36 #define svg(a...) do { snprintf(str, 8092, ## a); fputs(str, of); fflush(of); } while (0)
38 static char *colorwheel[12] = {
39 "rgb(255,32,32)", // red
40 "rgb(32,192,192)", // cyan
41 "rgb(255,128,32)", // orange
42 "rgb(128,32,192)", // blue-violet
43 "rgb(255,255,32)", // yellow
44 "rgb(192,32,128)", // red-violet
45 "rgb(32,255,32)", // green
46 "rgb(255,64,32)", // red-orange
47 "rgb(32,32,255)", // blue
48 "rgb(255,192,32)", // yellow-orange
49 "rgb(192,32,192)", // violet
50 "rgb(32,192,32)" // yellow-green
53 static double idletime = -1.0;
54 static int pfiltered = 0;
55 static int pcount = 0;
56 static int kcount = 0;
57 static float psize = 0;
58 static float ksize = 0;
59 static float esize = 0;
62 static void svg_header(void)
67 /* min width is about 1600px due to the label */
68 w = 150.0 + 10.0 + time_to_graph(sampletime[samples-1] - graph_start);
69 w = ((w < 1600.0) ? 1600.0 : w);
71 /* height is variable based on pss, psize, ksize */
72 h = 400.0 + (scale_y * 30.0) /* base graphs and title */
73 + (pss ? (100.0 * scale_y) + (scale_y * 7.0) : 0.0) /* pss estimate */
74 + psize + ksize + esize;
76 svg("<?xml version=\"1.0\" standalone=\"no\"?>\n");
77 svg("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" ");
78 svg("\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n");
80 //svg("<g transform=\"translate(10,%d)\">\n", 1000 + 150 + (pcount * 20));
81 svg("<svg width=\"%.0fpx\" height=\"%.0fpx\" version=\"1.1\" ",
83 svg("xmlns=\"http://www.w3.org/2000/svg\">\n\n");
85 /* write some basic info as a comment, including some help */
86 svg("<!-- This file is a bootchart SVG file. It is best rendered in a browser -->\n");
87 svg("<!-- such as Chrome/Chromium, firefox. Other applications that render -->\n");
88 svg("<!-- these files properly but much more slow are ImageMagick, gimp, -->\n");
89 svg("<!-- inkscape, etc.. To display the files on your system, just point -->\n");
90 svg("<!-- your browser to file:///var/log/ and click. This bootchart was -->\n\n");
92 svg("<!-- generated by bootchart version %s, running with options: -->\n", VERSION);
93 svg("<!-- hz=\"%f\" n=\"%d\" -->\n", hz, len);
94 svg("<!-- x=\"%f\" y=\"%f\" -->\n", scale_x, scale_y);
95 svg("<!-- rel=\"%d\" f=\"%d\" -->\n", relative, filter);
96 svg("<!-- p=\"%d\" e=\"%d\" -->\n", pss, entropy);
97 svg("<!-- o=\"%s\" i=\"%s\" -->\n\n", output_path, init_path);
100 svg("<defs>\n <style type=\"text/css\">\n <![CDATA[\n");
102 svg(" rect { stroke-width: 1; }\n");
103 svg(" rect.cpu { fill: rgb(64,64,240); stroke-width: 0; fill-opacity: 0.7; }\n");
104 svg(" rect.wait { fill: rgb(240,240,0); stroke-width: 0; fill-opacity: 0.7; }\n");
105 svg(" rect.bi { fill: rgb(240,128,128); stroke-width: 0; fill-opacity: 0.7; }\n");
106 svg(" rect.bo { fill: rgb(192,64,64); stroke-width: 0; fill-opacity: 0.7; }\n");
107 svg(" rect.ps { fill: rgb(192,192,192); stroke: rgb(128,128,128); fill-opacity: 0.7; }\n");
108 svg(" rect.krnl { fill: rgb(240,240,0); stroke: rgb(128,128,128); fill-opacity: 0.7; }\n");
109 svg(" rect.box { fill: rgb(240,240,240); stroke: rgb(192,192,192); }\n");
110 svg(" rect.clrw { stroke-width: 0; fill-opacity: 0.7;}\n");
111 svg(" line { stroke: rgb(64,64,64); stroke-width: 1; }\n");
112 svg("// line.sec1 { }\n");
113 svg(" line.sec5 { stroke-width: 2; }\n");
114 svg(" line.sec01 { stroke: rgb(224,224,224); stroke-width: 1; }\n");
115 svg(" line.dot { stroke-dasharray: 2 4; }\n");
116 svg(" line.idle { stroke: rgb(64,64,64); stroke-dasharray: 10 6; stroke-opacity: 0.7; }\n");
118 svg(" .run { font-size: 8; font-style: italic; }\n");
119 svg(" text { font-family: Verdana, Helvetica; font-size: 10; }\n");
120 svg(" text.sec { font-size: 8; }\n");
121 svg(" text.t1 { font-size: 24; }\n");
122 svg(" text.t2 { font-size: 12; }\n");
123 svg(" text.idle { font-size: 18; }\n");
125 svg(" ]]>\n </style>\n</defs>\n\n");
130 static void svg_title(void)
132 char cmdline[256] = "";
133 char filename[PATH_MAX];
135 char rootbdev[16] = "Unknown";
136 char model[256] = "Unknown";
137 char date[256] = "Unknown";
138 char cpu[256] = "Unknown";
139 char build[256] = "Unknown";
145 /* grab /proc/cmdline */
146 f = fopen("/proc/cmdline", "r");
148 if (!fgets(cmdline, 255, f))
149 sprintf(cmdline, "Unknown");
153 /* extract root fs so we can find disk model name in sysfs */
154 c = strstr(cmdline, "root=/dev/");
156 strncpy(rootbdev, &c[10], 3);
159 sprintf(filename, "/sys/block/%s/device/model", rootbdev);
160 f = fopen(filename, "r");
162 if (!fgets(model, 255, f))
163 fprintf(stderr, "Error reading disk model for %s\n", rootbdev);
167 /* various utsname parameters */
169 fprintf(stderr, "Error getting uname info\n");
173 strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", localtime(&t));
176 f = fopen("/proc/cpuinfo", "r");
178 while (fgets(buf, 255, f)) {
179 if (strstr(buf, "model name")) {
180 strncpy(cpu, &buf[13], 255);
187 /* Build - 1st line from /etc/system-release */
188 f = fopen("/etc/system-release", "r");
190 if (fgets(buf, 255, f))
191 strncpy(build, buf, 255);
195 svg("<text class=\"t1\" x=\"0\" y=\"30\">Bootchart for %s - %s</text>\n",
197 svg("<text class=\"t2\" x=\"20\" y=\"50\">System: %s %s %s %s</text>\n",
198 uts.sysname, uts.release, uts.version, uts.machine);
199 svg("<text class=\"t2\" x=\"20\" y=\"65\">CPU: %s</text>\n",
201 svg("<text class=\"t2\" x=\"20\" y=\"80\">Disk: %s</text>\n",
203 svg("<text class=\"t2\" x=\"20\" y=\"95\">Boot options: %s</text>\n",
205 svg("<text class=\"t2\" x=\"20\" y=\"110\">Build: %s</text>\n",
207 svg("<text class=\"t2\" x=\"20\" y=\"125\">Log start time: %.03fs</text>\n", log_start);
208 svg("<text class=\"t2\" x=\"20\" y=\"140\">Idle time: ");
211 svg("%.03fs", idletime);
215 svg("<text class=\"sec\" x=\"20\" y=\"155\">Graph data: %.03f samples/sec, recorded %i total, dropped %i samples, %i processes, %i filtered</text>\n",
216 hz, len, overrun, pscount, pfiltered);
220 static void svg_graph_box(int height)
225 /* outside box, fill */
226 svg("<rect class=\"box\" x=\"%.03f\" y=\"0\" width=\"%.03f\" height=\"%.03f\" />\n",
228 time_to_graph(sampletime[samples-1] - graph_start),
229 ps_to_graph(height));
231 for (d = graph_start; d <= sampletime[samples-1];
232 d += (scale_x < 2.0 ? 60.0 : scale_x < 10.0 ? 1.0 : 0.1)) {
233 /* lines for each second */
235 svg(" <line class=\"sec5\" x1=\"%.03f\" y1=\"0\" x2=\"%.03f\" y2=\"%.03f\" />\n",
236 time_to_graph(d - graph_start),
237 time_to_graph(d - graph_start),
238 ps_to_graph(height));
239 else if (i % 10 == 0)
240 svg(" <line class=\"sec1\" x1=\"%.03f\" y1=\"0\" x2=\"%.03f\" y2=\"%.03f\" />\n",
241 time_to_graph(d - graph_start),
242 time_to_graph(d - graph_start),
243 ps_to_graph(height));
245 svg(" <line class=\"sec01\" x1=\"%.03f\" y1=\"0\" x2=\"%.03f\" y2=\"%.03f\" />\n",
246 time_to_graph(d - graph_start),
247 time_to_graph(d - graph_start),
248 ps_to_graph(height));
252 svg(" <text class=\"sec\" x=\"%.03f\" y=\"%.03f\" >%.01fs</text>\n",
253 time_to_graph(d - graph_start),
262 static void svg_pss_graph(void)
264 struct ps_struct *ps;
267 svg("\n\n<!-- Pss memory size graph -->\n");
269 svg("\n <text class=\"t2\" x=\"5\" y=\"-15\">Memory allocation - Pss</text>\n");
271 /* vsize 1000 == 1000mb */
273 /* draw some hlines for usable memory sizes */
274 for (i = 100000; i < 1000000; i += 100000) {
275 svg(" <line class=\"sec01\" x1=\"%.03f\" y1=\"%.0f\" x2=\"%.03f\" y2=\"%.0f\"/>\n",
278 time_to_graph(sampletime[samples-1] - graph_start),
280 svg(" <text class=\"sec\" x=\"%.03f\" y=\"%.0f\">%dM</text>\n",
281 time_to_graph(sampletime[samples-1] - graph_start) + 5,
282 kb_to_graph(i), (1000000 - i) / 1000);
286 /* now plot the graph itself */
287 for (i = 1; i < samples ; i++) {
294 /* put all the small pss blocks into the bottom */
296 while (ps->next_ps) {
300 if (ps->sample[i].pss <= (100 * scale_y))
301 top += ps->sample[i].pss;
303 svg(" <rect class=\"clrw\" style=\"fill: %s\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
305 time_to_graph(sampletime[i - 1] - graph_start),
306 kb_to_graph(1000000.0 - top),
307 time_to_graph(sampletime[i] - sampletime[i - 1]),
308 kb_to_graph(top - bottom));
312 /* now plot the ones that are of significant size */
314 while (ps->next_ps) {
318 /* don't draw anything smaller than 2mb */
319 if (ps->sample[i].pss > (100 * scale_y)) {
320 top = bottom + ps->sample[i].pss;
321 svg(" <rect class=\"clrw\" style=\"fill: %s\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
322 colorwheel[ps->pid % 12],
323 time_to_graph(sampletime[i - 1] - graph_start),
324 kb_to_graph(1000000.0 - top),
325 time_to_graph(sampletime[i] - sampletime[i - 1]),
326 kb_to_graph(top - bottom));
332 /* overlay all the text labels */
333 for (i = 1; i < samples ; i++) {
340 /* put all the small pss blocks into the bottom */
342 while (ps->next_ps) {
346 if (ps->sample[i].pss <= (100 * scale_y))
347 top += ps->sample[i].pss;
352 /* now plot the ones that are of significant size */
354 while (ps->next_ps) {
358 /* don't draw anything smaller than 2mb */
359 if (ps->sample[i].pss > (100 * scale_y)) {
360 top = bottom + ps->sample[i].pss;
361 /* draw a label with the process / PID */
362 if ((i == 1) || (ps->sample[i - 1].pss <= (100 * scale_y)))
363 svg(" <text x=\"%.03f\" y=\"%.03f\">%s [%i]</text>\n",
364 time_to_graph(sampletime[i] - graph_start),
365 kb_to_graph(1000000.0 - bottom - ((top - bottom) / 2)),
373 /* debug output - full data dump */
374 svg("\n\n<!-- PSS map - csv format -->\n");
376 while (ps->next_ps) {
380 svg("<!-- %s [%d] pss=", ps->name, ps->pid);
381 for (i = 0; i < samples ; i++) {
382 svg("%d," , ps->sample[i].pss);
389 static void svg_io_bi_bar(void)
396 svg("<!-- IO utilization graph - In -->\n");
398 svg("<text class=\"t2\" x=\"5\" y=\"-15\">IO utilization - read</text>\n");
401 * calculate rounding range
403 * We need to round IO data since IO block data is not updated on
404 * each poll. Applying a smoothing function loses some burst data,
405 * so keep the smoothing range short.
407 range = 0.25 / (1.0 / hz);
409 range = 2.0; /* no smoothing */
411 /* surrounding box */
414 /* find the max IO first */
415 for (i = 1; i < samples; i++) {
420 start = max(i - ((range / 2) - 1), 0);
421 stop = min(i + (range / 2), samples - 1);
423 tot = (double)(blockstat[stop].bi - blockstat[start].bi)
429 tot = (double)(blockstat[stop].bo - blockstat[start].bo)
436 for (i = 1; i < samples; i++) {
442 start = max(i - ((range / 2) - 1), 0);
443 stop = min(i + (range / 2), samples);
445 tot = (double)(blockstat[stop].bi - blockstat[start].bi)
450 svg("<rect class=\"bi\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
451 time_to_graph(sampletime[i - 1] - graph_start),
452 (scale_y * 5) - (pbi * (scale_y * 5)),
453 time_to_graph(sampletime[i] - sampletime[i - 1]),
454 pbi * (scale_y * 5));
456 /* labels around highest value */
458 svg(" <text class=\"sec\" x=\"%.03f\" y=\"%.03f\">%0.2fmb/sec</text>\n",
459 time_to_graph(sampletime[i] - graph_start) + 5,
460 ((scale_y * 5) - (pbi * (scale_y * 5))) + 15,
461 max / 1024.0 / (interval / 1000000000.0));
466 static void svg_io_bo_bar(void)
473 svg("<!-- IO utilization graph - out -->\n");
475 svg("<text class=\"t2\" x=\"5\" y=\"-15\">IO utilization - write</text>\n");
478 * calculate rounding range
480 * We need to round IO data since IO block data is not updated on
481 * each poll. Applying a smoothing function loses some burst data,
482 * so keep the smoothing range short.
484 range = 0.25 / (1.0 / hz);
486 range = 2.0; /* no smoothing */
488 /* surrounding box */
491 /* find the max IO first */
492 for (i = 1; i < samples; i++) {
497 start = max(i - ((range / 2) - 1), 0);
498 stop = min(i + (range / 2), samples - 1);
500 tot = (double)(blockstat[stop].bi - blockstat[start].bi)
504 tot = (double)(blockstat[stop].bo - blockstat[start].bo)
513 for (i = 1; i < samples; i++) {
519 start = max(i - ((range / 2) - 1), 0);
520 stop = min(i + (range / 2), samples);
522 tot = (double)(blockstat[stop].bo - blockstat[start].bo)
527 svg("<rect class=\"bo\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
528 time_to_graph(sampletime[i - 1] - graph_start),
529 (scale_y * 5) - (pbo * (scale_y * 5)),
530 time_to_graph(sampletime[i] - sampletime[i - 1]),
531 pbo * (scale_y * 5));
533 /* labels around highest bo value */
535 svg(" <text class=\"sec\" x=\"%.03f\" y=\"%.03f\">%0.2fmb/sec</text>\n",
536 time_to_graph(sampletime[i] - graph_start) + 5,
537 ((scale_y * 5) - (pbo * (scale_y * 5))),
538 max / 1024.0 / (interval / 1000000000.0));
544 static void svg_cpu_bar(void)
548 svg("<!-- CPU utilization graph -->\n");
550 svg("<text class=\"t2\" x=\"5\" y=\"-15\">CPU utilization</text>\n");
551 /* surrounding box */
554 /* bars for each sample, proportional to the CPU util. */
555 for (i = 1; i < samples; i++) {
562 for (c = 0; c < cpus; c++)
563 trt += cpustat[c].sample[i].runtime - cpustat[c].sample[i - 1].runtime;
565 trt = trt / 1000000000.0;
567 trt = trt / (double)cpus;
570 ptrt = trt / (sampletime[i] - sampletime[i - 1]);
576 svg("<rect class=\"cpu\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
577 time_to_graph(sampletime[i - 1] - graph_start),
578 (scale_y * 5) - (ptrt * (scale_y * 5)),
579 time_to_graph(sampletime[i] - sampletime[i - 1]),
580 ptrt * (scale_y * 5));
585 static void svg_wait_bar(void)
589 svg("<!-- Wait time aggregation box -->\n");
591 svg("<text class=\"t2\" x=\"5\" y=\"-15\">CPU wait</text>\n");
593 /* surrounding box */
596 /* bars for each sample, proportional to the CPU util. */
597 for (i = 1; i < samples; i++) {
604 for (c = 0; c < cpus; c++)
605 twt += cpustat[c].sample[i].waittime - cpustat[c].sample[i - 1].waittime;
607 twt = twt / 1000000000.0;
609 twt = twt / (double)cpus;
612 ptwt = twt / (sampletime[i] - sampletime[i - 1]);
618 svg("<rect class=\"wait\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
619 time_to_graph(sampletime[i - 1] - graph_start),
620 ((scale_y * 5) - (ptwt * (scale_y * 5))),
621 time_to_graph(sampletime[i] - sampletime[i - 1]),
622 ptwt * (scale_y * 5));
628 static void svg_entropy_bar(void)
632 svg("<!-- entropy pool graph -->\n");
634 svg("<text class=\"t2\" x=\"5\" y=\"-15\">Entropy pool size</text>\n");
635 /* surrounding box */
638 /* bars for each sample, scale 0-4096 */
639 for (i = 1; i < samples; i++) {
640 /* svg("<!-- entropy %.03f %i -->\n", sampletime[i], entropy_avail[i]); */
641 svg("<rect class=\"cpu\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
642 time_to_graph(sampletime[i - 1] - graph_start),
643 ((scale_y * 5) - ((entropy_avail[i] / 4096.) * (scale_y * 5))),
644 time_to_graph(sampletime[i] - sampletime[i - 1]),
645 (entropy_avail[i] / 4096.) * (scale_y * 5));
650 static struct ps_struct *get_next_ps(struct ps_struct *ps)
653 * walk the list of processes and return the next one to be
667 /* go back for parent siblings */
670 if (ps->parent->next)
671 return ps->parent->next;
681 static int ps_filter(struct ps_struct *ps)
686 /* can't draw data when there is only 1 sample (need start + stop) */
687 if (ps->first == ps->last)
690 /* don't filter kthreadd */
694 /* drop stuff that doesn't use any real CPU time */
695 if (ps->total <= 0.001)
702 static void svg_do_initcall(int count_only)
710 /* can't plot initcall when disabled or in relative mode */
711 if (!initcall || relative) {
717 svg("<!-- initcall -->\n");
719 svg("<text class=\"t2\" x=\"5\" y=\"-15\">Kernel init threads</text>\n");
720 /* surrounding box */
721 svg_graph_box(kcount);
727 * Initcall graphing - parses dmesg buffer and displays kernel threads
728 * This somewhat uses the same methods and scaling to show processes
729 * but looks a lot simpler. It's overlaid entirely onto the PS graph
733 f = popen("dmesg", "r");
742 if (fgets(l, sizeof(l) - 1, f) == NULL)
745 c = sscanf(l, "[%lf] initcall %s %*s %d %*s %d %*s",
746 &t, func, &ret, &usecs);
748 /* also parse initcalls done by module loading */
749 c = sscanf(l, "[%lf] initcall %s %*s %*s %d %*s %d %*s",
750 &t, func, &ret, &usecs);
755 /* chop the +0xXX/0xXX stuff */
756 while(func[z] != '+')
761 /* filter out irrelevant stuff */
767 svg("<!-- thread=\"%s\" time=\"%.3f\" elapsed=\"%d\" result=\"%d\" -->\n",
768 func, t, usecs, ret);
774 svg(" <rect class=\"krnl\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
775 time_to_graph(t - (usecs / 1000000.0)),
777 time_to_graph(usecs / 1000000.0),
781 svg(" <text x=\"%.03f\" y=\"%.03f\">%s <tspan class=\"run\">%.03fs</tspan></text>\n",
782 time_to_graph(t - (usecs / 1000000.0)) + 5,
783 ps_to_graph(kcount) + 15,
794 static void svg_ps_bars(void)
796 struct ps_struct *ps;
802 svg("<!-- Process graph -->\n");
804 svg("<text class=\"t2\" x=\"5\" y=\"-15\">Processes</text>\n");
806 /* surrounding box */
807 svg_graph_box(pcount);
809 /* pass 2 - ps boxes */
811 while ((ps = get_next_ps(ps))) {
818 /* leave some trace of what we actually filtered etc. */
819 svg("<!-- %s [%i] ppid=%i runtime=%.03fs -->\n", ps->name, ps->pid,
820 ps->ppid, ps->total);
822 /* it would be nice if we could use exec_start from /proc/pid/sched,
823 * but it's unreliable and gives bogus numbers */
824 starttime = sampletime[ps->first];
826 if (!ps_filter(ps)) {
827 /* remember where _to_ our children need to draw a line */
828 ps->pos_x = time_to_graph(starttime - graph_start);
829 ps->pos_y = ps_to_graph(j+1); /* bottom left corner */
831 /* hook children to our parent coords instead */
832 ps->pos_x = ps->parent->pos_x;
833 ps->pos_y = ps->parent->pos_y;
835 /* if this is the last child, we might still need to draw a connecting line */
836 if ((!ps->next) && (ps->parent))
837 svg(" <line class=\"dot\" x1=\"%.03f\" y1=\"%.03f\" x2=\"%.03f\" y2=\"%.03f\" />\n",
839 ps_to_graph(j-1) + 10.0, /* whee, use the last value here */
845 svg(" <rect class=\"ps\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
846 time_to_graph(starttime - graph_start),
848 time_to_graph(sampletime[ps->last] - starttime),
851 /* paint cpu load over these */
852 for (t = ps->first + 1; t < ps->last; t++) {
856 /* calculate over interval */
857 rt = ps->sample[t].runtime - ps->sample[t-1].runtime;
858 wt = ps->sample[t].waittime - ps->sample[t-1].waittime;
860 prt = (rt / 1000000000) / (sampletime[t] - sampletime[t-1]);
861 wrt = (wt / 1000000000) / (sampletime[t] - sampletime[t-1]);
863 /* this can happen if timekeeping isn't accurate enough */
869 if ((prt < 0.1) && (wrt < 0.1)) /* =~ 26 (color threshold) */
872 svg(" <rect class=\"wait\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
873 time_to_graph(sampletime[t - 1] - graph_start),
875 time_to_graph(sampletime[t] - sampletime[t - 1]),
878 /* draw cpu over wait - TODO figure out how/why run + wait > interval */
879 svg(" <rect class=\"cpu\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
880 time_to_graph(sampletime[t - 1] - graph_start),
881 ps_to_graph(j + (1.0 - prt)),
882 time_to_graph(sampletime[t] - sampletime[t - 1]),
886 /* determine where to display the process name */
887 if (sampletime[ps->last] - sampletime[ps->first] < 1.5)
888 /* too small to fit label inside the box */
893 /* text label of process name */
894 svg(" <text x=\"%.03f\" y=\"%.03f\">%s [%i] <tspan class=\"run\">%.03fs</tspan></text>\n",
895 time_to_graph(sampletime[wt] - graph_start) + 5.0,
896 ps_to_graph(j) + 14.0,
899 (ps->sample[ps->last].runtime - ps->sample[ps->first].runtime) / 1000000000.0);
900 /* paint lines to the parent process */
902 /* horizontal part */
903 svg(" <line class=\"dot\" x1=\"%.03f\" y1=\"%.03f\" x2=\"%.03f\" y2=\"%.03f\" />\n",
904 time_to_graph(starttime - graph_start),
905 ps_to_graph(j) + 10.0,
907 ps_to_graph(j) + 10.0);
909 /* one vertical line connecting all the horizontal ones up */
911 svg(" <line class=\"dot\" x1=\"%.03f\" y1=\"%.03f\" x2=\"%.03f\" y2=\"%.03f\" />\n",
913 ps_to_graph(j) + 10.0,
918 j++; /* count boxes */
923 /* last pass - determine when idle */
925 /* make sure we start counting from the point where we actually have
926 * data: assume that bootchart's first sample is when data started
929 while (ps->next_ps) {
935 for (i = ps->first; i < samples - (hz / 2); i++) {
940 /* subtract bootchart cpu utilization from total */
942 for (c = 0; c < cpus; c++)
943 crt += cpustat[c].sample[i + ((int)hz / 2)].runtime - cpustat[c].sample[i].runtime;
944 brt = ps->sample[i + ((int)hz / 2)].runtime - ps->sample[i].runtime;
947 * our definition of "idle":
949 * if for (hz / 2) we've used less CPU than (interval / 2) ...
950 * defaults to 4.0%, which experimentally, is where atom idles
952 if ((crt - brt) < (interval / 2.0)) {
953 idletime = sampletime[i] - graph_start;
954 svg("\n<!-- idle detected at %.03f seconds -->\n",
956 svg("<line class=\"idle\" x1=\"%.03f\" y1=\"%.03f\" x2=\"%.03f\" y2=\"%.03f\" />\n",
957 time_to_graph(idletime),
959 time_to_graph(idletime),
960 ps_to_graph(pcount) + scale_y);
961 svg("<text class=\"idle\" x=\"%.03f\" y=\"%.03f\">%.01fs</text>\n",
962 time_to_graph(idletime) + 5.0,
963 ps_to_graph(pcount) + scale_y,
971 static void svg_top_ten_cpu(void)
973 struct ps_struct *top[10];
974 struct ps_struct emptyps;
975 struct ps_struct *ps;
978 memset(&emptyps, 0, sizeof(struct ps_struct));
979 for (n=0; n < 10; n++)
982 /* walk all ps's and setup ptrs */
984 while ((ps = get_next_ps(ps))) {
985 for (n = 0; n < 10; n++) {
986 if (ps->total <= top[n]->total)
989 for (m = 9; m > n; m--)
996 svg("<text class=\"t2\" x=\"20\" y=\"0\">Top CPU consumers:</text>\n");
997 for (n = 0; n < 10; n++)
998 svg("<text class=\"t3\" x=\"20\" y=\"%d\">%3.03fs - %s[%d]</text>\n",
1006 static void svg_top_ten_pss(void)
1008 struct ps_struct *top[10];
1009 struct ps_struct emptyps;
1010 struct ps_struct *ps;
1013 memset(&emptyps, 0, sizeof(struct ps_struct));
1014 for (n=0; n < 10; n++)
1017 /* walk all ps's and setup ptrs */
1019 while ((ps = get_next_ps(ps))) {
1020 for (n = 0; n < 10; n++) {
1021 if (ps->pss_max <= top[n]->pss_max)
1023 /* cascade insert */
1024 for (m = 9; m > n; m--)
1031 svg("<text class=\"t2\" x=\"20\" y=\"0\">Top PSS consumers:</text>\n");
1032 for (n = 0; n < 10; n++)
1033 svg("<text class=\"t3\" x=\"20\" y=\"%d\">%dK - %s[%d]</text>\n",
1043 struct ps_struct *ps;
1045 memset(&str, 0, sizeof(str));
1049 /* count initcall thread count first */
1051 ksize = (kcount ? ps_to_graph(kcount) + (scale_y * 2) : 0);
1053 /* then count processes */
1054 while ((ps = get_next_ps(ps))) {
1060 psize = ps_to_graph(pcount) + (scale_y * 2);
1062 esize = (entropy ? scale_y * 7 : 0);
1064 /* after this, we can draw the header with proper sizing */
1067 svg("<g transform=\"translate(10,400)\">\n");
1071 svg("<g transform=\"translate(10,%.03f)\">\n", 400.0 + (scale_y * 7.0));
1075 svg("<g transform=\"translate(10,%.03f)\">\n", 400.0 + (scale_y * 14.0));
1079 svg("<g transform=\"translate(10,%.03f)\">\n", 400.0 + (scale_y * 21.0));
1084 svg("<g transform=\"translate(10,%.03f)\">\n", 400.0 + (scale_y * 28.0));
1089 svg("<g transform=\"translate(10,%.03f)\">\n", 400.0 + (scale_y * 28.0) + ksize);
1093 svg("<g transform=\"translate(10, 0)\">\n");
1097 svg("<g transform=\"translate(10,200)\">\n");
1102 svg("<g transform=\"translate(10,%.03f)\">\n", 400.0 + (scale_y * 28.0) + ksize + psize);
1108 svg("<g transform=\"translate(10,%.03f)\">\n", 400.0 + (scale_y * 28.0) + ksize + psize + esize);
1112 svg("<g transform=\"translate(410,200)\">\n");