4 * Copyright (C) 2009-2012 Intel Coproration
7 * Auke Kok <auke-jan.h.kok@intel.com>
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; version 2
22 #include <sys/utsname.h>
24 #include "bootchart.h"
27 #define time_to_graph(t) ((t) * scale_x)
28 #define ps_to_graph(n) ((n) * scale_y)
29 #define kb_to_graph(m) ((m) * scale_y * 0.0001)
30 #define to_color(n) (192.0 - ((n) * 192.0))
32 #define max(x, y) (((x) > (y)) ? (x) : (y))
33 #define min(x, y) (((x) < (y)) ? (x) : (y))
35 static char str[8092];
37 #define svg(a...) do { snprintf(str, 8092, ## a); fputs(str, of); fflush(of); } while (0)
39 static const char *colorwheel[12] = {
40 "rgb(255,32,32)", // red
41 "rgb(32,192,192)", // cyan
42 "rgb(255,128,32)", // orange
43 "rgb(128,32,192)", // blue-violet
44 "rgb(255,255,32)", // yellow
45 "rgb(192,32,128)", // red-violet
46 "rgb(32,255,32)", // green
47 "rgb(255,64,32)", // red-orange
48 "rgb(32,32,255)", // blue
49 "rgb(255,192,32)", // yellow-orange
50 "rgb(192,32,192)", // violet
51 "rgb(32,192,32)" // yellow-green
54 static double idletime = -1.0;
55 static int pfiltered = 0;
56 static int pcount = 0;
57 static int kcount = 0;
58 static float psize = 0;
59 static float ksize = 0;
60 static float esize = 0;
63 static void svg_header(void)
68 /* min width is about 1600px due to the label */
69 w = 150.0 + 10.0 + time_to_graph(sampletime[samples-1] - graph_start);
70 w = ((w < 1600.0) ? 1600.0 : w);
72 /* height is variable based on pss, psize, ksize */
73 h = 400.0 + (scale_y * 30.0) /* base graphs and title */
74 + (pss ? (100.0 * scale_y) + (scale_y * 7.0) : 0.0) /* pss estimate */
75 + psize + ksize + esize;
77 svg("<?xml version=\"1.0\" standalone=\"no\"?>\n");
78 svg("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" ");
79 svg("\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n");
81 //svg("<g transform=\"translate(10,%d)\">\n", 1000 + 150 + (pcount * 20));
82 svg("<svg width=\"%.0fpx\" height=\"%.0fpx\" version=\"1.1\" ",
84 svg("xmlns=\"http://www.w3.org/2000/svg\">\n\n");
86 /* write some basic info as a comment, including some help */
87 svg("<!-- This file is a bootchart SVG file. It is best rendered in a browser -->\n");
88 svg("<!-- such as Chrome/Chromium, firefox. Other applications that render -->\n");
89 svg("<!-- these files properly but much more slow are ImageMagick, gimp, -->\n");
90 svg("<!-- inkscape, etc.. To display the files on your system, just point -->\n");
91 svg("<!-- your browser to file:///var/log/ and click. This bootchart was -->\n\n");
93 svg("<!-- generated by bootchart version %s, running with options: -->\n", VERSION);
94 svg("<!-- hz=\"%f\" n=\"%d\" -->\n", hz, len);
95 svg("<!-- x=\"%f\" y=\"%f\" -->\n", scale_x, scale_y);
96 svg("<!-- rel=\"%d\" f=\"%d\" -->\n", relative, filter);
97 svg("<!-- p=\"%d\" e=\"%d\" -->\n", pss, entropy);
98 svg("<!-- o=\"%s\" i=\"%s\" -->\n\n", output_path, init_path);
101 svg("<defs>\n <style type=\"text/css\">\n <![CDATA[\n");
103 svg(" rect { stroke-width: 1; }\n");
104 svg(" rect.cpu { fill: rgb(64,64,240); stroke-width: 0; fill-opacity: 0.7; }\n");
105 svg(" rect.wait { fill: rgb(240,240,0); stroke-width: 0; fill-opacity: 0.7; }\n");
106 svg(" rect.bi { fill: rgb(240,128,128); stroke-width: 0; fill-opacity: 0.7; }\n");
107 svg(" rect.bo { fill: rgb(192,64,64); stroke-width: 0; fill-opacity: 0.7; }\n");
108 svg(" rect.ps { fill: rgb(192,192,192); stroke: rgb(128,128,128); fill-opacity: 0.7; }\n");
109 svg(" rect.krnl { fill: rgb(240,240,0); stroke: rgb(128,128,128); fill-opacity: 0.7; }\n");
110 svg(" rect.box { fill: rgb(240,240,240); stroke: rgb(192,192,192); }\n");
111 svg(" rect.clrw { stroke-width: 0; fill-opacity: 0.7;}\n");
112 svg(" line { stroke: rgb(64,64,64); stroke-width: 1; }\n");
113 svg("// line.sec1 { }\n");
114 svg(" line.sec5 { stroke-width: 2; }\n");
115 svg(" line.sec01 { stroke: rgb(224,224,224); stroke-width: 1; }\n");
116 svg(" line.dot { stroke-dasharray: 2 4; }\n");
117 svg(" line.idle { stroke: rgb(64,64,64); stroke-dasharray: 10 6; stroke-opacity: 0.7; }\n");
119 svg(" .run { font-size: 8; font-style: italic; }\n");
120 svg(" text { font-family: Verdana, Helvetica; font-size: 10; }\n");
121 svg(" text.sec { font-size: 8; }\n");
122 svg(" text.t1 { font-size: 24; }\n");
123 svg(" text.t2 { font-size: 12; }\n");
124 svg(" text.idle { font-size: 18; }\n");
126 svg(" ]]>\n </style>\n</defs>\n\n");
131 static void svg_title(void)
133 char cmdline[256] = "";
134 char filename[PATH_MAX];
136 char rootbdev[16] = "Unknown";
137 char model[256] = "Unknown";
138 char date[256] = "Unknown";
139 char cpu[256] = "Unknown";
140 char build[256] = "Unknown";
146 /* grab /proc/cmdline */
147 f = fopen("/proc/cmdline", "r");
149 if (!fgets(cmdline, 255, f))
150 sprintf(cmdline, "Unknown");
154 /* extract root fs so we can find disk model name in sysfs */
155 c = strstr(cmdline, "root=/dev/");
157 strncpy(rootbdev, &c[10], 3);
160 sprintf(filename, "/sys/block/%s/device/model", rootbdev);
161 f = fopen(filename, "r");
163 if (!fgets(model, 255, f))
164 fprintf(stderr, "Error reading disk model for %s\n", rootbdev);
168 /* various utsname parameters */
170 fprintf(stderr, "Error getting uname info\n");
174 strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", localtime(&t));
177 f = fopen("/proc/cpuinfo", "r");
179 while (fgets(buf, 255, f)) {
180 if (strstr(buf, "model name")) {
181 strncpy(cpu, &buf[13], 255);
188 /* Build - 1st line from /etc/system-release */
189 f = fopen("/etc/system-release", "r");
191 if (fgets(buf, 255, f))
192 strncpy(build, buf, 255);
196 svg("<text class=\"t1\" x=\"0\" y=\"30\">Bootchart for %s - %s</text>\n",
198 svg("<text class=\"t2\" x=\"20\" y=\"50\">System: %s %s %s %s</text>\n",
199 uts.sysname, uts.release, uts.version, uts.machine);
200 svg("<text class=\"t2\" x=\"20\" y=\"65\">CPU: %s</text>\n",
202 svg("<text class=\"t2\" x=\"20\" y=\"80\">Disk: %s</text>\n",
204 svg("<text class=\"t2\" x=\"20\" y=\"95\">Boot options: %s</text>\n",
206 svg("<text class=\"t2\" x=\"20\" y=\"110\">Build: %s</text>\n",
208 svg("<text class=\"t2\" x=\"20\" y=\"125\">Log start time: %.03fs</text>\n", log_start);
209 svg("<text class=\"t2\" x=\"20\" y=\"140\">Idle time: ");
212 svg("%.03fs", idletime);
216 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",
217 hz, len, overrun, pscount, pfiltered);
221 static void svg_graph_box(int height)
226 /* outside box, fill */
227 svg("<rect class=\"box\" x=\"%.03f\" y=\"0\" width=\"%.03f\" height=\"%.03f\" />\n",
229 time_to_graph(sampletime[samples-1] - graph_start),
230 ps_to_graph(height));
232 for (d = graph_start; d <= sampletime[samples-1];
233 d += (scale_x < 2.0 ? 60.0 : scale_x < 10.0 ? 1.0 : 0.1)) {
234 /* lines for each second */
236 svg(" <line class=\"sec5\" x1=\"%.03f\" y1=\"0\" x2=\"%.03f\" y2=\"%.03f\" />\n",
237 time_to_graph(d - graph_start),
238 time_to_graph(d - graph_start),
239 ps_to_graph(height));
240 else if (i % 10 == 0)
241 svg(" <line class=\"sec1\" x1=\"%.03f\" y1=\"0\" x2=\"%.03f\" y2=\"%.03f\" />\n",
242 time_to_graph(d - graph_start),
243 time_to_graph(d - graph_start),
244 ps_to_graph(height));
246 svg(" <line class=\"sec01\" x1=\"%.03f\" y1=\"0\" x2=\"%.03f\" y2=\"%.03f\" />\n",
247 time_to_graph(d - graph_start),
248 time_to_graph(d - graph_start),
249 ps_to_graph(height));
253 svg(" <text class=\"sec\" x=\"%.03f\" y=\"%.03f\" >%.01fs</text>\n",
254 time_to_graph(d - graph_start),
263 static void svg_pss_graph(void)
265 struct ps_struct *ps;
268 svg("\n\n<!-- Pss memory size graph -->\n");
270 svg("\n <text class=\"t2\" x=\"5\" y=\"-15\">Memory allocation - Pss</text>\n");
272 /* vsize 1000 == 1000mb */
274 /* draw some hlines for usable memory sizes */
275 for (i = 100000; i < 1000000; i += 100000) {
276 svg(" <line class=\"sec01\" x1=\"%.03f\" y1=\"%.0f\" x2=\"%.03f\" y2=\"%.0f\"/>\n",
279 time_to_graph(sampletime[samples-1] - graph_start),
281 svg(" <text class=\"sec\" x=\"%.03f\" y=\"%.0f\">%dM</text>\n",
282 time_to_graph(sampletime[samples-1] - graph_start) + 5,
283 kb_to_graph(i), (1000000 - i) / 1000);
287 /* now plot the graph itself */
288 for (i = 1; i < samples ; i++) {
295 /* put all the small pss blocks into the bottom */
297 while (ps->next_ps) {
301 if (ps->sample[i].pss <= (100 * scale_y))
302 top += ps->sample[i].pss;
304 svg(" <rect class=\"clrw\" style=\"fill: %s\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
306 time_to_graph(sampletime[i - 1] - graph_start),
307 kb_to_graph(1000000.0 - top),
308 time_to_graph(sampletime[i] - sampletime[i - 1]),
309 kb_to_graph(top - bottom));
313 /* now plot the ones that are of significant size */
315 while (ps->next_ps) {
319 /* don't draw anything smaller than 2mb */
320 if (ps->sample[i].pss > (100 * scale_y)) {
321 top = bottom + ps->sample[i].pss;
322 svg(" <rect class=\"clrw\" style=\"fill: %s\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
323 colorwheel[ps->pid % 12],
324 time_to_graph(sampletime[i - 1] - graph_start),
325 kb_to_graph(1000000.0 - top),
326 time_to_graph(sampletime[i] - sampletime[i - 1]),
327 kb_to_graph(top - bottom));
333 /* overlay all the text labels */
334 for (i = 1; i < samples ; i++) {
341 /* put all the small pss blocks into the bottom */
343 while (ps->next_ps) {
347 if (ps->sample[i].pss <= (100 * scale_y))
348 top += ps->sample[i].pss;
353 /* now plot the ones that are of significant size */
355 while (ps->next_ps) {
359 /* don't draw anything smaller than 2mb */
360 if (ps->sample[i].pss > (100 * scale_y)) {
361 top = bottom + ps->sample[i].pss;
362 /* draw a label with the process / PID */
363 if ((i == 1) || (ps->sample[i - 1].pss <= (100 * scale_y)))
364 svg(" <text x=\"%.03f\" y=\"%.03f\">%s [%i]</text>\n",
365 time_to_graph(sampletime[i] - graph_start),
366 kb_to_graph(1000000.0 - bottom - ((top - bottom) / 2)),
374 /* debug output - full data dump */
375 svg("\n\n<!-- PSS map - csv format -->\n");
377 while (ps->next_ps) {
381 svg("<!-- %s [%d] pss=", ps->name, ps->pid);
382 for (i = 0; i < samples ; i++) {
383 svg("%d," , ps->sample[i].pss);
390 static void svg_io_bi_bar(void)
397 svg("<!-- IO utilization graph - In -->\n");
399 svg("<text class=\"t2\" x=\"5\" y=\"-15\">IO utilization - read</text>\n");
402 * calculate rounding range
404 * We need to round IO data since IO block data is not updated on
405 * each poll. Applying a smoothing function loses some burst data,
406 * so keep the smoothing range short.
408 range = 0.25 / (1.0 / hz);
410 range = 2.0; /* no smoothing */
412 /* surrounding box */
415 /* find the max IO first */
416 for (i = 1; i < samples; i++) {
421 start = max(i - ((range / 2) - 1), 0);
422 stop = min(i + (range / 2), samples - 1);
424 tot = (double)(blockstat[stop].bi - blockstat[start].bi)
430 tot = (double)(blockstat[stop].bo - blockstat[start].bo)
437 for (i = 1; i < samples; i++) {
443 start = max(i - ((range / 2) - 1), 0);
444 stop = min(i + (range / 2), samples);
446 tot = (double)(blockstat[stop].bi - blockstat[start].bi)
451 svg("<rect class=\"bi\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
452 time_to_graph(sampletime[i - 1] - graph_start),
453 (scale_y * 5) - (pbi * (scale_y * 5)),
454 time_to_graph(sampletime[i] - sampletime[i - 1]),
455 pbi * (scale_y * 5));
457 /* labels around highest value */
459 svg(" <text class=\"sec\" x=\"%.03f\" y=\"%.03f\">%0.2fmb/sec</text>\n",
460 time_to_graph(sampletime[i] - graph_start) + 5,
461 ((scale_y * 5) - (pbi * (scale_y * 5))) + 15,
462 max / 1024.0 / (interval / 1000000000.0));
467 static void svg_io_bo_bar(void)
474 svg("<!-- IO utilization graph - out -->\n");
476 svg("<text class=\"t2\" x=\"5\" y=\"-15\">IO utilization - write</text>\n");
479 * calculate rounding range
481 * We need to round IO data since IO block data is not updated on
482 * each poll. Applying a smoothing function loses some burst data,
483 * so keep the smoothing range short.
485 range = 0.25 / (1.0 / hz);
487 range = 2.0; /* no smoothing */
489 /* surrounding box */
492 /* find the max IO first */
493 for (i = 1; i < samples; i++) {
498 start = max(i - ((range / 2) - 1), 0);
499 stop = min(i + (range / 2), samples - 1);
501 tot = (double)(blockstat[stop].bi - blockstat[start].bi)
505 tot = (double)(blockstat[stop].bo - blockstat[start].bo)
514 for (i = 1; i < samples; i++) {
520 start = max(i - ((range / 2) - 1), 0);
521 stop = min(i + (range / 2), samples);
523 tot = (double)(blockstat[stop].bo - blockstat[start].bo)
528 svg("<rect class=\"bo\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
529 time_to_graph(sampletime[i - 1] - graph_start),
530 (scale_y * 5) - (pbo * (scale_y * 5)),
531 time_to_graph(sampletime[i] - sampletime[i - 1]),
532 pbo * (scale_y * 5));
534 /* labels around highest bo value */
536 svg(" <text class=\"sec\" x=\"%.03f\" y=\"%.03f\">%0.2fmb/sec</text>\n",
537 time_to_graph(sampletime[i] - graph_start) + 5,
538 ((scale_y * 5) - (pbo * (scale_y * 5))),
539 max / 1024.0 / (interval / 1000000000.0));
545 static void svg_cpu_bar(void)
549 svg("<!-- CPU utilization graph -->\n");
551 svg("<text class=\"t2\" x=\"5\" y=\"-15\">CPU utilization</text>\n");
552 /* surrounding box */
555 /* bars for each sample, proportional to the CPU util. */
556 for (i = 1; i < samples; i++) {
563 for (c = 0; c < cpus; c++)
564 trt += cpustat[c].sample[i].runtime - cpustat[c].sample[i - 1].runtime;
566 trt = trt / 1000000000.0;
568 trt = trt / (double)cpus;
571 ptrt = trt / (sampletime[i] - sampletime[i - 1]);
577 svg("<rect class=\"cpu\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
578 time_to_graph(sampletime[i - 1] - graph_start),
579 (scale_y * 5) - (ptrt * (scale_y * 5)),
580 time_to_graph(sampletime[i] - sampletime[i - 1]),
581 ptrt * (scale_y * 5));
586 static void svg_wait_bar(void)
590 svg("<!-- Wait time aggregation box -->\n");
592 svg("<text class=\"t2\" x=\"5\" y=\"-15\">CPU wait</text>\n");
594 /* surrounding box */
597 /* bars for each sample, proportional to the CPU util. */
598 for (i = 1; i < samples; i++) {
605 for (c = 0; c < cpus; c++)
606 twt += cpustat[c].sample[i].waittime - cpustat[c].sample[i - 1].waittime;
608 twt = twt / 1000000000.0;
610 twt = twt / (double)cpus;
613 ptwt = twt / (sampletime[i] - sampletime[i - 1]);
619 svg("<rect class=\"wait\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
620 time_to_graph(sampletime[i - 1] - graph_start),
621 ((scale_y * 5) - (ptwt * (scale_y * 5))),
622 time_to_graph(sampletime[i] - sampletime[i - 1]),
623 ptwt * (scale_y * 5));
629 static void svg_entropy_bar(void)
633 svg("<!-- entropy pool graph -->\n");
635 svg("<text class=\"t2\" x=\"5\" y=\"-15\">Entropy pool size</text>\n");
636 /* surrounding box */
639 /* bars for each sample, scale 0-4096 */
640 for (i = 1; i < samples; i++) {
641 /* svg("<!-- entropy %.03f %i -->\n", sampletime[i], entropy_avail[i]); */
642 svg("<rect class=\"cpu\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
643 time_to_graph(sampletime[i - 1] - graph_start),
644 ((scale_y * 5) - ((entropy_avail[i] / 4096.) * (scale_y * 5))),
645 time_to_graph(sampletime[i] - sampletime[i - 1]),
646 (entropy_avail[i] / 4096.) * (scale_y * 5));
651 static struct ps_struct *get_next_ps(struct ps_struct *ps)
654 * walk the list of processes and return the next one to be
668 /* go back for parent siblings */
671 if (ps->parent->next)
672 return ps->parent->next;
682 static int ps_filter(struct ps_struct *ps)
687 /* can't draw data when there is only 1 sample (need start + stop) */
688 if (ps->first == ps->last)
691 /* don't filter kthreadd */
695 /* drop stuff that doesn't use any real CPU time */
696 if (ps->total <= 0.001)
703 static void svg_do_initcall(int count_only)
711 /* can't plot initcall when disabled or in relative mode */
712 if (!initcall || relative) {
718 svg("<!-- initcall -->\n");
720 svg("<text class=\"t2\" x=\"5\" y=\"-15\">Kernel init threads</text>\n");
721 /* surrounding box */
722 svg_graph_box(kcount);
728 * Initcall graphing - parses dmesg buffer and displays kernel threads
729 * This somewhat uses the same methods and scaling to show processes
730 * but looks a lot simpler. It's overlaid entirely onto the PS graph
734 f = popen("dmesg", "r");
743 if (fgets(l, sizeof(l) - 1, f) == NULL)
746 c = sscanf(l, "[%lf] initcall %s %*s %d %*s %d %*s",
747 &t, func, &ret, &usecs);
749 /* also parse initcalls done by module loading */
750 c = sscanf(l, "[%lf] initcall %s %*s %*s %d %*s %d %*s",
751 &t, func, &ret, &usecs);
756 /* chop the +0xXX/0xXX stuff */
757 while(func[z] != '+')
762 /* filter out irrelevant stuff */
768 svg("<!-- thread=\"%s\" time=\"%.3f\" elapsed=\"%d\" result=\"%d\" -->\n",
769 func, t, usecs, ret);
775 svg(" <rect class=\"krnl\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
776 time_to_graph(t - (usecs / 1000000.0)),
778 time_to_graph(usecs / 1000000.0),
782 svg(" <text x=\"%.03f\" y=\"%.03f\">%s <tspan class=\"run\">%.03fs</tspan></text>\n",
783 time_to_graph(t - (usecs / 1000000.0)) + 5,
784 ps_to_graph(kcount) + 15,
795 static void svg_ps_bars(void)
797 struct ps_struct *ps;
803 svg("<!-- Process graph -->\n");
805 svg("<text class=\"t2\" x=\"5\" y=\"-15\">Processes</text>\n");
807 /* surrounding box */
808 svg_graph_box(pcount);
810 /* pass 2 - ps boxes */
812 while ((ps = get_next_ps(ps))) {
819 /* leave some trace of what we actually filtered etc. */
820 svg("<!-- %s [%i] ppid=%i runtime=%.03fs -->\n", ps->name, ps->pid,
821 ps->ppid, ps->total);
823 /* it would be nice if we could use exec_start from /proc/pid/sched,
824 * but it's unreliable and gives bogus numbers */
825 starttime = sampletime[ps->first];
827 if (!ps_filter(ps)) {
828 /* remember where _to_ our children need to draw a line */
829 ps->pos_x = time_to_graph(starttime - graph_start);
830 ps->pos_y = ps_to_graph(j+1); /* bottom left corner */
832 /* hook children to our parent coords instead */
833 ps->pos_x = ps->parent->pos_x;
834 ps->pos_y = ps->parent->pos_y;
836 /* if this is the last child, we might still need to draw a connecting line */
837 if ((!ps->next) && (ps->parent))
838 svg(" <line class=\"dot\" x1=\"%.03f\" y1=\"%.03f\" x2=\"%.03f\" y2=\"%.03f\" />\n",
840 ps_to_graph(j-1) + 10.0, /* whee, use the last value here */
846 svg(" <rect class=\"ps\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
847 time_to_graph(starttime - graph_start),
849 time_to_graph(sampletime[ps->last] - starttime),
852 /* paint cpu load over these */
853 for (t = ps->first + 1; t < ps->last; t++) {
857 /* calculate over interval */
858 rt = ps->sample[t].runtime - ps->sample[t-1].runtime;
859 wt = ps->sample[t].waittime - ps->sample[t-1].waittime;
861 prt = (rt / 1000000000) / (sampletime[t] - sampletime[t-1]);
862 wrt = (wt / 1000000000) / (sampletime[t] - sampletime[t-1]);
864 /* this can happen if timekeeping isn't accurate enough */
870 if ((prt < 0.1) && (wrt < 0.1)) /* =~ 26 (color threshold) */
873 svg(" <rect class=\"wait\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
874 time_to_graph(sampletime[t - 1] - graph_start),
876 time_to_graph(sampletime[t] - sampletime[t - 1]),
879 /* draw cpu over wait - TODO figure out how/why run + wait > interval */
880 svg(" <rect class=\"cpu\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
881 time_to_graph(sampletime[t - 1] - graph_start),
882 ps_to_graph(j + (1.0 - prt)),
883 time_to_graph(sampletime[t] - sampletime[t - 1]),
887 /* determine where to display the process name */
888 if (sampletime[ps->last] - sampletime[ps->first] < 1.5)
889 /* too small to fit label inside the box */
894 /* text label of process name */
895 svg(" <text x=\"%.03f\" y=\"%.03f\">%s [%i] <tspan class=\"run\">%.03fs</tspan></text>\n",
896 time_to_graph(sampletime[w] - graph_start) + 5.0,
897 ps_to_graph(j) + 14.0,
900 (ps->sample[ps->last].runtime - ps->sample[ps->first].runtime) / 1000000000.0);
901 /* paint lines to the parent process */
903 /* horizontal part */
904 svg(" <line class=\"dot\" x1=\"%.03f\" y1=\"%.03f\" x2=\"%.03f\" y2=\"%.03f\" />\n",
905 time_to_graph(starttime - graph_start),
906 ps_to_graph(j) + 10.0,
908 ps_to_graph(j) + 10.0);
910 /* one vertical line connecting all the horizontal ones up */
912 svg(" <line class=\"dot\" x1=\"%.03f\" y1=\"%.03f\" x2=\"%.03f\" y2=\"%.03f\" />\n",
914 ps_to_graph(j) + 10.0,
919 j++; /* count boxes */
924 /* last pass - determine when idle */
926 /* make sure we start counting from the point where we actually have
927 * data: assume that bootchart's first sample is when data started
930 while (ps->next_ps) {
936 for (i = ps->first; i < samples - (hz / 2); i++) {
941 /* subtract bootchart cpu utilization from total */
943 for (c = 0; c < cpus; c++)
944 crt += cpustat[c].sample[i + ((int)hz / 2)].runtime - cpustat[c].sample[i].runtime;
945 brt = ps->sample[i + ((int)hz / 2)].runtime - ps->sample[i].runtime;
948 * our definition of "idle":
950 * if for (hz / 2) we've used less CPU than (interval / 2) ...
951 * defaults to 4.0%, which experimentally, is where atom idles
953 if ((crt - brt) < (interval / 2.0)) {
954 idletime = sampletime[i] - graph_start;
955 svg("\n<!-- idle detected at %.03f seconds -->\n",
957 svg("<line class=\"idle\" x1=\"%.03f\" y1=\"%.03f\" x2=\"%.03f\" y2=\"%.03f\" />\n",
958 time_to_graph(idletime),
960 time_to_graph(idletime),
961 ps_to_graph(pcount) + scale_y);
962 svg("<text class=\"idle\" x=\"%.03f\" y=\"%.03f\">%.01fs</text>\n",
963 time_to_graph(idletime) + 5.0,
964 ps_to_graph(pcount) + scale_y,
972 static void svg_top_ten_cpu(void)
974 struct ps_struct *top[10];
975 struct ps_struct emptyps;
976 struct ps_struct *ps;
979 memset(&emptyps, 0, sizeof(struct ps_struct));
980 for (n=0; n < 10; n++)
983 /* walk all ps's and setup ptrs */
985 while ((ps = get_next_ps(ps))) {
986 for (n = 0; n < 10; n++) {
987 if (ps->total <= top[n]->total)
990 for (m = 9; m > n; m--)
997 svg("<text class=\"t2\" x=\"20\" y=\"0\">Top CPU consumers:</text>\n");
998 for (n = 0; n < 10; n++)
999 svg("<text class=\"t3\" x=\"20\" y=\"%d\">%3.03fs - %s[%d]</text>\n",
1007 static void svg_top_ten_pss(void)
1009 struct ps_struct *top[10];
1010 struct ps_struct emptyps;
1011 struct ps_struct *ps;
1014 memset(&emptyps, 0, sizeof(struct ps_struct));
1015 for (n=0; n < 10; n++)
1018 /* walk all ps's and setup ptrs */
1020 while ((ps = get_next_ps(ps))) {
1021 for (n = 0; n < 10; n++) {
1022 if (ps->pss_max <= top[n]->pss_max)
1024 /* cascade insert */
1025 for (m = 9; m > n; m--)
1032 svg("<text class=\"t2\" x=\"20\" y=\"0\">Top PSS consumers:</text>\n");
1033 for (n = 0; n < 10; n++)
1034 svg("<text class=\"t3\" x=\"20\" y=\"%d\">%dK - %s[%d]</text>\n",
1044 struct ps_struct *ps;
1046 memset(&str, 0, sizeof(str));
1050 /* count initcall thread count first */
1052 ksize = (kcount ? ps_to_graph(kcount) + (scale_y * 2) : 0);
1054 /* then count processes */
1055 while ((ps = get_next_ps(ps))) {
1061 psize = ps_to_graph(pcount) + (scale_y * 2);
1063 esize = (entropy ? scale_y * 7 : 0);
1065 /* after this, we can draw the header with proper sizing */
1068 svg("<g transform=\"translate(10,400)\">\n");
1072 svg("<g transform=\"translate(10,%.03f)\">\n", 400.0 + (scale_y * 7.0));
1076 svg("<g transform=\"translate(10,%.03f)\">\n", 400.0 + (scale_y * 14.0));
1080 svg("<g transform=\"translate(10,%.03f)\">\n", 400.0 + (scale_y * 21.0));
1085 svg("<g transform=\"translate(10,%.03f)\">\n", 400.0 + (scale_y * 28.0));
1090 svg("<g transform=\"translate(10,%.03f)\">\n", 400.0 + (scale_y * 28.0) + ksize);
1094 svg("<g transform=\"translate(10, 0)\">\n");
1098 svg("<g transform=\"translate(10,200)\">\n");
1103 svg("<g transform=\"translate(10,%.03f)\">\n", 400.0 + (scale_y * 28.0) + ksize + psize);
1109 svg("<g transform=\"translate(10,%.03f)\">\n", 400.0 + (scale_y * 28.0) + ksize + psize + esize);
1113 svg("<g transform=\"translate(410,200)\">\n");