X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fbootchart%2Fsvg.c;h=9fee810795b30afb471d4a6fc40a54cba622aed1;hp=156918a94bf7f79e865b0f2dda57ead92f7e795f;hb=1f3523baf7418adf3b2738b3917ef956a8414ab7;hpb=28989b63f5e3a959557000f21f3891af08be40f7 diff --git a/src/bootchart/svg.c b/src/bootchart/svg.c index 156918a94..9fee81079 100644 --- a/src/bootchart/svg.c +++ b/src/bootchart/svg.c @@ -1,16 +1,24 @@ -/* - * svg.c - * - * Copyright (C) 2009-2012 Intel Coproration - * - * Authors: - * Auke Kok - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; version 2 - * of the License. - */ +/*** + bootchart.c - This file is part of systemd-bootchart + + Copyright (C) 2009-2013 Intel Coproration + + Authors: + Auke Kok + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see . + ***/ #include #include @@ -20,8 +28,12 @@ #include #include #include +#include +#include #include "bootchart.h" +#include "util.h" +#include "macro.h" #define time_to_graph(t) ((t) * scale_x) @@ -85,13 +97,13 @@ static void svg_header(void) /* write some basic info as a comment, including some help */ svg("\n"); - svg("\n"); - svg("\n"); - svg("\n"); - svg("\n\n"); + svg("\n"); + svg("\n"); + svg("\n"); + svg("\n\n"); svg("\n", VERSION); - svg("\n", hz, len); + svg("\n", hz, samples_len); svg("\n", scale_x, scale_y); svg("\n", relative, filter); svg("\n", pss, entropy); @@ -128,7 +140,7 @@ static void svg_header(void) } -static void svg_title(void) +static void svg_title(const char *build) { char cmdline[256] = ""; char filename[PATH_MAX]; @@ -137,14 +149,15 @@ static void svg_title(void) char model[256] = "Unknown"; char date[256] = "Unknown"; char cpu[256] = "Unknown"; - char build[256] = "Unknown"; char *c; FILE *f; time_t t; + int fd; struct utsname uts; /* grab /proc/cmdline */ - f = fopen("/proc/cmdline", "r"); + fd = openat(procfd, "cmdline", O_RDONLY); + f = fdopen(fd, "r"); if (f) { if (!fgets(cmdline, 255, f)) sprintf(cmdline, "Unknown"); @@ -152,17 +165,19 @@ static void svg_title(void) } /* extract root fs so we can find disk model name in sysfs */ + /* FIXME: this works only in the simple case */ c = strstr(cmdline, "root=/dev/"); if (c) { strncpy(rootbdev, &c[10], 3); rootbdev[3] = '\0'; - } - sprintf(filename, "/sys/block/%s/device/model", rootbdev); - f = fopen(filename, "r"); - if (f) { - if (!fgets(model, 255, f)) - fprintf(stderr, "Error reading disk model for %s\n", rootbdev); - fclose(f); + sprintf(filename, "block/%s/device/model", rootbdev); + fd = openat(sysfd, filename, O_RDONLY); + f = fdopen(fd, "r"); + if (f) { + if (!fgets(model, 255, f)) + fprintf(stderr, "Error reading disk model for %s\n", rootbdev); + fclose(f); + } } /* various utsname parameters */ @@ -174,7 +189,8 @@ static void svg_title(void) strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", localtime(&t)); /* CPU type */ - f = fopen("/proc/cpuinfo", "r"); + fd = openat(procfd, "cpuinfo", O_RDONLY); + f = fdopen(fd, "r"); if (f) { while (fgets(buf, 255, f)) { if (strstr(buf, "model name")) { @@ -185,14 +201,6 @@ static void svg_title(void) fclose(f); } - /* Build - 1st line from /etc/system-release */ - f = fopen("/etc/system-release", "r"); - if (f) { - if (fgets(buf, 255, f)) - strncpy(build, buf, 255); - fclose(f); - } - svg("Bootchart for %s - %s\n", uts.nodename, date); svg("System: %s %s %s %s\n", @@ -214,7 +222,7 @@ static void svg_title(void) svg("Not detected"); svg("\n"); svg("Graph data: %.03f samples/sec, recorded %i total, dropped %i samples, %i processes, %i filtered\n", - hz, len, overrun, pscount, pfiltered); + hz, samples_len, overrun, pscount, pfiltered); } @@ -259,6 +267,20 @@ static void svg_graph_box(int height) } } +/* xml comments must not contain "--" */ +static char* xml_comment_encode(const char* name) { + char *enc_name, *p; + + enc_name = strdup(name); + if (!enc_name) + return NULL; + + for (p = enc_name; *p; p++) + if (p[0] == '-' && p[1] == '-') + p[1] = '_'; + + return enc_name; +} static void svg_pss_graph(void) { @@ -361,7 +383,7 @@ static void svg_pss_graph(void) top = bottom + ps->sample[i].pss; /* draw a label with the process / PID */ if ((i == 1) || (ps->sample[i - 1].pss <= (100 * scale_y))) - svg(" %s [%i]\n", + svg(" [%i]\n", time_to_graph(sampletime[i] - graph_start), kb_to_graph(1000000.0 - bottom - ((top - bottom) / 2)), ps->name, @@ -375,10 +397,17 @@ static void svg_pss_graph(void) svg("\n\n\n"); ps = ps_first; while (ps->next_ps) { + char _cleanup_free_*enc_name; ps = ps->next_ps; if (!ps) continue; - svg("\n", ps->name, ps->pid, + svg("\n", enc_name, ps->pid, ps->ppid, ps->total); /* it would be nice if we could use exec_start from /proc/pid/sched, @@ -892,7 +925,7 @@ static void svg_ps_bars(void) w = ps->first; /* text label of process name */ - svg(" %s [%i] %.03fs\n", + svg(" [%i]%.03fs\n", time_to_graph(sampletime[w] - graph_start) + 5.0, ps_to_graph(j) + 14.0, ps->name, @@ -996,7 +1029,7 @@ static void svg_top_ten_cpu(void) svg("Top CPU consumers:\n"); for (n = 0; n < 10; n++) - svg("%3.03fs - %s[%d]\n", + svg("%3.03fs - [%d]\n", 20 + (n * 13), top[n]->total, top[n]->name, @@ -1031,7 +1064,7 @@ static void svg_top_ten_pss(void) svg("Top PSS consumers:\n"); for (n = 0; n < 10; n++) - svg("%dK - %s[%d]\n", + svg("%dK - [%d]\n", 20 + (n * 13), top[n]->pss_max, top[n]->name, @@ -1039,7 +1072,7 @@ static void svg_top_ten_pss(void) } -void svg_do(void) +void svg_do(const char *build) { struct ps_struct *ps; @@ -1092,7 +1125,7 @@ void svg_do(void) svg("\n\n"); svg("\n"); - svg_title(); + svg_title(build); svg("\n\n"); svg("\n");