[systemd-devel] [PATCH] cgtop: raw output option (disable conversion to human-readable units)

Charles Duffy charles at dyfis.net
Fri May 22 14:56:15 PDT 2015


From: Charles Duffy <chaduffy at cisco.com>

---
 src/cgtop/cgtop.c | 28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c
index a390cf3..0dbac7f 100644
--- a/src/cgtop/cgtop.c
+++ b/src/cgtop/cgtop.c
@@ -62,6 +62,7 @@ typedef struct Group {
 static unsigned arg_depth = 3;
 static unsigned arg_iterations = 0;
 static bool arg_batch = false;
+static bool arg_raw = false;
 static usec_t arg_delay = 1*USEC_PER_SEC;
 
 static enum {
@@ -533,15 +534,24 @@ static int display(Hashmap *a) {
                         printf(" %*s", maxtcpu, format_timespan(buffer, sizeof(buffer), (nsec_t) (g->cpu_usage / NSEC_PER_USEC), 0));
 
                 if (g->memory_valid)
-                        printf(" %8s", format_bytes(buffer, sizeof(buffer), g->memory));
+                        if(arg_raw) {
+                                printf(" %8ld", g->memory);
+                        } else {
+                                printf(" %8s", format_bytes(buffer, sizeof(buffer), g->memory));
+                        }
                 else
                         fputs("        -", stdout);
 
                 if (g->io_valid) {
-                        printf(" %8s",
-                               format_bytes(buffer, sizeof(buffer), g->io_input_bps));
-                        printf(" %8s",
-                               format_bytes(buffer, sizeof(buffer), g->io_output_bps));
+                        if(arg_raw) {
+                                printf(" %8ld", g->io_input_bps);
+                                printf(" %8ld", g->io_output_bps);
+                        } else {
+                                printf(" %8s",
+                                       format_bytes(buffer, sizeof(buffer), g->io_input_bps));
+                                printf(" %8s",
+                                       format_bytes(buffer, sizeof(buffer), g->io_output_bps));
+                        }
                 } else
                         fputs("        -        -", stdout);
 
@@ -561,6 +571,7 @@ static void help(void) {
                "  -c                  Order by CPU load\n"
                "  -m                  Order by memory load\n"
                "  -i                  Order by IO load\n"
+               "  -r                  Provide raw (not human-readable) numbers\n"
                "     --cpu[=TYPE]     Show CPU usage as time or percentage (default)\n"
                "  -d --delay=DELAY    Delay between updates\n"
                "  -n --iterations=N   Run for N iterations before exiting\n"
@@ -583,6 +594,7 @@ static int parse_argv(int argc, char *argv[]) {
                 { "delay",      required_argument, NULL, 'd'         },
                 { "iterations", required_argument, NULL, 'n'         },
                 { "batch",      no_argument,       NULL, 'b'         },
+                { "raw",        no_argument,       NULL, 'r'         },
                 { "depth",      required_argument, NULL, ARG_DEPTH   },
                 { "cpu",        optional_argument, NULL, ARG_CPU_TYPE},
                 {}
@@ -594,7 +606,7 @@ static int parse_argv(int argc, char *argv[]) {
         assert(argc >= 1);
         assert(argv);
 
-        while ((c = getopt_long(argc, argv, "hptcmin:bd:", options, NULL)) >= 0)
+        while ((c = getopt_long(argc, argv, "hptcmin:brd:", options, NULL)) >= 0)
 
                 switch (c) {
 
@@ -649,6 +661,10 @@ static int parse_argv(int argc, char *argv[]) {
                         arg_batch = true;
                         break;
 
+                case 'r':
+                        arg_raw = true;
+                        break;
+
                 case 'p':
                         arg_order = ORDER_PATH;
                         break;
-- 
2.0.0



More information about the systemd-devel mailing list