]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
irqtop: include hostname and timestamp to output header
authorSami Kerola <kerolasa@iki.fi>
Sun, 5 Jan 2020 10:40:12 +0000 (10:40 +0000)
committerSami Kerola <kerolasa@iki.fi>
Fri, 21 Feb 2020 21:09:15 +0000 (21:09 +0000)
Having a when and from where information is useful in situations when output
is examined later and possibly elsewhere.  Typical example would be a
screenshot or output copy-paste of a terminal to a ticketing system.

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

index f3aea22f983d2110a22241b87f890766b61fea2d..61ff2cd6a371c08ab1f0d4b766cf565a50e8d69e 100644 (file)
@@ -62,6 +62,7 @@
 #include "nls.h"
 #include "pathnames.h"
 #include "strutils.h"
+#include "timeutils.h"
 #include "ttyutils.h"
 #include "xalloc.h"
 
@@ -69,7 +70,7 @@
 #define IRQ_NAME_LEN           4
 #define IRQ_DESC_LEN           64
 #define IRQ_INFO_LEN           64
-#define RESERVE_ROWS           (1 + 1 + 1)     /* summary + header + last row */
+#define RESERVE_ROWS           (1 + 2 + 1)     /* summary + header + last row */
 #define MAX_EVENTS             3
 
 struct irq_info {
@@ -97,6 +98,7 @@ struct irqtop_ctl {
        int (*sort_func)(const struct irq_info *, const struct irq_info *);
        long smp_num_cpus;
        struct irq_stat *last_stat;
+       char *hostname;
        unsigned int
                request_exit:1,
                run_once:1;
@@ -303,6 +305,8 @@ static int update_screen(struct irqtop_ctl *ctl)
        struct irq_stat *stat;
        size_t size;
        size_t index;
+       time_t now;
+       char timestr[64];
 
        stat = get_irqinfo(ctl);
        if (!stat) {
@@ -318,9 +322,13 @@ static int update_screen(struct irqtop_ctl *ctl)
        move(0, 0);
 
        /* summary stat */
-       print_line(ctl, "irqtop - IRQ : %d, TOTAL : %ld, CPU : %ld, "
-                  "ACTIVE CPU : %ld\n", stat->nr_irq, stat->total_irq,
-                  stat->nr_online_cpu, stat->nr_active_cpu);
+       now = time(NULL);
+       strtime_iso(&now, ISO_TIMESTAMP_T, timestr, sizeof(timestr));
+       print_line(ctl,
+                  "irqtop - IRQ: %d TOTAL: %ld CPU: %ld ACTIVE CPU: %ld\n"
+                  "HOST: %s TIME: %s\n",
+                  stat->nr_irq, stat->total_irq, stat->nr_online_cpu, stat->nr_active_cpu,
+                  ctl->hostname, timestr);
 
        /* header */
        attron(A_REVERSE);
@@ -518,6 +526,7 @@ int main(int argc, char **argv)
        }
        ctl.smp_num_cpus = sysconf(_SC_NPROCESSORS_ONLN);
        gettime_monotonic(&ctl.uptime_tv);
+       ctl.hostname = xgethostname();
 
        if (ctl.run_once)
                retval = update_screen(&ctl);
@@ -525,6 +534,7 @@ int main(int argc, char **argv)
                event_loop(&ctl);
 
        free_irqinfo(ctl.last_stat);
+       free(ctl.hostname);
 
        if (is_tty)
                tcsetattr(STDIN_FILENO, TCSAFLUSH, &saved_tty);