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"
29 #define time_to_graph(t) ((t) * scale_x)
30 #define ps_to_graph(n) ((n) * scale_y)
31 #define kb_to_graph(m) ((m) * scale_y * 0.0001)
32 #define to_color(n) (192.0 - ((n) * 192.0))
34 #define max(x, y) (((x) > (y)) ? (x) : (y))
35 #define min(x, y) (((x) < (y)) ? (x) : (y))
37 static char str[8092];
39 #define svg(a...) do { snprintf(str, 8092, ## a); fputs(str, of); fflush(of); } while (0)
41 static const char *colorwheel[12] = {
42 "rgb(255,32,32)", // red
43 "rgb(32,192,192)", // cyan
44 "rgb(255,128,32)", // orange
45 "rgb(128,32,192)", // blue-violet
46 "rgb(255,255,32)", // yellow
47 "rgb(192,32,128)", // red-violet
48 "rgb(32,255,32)", // green
49 "rgb(255,64,32)", // red-orange
50 "rgb(32,32,255)", // blue
51 "rgb(255,192,32)", // yellow-orange
52 "rgb(192,32,192)", // violet
53 "rgb(32,192,32)" // yellow-green
56 static double idletime = -1.0;
57 static int pfiltered = 0;
58 static int pcount = 0;
59 static int kcount = 0;
60 static float psize = 0;
61 static float ksize = 0;
62 static float esize = 0;
65 static void svg_header(void)
70 /* min width is about 1600px due to the label */
71 w = 150.0 + 10.0 + time_to_graph(sampletime[samples-1] - graph_start);
72 w = ((w < 1600.0) ? 1600.0 : w);
74 /* height is variable based on pss, psize, ksize */
75 h = 400.0 + (scale_y * 30.0) /* base graphs and title */
76 + (pss ? (100.0 * scale_y) + (scale_y * 7.0) : 0.0) /* pss estimate */
77 + psize + ksize + esize;
79 svg("<?xml version=\"1.0\" standalone=\"no\"?>\n");
80 svg("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" ");
81 svg("\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n");
83 //svg("<g transform=\"translate(10,%d)\">\n", 1000 + 150 + (pcount * 20));
84 svg("<svg width=\"%.0fpx\" height=\"%.0fpx\" version=\"1.1\" ",
86 svg("xmlns=\"http://www.w3.org/2000/svg\">\n\n");
88 /* write some basic info as a comment, including some help */
89 svg("<!-- This file is a bootchart SVG file. It is best rendered in a browser -->\n");
90 svg("<!-- such as Chrome/Chromium, firefox. Other applications that render -->\n");
91 svg("<!-- these files properly but much more slow are ImageMagick, gimp, -->\n");
92 svg("<!-- inkscape, etc.. To display the files on your system, just point -->\n");
93 svg("<!-- your browser to file:///var/log/ and click. This bootchart was -->\n\n");
95 svg("<!-- generated by bootchart version %s, running with options: -->\n", VERSION);
96 svg("<!-- hz=\"%f\" n=\"%d\" -->\n", hz, len);
97 svg("<!-- x=\"%f\" y=\"%f\" -->\n", scale_x, scale_y);
98 svg("<!-- rel=\"%d\" f=\"%d\" -->\n", relative, filter);
99 svg("<!-- p=\"%d\" e=\"%d\" -->\n", pss, entropy);
100 svg("<!-- o=\"%s\" i=\"%s\" -->\n\n", output_path, init_path);
103 svg("<defs>\n <style type=\"text/css\">\n <![CDATA[\n");
105 svg(" rect { stroke-width: 1; }\n");
106 svg(" rect.cpu { fill: rgb(64,64,240); stroke-width: 0; fill-opacity: 0.7; }\n");
107 svg(" rect.wait { fill: rgb(240,240,0); stroke-width: 0; fill-opacity: 0.7; }\n");
108 svg(" rect.bi { fill: rgb(240,128,128); stroke-width: 0; fill-opacity: 0.7; }\n");
109 svg(" rect.bo { fill: rgb(192,64,64); stroke-width: 0; fill-opacity: 0.7; }\n");
110 svg(" rect.ps { fill: rgb(192,192,192); stroke: rgb(128,128,128); fill-opacity: 0.7; }\n");
111 svg(" rect.krnl { fill: rgb(240,240,0); stroke: rgb(128,128,128); fill-opacity: 0.7; }\n");
112 svg(" rect.box { fill: rgb(240,240,240); stroke: rgb(192,192,192); }\n");
113 svg(" rect.clrw { stroke-width: 0; fill-opacity: 0.7;}\n");
114 svg(" line { stroke: rgb(64,64,64); stroke-width: 1; }\n");
115 svg("// line.sec1 { }\n");
116 svg(" line.sec5 { stroke-width: 2; }\n");
117 svg(" line.sec01 { stroke: rgb(224,224,224); stroke-width: 1; }\n");
118 svg(" line.dot { stroke-dasharray: 2 4; }\n");
119 svg(" line.idle { stroke: rgb(64,64,64); stroke-dasharray: 10 6; stroke-opacity: 0.7; }\n");
121 svg(" .run { font-size: 8; font-style: italic; }\n");
122 svg(" text { font-family: Verdana, Helvetica; font-size: 10; }\n");
123 svg(" text.sec { font-size: 8; }\n");
124 svg(" text.t1 { font-size: 24; }\n");
125 svg(" text.t2 { font-size: 12; }\n");
126 svg(" text.idle { font-size: 18; }\n");
128 svg(" ]]>\n </style>\n</defs>\n\n");
133 static void svg_title(void)
135 char cmdline[256] = "";
136 char filename[PATH_MAX];
138 char rootbdev[16] = "Unknown";
139 char model[256] = "Unknown";
140 char date[256] = "Unknown";
141 char cpu[256] = "Unknown";
142 char build[256] = "Unknown";
148 /* grab /proc/cmdline */
149 f = fopen("/proc/cmdline", "r");
151 if (!fgets(cmdline, 255, f))
152 sprintf(cmdline, "Unknown");
156 /* extract root fs so we can find disk model name in sysfs */
157 c = strstr(cmdline, "root=/dev/");
159 strncpy(rootbdev, &c[10], 3);
162 sprintf(filename, "/sys/block/%s/device/model", rootbdev);
163 f = fopen(filename, "r");
165 if (!fgets(model, 255, f))
166 fprintf(stderr, "Error reading disk model for %s\n", rootbdev);
170 /* various utsname parameters */
172 fprintf(stderr, "Error getting uname info\n");
176 strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", localtime(&t));
179 f = fopen("/proc/cpuinfo", "r");
181 while (fgets(buf, 255, f)) {
182 if (strstr(buf, "model name")) {
183 strncpy(cpu, &buf[13], 255);
190 /* Build - 1st line from /etc/system-release */
191 f = fopen("/etc/system-release", "r");
193 if (fgets(buf, 255, f))
194 strncpy(build, buf, 255);
198 svg("<text class=\"t1\" x=\"0\" y=\"30\">Bootchart for %s - %s</text>\n",
200 svg("<text class=\"t2\" x=\"20\" y=\"50\">System: %s %s %s %s</text>\n",
201 uts.sysname, uts.release, uts.version, uts.machine);
202 svg("<text class=\"t2\" x=\"20\" y=\"65\">CPU: %s</text>\n",
204 svg("<text class=\"t2\" x=\"20\" y=\"80\">Disk: %s</text>\n",
206 svg("<text class=\"t2\" x=\"20\" y=\"95\">Boot options: %s</text>\n",
208 svg("<text class=\"t2\" x=\"20\" y=\"110\">Build: %s</text>\n",
210 svg("<text class=\"t2\" x=\"20\" y=\"125\">Log start time: %.03fs</text>\n", log_start);
211 svg("<text class=\"t2\" x=\"20\" y=\"140\">Idle time: ");
214 svg("%.03fs", idletime);
218 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",
219 hz, len, overrun, pscount, pfiltered);
223 static void svg_graph_box(int height)
228 /* outside box, fill */
229 svg("<rect class=\"box\" x=\"%.03f\" y=\"0\" width=\"%.03f\" height=\"%.03f\" />\n",
231 time_to_graph(sampletime[samples-1] - graph_start),
232 ps_to_graph(height));
234 for (d = graph_start; d <= sampletime[samples-1];
235 d += (scale_x < 2.0 ? 60.0 : scale_x < 10.0 ? 1.0 : 0.1)) {
236 /* lines for each second */
238 svg(" <line class=\"sec5\" x1=\"%.03f\" y1=\"0\" x2=\"%.03f\" y2=\"%.03f\" />\n",
239 time_to_graph(d - graph_start),
240 time_to_graph(d - graph_start),
241 ps_to_graph(height));
242 else if (i % 10 == 0)
243 svg(" <line class=\"sec1\" x1=\"%.03f\" y1=\"0\" x2=\"%.03f\" y2=\"%.03f\" />\n",
244 time_to_graph(d - graph_start),
245 time_to_graph(d - graph_start),
246 ps_to_graph(height));
248 svg(" <line class=\"sec01\" x1=\"%.03f\" y1=\"0\" x2=\"%.03f\" y2=\"%.03f\" />\n",
249 time_to_graph(d - graph_start),
250 time_to_graph(d - graph_start),
251 ps_to_graph(height));
255 svg(" <text class=\"sec\" x=\"%.03f\" y=\"%.03f\" >%.01fs</text>\n",
256 time_to_graph(d - graph_start),
265 static void svg_pss_graph(void)
267 struct ps_struct *ps;
270 svg("\n\n<!-- Pss memory size graph -->\n");
272 svg("\n <text class=\"t2\" x=\"5\" y=\"-15\">Memory allocation - Pss</text>\n");
274 /* vsize 1000 == 1000mb */
276 /* draw some hlines for usable memory sizes */
277 for (i = 100000; i < 1000000; i += 100000) {
278 svg(" <line class=\"sec01\" x1=\"%.03f\" y1=\"%.0f\" x2=\"%.03f\" y2=\"%.0f\"/>\n",
281 time_to_graph(sampletime[samples-1] - graph_start),
283 svg(" <text class=\"sec\" x=\"%.03f\" y=\"%.0f\">%dM</text>\n",
284 time_to_graph(sampletime[samples-1] - graph_start) + 5,
285 kb_to_graph(i), (1000000 - i) / 1000);
289 /* now plot the graph itself */
290 for (i = 1; i < samples ; i++) {
297 /* put all the small pss blocks into the bottom */
299 while (ps->next_ps) {
303 if (ps->sample[i].pss <= (100 * scale_y))
304 top += ps->sample[i].pss;
306 svg(" <rect class=\"clrw\" style=\"fill: %s\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
308 time_to_graph(sampletime[i - 1] - graph_start),
309 kb_to_graph(1000000.0 - top),
310 time_to_graph(sampletime[i] - sampletime[i - 1]),
311 kb_to_graph(top - bottom));
315 /* now plot the ones that are of significant size */
317 while (ps->next_ps) {
321 /* don't draw anything smaller than 2mb */
322 if (ps->sample[i].pss > (100 * scale_y)) {
323 top = bottom + ps->sample[i].pss;
324 svg(" <rect class=\"clrw\" style=\"fill: %s\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
325 colorwheel[ps->pid % 12],
326 time_to_graph(sampletime[i - 1] - graph_start),
327 kb_to_graph(1000000.0 - top),
328 time_to_graph(sampletime[i] - sampletime[i - 1]),
329 kb_to_graph(top - bottom));
335 /* overlay all the text labels */
336 for (i = 1; i < samples ; i++) {
343 /* put all the small pss blocks into the bottom */
345 while (ps->next_ps) {
349 if (ps->sample[i].pss <= (100 * scale_y))
350 top += ps->sample[i].pss;
355 /* now plot the ones that are of significant size */
357 while (ps->next_ps) {
361 /* don't draw anything smaller than 2mb */
362 if (ps->sample[i].pss > (100 * scale_y)) {
363 top = bottom + ps->sample[i].pss;
364 /* draw a label with the process / PID */
365 if ((i == 1) || (ps->sample[i - 1].pss <= (100 * scale_y)))
366 svg(" <text x=\"%.03f\" y=\"%.03f\">%s [%i]</text>\n",
367 time_to_graph(sampletime[i] - graph_start),
368 kb_to_graph(1000000.0 - bottom - ((top - bottom) / 2)),
376 /* debug output - full data dump */
377 svg("\n\n<!-- PSS map - csv format -->\n");
379 while (ps->next_ps) {
383 svg("<!-- %s [%d] pss=", ps->name, ps->pid);
384 for (i = 0; i < samples ; i++) {
385 svg("%d," , ps->sample[i].pss);
392 static void svg_io_bi_bar(void)
399 svg("<!-- IO utilization graph - In -->\n");
401 svg("<text class=\"t2\" x=\"5\" y=\"-15\">IO utilization - read</text>\n");
404 * calculate rounding range
406 * We need to round IO data since IO block data is not updated on
407 * each poll. Applying a smoothing function loses some burst data,
408 * so keep the smoothing range short.
410 range = 0.25 / (1.0 / hz);
412 range = 2.0; /* no smoothing */
414 /* surrounding box */
417 /* find the max IO first */
418 for (i = 1; i < samples; i++) {
423 start = max(i - ((range / 2) - 1), 0);
424 stop = min(i + (range / 2), samples - 1);
426 tot = (double)(blockstat[stop].bi - blockstat[start].bi)
432 tot = (double)(blockstat[stop].bo - blockstat[start].bo)
439 for (i = 1; i < samples; i++) {
445 start = max(i - ((range / 2) - 1), 0);
446 stop = min(i + (range / 2), samples);
448 tot = (double)(blockstat[stop].bi - blockstat[start].bi)
453 svg("<rect class=\"bi\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
454 time_to_graph(sampletime[i - 1] - graph_start),
455 (scale_y * 5) - (pbi * (scale_y * 5)),
456 time_to_graph(sampletime[i] - sampletime[i - 1]),
457 pbi * (scale_y * 5));
459 /* labels around highest value */
461 svg(" <text class=\"sec\" x=\"%.03f\" y=\"%.03f\">%0.2fmb/sec</text>\n",
462 time_to_graph(sampletime[i] - graph_start) + 5,
463 ((scale_y * 5) - (pbi * (scale_y * 5))) + 15,
464 max / 1024.0 / (interval / 1000000000.0));
469 static void svg_io_bo_bar(void)
476 svg("<!-- IO utilization graph - out -->\n");
478 svg("<text class=\"t2\" x=\"5\" y=\"-15\">IO utilization - write</text>\n");
481 * calculate rounding range
483 * We need to round IO data since IO block data is not updated on
484 * each poll. Applying a smoothing function loses some burst data,
485 * so keep the smoothing range short.
487 range = 0.25 / (1.0 / hz);
489 range = 2.0; /* no smoothing */
491 /* surrounding box */
494 /* find the max IO first */
495 for (i = 1; i < samples; i++) {
500 start = max(i - ((range / 2) - 1), 0);
501 stop = min(i + (range / 2), samples - 1);
503 tot = (double)(blockstat[stop].bi - blockstat[start].bi)
507 tot = (double)(blockstat[stop].bo - blockstat[start].bo)
516 for (i = 1; i < samples; i++) {
522 start = max(i - ((range / 2) - 1), 0);
523 stop = min(i + (range / 2), samples);
525 tot = (double)(blockstat[stop].bo - blockstat[start].bo)
530 svg("<rect class=\"bo\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
531 time_to_graph(sampletime[i - 1] - graph_start),
532 (scale_y * 5) - (pbo * (scale_y * 5)),
533 time_to_graph(sampletime[i] - sampletime[i - 1]),
534 pbo * (scale_y * 5));
536 /* labels around highest bo value */
538 svg(" <text class=\"sec\" x=\"%.03f\" y=\"%.03f\">%0.2fmb/sec</text>\n",
539 time_to_graph(sampletime[i] - graph_start) + 5,
540 ((scale_y * 5) - (pbo * (scale_y * 5))),
541 max / 1024.0 / (interval / 1000000000.0));
547 static void svg_cpu_bar(void)
551 svg("<!-- CPU utilization graph -->\n");
553 svg("<text class=\"t2\" x=\"5\" y=\"-15\">CPU utilization</text>\n");
554 /* surrounding box */
557 /* bars for each sample, proportional to the CPU util. */
558 for (i = 1; i < samples; i++) {
565 for (c = 0; c < cpus; c++)
566 trt += cpustat[c].sample[i].runtime - cpustat[c].sample[i - 1].runtime;
568 trt = trt / 1000000000.0;
570 trt = trt / (double)cpus;
573 ptrt = trt / (sampletime[i] - sampletime[i - 1]);
579 svg("<rect class=\"cpu\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
580 time_to_graph(sampletime[i - 1] - graph_start),
581 (scale_y * 5) - (ptrt * (scale_y * 5)),
582 time_to_graph(sampletime[i] - sampletime[i - 1]),
583 ptrt * (scale_y * 5));
588 static void svg_wait_bar(void)
592 svg("<!-- Wait time aggregation box -->\n");
594 svg("<text class=\"t2\" x=\"5\" y=\"-15\">CPU wait</text>\n");
596 /* surrounding box */
599 /* bars for each sample, proportional to the CPU util. */
600 for (i = 1; i < samples; i++) {
607 for (c = 0; c < cpus; c++)
608 twt += cpustat[c].sample[i].waittime - cpustat[c].sample[i - 1].waittime;
610 twt = twt / 1000000000.0;
612 twt = twt / (double)cpus;
615 ptwt = twt / (sampletime[i] - sampletime[i - 1]);
621 svg("<rect class=\"wait\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
622 time_to_graph(sampletime[i - 1] - graph_start),
623 ((scale_y * 5) - (ptwt * (scale_y * 5))),
624 time_to_graph(sampletime[i] - sampletime[i - 1]),
625 ptwt * (scale_y * 5));
631 static void svg_entropy_bar(void)
635 svg("<!-- entropy pool graph -->\n");
637 svg("<text class=\"t2\" x=\"5\" y=\"-15\">Entropy pool size</text>\n");
638 /* surrounding box */
641 /* bars for each sample, scale 0-4096 */
642 for (i = 1; i < samples; i++) {
643 /* svg("<!-- entropy %.03f %i -->\n", sampletime[i], entropy_avail[i]); */
644 svg("<rect class=\"cpu\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
645 time_to_graph(sampletime[i - 1] - graph_start),
646 ((scale_y * 5) - ((entropy_avail[i] / 4096.) * (scale_y * 5))),
647 time_to_graph(sampletime[i] - sampletime[i - 1]),
648 (entropy_avail[i] / 4096.) * (scale_y * 5));
653 static struct ps_struct *get_next_ps(struct ps_struct *ps)
656 * walk the list of processes and return the next one to be
670 /* go back for parent siblings */
673 if (ps->parent->next)
674 return ps->parent->next;
684 static int ps_filter(struct ps_struct *ps)
689 /* can't draw data when there is only 1 sample (need start + stop) */
690 if (ps->first == ps->last)
693 /* don't filter kthreadd */
697 /* drop stuff that doesn't use any real CPU time */
698 if (ps->total <= 0.001)
705 static void svg_do_initcall(int count_only)
707 FILE _cleanup_pclose_ *f = NULL;
713 /* can't plot initcall when disabled or in relative mode */
714 if (!initcall || relative) {
720 svg("<!-- initcall -->\n");
722 svg("<text class=\"t2\" x=\"5\" y=\"-15\">Kernel init threads</text>\n");
723 /* surrounding box */
724 svg_graph_box(kcount);
730 * Initcall graphing - parses dmesg buffer and displays kernel threads
731 * This somewhat uses the same methods and scaling to show processes
732 * but looks a lot simpler. It's overlaid entirely onto the PS graph
736 f = popen("dmesg", "r");
745 if (fgets(l, sizeof(l) - 1, f) == NULL)
748 c = sscanf(l, "[%lf] initcall %s %*s %d %*s %d %*s",
749 &t, func, &ret, &usecs);
751 /* also parse initcalls done by module loading */
752 c = sscanf(l, "[%lf] initcall %s %*s %*s %d %*s %d %*s",
753 &t, func, &ret, &usecs);
758 /* chop the +0xXX/0xXX stuff */
759 while(func[z] != '+')
764 /* filter out irrelevant stuff */
770 svg("<!-- thread=\"%s\" time=\"%.3f\" elapsed=\"%d\" result=\"%d\" -->\n",
771 func, t, usecs, ret);
777 svg(" <rect class=\"krnl\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
778 time_to_graph(t - (usecs / 1000000.0)),
780 time_to_graph(usecs / 1000000.0),
784 svg(" <text x=\"%.03f\" y=\"%.03f\">%s <tspan class=\"run\">%.03fs</tspan></text>\n",
785 time_to_graph(t - (usecs / 1000000.0)) + 5,
786 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");