]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
irqtop: use lib/monotonic.c to determine uptime
authorSami Kerola <kerolasa@iki.fi>
Sat, 4 Jan 2020 07:45:43 +0000 (07:45 +0000)
committerSami Kerola <kerolasa@iki.fi>
Fri, 21 Feb 2020 21:09:14 +0000 (21:09 +0000)
This should be functionally the same, and has the advantage of avoiding
duplicated code.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
sys-utils/Makemodule.am
sys-utils/irqtop.c

index e64d68037117324f0844113dcf61a2af121e76b0..8a0cd9c901d6c6d54c65afd126fa55bfc4058205 100644 (file)
@@ -52,8 +52,9 @@ endif
 
 if BUILD_IRQTOP
 usrbin_exec_PROGRAMS += irqtop
-irqtop_SOURCES = sys-utils/irqtop.c
-irqtop_LDADD = $(LDADD) libcommon.la $(NCURSES_LIBS)
+irqtop_SOURCES = sys-utils/irqtop.c \
+                lib/monotonic.c
+irqtop_LDADD = $(LDADD) libcommon.la $(NCURSES_LIBS) $(REALTIME_LIBS)
 irqtop_CFLAGS = $(AM_CFLAGS) $(NCURSES_CFLAGS)
 endif
 
index 79a292d101a18636eb292b5187e1b21a5e7c474d..6932ad5cfdfcd1e59e3c0fe2c568c5618fd0c1ba 100644 (file)
@@ -55,6 +55,7 @@
 
 #include "c.h"
 #include "closestream.h"
+#include "monotonic.h"
 #include "nls.h"
 #include "pathnames.h"
 #include "ttyutils.h"
@@ -213,36 +214,6 @@ static void term_size(int unusused __attribute__((__unused__)))
        get_terminal_dimension(&cols, &rows);
 }
 
-static int uptime(double *uptime_secs, double *idle_secs)
-{
-       double up, idle;
-       FILE *f;
-       char buf[64];
-
-       f = fopen(_PATH_PROC_UPTIME, "r");
-       if (!f)
-               return errno;
-
-       if (!fgets(buf, sizeof(buf), f)) {
-               fclose(f);
-               return errno;
-       }
-
-       if (sscanf(buf, "%lf %lf", &up, &idle) < 2) {
-               fclose(f);
-               return errno;
-       }
-
-       if (uptime_secs)
-               *uptime_secs = up;
-
-       if (idle_secs)
-               *idle_secs = idle;
-
-       fclose(f);
-       return 0;
-}
-
 static void sigint_handler(int unused __attribute__((__unused__)))
 {
        delay = 0;
@@ -328,7 +299,7 @@ int main(int argc, char *argv[])
        int is_tty, o;
        unsigned short old_rows;
        struct irq_stat *stat, *last_stat = NULL;
-       double uptime_secs = 1;
+       struct timeval uptime_tv;
        int retval = EXIT_SUCCESS;
 
        static const struct option longopts[] = {
@@ -383,8 +354,7 @@ int main(int argc, char *argv[])
        signal(SIGINT, sigint_handler);
 
        smp_num_cpus = sysconf(_SC_NPROCESSORS_ONLN);
-       if (uptime(&uptime_secs, NULL))
-               errx(EXIT_FAILURE, _("could not read uptime"));
+       gettime_monotonic(&uptime_tv);
 
        do {
                struct timeval tv;
@@ -424,7 +394,7 @@ int main(int argc, char *argv[])
 
                        for (index = 0; index < stat->nr_irq; index++) {
                                curr = result + index;
-                               curr->count /= uptime_secs;
+                               curr->count /= uptime_tv.tv_sec;
                        }
                        last_stat = stat;
                } else {