diff options
Diffstat (limited to 'src/bootchart')
-rw-r--r-- | src/bootchart/bootchart.c | 29 | ||||
-rw-r--r-- | src/bootchart/svg.c | 28 |
2 files changed, 19 insertions, 38 deletions
diff --git a/src/bootchart/bootchart.c b/src/bootchart/bootchart.c index 3360bc85be..83ad90c222 100644 --- a/src/bootchart/bootchart.c +++ b/src/bootchart/bootchart.c @@ -338,10 +338,9 @@ int main(int argc, char *argv[]) { * - child logs data */ if (getpid() == 1) { - if (fork()) { + if (fork()) /* parent */ execl(arg_init_path, arg_init_path, NULL); - } } argv[0][0] = '@'; @@ -367,7 +366,7 @@ int main(int argc, char *argv[]) { struct timespec n; double uptime; - clock_gettime(CLOCK_BOOTTIME, &n); + clock_gettime(clock_boottime_or_monotonic(), &n); uptime = (n.tv_sec + (n.tv_nsec / (double) NSEC_PER_SEC)); log_start = gettime_ns(); @@ -387,9 +386,6 @@ int main(int argc, char *argv[]) { for (samples = 0; !exiting && samples < arg_samples_len; samples++) { int res; double sample_stop; - struct timespec req; - time_t newint_s; - long newint_ns; double elapsed; double timeleft; @@ -427,32 +423,30 @@ int main(int argc, char *argv[]) { elapsed = (sample_stop - sampledata->sampletime) * 1000000000.0; timeleft = interval - elapsed; - newint_s = (time_t)(timeleft / 1000000000.0); - newint_ns = (long)(timeleft - (newint_s * 1000000000.0)); - /* * check if we have not consumed our entire timeslice. If we * do, don't sleep and take a new sample right away. * we'll lose all the missed samples and overrun our total * time */ - if (newint_ns > 0 || newint_s > 0) { - req.tv_sec = newint_s; - req.tv_nsec = newint_ns; + if (timeleft > 0) { + struct timespec req; + + req.tv_sec = (time_t)(timeleft / 1000000000.0); + req.tv_nsec = (long)(timeleft - (req.tv_sec * 1000000000.0)); res = nanosleep(&req, NULL); if (res) { - if (errno == EINTR) { + if (errno == EINTR) /* caught signal, probably HUP! */ break; - } log_error_errno(errno, "nanosleep() failed: %m"); return EXIT_FAILURE; } } else { overrun++; /* calculate how many samples we lost and scrap them */ - arg_samples_len -= (int)(newint_ns / interval); + arg_samples_len -= (int)(-timeleft / interval); } LIST_PREPEND(link, head, sampledata); } @@ -463,10 +457,7 @@ int main(int argc, char *argv[]) { ps = ps->next_ps; ps->schedstat = safe_close(ps->schedstat); ps->sched = safe_close(ps->sched); - if (ps->smaps) { - fclose(ps->smaps); - ps->smaps = NULL; - } + ps->smaps = safe_fclose(ps->smaps); } if (!of) { diff --git a/src/bootchart/svg.c b/src/bootchart/svg.c index a7ef653d5d..db5fc863b0 100644 --- a/src/bootchart/svg.c +++ b/src/bootchart/svg.c @@ -30,6 +30,7 @@ #include <sys/utsname.h> #include <fcntl.h> +#include "architecture.h" #include "util.h" #include "fileio.h" #include "macro.h" @@ -147,7 +148,7 @@ static int svg_title(FILE *of, const char *build, int pscount, double log_start, _cleanup_free_ char *model = NULL; _cleanup_free_ char *buf = NULL; char date[256] = "Unknown"; - char *cpu; + const char *cpu; char *c; time_t t; int r; @@ -188,20 +189,11 @@ static int svg_title(FILE *of, const char *build, int pscount, double log_start, assert_se(r > 0); /* CPU type */ - r = read_full_file("/proc/cpuinfo", &buf, NULL); + r = get_proc_field("/proc/cpuinfo", PROC_CPUINFO_MODEL, "\n", &buf); if (r < 0) - return log_error_errno(r, "Unable to read cpuinfo: %m"); - - cpu = strstr(buf, "model name"); - if (!cpu) { - log_error("Unable to read module name from cpuinfo.\n"); - return -ENOENT; - } - - cpu += 13; - c = strchr(cpu, '\n'); - if (c) - *c = '\0'; + cpu = "Unknown"; + else + cpu = buf; fprintf(of, "<text class=\"t1\" x=\"0\" y=\"30\">Bootchart for %s - %s</text>\n", uts.nodename, date); @@ -630,12 +622,11 @@ static void svg_io_bi_bar(FILE *of, pbi * (arg_scale_y * 5)); /* labels around highest value */ - if (i == max_here) { + if (i == max_here) fprintf(of, " <text class=\"sec\" x=\"%.03f\" y=\"%.03f\">%0.2fmb/sec</text>\n", time_to_graph(sampledata->sampletime - graph_start) + 5, ((arg_scale_y * 5) - (pbi * (arg_scale_y * 5))) + 15, max / 1024.0 / (interval / 1000000000.0)); - } i++; prev_sampledata = sampledata; @@ -743,12 +734,11 @@ static void svg_io_bo_bar(FILE *of, pbo * (arg_scale_y * 5)); /* labels around highest bo value */ - if (i == max_here) { + if (i == max_here) fprintf(of, " <text class=\"sec\" x=\"%.03f\" y=\"%.03f\">%0.2fmb/sec</text>\n", time_to_graph(sampledata->sampletime - graph_start) + 5, ((arg_scale_y * 5) - (pbo * (arg_scale_y * 5))), max / 1024.0 / (interval / 1000000000.0)); - } i++; prev_sampledata = sampledata; @@ -890,7 +880,7 @@ static struct ps_struct *get_next_ps(struct ps_struct *ps, struct ps_struct *ps_ return ps->next; /* go back for parent siblings */ - while (1) { + for (;;) { if (ps->parent && ps->parent->next) return ps->parent->next; |