]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/bootchart/bootchart.c
tree-wide: drop {} from one-line if blocks
[thirdparty/systemd.git] / src / bootchart / bootchart.c
index 3360bc85beae34431cde9cb8c3593694a3efe918..e61b58b5e5f0494905942c51e946936dc7221400 100644 (file)
@@ -367,7 +367,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 +387,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 +424,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);
         }