netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH iproute2] ss: make socket statistic parseable
@ 2013-10-19 17:54 Hagen Paul Pfeifer
  2013-10-19 21:56 ` Eric Dumazet
  0 siblings, 1 reply; 4+ messages in thread
From: Hagen Paul Pfeifer @ 2013-10-19 17:54 UTC (permalink / raw)
  To: netdev; +Cc: shemminger, Hagen Paul Pfeifer, Eric Dumazet

Currently "ss -emoi" output is nearly perfect: key value(s) tuples are
delimited by colon. Except three groups: socket options, congestion
control algorithm and send data. Especially the first two groups prevent
automated parsing: what if a future congestion control algorithm is
named "faster" - is this a TCP flag or a congestion control algorithm?
The current syntax allow no parsing.

This patch harmonize the syntax for the last three remaining groups.

Signed-off-by: Hagen Paul Pfeifer <hagen@jauu.net>
---
 misc/ss.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/misc/ss.c b/misc/ss.c
index c0369f1..beca2eb 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -1386,20 +1386,22 @@ static void tcp_show_info(const struct nlmsghdr *nlh, struct inet_diag_msg *r,
 			info = RTA_DATA(tb[INET_DIAG_INFO]);
 
 		if (show_options) {
+			int is_not_first_element = 0;
+			printf(" options:");
 			if (info->tcpi_options & TCPI_OPT_TIMESTAMPS)
-				printf(" ts");
+				printf("%cts", is_not_first_element++ ? ',' : '\0');
 			if (info->tcpi_options & TCPI_OPT_SACK)
-				printf(" sack");
+				printf("%csack", is_not_first_element++ ? ',' : '\0');
 			if (info->tcpi_options & TCPI_OPT_ECN)
-				printf(" ecn");
+				printf("%cecn", is_not_first_element++ ? ',' : '\0');
 			if (info->tcpi_options & TCPI_OPT_ECN_SEEN)
-				printf(" ecnseen");
+				printf("%cecnseen", is_not_first_element++ ? ',' : '\0');
 			if (info->tcpi_options & TCPI_OPT_SYN_DATA)
-				printf(" fastopen");
+				printf("%cfastopen", is_not_first_element++ ? ',' : '\0');
 		}
 
 		if (tb[INET_DIAG_CONG])
-			printf(" %s", rta_getattr_str(tb[INET_DIAG_CONG]));
+			printf(" cc:%s", rta_getattr_str(tb[INET_DIAG_CONG]));
 
 		if (info->tcpi_options & TCPI_OPT_WSCALE)
 			printf(" wscale:%d,%d", info->tcpi_snd_wscale,
@@ -1429,7 +1431,7 @@ static void tcp_show_info(const struct nlmsghdr *nlh, struct inet_diag_msg *r,
 		}
 
 		if (rtt > 0 && info->tcpi_snd_mss && info->tcpi_snd_cwnd) {
-			printf(" send %sbps",
+			printf(" send:%sbps",
 			       sprint_bw(b1, (double) info->tcpi_snd_cwnd *
 					 (double) info->tcpi_snd_mss * 8000000.
 					 / rtt));
-- 
1.8.4.rc3

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

end of thread, other threads:[~2013-10-20 13:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-19 17:54 [PATCH iproute2] ss: make socket statistic parseable Hagen Paul Pfeifer
2013-10-19 21:56 ` Eric Dumazet
2013-10-20 13:24   ` Hagen Paul Pfeifer
2013-10-20 13:44     ` Eric Dumazet

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