netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ss: introduce switch to print exact value of data rates
@ 2018-02-01 14:19 Tomasz Torcz
  2018-02-02 23:32 ` David Ahern
  0 siblings, 1 reply; 9+ messages in thread
From: Tomasz Torcz @ 2018-02-01 14:19 UTC (permalink / raw)
  To: netdev; +Cc: tomek, Tomasz Torcz

  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;
 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;
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] ss: introduce switch to print exact value of data rates
  2018-02-01 14:19 [PATCH] ss: introduce switch to print exact value of data rates Tomasz Torcz
@ 2018-02-02 23:32 ` David Ahern
  2018-02-06  1:02   ` Stephen Hemminger
  2018-03-11 16:26   ` [PATCH v2] " Tomasz Torcz
  0 siblings, 2 replies; 9+ messages in thread
From: David Ahern @ 2018-02-02 23:32 UTC (permalink / raw)
  To: Tomasz Torcz, netdev; +Cc: tomek

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?

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] ss: introduce switch to print exact value of data rates
  2018-02-02 23:32 ` David Ahern
@ 2018-02-06  1:02   ` Stephen Hemminger
  2018-03-11 16:26   ` [PATCH v2] " Tomasz Torcz
  1 sibling, 0 replies; 9+ messages in thread
From: Stephen Hemminger @ 2018-02-06  1:02 UTC (permalink / raw)
  To: David Ahern; +Cc: Tomasz Torcz, netdev, tomek

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?)

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v2] ss: introduce switch to print exact value of data rates
  2018-02-02 23:32 ` David Ahern
  2018-02-06  1:02   ` Stephen Hemminger
@ 2018-03-11 16:26   ` Tomasz Torcz
  2018-03-11 16:26     ` [PATCH] " Tomasz Torcz
  1 sibling, 1 reply; 9+ messages in thread
From: Tomasz Torcz @ 2018-03-11 16:26 UTC (permalink / raw)
  To: netdev

   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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH] ss: introduce switch to print exact value of data rates
  2018-03-11 16:26   ` [PATCH v2] " Tomasz Torcz
@ 2018-03-11 16:26     ` Tomasz Torcz
  2018-03-16 15:40       ` David Ahern
  0 siblings, 1 reply; 9+ messages in thread
From: Tomasz Torcz @ 2018-03-11 16:26 UTC (permalink / raw)
  To: netdev; +Cc: Tomasz Torcz

  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 e087bef7..61c917e4 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_human_readable = 1;
 int show_users;
 int show_mem;
 int show_tcpinfo;
@@ -2276,7 +2277,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_human_readable)
+		sprintf(buf, "%.0f", bw);
+	else if (bw > 1000000.)
 		sprintf(buf, "%.1fM", bw / 1000000.);
 	else if (bw > 1000.)
 		sprintf(buf, "%.1fK", bw / 1000.);
@@ -4502,6 +4505,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, instead of human-readable\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"
@@ -4634,6 +4638,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 }
 
 };
@@ -4650,7 +4655,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':
@@ -4701,6 +4706,9 @@ int main(int argc, char *argv[])
 		case 'x':
 			filter_af_set(&current_filter, AF_UNIX);
 			break;
+		case 'X':
+			show_human_readable = 0;
+			break;
 		case OPT_VSOCK:
 			filter_af_set(&current_filter, AF_VSOCK);
 			break;
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] ss: introduce switch to print exact value of data rates
  2018-03-11 16:26     ` [PATCH] " Tomasz Torcz
@ 2018-03-16 15:40       ` David Ahern
  2019-07-01 11:52         ` [PATCH v3] " Tomasz Torcz
  0 siblings, 1 reply; 9+ messages in thread
From: David Ahern @ 2018-03-16 15:40 UTC (permalink / raw)
  To: Tomasz Torcz, netdev

On 3/11/18 9:26 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(-)
> 


still not a fan of --exact for the long name, but I can't think of
anything better at the moment. Please update the man page as well.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v3] ss: introduce switch to print exact value of data rates
  2018-03-16 15:40       ` David Ahern
@ 2019-07-01 11:52         ` Tomasz Torcz
  2019-07-01 14:51           ` David Ahern
  0 siblings, 1 reply; 9+ messages in thread
From: Tomasz Torcz @ 2019-07-01 11:52 UTC (permalink / raw)
  To: dsahern; +Cc: netdev, Tomasz Torcz

  Introduce -X/--exact switch to disable human-friendly printing
 of data rates. Without the switch (default), data is presented as MBps/Kbps.

  Signed-off-by: Tomasz Torcz <tomasz.torcz@nordea.com>
---
 man/man8/ss.8 |  3 +++
 misc/ss.c     | 12 ++++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)

 Changes in v3:
  - updated ss man page with new option

diff --git a/man/man8/ss.8 b/man/man8/ss.8
index 9054fab9..2ba5fda2 100644
--- a/man/man8/ss.8
+++ b/man/man8/ss.8
@@ -290,6 +290,9 @@ that parsing /proc/net/tcp is painful.
 .B \-E, \-\-events
 Continually display sockets as they are destroyed
 .TP
+.B \-X, \-\-exact
+Show exact bandwidth values, instead of human-readable
+.TP
 .B \-Z, \-\-context
 As the
 .B \-p
diff --git a/misc/ss.c b/misc/ss.c
index 99c06d31..ba1bfff6 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -110,6 +110,7 @@ static int resolve_services = 1;
 int preferred_family = AF_UNSPEC;
 static int show_options;
 int show_details;
+static int show_human_readable = 1;
 static int show_users;
 static int show_mem;
 static int show_tcpinfo;
@@ -2361,7 +2362,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_human_readable)
+		sprintf(buf, "%.0f", bw);
+	else if (bw > 1000000.)
 		sprintf(buf, "%.1fM", bw / 1000000.);
 	else if (bw > 1000.)
 		sprintf(buf, "%.1fK", bw / 1000.);
@@ -4883,6 +4886,7 @@ static void _usage(FILE *dest)
 "       --tos           show tos and priority information\n"
 "   -b, --bpf           show bpf filter socket information\n"
 "   -E, --events        continually display sockets as they are destroyed\n"
+"   -X, --exact         show exact bandwidth values, instead of human-readable\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"
@@ -5031,6 +5035,7 @@ static const struct option long_opts[] = {
 	{ "no-header", 0, 0, 'H' },
 	{ "xdp", 0, 0, OPT_XDPSOCK},
 	{ "oneline", 0, 0, 'O' },
+	{ "exact", 0, 0, 'X' },
 	{ 0 }
 
 };
@@ -5046,7 +5051,7 @@ int main(int argc, char *argv[])
 	int state_filter = 0;
 
 	while ((ch = getopt_long(argc, argv,
-				 "dhaletuwxnro460spbEf:miA:D:F:vVzZN:KHSO",
+				 "dhaletuwxXnro460spbEf:miA:D:F:vVzZN:KHSO",
 				 long_opts, NULL)) != EOF) {
 		switch (ch) {
 		case 'n':
@@ -5097,6 +5102,9 @@ int main(int argc, char *argv[])
 		case 'x':
 			filter_af_set(&current_filter, AF_UNIX);
 			break;
+		case 'X':
+			show_human_readable = 0;
+			break;
 		case OPT_VSOCK:
 			filter_af_set(&current_filter, AF_VSOCK);
 			break;
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v3] ss: introduce switch to print exact value of data rates
  2019-07-01 11:52         ` [PATCH v3] " Tomasz Torcz
@ 2019-07-01 14:51           ` David Ahern
  2019-07-02  6:53             ` [PATCH] ss: in --numeric mode, print raw numbers for " Tomasz Torcz
  0 siblings, 1 reply; 9+ messages in thread
From: David Ahern @ 2019-07-01 14:51 UTC (permalink / raw)
  To: Tomasz Torcz; +Cc: netdev

On 7/1/19 5:52 AM, Tomasz Torcz wrote:
>   Introduce -X/--exact switch to disable human-friendly printing
>  of data rates. Without the switch (default), data is presented as MBps/Kbps.
> 
>   Signed-off-by: Tomasz Torcz <tomasz.torcz@nordea.com>
> ---
>  man/man8/ss.8 |  3 +++
>  misc/ss.c     | 12 ++++++++++--
>  2 files changed, 13 insertions(+), 2 deletions(-)
> 
>  Changes in v3:
>   - updated ss man page with new option
> 

ss now has Numeric option which can be used for this as well if we
broaden the meaning to be 'raw numbers over human readable'.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH] ss: in --numeric mode, print raw numbers for data rates
  2019-07-01 14:51           ` David Ahern
@ 2019-07-02  6:53             ` Tomasz Torcz
  0 siblings, 0 replies; 9+ messages in thread
From: Tomasz Torcz @ 2019-07-02  6:53 UTC (permalink / raw)
  To: dsahern; +Cc: netdev, Tomasz Torcz

  ss by default shows data rates in human-readable form - as Mbps/Gbps etc.
 Enhance --numeric mode to show raw values in bps, without conversion.

  Signed-of-by: Tomasz Torcz <tomasz.torcz@nordea.com>
---
 man/man8/ss.8 | 2 +-
 misc/ss.c     | 4 +++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/man/man8/ss.8 b/man/man8/ss.8
index 9054fab9..f428e60c 100644
--- a/man/man8/ss.8
+++ b/man/man8/ss.8
@@ -28,7 +28,7 @@ Suppress header line.
 Print each socket's data on a single line.
 .TP
 .B \-n, \-\-numeric
-Do not try to resolve service names.
+Do not try to resolve service names. Show exact bandwidth values, instead of human-readable.
 .TP
 .B \-r, \-\-resolve
 Try to resolve numeric address/ports.
diff --git a/misc/ss.c b/misc/ss.c
index 99c06d31..3d9d1d8f 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -2361,7 +2361,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 (!resolve_services)
+		sprintf(buf, "%.0f", bw);
+	else if (bw > 1000000.)
 		sprintf(buf, "%.1fM", bw / 1000000.);
 	else if (bw > 1000.)
 		sprintf(buf, "%.1fK", bw / 1000.);
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2019-07-02  6:54 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-01 14:19 [PATCH] ss: introduce switch to print exact value of data rates Tomasz Torcz
2018-02-02 23:32 ` David Ahern
2018-02-06  1:02   ` Stephen Hemminger
2018-03-11 16:26   ` [PATCH v2] " Tomasz Torcz
2018-03-11 16:26     ` [PATCH] " Tomasz Torcz
2018-03-16 15:40       ` David Ahern
2019-07-01 11:52         ` [PATCH v3] " Tomasz Torcz
2019-07-01 14:51           ` David Ahern
2019-07-02  6:53             ` [PATCH] ss: in --numeric mode, print raw numbers for " Tomasz Torcz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).