diff mbox series

ss: introduce switch to print exact value of data rates

Message ID 20180201141915.27985-1-tomasz.torcz@nordea.com
State Changes Requested, archived
Delegated to: stephen hemminger
Headers show
Series ss: introduce switch to print exact value of data rates | expand

Commit Message

Tomasz Torcz Feb. 1, 2018, 2:19 p.m. UTC
Introduce -X/--exact switch to disable human-friendly printing
 of datarates. With the switch, data is not presented as MBps/Kbps.

  Signed-off-by: Tomasz Torcz <tomasz.torcz@nordea.com>
---
 misc/ss.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

Comments

David Ahern Feb. 2, 2018, 11:32 p.m. UTC | #1
On 2/1/18 7:19 AM, Tomasz Torcz wrote:
>   Introduce -X/--exact switch to disable human-friendly printing
>  of datarates. With the switch, data is not presented as MBps/Kbps.
> 
>   Signed-off-by: Tomasz Torcz <tomasz.torcz@nordea.com>
> ---
>  misc/ss.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/misc/ss.c b/misc/ss.c
> index 29a25070..5ca5112a 100644
> --- a/misc/ss.c
> +++ b/misc/ss.c
> @@ -95,6 +95,7 @@ int resolve_services = 1;
>  int preferred_family = AF_UNSPEC;
>  int show_options;
>  int show_details;
> +int show_exact;

show_exact suggests the other versions are not exact. show_raw? or

int human_readable = 1;

and -X disables it?
Stephen Hemminger Feb. 6, 2018, 1:02 a.m. UTC | #2
On Fri, 2 Feb 2018 16:32:47 -0700
David Ahern <dsahern@gmail.com> wrote:

> On 2/1/18 7:19 AM, Tomasz Torcz wrote:
> >   Introduce -X/--exact switch to disable human-friendly printing
> >  of datarates. With the switch, data is not presented as MBps/Kbps.
> > 
> >   Signed-off-by: Tomasz Torcz <tomasz.torcz@nordea.com>
> > ---
> >  misc/ss.c | 12 ++++++++++--
> >  1 file changed, 10 insertions(+), 2 deletions(-)
> > 
> > diff --git a/misc/ss.c b/misc/ss.c
> > index 29a25070..5ca5112a 100644
> > --- a/misc/ss.c
> > +++ b/misc/ss.c
> > @@ -95,6 +95,7 @@ int resolve_services = 1;
> >  int preferred_family = AF_UNSPEC;
> >  int show_options;
> >  int show_details;
> > +int show_exact;  
> 
> show_exact suggests the other versions are not exact. show_raw? or
> 
> int human_readable = 1;
> 
> and -X disables it?

agree with david, think of another flag name (raw? or no-prefix?)
Tomasz Torcz March 11, 2018, 4:26 p.m. UTC | #3
Introduce -X/--exact switch to disable human-friendly printing  of 
datarates. With the switch, data is not presented as MBps/Kbps.

Changes in v2:
- change variable name into to show_human_readable
diff mbox series

Patch

diff --git a/misc/ss.c b/misc/ss.c
index 29a25070..5ca5112a 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -95,6 +95,7 @@  int resolve_services = 1;
 int preferred_family = AF_UNSPEC;
 int show_options;
 int show_details;
+int show_exact;
 int show_users;
 int show_mem;
 int show_tcpinfo;
@@ -2270,7 +2271,9 @@  static int proc_inet_split_line(char *line, char **loc, char **rem, char **data)
 
 static char *sprint_bw(char *buf, double bw)
 {
-	if (bw > 1000000.)
+	if (show_exact)
+		sprintf(buf, "%.0f", bw);
+	else if (bw > 1000000.)
 		sprintf(buf, "%.1fM", bw / 1000000.);
 	else if (bw > 1000.)
 		sprintf(buf, "%.1fK", bw / 1000.);
@@ -4485,6 +4488,7 @@  static void _usage(FILE *dest)
 "   -s, --summary       show socket usage summary\n"
 "   -b, --bpf           show bpf filter socket information\n"
 "   -E, --events        continually display sockets as they are destroyed\n"
+"   -X, --exact         show exact values\n"
 "   -Z, --context       display process SELinux security contexts\n"
 "   -z, --contexts      display process and socket SELinux security contexts\n"
 "   -N, --net           switch to the specified network namespace name\n"
@@ -4617,6 +4621,7 @@  static const struct option long_opts[] = {
 	{ "net", 1, 0, 'N' },
 	{ "kill", 0, 0, 'K' },
 	{ "no-header", 0, 0, 'H' },
+	{ "exact", 0, 0, 'X' },
 	{ 0 }
 
 };
@@ -4633,7 +4638,7 @@  int main(int argc, char *argv[])
 	int screen_width = 80;
 
 	while ((ch = getopt_long(argc, argv,
-				 "dhaletuwxnro460spbEf:miA:D:F:vVzZN:KHS",
+				 "dhaletuwxXnro460spbEf:miA:D:F:vVzZN:KHS",
 				 long_opts, NULL)) != EOF) {
 		switch (ch) {
 		case 'n':
@@ -4684,6 +4689,9 @@  int main(int argc, char *argv[])
 		case 'x':
 			filter_af_set(&current_filter, AF_UNIX);
 			break;
+		case 'X':
+			show_exact = 1;
+			break;
 		case OPT_VSOCK:
 			filter_af_set(&current_filter, AF_VSOCK);
 			break;