diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bootchart/bootchart.c | 11 | ||||
-rw-r--r-- | src/bootchart/store.c | 29 |
2 files changed, 19 insertions, 21 deletions
diff --git a/src/bootchart/bootchart.c b/src/bootchart/bootchart.c index 0ae72c29bb..fc00b4e3f2 100644 --- a/src/bootchart/bootchart.c +++ b/src/bootchart/bootchart.c @@ -310,6 +310,7 @@ int main(int argc, char *argv[]) { time_t t = 0; int r; struct rlimit rlim; + bool has_procfs = false; parse_conf(); @@ -349,6 +350,8 @@ int main(int argc, char *argv[]) { log_uptime(); + has_procfs = access("/proc/vmstat", F_OK) == 0; + LIST_HEAD_INIT(head); /* main program loop */ @@ -385,11 +388,11 @@ int main(int argc, char *argv[]) { parse_env_file("/usr/lib/os-release", NEWLINE, "PRETTY_NAME", &build, NULL); } - /* wait for /proc to become available, discarding samples */ - if (graph_start <= 0.0) - log_uptime(); - else + if (has_procfs) log_sample(samples, &sampledata); + else + /* wait for /proc to become available, discarding samples */ + has_procfs = access("/proc/vmstat", F_OK) == 0; sample_stop = gettime_ns(); diff --git a/src/bootchart/store.c b/src/bootchart/store.c index e0719838d5..cedcba88ed 100644 --- a/src/bootchart/store.c +++ b/src/bootchart/store.c @@ -57,27 +57,22 @@ double gettime_ns(void) { return (n.tv_sec + (n.tv_nsec / 1000000000.0)); } -void log_uptime(void) { - _cleanup_fclose_ FILE *f = NULL; - char str[32]; - double uptime; - - f = fopen("/proc/uptime", "re"); - - if (!f) - return; - if (!fscanf(f, "%s %*s", str)) - return; - - uptime = strtod(str, NULL); +static double gettime_up(void) { + struct timespec n; - log_start = gettime_ns(); + clock_gettime(CLOCK_BOOTTIME, &n); + return (n.tv_sec + (n.tv_nsec / 1000000000.0)); +} - /* start graph at kernel boot time */ +void log_uptime(void) { if (arg_relative) - graph_start = log_start; - else + graph_start = log_start = gettime_ns(); + else { + double uptime = gettime_up(); + + log_start = gettime_ns(); graph_start = log_start - uptime; + } } static char *bufgetline(char *buf) { |