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

2015-05-27 Thread Charles Duffy
From: Charles Duffy chadu...@cisco.com

Replace the single -r (raw) option with separate flags for memory and IO,
patterned off of --cpu[=TYPE], per feedback from Umut.

Fold repeated conditional logic around formatting into a static function, per
feedback from Zbyszek.

Charles Duffy (1):
  cgtop: add options to format memory, IO usage in raw bytes

 src/cgtop/cgtop.c | 64 ---
 1 file changed, 51 insertions(+), 13 deletions(-)

-- 
2.0.0

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


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

2015-05-27 Thread Zbigniew Jędrzejewski-Szmek
On Fri, May 22, 2015 at 04:56:15PM -0500, Charles Duffy wrote:
 From: Charles Duffy chadu...@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
Please add a new (static) function which wraps format_bytes and instead
of adding if's everywhere, just call that function.

Also, please don't use braces for single statements.

Zbyszek

  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=DELAYDelay 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
 
 ___
 systemd-devel mailing list
 systemd-devel@lists.freedesktop.org
 http://lists.freedesktop.org/mailman/listinfo/systemd-devel
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


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

2015-05-27 Thread Charles Duffy
From: Charles Duffy chadu...@cisco.com

---
 src/cgtop/cgtop.c | 34 +-
 1 file changed, 21 insertions(+), 13 deletions(-)

diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c
index a390cf3..2849a1d 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 {
@@ -96,6 +97,16 @@ static void group_hashmap_free(Hashmap *h) {
 hashmap_free(h);
 }
 
+static const char *cond_format_bytes(char *buf, size_t l, off_t t, bool raw, 
bool is_valid) {
+if (!is_valid)
+return -;
+if (raw) {
+snprintf(buf, l, %zd, t);
+return buf;
+}
+return format_bytes(buf, l, t);
+}
+
 static int process(const char *controller, const char *path, Hashmap *a, 
Hashmap *b, unsigned iteration) {
 Group *g;
 int r;
@@ -532,18 +543,9 @@ static int display(Hashmap *a) {
 } else
 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));
-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));
-} else
-fputs(--, stdout);
+printf( %8s, cond_format_bytes(buffer, sizeof(buffer), 
g-memory, arg_raw, g-memory_valid));
+printf( %8s, cond_format_bytes(buffer, sizeof(buffer), 
g-io_input_bps, arg_raw, g-io_valid));
+printf( %8s, cond_format_bytes(buffer, sizeof(buffer), 
g-io_output_bps, arg_raw, g-io_valid));
 
 putchar('\n');
 }
@@ -561,6 +563,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=DELAYDelay between updates\n
  -n --iterations=N   Run for N iterations before exiting\n
@@ -583,6 +586,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 +598,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 +653,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

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


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

2015-05-27 Thread Charles Duffy
From: Charles Duffy chadu...@cisco.com

Another take, incorporating feedback from r2.

Charles Duffy (1):
  cgtop: raw output option (disable conversion to human-readable units)

 src/cgtop/cgtop.c | 34 +-
 1 file changed, 21 insertions(+), 13 deletions(-)

-- 
2.0.0

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


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

2015-05-27 Thread systemd github import bot
Patchset imported to github.
Pull request:
https://github.com/systemd-devs/systemd/compare/master...systemd-mailing-devs:1432339750-31673-2-git-send-email-charles%40dyfis.net

--
Generated by https://github.com/haraldh/mail2git
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


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

2015-05-27 Thread Umut Tezduyar Lindskog
Hi Charles,

We have done something similar to this with the cpu accounting. The
option is --cpu=TYPE (There is also hidden key '%' on the tty output
which toggles between different display modes). If this patch will be
taken I think we should be consistent. Maybe something like --io=TYPE
or --memory=TYPE.

Umut

On Fri, May 22, 2015 at 11:56 PM, Charles Duffy char...@dyfis.net wrote:
 From: Charles Duffy chadu...@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=DELAYDelay 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

 ___
 systemd-devel mailing list
 systemd-devel@lists.freedesktop.org
 http://lists.freedesktop.org/mailman/listinfo/systemd-devel
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


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

2015-05-26 Thread systemd github import bot
Patchset imported to github.
Pull request:
https://github.com/systemd-devs/systemd/compare/master...systemd-mailing-devs:1432331775-28932-2-git-send-email-charles%40dyfis.net

--
Generated by https://github.com/haraldh/mail2git
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH] cgtop raw output option

2015-05-26 Thread Charles Duffy
From: Charles Duffy chadu...@cisco.com

At present, systemd-cgtop converts quantities in bytes (memory and IO bandwidth
values) to human-readable form unconditionally.

Given as batch mode already exists as a supported option, there clearly is
intent for cgtop to be usable with data routed to locations other than
(directly) to human eyeballs. Given such, an option to skip this processing and
emit raw numbers (in bytes) for these values is sensible.

Charles Duffy (1):
  cgtop: raw output option (disable conversion to human-readable units)

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

-- 
2.0.0

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


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

2015-05-26 Thread Charles Duffy
From: Charles Duffy chadu...@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=DELAYDelay 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

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel