iovisor / bcc

BCC - Tools for BPF-based Linux IO analysis, networking, monitoring, and more
Apache License 2.0
20.36k stars 3.86k forks source link

libbpf tcptop: Fix PID column alignment when pids are large #5004

Closed bernhardkaindl closed 4 months ago

bernhardkaindl commented 4 months ago

Fix PID column alignment when PIDs are large in libbpf-tools/tcptop:

Check the maximum width of the PIDs on the system and adjust the format to avoid column misalignment:

PID     COMM         LADDR                 RADDR                  RX_KB  TX_KB
1987802 wget         127.0.0.1:44960       127.0.0.1:443              6      0
1987815 wget         127.0.0.1:44968       127.0.0.1:443              6      0
2770    stunnel      127.0.0.1:51460       127.0.0.1:80               4      0
2770    stunnel      127.0.0.1:51452       127.0.0.1:80               4      0
1936412 sshd         10.71.56.137:22       10.71.8.14:45682           0      2
1987805 curl         127.0.0.1:44964       127.0.0.1:443              1      0
1987818 curl         127.0.0.1:44972       127.0.0.1:443              1      0
2770    stunnel      127.0.0.1:51456       127.0.0.1:80               0      0
2770    stunnel      127.0.0.1:51464       127.0.0.1:80               0      0
1918977 sshd         10.71.56.137:22       10.71.8.14:51046           0      0

PS: It seems that GitHub CI fails on a few test cases (flaky), not caused by this PR.