summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mack <daniel@zonque.org>2015-04-03 00:40:01 +0200
committerDaniel Mack <daniel@zonque.org>2015-04-03 15:29:18 +0200
commitaf672f03eccd2df655edb585af25f4b8f3e153ac (patch)
treea29670bc655464f71c412d70f7996d55b8b43d9f
parent1f2ecb0393bf071fcd476300e0b3f94726b01b15 (diff)
bootchart: assorted coding style fixes
* kill unnecessary {} * add newlines where appropriate * remove dead code * reorder variable declarations * fix more return code logic * pass O_CLOEXEC to all open*() calles * use safe_close() where possible
-rw-r--r--src/bootchart/bootchart.c95
-rw-r--r--src/bootchart/store.c88
-rw-r--r--src/bootchart/svg.c130
3 files changed, 158 insertions, 155 deletions
diff --git a/src/bootchart/bootchart.c b/src/bootchart/bootchart.c
index 95939007b8..65cb3226e5 100644
--- a/src/bootchart/bootchart.c
+++ b/src/bootchart/bootchart.c
@@ -85,8 +85,6 @@ char arg_init_path[PATH_MAX] = DEFAULT_INIT;
char arg_output_path[PATH_MAX] = DEFAULT_OUTPUT;
static void signal_handler(int sig) {
- if (sig++)
- sig--;
exiting = 1;
}
@@ -253,43 +251,41 @@ static int parse_argv(int argc, char *argv[]) {
return 1;
}
-static void do_journal_append(char *file) {
+static int do_journal_append(char *file) {
+ _cleanup_free_ char *bootchart_message = NULL;
+ _cleanup_free_ char *bootchart_file = NULL;
+ _cleanup_free_ char *p = NULL;
+ _cleanup_close_ int fd = -1;
struct iovec iovec[5];
int r, j = 0;
ssize_t n;
- _cleanup_free_ char *bootchart_file = NULL, *bootchart_message = NULL,
- *p = NULL;
- _cleanup_close_ int fd = -1;
bootchart_file = strappend("BOOTCHART_FILE=", file);
- if (bootchart_file)
- IOVEC_SET_STRING(iovec[j++], bootchart_file);
+ if (!bootchart_file)
+ return log_oom();
+ IOVEC_SET_STRING(iovec[j++], bootchart_file);
IOVEC_SET_STRING(iovec[j++], "MESSAGE_ID=9f26aa562cf440c2b16c773d0479b518");
IOVEC_SET_STRING(iovec[j++], "PRIORITY=7");
bootchart_message = strjoin("MESSAGE=Bootchart created: ", file, NULL);
- if (bootchart_message)
- IOVEC_SET_STRING(iovec[j++], bootchart_message);
+ if (!bootchart_message)
+ return log_oom();
- p = malloc(9 + BOOTCHART_MAX);
- if (!p) {
- log_oom();
- return;
- }
+ IOVEC_SET_STRING(iovec[j++], bootchart_message);
+
+ p = malloc(10 + BOOTCHART_MAX);
+ if (!p)
+ return log_oom();
memcpy(p, "BOOTCHART=", 10);
fd = open(file, O_RDONLY|O_CLOEXEC);
- if (fd < 0) {
- log_error_errno(errno, "Failed to open bootchart data \"%s\": %m", file);
- return;
- }
+ if (fd < 0)
+ return log_error_errno(errno, "Failed to open bootchart data \"%s\": %m", file);
n = loop_read(fd, p + 10, BOOTCHART_MAX, false);
- if (n < 0) {
- log_error_errno(n, "Failed to read bootchart data: %m");
- return;
- }
+ if (n < 0)
+ return log_error_errno(n, "Failed to read bootchart data: %m");
iovec[j].iov_base = p;
iovec[j].iov_len = 10 + n;
@@ -298,32 +294,33 @@ static void do_journal_append(char *file) {
r = sd_journal_sendv(iovec, j);
if (r < 0)
log_error_errno(r, "Failed to send bootchart: %m");
+
+ return 0;
}
int main(int argc, char *argv[]) {
- _cleanup_free_ char *build = NULL;
- _cleanup_close_ int sysfd = -1;
+ static struct list_sample_data *sampledata;
_cleanup_closedir_ DIR *proc = NULL;
+ _cleanup_free_ char *build = NULL;
_cleanup_fclose_ FILE *of = NULL;
+ _cleanup_close_ int sysfd = -1;
+ struct ps_struct *ps_first;
double graph_start;
double log_start;
double interval;
- struct ps_struct *ps_first;
- struct sigaction sig = {
- .sa_handler = signal_handler,
- };
- struct ps_struct *ps;
char output_file[PATH_MAX];
char datestr[200];
- time_t t = 0;
- int r;
int pscount = 0;
int n_cpus = 0;
int overrun = 0;
- int samples;
+ time_t t = 0;
+ int r, samples;
+ struct ps_struct *ps;
struct rlimit rlim;
struct list_sample_data *head;
- static struct list_sample_data *sampledata;
+ struct sigaction sig = {
+ .sa_handler = signal_handler,
+ };
parse_conf();
@@ -464,12 +461,12 @@ int main(int argc, char *argv[]) {
ps = ps_first;
while (ps->next_ps) {
ps = ps->next_ps;
- if (ps->schedstat >= 0)
- close(ps->schedstat);
- if (ps->sched >= 0)
- close(ps->sched);
- if (ps->smaps)
+ ps->schedstat = safe_close(ps->schedstat);
+ ps->sched = safe_close(ps->sched);
+ if (ps->smaps) {
fclose(ps->smaps);
+ ps->smaps = NULL;
+ }
}
if (!of) {
@@ -486,17 +483,9 @@ int main(int argc, char *argv[]) {
return EXIT_FAILURE;
}
- r = svg_do(of,
- strna(build),
- head,
- ps_first,
- samples,
- pscount,
- n_cpus,
- graph_start,
- log_start,
- interval,
- overrun);
+ r = svg_do(of, strna(build), head, ps_first,
+ samples, pscount, n_cpus, graph_start,
+ log_start, interval, overrun);
if (r < 0) {
log_error_errno(r, "Error generating svg file: %m\n");
@@ -505,7 +494,9 @@ int main(int argc, char *argv[]) {
log_info("systemd-bootchart wrote %s\n", output_file);
- do_journal_append(output_file);
+ r = do_journal_append(output_file);
+ if (r < 0)
+ return EXIT_FAILURE;
/* nitpic cleanups */
ps = ps_first->next_ps;
@@ -525,6 +516,7 @@ int main(int argc, char *argv[]) {
free(old->sample);
free(old);
}
+
free(ps->cgroup);
free(ps->sample);
free(ps);
@@ -536,6 +528,7 @@ int main(int argc, char *argv[]) {
free(old_sampledata);
}
free(sampledata);
+
/* don't complain when overrun once, happens most commonly on 1st sample */
if (overrun > 1)
log_warning("systemd-boochart: sample time overrun %i times\n", overrun);
diff --git a/src/bootchart/store.c b/src/bootchart/store.c
index b0aab4f254..f19427e93d 100644
--- a/src/bootchart/store.c
+++ b/src/bootchart/store.c
@@ -63,16 +63,17 @@ static char *bufgetline(char *buf) {
c = strchr(buf, '\n');
if (c)
c++;
+
return c;
}
static int pid_cmdline_strscpy(int procfd, char *buffer, size_t buf_len, int pid) {
char filename[PATH_MAX];
- _cleanup_close_ int fd=-1;
+ _cleanup_close_ int fd = -1;
ssize_t n;
sprintf(filename, "%d/cmdline", pid);
- fd = openat(procfd, filename, O_RDONLY);
+ fd = openat(procfd, filename, O_RDONLY|O_CLOEXEC);
if (fd < 0)
return -errno;
@@ -84,6 +85,7 @@ static int pid_cmdline_strscpy(int procfd, char *buffer, size_t buf_len, int pid
buffer[i] = ' ';
buffer[n] = '\0';
}
+
return 0;
}
@@ -122,8 +124,8 @@ int log_sample(DIR *proc,
if (vmstat < 0) {
/* block stuff */
- vmstat = openat(procfd, "vmstat", O_RDONLY);
- if (vmstat == -1)
+ vmstat = openat(procfd, "vmstat", O_RDONLY|O_CLOEXEC);
+ if (vmstat < 0)
return log_error_errno(errno, "Failed to open /proc/vmstat: %m");
}
@@ -134,6 +136,7 @@ int log_sample(DIR *proc,
return -errno;
return -ENODATA;
}
+
buf[n] = '\0';
m = buf;
@@ -154,8 +157,8 @@ vmstat_next:
if (schedstat < 0) {
/* overall CPU utilization */
- schedstat = openat(procfd, "schedstat", O_RDONLY);
- if (schedstat == -1)
+ schedstat = openat(procfd, "schedstat", O_RDONLY|O_CLOEXEC);
+ if (schedstat < 0)
return log_error_errno(errno, "Failed to open /proc/schedstat (requires CONFIG_SCHEDSTATS=y in kernel config): %m");
}
@@ -166,6 +169,7 @@ vmstat_next:
return -errno;
return -ENODATA;
}
+
buf[n] = '\0';
m = buf;
@@ -194,15 +198,14 @@ schedstat_next:
if (arg_entropy) {
if (e_fd < 0) {
- e_fd = openat(procfd, "sys/kernel/random/entropy_avail", O_RDONLY);
- if (e_fd == -1)
+ e_fd = openat(procfd, "sys/kernel/random/entropy_avail", O_RDONLY|O_CLOEXEC);
+ if (e_fd < 0)
return log_error_errno(errno, "Failed to open /proc/sys/kernel/random/entropy_avail: %m");
}
n = pread(e_fd, buf, sizeof(buf) - 1, 0);
if (n <= 0) {
- close(e_fd);
- e_fd = -1;
+ e_fd = safe_close(e_fd);
} else {
buf[n] = '\0';
sampledata->entropy_avail = atoi(buf);
@@ -261,15 +264,14 @@ schedstat_next:
/* get name, start time */
if (ps->sched < 0) {
sprintf(filename, "%d/sched", pid);
- ps->sched = openat(procfd, filename, O_RDONLY);
- if (ps->sched == -1)
+ ps->sched = openat(procfd, filename, O_RDONLY|O_CLOEXEC);
+ if (ps->sched < 0)
continue;
}
s = pread(ps->sched, buf, sizeof(buf) - 1, 0);
if (s <= 0) {
- close(ps->sched);
- ps->sched = -1;
+ ps->sched = safe_close(ps->sched);
continue;
}
buf[s] = '\0';
@@ -308,17 +310,19 @@ schedstat_next:
/* ppid */
sprintf(filename, "%d/stat", pid);
- fd = openat(procfd, filename, O_RDONLY);
- if (fd == -1)
+ fd = openat(procfd, filename, O_RDONLY|O_CLOEXEC);
+ if (fd < 0)
continue;
- st = fdopen(fd, "r");
+
+ st = fdopen(fd, "re");
if (!st) {
close(fd);
continue;
}
- if (!fscanf(st, "%*s %*s %*s %i", &p)) {
+
+ if (!fscanf(st, "%*s %*s %*s %i", &p))
continue;
- }
+
ps->ppid = p;
/*
@@ -355,6 +359,7 @@ schedstat_next:
children = parent->children;
while (children->next)
children = children->next;
+
children->next = ps;
}
}
@@ -367,23 +372,20 @@ schedstat_next:
/* rt, wt */
if (ps->schedstat < 0) {
sprintf(filename, "%d/schedstat", pid);
- ps->schedstat = openat(procfd, filename, O_RDONLY);
- if (ps->schedstat == -1)
+ ps->schedstat = openat(procfd, filename, O_RDONLY|O_CLOEXEC);
+ if (ps->schedstat < 0)
continue;
}
+
s = pread(ps->schedstat, buf, sizeof(buf) - 1, 0);
if (s <= 0) {
/* clean up our file descriptors - assume that the process exited */
close(ps->schedstat);
ps->schedstat = -1;
- if (ps->sched) {
- close(ps->sched);
- ps->sched = -1;
- }
- //if (ps->smaps)
- // fclose(ps->smaps);
+ ps->sched = safe_close(ps->sched);
continue;
}
+
buf[s] = '\0';
if (!sscanf(buf, "%s %s %*s", rt, wt))
@@ -400,9 +402,9 @@ schedstat_next:
ps->sample->waittime = atoll(wt);
ps->sample->sampledata = sampledata;
ps->sample->ps_new = ps;
- if (ps_prev) {
+ if (ps_prev)
ps_prev->cross = ps->sample;
- }
+
ps_prev = ps->sample;
ps->total = (ps->last->runtime - ps->first->runtime)
/ 1000000000.0;
@@ -413,19 +415,19 @@ schedstat_next:
/* Pss */
if (!ps->smaps) {
sprintf(filename, "%d/smaps", pid);
- fd = openat(procfd, filename, O_RDONLY);
- if (fd == -1)
+ fd = openat(procfd, filename, O_RDONLY|O_CLOEXEC);
+ if (fd < 0)
continue;
- ps->smaps = fdopen(fd, "r");
+ ps->smaps = fdopen(fd, "re");
if (!ps->smaps) {
close(fd);
continue;
}
setvbuf(ps->smaps, smaps_buf, _IOFBF, sizeof(smaps_buf));
- }
- else {
+ } else {
rewind(ps->smaps);
}
+
/* test to see if we need to skip another field */
if (skip == 0) {
if (fgets(buf, sizeof(buf), ps->smaps) == NULL) {
@@ -442,6 +444,7 @@ schedstat_next:
}
rewind(ps->smaps);
}
+
while (1) {
int pss_kb;
@@ -462,6 +465,7 @@ schedstat_next:
break;
}
}
+
if (ps->sample->pss > ps->pss_max)
ps->pss_max = ps->sample->pss;
@@ -474,23 +478,19 @@ catch_rename:
/* get name, start time */
if (!ps->sched) {
sprintf(filename, "%d/sched", pid);
- ps->sched = openat(procfd, filename, O_RDONLY);
- if (ps->sched == -1)
+ ps->sched = openat(procfd, filename, O_RDONLY|O_CLOEXEC);
+ if (ps->sched < 0)
continue;
}
+
s = pread(ps->sched, buf, sizeof(buf) - 1, 0);
if (s <= 0) {
/* clean up file descriptors */
- close(ps->sched);
- ps->sched = -1;
- if (ps->schedstat) {
- close(ps->schedstat);
- ps->schedstat = -1;
- }
- //if (ps->smaps)
- // fclose(ps->smaps);
+ ps->sched = safe_close(ps->sched);
+ ps->schedstat = safe_close(ps->schedstat);
continue;
}
+
buf[s] = '\0';
if (!sscanf(buf, "%s %*s %*s", key))
diff --git a/src/bootchart/svg.c b/src/bootchart/svg.c
index c89ef8ed5c..c63fd0406e 100644
--- a/src/bootchart/svg.c
+++ b/src/bootchart/svg.c
@@ -191,10 +191,8 @@ static int svg_title(FILE *of, const char *build, int pscount, double log_start,
/* CPU type */
r = read_full_file("/proc/cpuinfo", &buf, NULL);
- if (r < 0) {
- log_error_errno(r, "Unable to read cpuinfo: %m\n");
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Unable to read cpuinfo: %m\n");
cpu = strstr(buf, "model name");
if (!cpu) {
@@ -364,11 +362,11 @@ static void svg_pss_graph(FILE *of,
}
fprintf(of, " <rect class=\"clrw\" style=\"fill: %s\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
- "rgb(64,64,64)",
- time_to_graph(prev_sampledata->sampletime - graph_start),
- kb_to_graph(1000000.0 - top),
- time_to_graph(sampledata->sampletime - prev_sampledata->sampletime),
- kb_to_graph(top - bottom));
+ "rgb(64,64,64)",
+ time_to_graph(prev_sampledata->sampletime - graph_start),
+ kb_to_graph(1000000.0 - top),
+ time_to_graph(sampledata->sampletime - prev_sampledata->sampletime),
+ kb_to_graph(top - bottom));
bottom = top;
/* now plot the ones that are of significant size */
@@ -384,34 +382,36 @@ static void svg_pss_graph(FILE *of,
break;
}
/* don't draw anything smaller than 2mb */
- if (ps->sample->sampledata == sampledata) {
- if (ps->sample->pss > (100 * arg_scale_y)) {
+ if (ps->sample->sampledata != sampledata)
+ continue;
+ if (ps->sample->pss > (100 * arg_scale_y)) {
top = bottom + ps->sample->pss;
fprintf(of, " <rect class=\"clrw\" style=\"fill: %s\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
- colorwheel[ps->pid % 12],
- time_to_graph(prev_sampledata->sampletime - graph_start),
- kb_to_graph(1000000.0 - top),
- time_to_graph(sampledata->sampletime - prev_sampledata->sampletime),
- kb_to_graph(top - bottom));
+ colorwheel[ps->pid % 12],
+ time_to_graph(prev_sampledata->sampletime - graph_start),
+ kb_to_graph(1000000.0 - top),
+ time_to_graph(sampledata->sampletime - prev_sampledata->sampletime),
+ kb_to_graph(top - bottom));
bottom = top;
- }
- break;
}
+ break;
}
+
while ((cross_place = ps->sample->cross)) {
ps = ps->sample->cross->ps_new;
ps->sample = cross_place;
if (ps->sample->pss > (100 * arg_scale_y)) {
top = bottom + ps->sample->pss;
fprintf(of, " <rect class=\"clrw\" style=\"fill: %s\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
- colorwheel[ps->pid % 12],
- time_to_graph(prev_sampledata->sampletime - graph_start),
- kb_to_graph(1000000.0 - top),
- time_to_graph(sampledata->sampletime - prev_sampledata->sampletime),
- kb_to_graph(top - bottom));
+ colorwheel[ps->pid % 12],
+ time_to_graph(prev_sampledata->sampletime - graph_start),
+ kb_to_graph(1000000.0 - top),
+ time_to_graph(sampledata->sampletime - prev_sampledata->sampletime),
+ kb_to_graph(top - bottom));
bottom = top;
}
}
+
prev_sampledata = sampledata;
i++;
}
@@ -430,18 +430,22 @@ static void svg_pss_graph(FILE *of,
ps = ps->next_ps;
if (!ps)
continue;
+
ps->sample = ps->first;
while (ps->sample->next) {
ps->sample = ps->sample->next;
if (ps->sample->sampledata == sampledata)
break;
}
+
if (ps->sample->sampledata == sampledata) {
if (ps->sample->pss <= (100 * arg_scale_y))
top += ps->sample->pss;
+
break;
}
}
+
while ((cross_place = ps->sample->cross)) {
ps = ps->sample->cross->ps_new;
ps->sample = cross_place;
@@ -471,10 +475,9 @@ static void svg_pss_graph(FILE *of,
/* draw a label with the process / PID */
if ((i == 1) || (prev_sample->pss <= (100 * arg_scale_y)))
fprintf(of, " <text x=\"%.03f\" y=\"%.03f\"><![CDATA[%s]]> [%i]</text>\n",
- time_to_graph(sampledata->sampletime - graph_start),
- kb_to_graph(1000000.0 - bottom - ((top - bottom) / 2)),
- ps->name,
- ps->pid);
+ time_to_graph(sampledata->sampletime - graph_start),
+ kb_to_graph(1000000.0 - bottom - ((top - bottom) / 2)),
+ ps->name, ps->pid);
bottom = top;
}
break;
@@ -495,6 +498,7 @@ static void svg_pss_graph(FILE *of,
bottom = top;
}
}
+
i++;
}
@@ -518,6 +522,7 @@ static void svg_pss_graph(FILE *of,
ps->sample = ps->sample->next;
fprintf(of, "%d," , ps->sample->pss);
}
+
fprintf(of, " -->\n");
}
@@ -569,21 +574,20 @@ static void svg_io_bi_bar(FILE *of,
start_sampledata = sampledata;
stop_sampledata = sampledata;
- for (k=0;(k<((range/2)-1))&&(start_sampledata->link_next);k++)
+ for (k = 0; k < ((range/2) - 1) && start_sampledata->link_next; k++)
start_sampledata = start_sampledata->link_next;
- for (k=0;(k<(range/2))&&(stop_sampledata->link_prev);k++)
+
+ for (k = 0; k < (range/2) && stop_sampledata->link_prev; k++)
stop_sampledata = stop_sampledata->link_prev;
- tot = (double)(stop_sampledata->blockstat.bi - start_sampledata->blockstat.bi)
- / diff;
+ tot = (double)(stop_sampledata->blockstat.bi - start_sampledata->blockstat.bi) / diff;
if (tot > max) {
max = tot;
max_here = i;
}
- tot = (double)(stop_sampledata->blockstat.bo - start_sampledata->blockstat.bo)
- / diff;
+ tot = (double)(stop_sampledata->blockstat.bo - start_sampledata->blockstat.bo) / diff;
if (tot > max)
max = tot;
@@ -608,13 +612,13 @@ static void svg_io_bi_bar(FILE *of,
start_sampledata = sampledata;
stop_sampledata = sampledata;
- for (k=0;(k<((range/2)-1))&&(start_sampledata->link_next);k++)
+ for (k = 0; k < ((range/2)-1) && start_sampledata->link_next; k++)
start_sampledata = start_sampledata->link_next;
- for (k=0;(k<(range/2))&&(stop_sampledata->link_prev);k++)
+
+ for (k = 0; k < (range/2) && stop_sampledata->link_prev; k++)
stop_sampledata = stop_sampledata->link_prev;
- tot = (double)(stop_sampledata->blockstat.bi - start_sampledata->blockstat.bi)
- / diff;
+ tot = (double)(stop_sampledata->blockstat.bi - start_sampledata->blockstat.bi) / diff;
if (max > 0)
pbi = tot / max;
@@ -633,6 +637,7 @@ static void svg_io_bi_bar(FILE *of,
((arg_scale_y * 5) - (pbi * (arg_scale_y * 5))) + 15,
max / 1024.0 / (interval / 1000000000.0));
}
+
i++;
prev_sampledata = sampledata;
}
@@ -683,33 +688,32 @@ static void svg_io_bo_bar(FILE *of,
start_sampledata = sampledata;
stop_sampledata = sampledata;
- for (k=0;(k<((range/2)-1))&&(start_sampledata->link_next);k++)
+ for (k = 0; k < (range/2) - 1 && start_sampledata->link_next; k++)
start_sampledata = start_sampledata->link_next;
- for (k=0;(k<(range/2))&&(stop_sampledata->link_prev);k++)
+
+ for (k = 0; k < (range/2) && stop_sampledata->link_prev; k++)
stop_sampledata = stop_sampledata->link_prev;
- tot = (double)(stop_sampledata->blockstat.bi - start_sampledata->blockstat.bi)
- / diff;
+ tot = (double)(stop_sampledata->blockstat.bi - start_sampledata->blockstat.bi) / diff;
if (tot > max)
max = tot;
- tot = (double)(stop_sampledata->blockstat.bo - start_sampledata->blockstat.bo)
- / diff;
+
+ tot = (double)(stop_sampledata->blockstat.bo - start_sampledata->blockstat.bo) / diff;
if (tot > max) {
max = tot;
max_here = i;
}
+
i++;
}
/* plot bo */
prev_sampledata = head;
- i=1;
+ i = 1;
+
LIST_FOREACH_BEFORE(link, sampledata, head) {
- int start;
- int stop;
- int diff;
- double tot;
- double pbo;
+ int start, stop, diff;
+ double tot, pbo;
pbo = 0;
@@ -720,9 +724,10 @@ static void svg_io_bo_bar(FILE *of,
start_sampledata = sampledata;
stop_sampledata = sampledata;
- for (k=0;(k<((range/2)-1))&&(start_sampledata->link_next);k++)
+ for (k = 0; k < ((range/2)-1) && start_sampledata->link_next; k++)
start_sampledata = start_sampledata->link_next;
- for (k=0;(k<(range/2))&&(stop_sampledata->link_prev);k++)
+
+ for (k = 0; k < (range/2) && stop_sampledata->link_prev; k++)
stop_sampledata = stop_sampledata->link_prev;
tot = (double)(stop_sampledata->blockstat.bo - start_sampledata->blockstat.bo)
@@ -745,6 +750,7 @@ static void svg_io_bo_bar(FILE *of,
((arg_scale_y * 5) - (pbo * (arg_scale_y * 5))),
max / 1024.0 / (interval / 1000000000.0));
}
+
i++;
prev_sampledata = sampledata;
}
@@ -758,6 +764,7 @@ static void svg_cpu_bar(FILE *of, struct list_sample_data *head, int n_cpus, int
fprintf(of, "<text class=\"t2\" x=\"5\" y=\"-15\">CPU[overall] utilization</text>\n");
else
fprintf(of, "<text class=\"t2\" x=\"5\" y=\"-15\">CPU[%d] utilization</text>\n", cpu_num);
+
/* surrounding box */
svg_graph_box(of, head, 5, graph_start);
@@ -787,13 +794,13 @@ static void svg_cpu_bar(FILE *of, struct list_sample_data *head, int n_cpus, int
if (ptrt > 1.0)
ptrt = 1.0;
- if (ptrt > 0.001) {
+ if (ptrt > 0.001)
fprintf(of, "<rect class=\"cpu\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
time_to_graph(prev_sampledata->sampletime - graph_start),
(arg_scale_y * 5) - (ptrt * (arg_scale_y * 5)),
time_to_graph(sampledata->sampletime - prev_sampledata->sampletime),
ptrt * (arg_scale_y * 5));
- }
+
prev_sampledata = sampledata;
}
}
@@ -836,13 +843,13 @@ static void svg_wait_bar(FILE *of, struct list_sample_data *head, int n_cpus, in
if (ptwt > 1.0)
ptwt = 1.0;
- if (ptwt > 0.001) {
+ if (ptwt > 0.001)
fprintf(of, "<rect class=\"wait\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n",
time_to_graph(prev_sampledata->sampletime - graph_start),
((arg_scale_y * 5) - (ptwt * (arg_scale_y * 5))),
time_to_graph(sampledata->sampletime - prev_sampledata->sampletime),
ptwt * (arg_scale_y * 5));
- }
+
prev_sampledata = sampledata;
}
}
@@ -885,9 +892,9 @@ static struct ps_struct *get_next_ps(struct ps_struct *ps, struct ps_struct *ps_
/* go back for parent siblings */
while (1) {
- if (ps->parent)
- if (ps->parent->next)
- return ps->parent->next;
+ if (ps->parent && ps->parent->next)
+ return ps->parent->next;
+
ps = ps->parent;
if (!ps)
return ps;
@@ -1174,13 +1181,14 @@ static void svg_ps_bars(FILE *of,
ps->sample = ps->sample->next;
sample_hz = ps->sample;
- for (ii=0;((ii<(int)arg_hz/2)&&(sample_hz->next));ii++)
+ for (ii = 0; (ii < (int)arg_hz/2) && sample_hz->next; ii++)
sample_hz = sample_hz->next;
/* subtract bootchart cpu utilization from total */
crt = 0.0;
for (c = 0; c < n_cpus; c++)
crt += sample_hz->sampledata->runtime[c] - ps->sample->sampledata->runtime[c];
+
brt = sample_hz->runtime - ps->sample->runtime;
/*
* our definition of "idle":
@@ -1202,6 +1210,7 @@ static void svg_ps_bars(FILE *of,
idletime);
break;
}
+
i++;
}
}
@@ -1253,6 +1262,7 @@ static void svg_top_ten_pss(FILE *of, struct ps_struct *ps_first) {
for (n = 0; n < 10; n++) {
if (ps->pss_max <= top[n]->pss_max)
continue;
+
/* cascade insert */
for (m = 9; m > n; m--)
top[m] = top[m-1];
@@ -1290,7 +1300,7 @@ int svg_do(FILE *of,
/* count initcall thread count first */
svg_do_initcall(of, head, 1, graph_start);
- ksize = (kcount ? ps_to_graph(kcount) + (arg_scale_y * 2) : 0);
+ ksize = kcount ? ps_to_graph(kcount) + (arg_scale_y * 2) : 0;
/* then count processes */
while ((ps = get_next_ps(ps, ps_first))) {