summaryrefslogtreecommitdiff
path: root/src/bootchart/bootchart.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bootchart/bootchart.c')
-rw-r--r--src/bootchart/bootchart.c29
1 files changed, 10 insertions, 19 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) {