static void draw_process_bars(void) { struct per_pid *p; struct per_pidcomm *c; struct cpu_sample *sample; int Y = 0; Y = 2 * numcpus + 2; p = all_data; while (p) { c = p->all; while (c) { if (!c->display) { c->Y = 0; c = c->next; continue; } svg_box(Y, c->start_time, c->end_time, "process"); sample = c->samples; while (sample) { if (sample->type == TYPE_RUNNING) svg_sample(Y, sample->cpu, sample->start_time, sample->end_time); if (sample->type == TYPE_BLOCKED) svg_box(Y, sample->start_time, sample->end_time, "blocked"); if (sample->type == TYPE_WAITING) svg_waiting(Y, sample->start_time, sample->end_time); sample = sample->next; } if (c->comm) { char comm[256]; if (c->total_time > 5000000000) /* 5 seconds */ sprintf(comm, "%s:%i (%2.2fs)", c->comm, p->pid, c->total_time / 1000000000.0); else sprintf(comm, "%s:%i (%3.1fms)", c->comm, p->pid, c->total_time / 1000000.0); svg_text(Y, c->start_time, comm); } c->Y = Y; Y++; c = c->next; } p = p->next; } }
static int analyze_plot(sd_bus *bus) { struct unit_times *times; struct boot_times *boot; struct utsname name; int n, m = 1, y=0; double width; _cleanup_free_ char *pretty_times = NULL, *osname = NULL; struct unit_times *u; n = acquire_boot_times(bus, &boot); if (n < 0) return n; n = pretty_boot_time(bus, &pretty_times); if (n < 0) return n; get_os_name(&osname); assert_se(uname(&name) >= 0); n = acquire_time_data(bus, ×); if (n <= 0) return n; qsort(times, n, sizeof(struct unit_times), compare_unit_start); width = SCALE_X * (boot->firmware_time + boot->finish_time); if (width < 800.0) width = 800.0; if (boot->firmware_time > boot->loader_time) m++; if (boot->loader_time) { m++; if (width < 1000.0) width = 1000.0; } if (boot->initrd_time) m++; if (boot->kernel_time) m++; for (u = times; u < times + n; u++) { double text_start, text_width; if (u->activating < boot->userspace_time || u->activating > boot->finish_time) { free(u->name); u->name = NULL; continue; } /* If the text cannot fit on the left side then * increase the svg width so it fits on the right. * TODO: calculate the text width more accurately */ text_width = 8.0 * strlen(u->name); text_start = (boot->firmware_time + u->activating) * SCALE_X; if (text_width > text_start && text_width + text_start > width) width = text_width + text_start; if (u->deactivated > u->activating && u->deactivated <= boot->finish_time && u->activated == 0 && u->deactivating == 0) u->activated = u->deactivating = u->deactivated; if (u->activated < u->activating || u->activated > boot->finish_time) u->activated = boot->finish_time; if (u->deactivating < u->activated || u->activated > boot->finish_time) u->deactivating = boot->finish_time; if (u->deactivated < u->deactivating || u->deactivated > boot->finish_time) u->deactivated = boot->finish_time; m++; } svg("<?xml version=\"1.0\" standalone=\"no\"?>\n" "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" " "\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"); svg("<svg width=\"%.0fpx\" height=\"%.0fpx\" version=\"1.1\" " "xmlns=\"http://www.w3.org/2000/svg\">\n\n", 80.0 + width, 150.0 + (m * SCALE_Y) + 5 * SCALE_Y /* legend */); /* write some basic info as a comment, including some help */ svg("<!-- This file is a systemd-analyze SVG file. It is best rendered in a -->\n" "<!-- browser such as Chrome, Chromium or Firefox. Other applications -->\n" "<!-- that render these files properly but much slower are ImageMagick, -->\n" "<!-- gimp, inkscape, etc. To display the files on your system, just -->\n" "<!-- point your browser to this file. -->\n\n" "<!-- This plot was generated by systemd-analyze version %-16.16s -->\n\n", VERSION); /* style sheet */ svg("<defs>\n <style type=\"text/css\">\n <![CDATA[\n" " rect { stroke-width: 1; stroke-opacity: 0; }\n" " rect.background { fill: rgb(255,255,255); }\n" " rect.activating { fill: rgb(255,0,0); fill-opacity: 0.7; }\n" " rect.active { fill: rgb(200,150,150); fill-opacity: 0.7; }\n" " rect.deactivating { fill: rgb(150,100,100); fill-opacity: 0.7; }\n" " rect.kernel { fill: rgb(150,150,150); fill-opacity: 0.7; }\n" " rect.initrd { fill: rgb(150,150,150); fill-opacity: 0.7; }\n" " rect.firmware { fill: rgb(150,150,150); fill-opacity: 0.7; }\n" " rect.loader { fill: rgb(150,150,150); fill-opacity: 0.7; }\n" " rect.userspace { fill: rgb(150,150,150); fill-opacity: 0.7; }\n" " rect.security { fill: rgb(144,238,144); fill-opacity: 0.7; }\n" " rect.generators { fill: rgb(102,204,255); fill-opacity: 0.7; }\n" " rect.unitsload { fill: rgb( 82,184,255); fill-opacity: 0.7; }\n" " rect.box { fill: rgb(240,240,240); stroke: rgb(192,192,192); }\n" " line { stroke: rgb(64,64,64); stroke-width: 1; }\n" "// line.sec1 { }\n" " line.sec5 { stroke-width: 2; }\n" " line.sec01 { stroke: rgb(224,224,224); stroke-width: 1; }\n" " text { font-family: Verdana, Helvetica; font-size: 14px; }\n" " text.left { font-family: Verdana, Helvetica; font-size: 14px; text-anchor: start; }\n" " text.right { font-family: Verdana, Helvetica; font-size: 14px; text-anchor: end; }\n" " text.sec { font-size: 10px; }\n" " ]]>\n </style>\n</defs>\n\n"); svg("<rect class=\"background\" width=\"100%%\" height=\"100%%\" />\n"); svg("<text x=\"20\" y=\"50\">%s</text>", pretty_times); svg("<text x=\"20\" y=\"30\">%s %s (%s %s) %s</text>", isempty(osname) ? "Linux" : osname, name.nodename, name.release, name.version, name.machine); svg("<g transform=\"translate(%.3f,100)\">\n", 20.0 + (SCALE_X * boot->firmware_time)); svg_graph_box(m, -boot->firmware_time, boot->finish_time); if (boot->firmware_time) { svg_bar("firmware", -(double) boot->firmware_time, -(double) boot->loader_time, y); svg_text(true, -(double) boot->firmware_time, y, "firmware"); y++; } if (boot->loader_time) { svg_bar("loader", -(double) boot->loader_time, 0, y); svg_text(true, -(double) boot->loader_time, y, "loader"); y++; } if (boot->kernel_time) { svg_bar("kernel", 0, boot->kernel_done_time, y); svg_text(true, 0, y, "kernel"); y++; } if (boot->initrd_time) { svg_bar("initrd", boot->initrd_time, boot->userspace_time, y); svg_text(true, boot->initrd_time, y, "initrd"); y++; } svg_bar("active", boot->userspace_time, boot->finish_time, y); svg_bar("security", boot->security_start_time, boot->security_finish_time, y); svg_bar("generators", boot->generators_start_time, boot->generators_finish_time, y); svg_bar("unitsload", boot->unitsload_start_time, boot->unitsload_finish_time, y); svg_text(true, boot->userspace_time, y, "systemd"); y++; for (u = times; u < times + n; u++) { char ts[FORMAT_TIMESPAN_MAX]; bool b; if (!u->name) continue; svg_bar("activating", u->activating, u->activated, y); svg_bar("active", u->activated, u->deactivating, y); svg_bar("deactivating", u->deactivating, u->deactivated, y); /* place the text on the left if we have passed the half of the svg width */ b = u->activating * SCALE_X < width / 2; if (u->time) svg_text(b, u->activating, y, "%s (%s)", u->name, format_timespan(ts, sizeof(ts), u->time, USEC_PER_MSEC)); else svg_text(b, u->activating, y, "%s", u->name); y++; } /* Legend */ y++; svg_bar("activating", 0, 300000, y); svg_text(true, 400000, y, "Activating"); y++; svg_bar("active", 0, 300000, y); svg_text(true, 400000, y, "Active"); y++; svg_bar("deactivating", 0, 300000, y); svg_text(true, 400000, y, "Deactivating"); y++; svg_bar("security", 0, 300000, y); svg_text(true, 400000, y, "Setting up security module"); y++; svg_bar("generators", 0, 300000, y); svg_text(true, 400000, y, "Generators"); y++; svg_bar("unitsload", 0, 300000, y); svg_text(true, 400000, y, "Loading unit files"); y++; svg("</g>\n\n"); svg("</svg>\n"); free_unit_times(times, (unsigned) n); return 0; }