Skip to content

Abstract columns, properly space and wrap fields

Stefano Brivio netdev 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest4 patches 14 repliesIn review
  2. v14 patches 3 repliesSuperseded

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4ss: Replace printf() calls for "main" output by calls to helpermisc/ss.c+205 -1940 replies
2/4ss: Introduce columns lightweight abstractionmisc/ss.c+198 -930 replies
3/4ss: Buffer raw fields first, then render them as a tablemisc/ss.c+225 -4613 replies
4/4ss: Implement automatic column width calculationmisc/ss.c+120 -680 replies

Reviews trailers per patch

All 4 patches have a Reviewed-by or Acked-by.

PatchSabrina Dubroca
1/4R-b
2/4R-b
3/4R-b
4/4R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH iproute2 net-next v2 0/4] Abstract columns, properly space and wrap fields

Currently, 'ss' simply subdivides the whole available screen width between available columns, starting from a set of hardcoded amount of spacing and growing column widths.

This makes the output unreadable in several cases, as it doesn't take into account the actual content width.

Fix this by introducing a simple abstraction for columns, buffering the output, measuring the width of the fields, grouping fields into lines as they fit, equally distributing any remaining whitespace, and finally rendering the result. Some examples are reported below [1].

This implementation doesn't seem to cause any significant performance issues, as reported in 3/4.

Patch 1/4 replaces all relevant printf() calls by the out() helper, which simply consists of the usual printf() implementation.

Patch 2/4 implements column abstraction, with configurable column width and delimiters, and 3/4 splits buffering and rendering phases, employing a simple buffering mechanism with chunked allocation and introducing a rendering function.

Up to this point, the output is still unchanged.

Finally, 4/4 introduces field width calculation based on content length measured while buffering, in order to split fields onto multiple lines and equally space them within the single lines.

Now that column behaviour is well-defined and more easily configurable, it should be easier to further improve the output by splitting logically separable information (e.g. TCP details) into additional columns. However, this patchset keeps the full "extended" information into a single column, for the moment being.

v2: rebase after conflict with 00ac78d39c29 ("ss: print tcpi_rcv_ssthresh")

[1]

- 80 columns terminal, ss -Z -f netlink
* before:
Recv-Q Send-Q Local Address:Port Peer Address:Port

0 0 rtnl:evolution-calen/2075 * pr
oc_ctx=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
0 0 rtnl:abrt-applet/32700 * pr
oc_ctx=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
0 0 rtnl:firefox/21619 * pr
oc_ctx=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
0 0 rtnl:evolution-calen/32639 * p
roc_ctx=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 [...]

* after:
Recv-Q Send-Q Local Address:Port Peer Address:Port
0 0 rtnl:evolution-calen/2075 *
proc_ctx=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
0 0 rtnl:abrt-applet/32700 *
proc_ctx=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
0 0 rtnl:firefox/21619 *
proc_ctx=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
0 0 rtnl:evolution-calen/32639 *
proc_ctx=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[...]

- 80 columns terminal, ss -tunpl
* before:

Netid  State      Recv-Q Send-Q Local Address:Port               Peer Address:Port
udp    UNCONN     0      0         *:37732                 *:*
udp    UNCONN     0      0         *:5353                  *:*
udp    UNCONN     0      0      192.168.122.1:53                    *:*
udp    UNCONN     0      0      *%virbr0:67                    *:*

[...]

* after:

Netid   State    Recv-Q   Send-Q     Local Address:Port      Peer Address:Port
udp     UNCONN   0        0                      *:37732                *:*
udp     UNCONN   0        0                      *:5353                 *:*
udp     UNCONN   0        0          192.168.122.1:53                   *:*
udp     UNCONN   0        0               *%virbr0:67                   *:*

[...]

- 66 columns terminal, ss -tunpl
* before:
Netid State Recv-Q Send-Q Local Address:Port P
eer Address:Port
udp UNCONN 0 0 *:37732 *:*

udp UNCONN 0 0 *:5353 *:*

udp UNCONN 0 0 192.168.122.1:53
*:*
udp UNCONN 0 0 *%virbr0:67 *:*
[...]

* after:
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port

udp   UNCONN 0      0                  *:37732             *:*
udp   UNCONN 0      0                  *:5353              *:*
udp   UNCONN 0      0      192.168.122.1:53                *:*
udp   UNCONN 0      0           *%virbr0:67                *:*

[...]

Stefano Brivio (4):
ss: Replace printf() calls for "main" output by calls to helper
ss: Introduce columns lightweight abstraction
ss: Buffer raw fields first, then render them as a table
ss: Implement automatic column width calculation

 misc/ss.c | 895 +++++++++++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 621 insertions(+), 274 deletions(-)
Signature · 1 line
2.9.4