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 { sprintf(str, ## 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;
66 /* min width is about 1600px due to the label */
67 w = 150 + 10 + time_to_graph(sampletime[samples-1] - graph_start);
68 w = ((w < 1600.0) ? 1600.0 : w);
70 /* height is variable based on pss, psize, ksize */
71 h = 400 + (scale_y * 30) /* base graphs and title */
72 + (pss ? (100 * scale_y) + (scale_y * 7) : 0) /* pss estimate */
75 svg("<?xml version=\"1.0\" standalone=\"no\"?>\n");
76 svg("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" ");
77 svg("\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n");
79 //svg("<g transform=\"translate(10,%d)\">\n", 1000 + 150 + (pcount * 20));
80 svg("<svg width=\"%.0fpx\" height=\"%ipx\" version=\"1.1\" ",
82 svg("xmlns=\"http://www.w3.org/2000/svg\">\n\n");
84 /* write some basic info as a comment, including some help */
85 svg("<!-- This file is a bootchart SVG file. It is best rendered in a browser -->\n");
86 svg("<!-- such as Chrome/Chromium, firefox. Other applications that render -->\n");
87 svg("<!-- these files properly but much more slow are ImageMagick, gimp, -->\n");
88 svg("<!-- inkscape, etc.. To display the files on your system, just point -->\n");
89 svg("<!-- your browser to file:///var/log/ and click. This bootchart was -->\n\n");
91 svg("<!-- generated by bootchart version %s, running with options: -->\n", BOOTCHARTVERSION);
92 svg("<!-- hz=\"%d\" n=\"%d\" -->\n", hz, len);
93 svg("<!-- x=\"%d\" y=\"%d\" -->\n", scale_x, scale_y);
94 svg("<!-- rel=\"%d\" f=\"%d\" p=\"%d\" -->\n", relative, filter, pss);
95 svg("<!-- o=\"%s\" i=\"%s\" -->\n\n", output_path, init_path);
98 svg("<defs>\n <style type=\"text/css\">\n <![CDATA[\n");
100 svg(" rect { stroke-width: 1; }\n");
101 svg(" rect.cpu { fill: rgb(64,64,240); stroke-width: 0; fill-opacity: 0.7; }\n");
102 svg(" rect.wait { fill: rgb(240,240,0); stroke-width: 0; fill-opacity: 0.7; }\n");
103 svg(" rect.bi { fill: rgb(240,128,128); stroke-width: 0; fill-opacity: 0.7; }\n");
104 svg(" rect.bo { fill: rgb(192,64,64); stroke-width: 0; fill-opacity: 0.7; }\n");
105 svg(" rect.ps { fill: rgb(192,192,192); stroke: rgb(128,128,128); fill-opacity: 0.7; }\n");
106 svg(" rect.krnl { fill: rgb(240,240,0); stroke: rgb(128,128,128); fill-opacity: 0.7; }\n");
107 svg(" rect.box { fill: rgb(240,240,240); stroke: rgb(192,192,192); }\n");
108 svg(" rect.clrw { stroke-width: 0; fill-opacity: 0.7;}\n");
109 svg(" line { stroke: rgb(64,64,64); stroke-width: 1; }\n");
110 svg("// line.sec1 { }\n");
111 svg(" line.sec5 { stroke-width: 2; }\n");
112 svg(" line.sec01 { stroke: rgb(224,224,224); stroke-width: 1; }\n");
113 svg(" line.dot { stroke-dasharray: 2 4; }\n");
114 svg(" line.idle { stroke: rgb(64,64,64); stroke-dasharray: 10 6; stroke-opacity: 0.7; }\n");
116 svg(" .run { font-size: 8; font-style: italic; }\n");
117 svg(" text { font-family: Verdana, Helvetica; font-size: 10; }\n");
118 svg(" text.sec { font-size: 8; }\n");
119 svg(" text.t1 { font-size: 24; }\n");
120 svg(" text.t2 { font-size: 12; }\n");
121 svg(" text.idle { font-size: 18; }\n");
123 svg(" ]]>\n </style>\n</defs>\n\n");
130 char cmdline[256] = "";
131 char filename[PATH_MAX];
133 char rootbdev[16] = "Unknown";
134 char model[256] = "Unknown";
135 char date[256] = "Unknown";
136 char cpu[256] = "Unknown";
137 char build[256] = "Unknown";
143 /* grab /proc/cmdline */
144 f = fopen("/proc/cmdline", "r");
146 if (!fgets(cmdline, 255, f))
147 sprintf(cmdline, "Unknown");
151 /* extract root fs so we can find disk model name in sysfs */
152 c = strstr(cmdline, "root=/dev/");
154 strncpy(rootbdev, &c[10], 3);
157 sprintf(filename, "/sys/block/%s/device/model", rootbdev);
158 f = fopen(filename, "r");
160 if (!fgets(model, 255, f))
161 fprintf(stderr, "Error reading disk model for %s\n", rootbdev);
165 /* various utsname parameters */
167 fprintf(stderr, "Error getting uname info\n");
171 strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", localtime(&t));
174 f = fopen("/proc/cpuinfo", "r");
176 while (fgets(buf, 255, f)) {
177 if (strstr(buf, "model name")) {
178 strncpy(cpu, &buf[13], 255);
185 /* Build - 1st line from /etc/system-release */
186 f = fopen("/etc/system-release", "r");
188 if (fgets(buf, 255, f))
189 strncpy(build, buf, 255);
193 svg("<text class=\"t1\" x=\"0\" y=\"30\">Bootchart for %s - %s</text>\n",
195 svg("<text class=\"t2\" x=\"20\" y=\"50\">System: %s %s %s %s</text>\n",
196 uts.sysname, uts.release, uts.version, uts.machine);
197 svg("<text class=\"t2\" x=\"20\" y=\"65\">CPU: %s</text>\n",
199 svg("<text class=\"t2\" x=\"20\" y=\"80\">Disk: %s</text>\n",
201 svg("<text class=\"t2\" x=\"20\" y=\"95\">Boot options: %s</text>\n",
203 svg("<text class=\"t2\" x=\"20\" y=\"110\">Build: %s</text>\n",
205 svg("<text class=\"t2\" x=\"20\" y=\"125\">Log start time: %.03fs</text>\n", log_start);
206 svg("<text class=\"t2\" x=\"20\" y=\"140\">Idle time: ");
209 svg("%.03fs", idletime);
213 svg("<text class=\"sec\" x=\"20\" y=\"155\">Graph data: %i samples/sec, recorded %i total, dropped %i samples, %i processes, %i filtered</text>\n",
214 hz, len, overrun, pscount, pfiltered);
218 void svg_graph_box(int height)
223 /* outside box, fill */
224 svg("<rect class=\"box\" x=\"%.03f\" y=\"0\" width=\"%.03f\" height=\"%i\" />\n",
226 time_to_graph(sampletime[samples-1] - graph_start),
227 ps_to_graph(height));
229 for (d = graph_start; d <= sampletime[samples-1]; d += 0.1) {
230 /* lines for each second */
232 svg(" <line class=\"sec5\" x1=\"%.03f\" y1=\"0\" x2=\"%.03f\" y2=\"%i\" />\n",
233 time_to_graph(d - graph_start),
234 time_to_graph(d - graph_start),
235 ps_to_graph(height));
236 else if (i % 10 == 0)
237 svg(" <line class=\"sec1\" x1=\"%.03f\" y1=\"0\" x2=\"%.03f\" y2=\"%i\" />\n",
238 time_to_graph(d - graph_start),
239 time_to_graph(d - graph_start),
240 ps_to_graph(height));
242 svg(" <line class=\"sec01\" x1=\"%.03f\" y1=\"0\" x2=\"%.03f\" y2=\"%i\" />\n",
243 time_to_graph(d - graph_start),
244 time_to_graph(d - graph_start),
245 ps_to_graph(height));
249 svg(" <text class=\"sec\" x=\"%.03f\" y=\"%i\" >%.01fs</text>\n",
250 time_to_graph(d - graph_start),
259 void svg_pss_graph(void)
264 svg("\n\n<!-- Pss memory size graph -->\n");
266 svg("\n <text class=\"t2\" x=\"5\" y=\"-15\">Memory allocation - Pss</text>\n");
268 /* vsize 1000 == 1000mb */
270 /* draw some hlines for usable memory sizes */
271 for (i = 100000; i < 1000000; i += 100000) {
272 svg(" <line class=\"sec01\" x1=\"%.03f\" y1=\"%.0f\" x2=\"%.03f\" y2=\"%.0f\"/>\n",
275 time_to_graph(sampletime[samples-1] - graph_start),
277 svg(" <text class=\"sec\" x=\"%.03f\" y=\"%.0f\">%dM</text>\n",
278 time_to_graph(sampletime[samples-1] - graph_start) + 5,
279 kb_to_graph(i), (1000000 - i) / 1000);
283 /* now plot the graph itself */
284 for (i = 1; i < samples ; i++) {
291 /* put all the small pss blocks into the bottom */
292 for (p = 0; p < MAXPIDS ; p++) {
295 if (ps[p]->sample[i].pss <= (100 * scale_y))
296 top += ps[p]->sample[i].pss;
298 svg(" <rect class=\"clrw\" style=\"fill: %s\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
300 time_to_graph(sampletime[i - 1] - graph_start),
301 kb_to_graph(1000000.0 - top),
302 time_to_graph(sampletime[i] - sampletime[i - 1]),
303 kb_to_graph(top - bottom));
307 /* now plot the ones that are of significant size */
308 for (p = 0; p < MAXPIDS ; p++) {
311 /* don't draw anything smaller than 2mb */
312 if (ps[p]->sample[i].pss > (100 * scale_y)) {
313 top = bottom + ps[p]->sample[i].pss;
314 svg(" <rect class=\"clrw\" style=\"fill: %s\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
316 time_to_graph(sampletime[i - 1] - graph_start),
317 kb_to_graph(1000000.0 - top),
318 time_to_graph(sampletime[i] - sampletime[i - 1]),
319 kb_to_graph(top - bottom));
325 /* overlay all the text labels */
326 for (i = 1; i < samples ; i++) {
333 /* put all the small pss blocks into the bottom */
334 for (p = 0; p < MAXPIDS ; p++) {
337 if (ps[p]->sample[i].pss <= (100 * scale_y))
338 top += ps[p]->sample[i].pss;
343 /* now plot the ones that are of significant size */
344 for (p = 0; p < MAXPIDS ; p++) {
347 /* don't draw anything smaller than 2mb */
348 if (ps[p]->sample[i].pss > (100 * scale_y)) {
349 top = bottom + ps[p]->sample[i].pss;
350 /* draw a label with the process / PID */
351 if ((i == 1) || (ps[p]->sample[i - 1].pss <= (100 * scale_y)))
352 svg(" <text x=\"%.03f\" y=\"%.03f\">%s [%i]</text>\n",
353 time_to_graph(sampletime[i] - graph_start),
354 kb_to_graph(1000000.0 - bottom - ((top - bottom) / 2)),
362 /* debug output - full data dump */
363 svg("\n\n<!-- PSS map - csv format -->\n");
364 for (p = 0; p < MAXPIDS ; p++) {
367 svg("<!-- %s [%d] pss=", ps[p]->name, p);
368 for (i = 0; i < samples ; i++) {
369 svg("%d," , ps[p]->sample[i].pss);
376 void svg_io_bi_bar(void)
383 svg("<!-- IO utilization graph - In -->\n");
385 svg("<text class=\"t2\" x=\"5\" y=\"-15\">IO utilization - read</text>\n");
388 * calculate rounding range
390 * We need to round IO data since IO block data is not updated on
391 * each poll. Applying a smoothing function loses some burst data,
392 * so keep the smoothing range short.
394 range = 0.25 / (1.0 / hz);
396 range = 2.0; /* no smoothing */
398 /* surrounding box */
401 /* find the max IO first */
402 for (i = 1; i < samples; i++) {
407 start = max(i - ((range / 2) - 1), 0);
408 stop = min(i + (range / 2), samples - 1);
410 tot = (double)(blockstat[stop].bi - blockstat[start].bi)
416 tot = (double)(blockstat[stop].bo - blockstat[start].bo)
423 for (i = 1; i < samples; i++) {
429 start = max(i - ((range / 2) - 1), 0);
430 stop = min(i + (range / 2), samples);
432 tot = (double)(blockstat[stop].bi - blockstat[start].bi)
437 svg("<rect class=\"bi\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
438 time_to_graph(sampletime[i - 1] - graph_start),
439 (scale_y * 5) - (pbi * (scale_y * 5)),
440 time_to_graph(sampletime[i] - sampletime[i - 1]),
441 pbi * (scale_y * 5));
443 /* labels around highest value */
445 svg(" <text class=\"sec\" x=\"%.03f\" y=\"%.03f\">%0.2fmb/sec</text>\n",
446 time_to_graph(sampletime[i] - graph_start) + 5,
447 ((scale_y * 5) - (pbi * (scale_y * 5))) + 15,
448 max / 1024.0 / (interval / 1000000000.0));
453 void svg_io_bo_bar(void)
460 svg("<!-- IO utilization graph - out -->\n");
462 svg("<text class=\"t2\" x=\"5\" y=\"-15\">IO utilization - write</text>\n");
465 * calculate rounding range
467 * We need to round IO data since IO block data is not updated on
468 * each poll. Applying a smoothing function loses some burst data,
469 * so keep the smoothing range short.
471 range = 0.25 / (1.0 / hz);
473 range = 2.0; /* no smoothing */
475 /* surrounding box */
478 /* find the max IO first */
479 for (i = 1; i < samples; i++) {
484 start = max(i - ((range / 2) - 1), 0);
485 stop = min(i + (range / 2), samples - 1);
487 tot = (double)(blockstat[stop].bi - blockstat[start].bi)
491 tot = (double)(blockstat[stop].bo - blockstat[start].bo)
500 for (i = 1; i < samples; i++) {
506 start = max(i - ((range / 2) - 1), 0);
507 stop = min(i + (range / 2), samples);
509 tot = (double)(blockstat[stop].bo - blockstat[start].bo)
514 svg("<rect class=\"bo\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
515 time_to_graph(sampletime[i - 1] - graph_start),
516 (scale_y * 5) - (pbo * (scale_y * 5)),
517 time_to_graph(sampletime[i] - sampletime[i - 1]),
518 pbo * (scale_y * 5));
520 /* labels around highest bo value */
522 svg(" <text class=\"sec\" x=\"%.03f\" y=\"%.03f\">%0.2fmb/sec</text>\n",
523 time_to_graph(sampletime[i] - graph_start) + 5,
524 ((scale_y * 5) - (pbo * (scale_y * 5))),
525 max / 1024.0 / (interval / 1000000000.0));
531 void svg_cpu_bar(void)
535 svg("<!-- CPU utilization graph -->\n");
537 svg("<text class=\"t2\" x=\"5\" y=\"-15\">CPU utilization</text>\n");
538 /* surrounding box */
541 /* bars for each sample, proportional to the CPU util. */
542 for (i = 1; i < samples; i++) {
549 for (c = 0; c < cpus; c++)
550 trt += cpustat[c].sample[i].runtime - cpustat[c].sample[i - 1].runtime;
552 trt = trt / 1000000000.0;
554 trt = trt / (double)cpus;
557 ptrt = trt / (sampletime[i] - sampletime[i - 1]);
563 svg("<rect class=\"cpu\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
564 time_to_graph(sampletime[i - 1] - graph_start),
565 (scale_y * 5) - (ptrt * (scale_y * 5)),
566 time_to_graph(sampletime[i] - sampletime[i - 1]),
567 ptrt * (scale_y * 5));
572 void svg_wait_bar(void)
576 svg("<!-- Wait time aggregation box -->\n");
578 svg("<text class=\"t2\" x=\"5\" y=\"-15\">CPU wait</text>\n");
580 /* surrounding box */
583 /* bars for each sample, proportional to the CPU util. */
584 for (i = 1; i < samples; i++) {
591 for (c = 0; c < cpus; c++)
592 twt += cpustat[c].sample[i].waittime - cpustat[c].sample[i - 1].waittime;
594 twt = twt / 1000000000.0;
596 twt = twt / (double)cpus;
599 ptwt = twt / (sampletime[i] - sampletime[i - 1]);
605 svg("<rect class=\"wait\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
606 time_to_graph(sampletime[i - 1] - graph_start),
607 ((scale_y * 5) - (ptwt * (scale_y * 5))),
608 time_to_graph(sampletime[i] - sampletime[i - 1]),
609 ptwt * (scale_y * 5));
615 int get_next_ps(int start)
618 * walk the list of processes and return the next one to be
623 struct ps_struct *children;
624 struct ps_struct *siblings;
626 /* start with init [1] */
632 children = ps[here]->children;
636 here = ps[here]->children->pid;
641 siblings = ps[here]->next;
643 here = ps[here]->next->pid;
647 /* go back for parent siblings */
648 while (ps[ps[here]->ppid]) {
649 here = ps[ps[here]->ppid]->pid;
650 /* go to sibling of parent */
651 if (ps[here]->next) {
652 here = ps[here]->next->pid;
661 int ps_filter(int pid)
666 /* can't draw data when there is only 1 sample (need start + stop) */
667 if (ps[pid]->first == ps[pid]->last)
670 /* don't filter kthreadd */
674 /* drop stuff that doesn't use any real CPU time */
675 if (ps[pid]->total <= 0.001)
682 void svg_do_initcall(int count_only)
690 /* can't plot initcall when disabled or in relative mode */
691 if (!initcall || relative) {
697 svg("<!-- initcall -->\n");
699 svg("<text class=\"t2\" x=\"5\" y=\"-15\">Kernel init threads</text>\n");
700 /* surrounding box */
701 svg_graph_box(kcount);
707 * Initcall graphing - parses dmesg buffer and displays kernel threads
708 * This somewhat uses the same methods and scaling to show processes
709 * but looks a lot simpler. It's overlaid entirely onto the PS graph
713 f = popen("dmesg", "r");
722 if (fgets(l, sizeof(l) - 1, f) == NULL)
725 c = sscanf(l, "[%lf] initcall %s %*s %d %*s %d %*s",
726 &t, func, &ret, &usecs);
730 /* chop the +0xXX/0xXX stuff */
731 while(func[z] != '+')
736 /* filter out irrelevant stuff */
742 svg("<!-- thread=\"%s\" time=\"%.3f\" elapsed=\"%d\" result=\"%d\" -->\n",
743 func, t, usecs, ret);
749 svg(" <rect class=\"krnl\" x=\"%.03f\" y=\"%i\" width=\"%.03f\" height=\"%i\" />\n",
750 time_to_graph(t - (usecs / 1000000.0)),
752 time_to_graph(usecs / 1000000.0),
756 svg(" <text x=\"%.03f\" y=\"%i\">%s <tspan class=\"run\">%.03fs</tspan></text>\n",
757 time_to_graph(t - (usecs / 1000000.0)) + 5,
758 ps_to_graph(kcount) + 15,
769 void svg_ps_bars(void)
776 svg("<!-- Process graph -->\n");
778 svg("<text class=\"t2\" x=\"5\" y=\"-15\">Processes</text>\n");
780 /* surrounding box */
781 svg_graph_box(pcount);
783 /* pass 2 - ps boxes */
785 while ((i = get_next_ps(i))) {
792 /* leave some trace of what we actually filtered etc. */
793 svg("<!-- %s [%i] ppid=%i runtime=%.03fs -->\n", ps[i]->name, i,
794 ps[i]->ppid, ps[i]->total);
796 /* it would be nice if we could use exec_start from /proc/pid/sched,
797 * but it's unreliable and gives bogus numbers */
798 starttime = sampletime[ps[i]->first];
801 /* remember where _to_ our children need to draw a line */
802 ps[i]->pos_x = time_to_graph(starttime - graph_start);
803 ps[i]->pos_y = ps_to_graph(j+1); /* bottom left corner */
805 /* hook children to our parent coords instead */
806 ps[i]->pos_x = ps[ps[i]->ppid]->pos_x;
807 ps[i]->pos_y = ps[ps[i]->ppid]->pos_y;
809 /* if this is the last child, we might still need to draw a connecting line */
810 if ((!ps[i]->next) && (ps[ps[i]->ppid]))
811 svg(" <line class=\"dot\" x1=\"%.03f\" y1=\"%i\" x2=\"%.03f\" y2=\"%.03f\" />\n",
812 ps[ps[i]->ppid]->pos_x,
813 ps_to_graph(j-1) + 10, /* whee, use the last value here */
814 ps[ps[i]->ppid]->pos_x,
815 ps[ps[i]->ppid]->pos_y);
819 svg(" <rect class=\"ps\" x=\"%.03f\" y=\"%i\" width=\"%.03f\" height=\"%i\" />\n",
820 time_to_graph(starttime - graph_start),
822 time_to_graph(sampletime[ps[i]->last] - starttime),
825 /* paint cpu load over these */
826 for (t = ps[i]->first + 1; t < ps[i]->last; t++) {
830 /* calculate over interval */
831 rt = ps[i]->sample[t].runtime - ps[i]->sample[t-1].runtime;
832 wt = ps[i]->sample[t].waittime - ps[i]->sample[t-1].waittime;
834 prt = (rt / 1000000000) / (sampletime[t] - sampletime[t-1]);
835 wrt = (wt / 1000000000) / (sampletime[t] - sampletime[t-1]);
837 /* this can happen if timekeeping isn't accurate enough */
843 if ((prt < 0.1) && (wrt < 0.1)) /* =~ 26 (color threshold) */
846 svg(" <rect class=\"wait\" x=\"%.03f\" y=\"%i\" width=\"%.03f\" height=\"%.03f\" />\n",
847 time_to_graph(sampletime[t - 1] - graph_start),
849 time_to_graph(sampletime[t] - sampletime[t - 1]),
852 /* draw cpu over wait - TODO figure out how/why run + wait > interval */
853 svg(" <rect class=\"cpu\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
854 time_to_graph(sampletime[t - 1] - graph_start),
855 ps_to_graph(j + (1.0 - prt)),
856 time_to_graph(sampletime[t] - sampletime[t - 1]),
860 /* determine where to display the process name */
861 if (sampletime[ps[i]->last] - sampletime[ps[i]->first] < 1.5)
862 /* too small to fit label inside the box */
867 /* text label of process name */
868 svg(" <text x=\"%.03f\" y=\"%i\">%s [%i] <tspan class=\"run\">%.03fs</tspan></text>\n",
869 time_to_graph(sampletime[wt] - graph_start) + 5,
873 (ps[i]->sample[ps[i]->last].runtime - ps[i]->sample[ps[i]->first].runtime) / 1000000000.0);
875 /* paint lines to the parent process */
876 if (ps[ps[i]->ppid]) {
877 /* horizontal part */
878 svg(" <line class=\"dot\" x1=\"%.03f\" y1=\"%i\" x2=\"%.03f\" y2=\"%i\" />\n",
879 time_to_graph(starttime - graph_start),
881 ps[ps[i]->ppid]->pos_x,
882 ps_to_graph(j) + 10);
884 /* one vertical line connecting all the horizontal ones up */
886 svg(" <line class=\"dot\" x1=\"%.03f\" y1=\"%i\" x2=\"%.03f\" y2=\"%.03f\" />\n",
887 ps[ps[i]->ppid]->pos_x,
889 ps[ps[i]->ppid]->pos_x,
890 ps[ps[i]->ppid]->pos_y);
893 j++; /* count boxes */
898 /* last pass - determine when idle */
900 /* make sure we start counting from the point where we actually have
901 * data: assume that bootchart's first sample is when data started
903 for (i = ps[pid]->first; i < samples - (hz / 2); i++) {
908 /* subtract bootchart cpu utilization from total */
910 for (c = 0; c < cpus; c++)
911 crt += cpustat[c].sample[i + (hz / 2)].runtime - cpustat[c].sample[i].runtime;
912 brt = ps[pid]->sample[i + (hz / 2)].runtime - ps[pid]->sample[i].runtime;
915 * our definition of "idle":
917 * if for (hz / 2) we've used less CPU than (interval / 2) ...
918 * defaults to 4.0%, which experimentally, is where atom idles
920 if ((crt - brt) < (interval / 2)) {
921 idletime = sampletime[i] - graph_start;
922 svg("\n<!-- idle detected at %.03f seconds -->\n",
924 svg("<line class=\"idle\" x1=\"%.03f\" y1=\"%i\" x2=\"%.03f\" y2=\"%i\" />\n",
925 time_to_graph(idletime),
927 time_to_graph(idletime),
928 ps_to_graph(pcount) + scale_y);
929 svg("<text class=\"idle\" x=\"%.03f\" y=\"%i\">%.01fs</text>\n",
930 time_to_graph(idletime) + 5,
931 ps_to_graph(pcount) + scale_y,
939 void svg_top_ten_cpu(void)
941 struct ps_struct *top[10];
942 struct ps_struct emptyps;
945 memset(&emptyps, 0, sizeof(emptyps));
946 for (n=0; n < 10; n++)
949 /* walk all ps's and setup ptrs */
951 while ((i = get_next_ps(i))) {
952 for (n = 0; n < 10; n++) {
953 if (ps[i]->total <= top[n]->total)
956 for (m = 9; m > n; m--)
963 svg("<text class=\"t2\" x=\"20\" y=\"0\">Top CPU consumers:</text>\n");
964 for (n = 0; n < 10; n++)
965 svg("<text class=\"t3\" x=\"20\" y=\"%d\">%3.03fs - %s[%d]</text>\n",
973 void svg_top_ten_pss(void)
975 struct ps_struct *top[10];
976 struct ps_struct emptyps;
979 memset(&emptyps, 0, sizeof(emptyps));
980 for (n=0; n < 10; n++)
983 /* walk all ps's and setup ptrs */
985 while ((i = get_next_ps(i))) {
986 for (n = 0; n < 10; n++) {
987 if (ps[i]->pss_max <= top[n]->pss_max)
990 for (m = 9; m > n; m--)
997 svg("<text class=\"t2\" x=\"20\" y=\"0\">Top PSS consumers:</text>\n");
998 for (n = 0; n < 10; n++)
999 svg("<text class=\"t3\" x=\"20\" y=\"%d\">%dK - %s[%d]</text>\n",
1011 memset(&str, 0, sizeof(str));
1013 /* count initcall thread count first */
1015 ksize = (kcount ? ps_to_graph(kcount) + (scale_y * 2) : 0);
1017 /* then count processes */
1018 while ((i = get_next_ps(i))) {
1024 psize = ps_to_graph(pcount) + (scale_y * 2);
1026 /* after this, we can draw the header with proper sizing */
1029 svg("<g transform=\"translate(10,400)\">\n");
1033 svg("<g transform=\"translate(10,%d)\">\n", 400 + (scale_y * 7));
1037 svg("<g transform=\"translate(10,%d)\">\n", 400 + (scale_y * 14));
1041 svg("<g transform=\"translate(10,%d)\">\n", 400 + (scale_y * 21));
1046 svg("<g transform=\"translate(10,%d)\">\n", 400 + (scale_y * 28));
1051 svg("<g transform=\"translate(10,%d)\">\n", 400 + (scale_y * 28) + ksize);
1055 svg("<g transform=\"translate(10, 0)\">\n");
1059 svg("<g transform=\"translate(10,200)\">\n");
1064 svg("<g transform=\"translate(10,%d)\">\n", 400 + (scale_y * 28) + ksize + psize);
1068 svg("<g transform=\"translate(410,200)\">\n");