Skip to content

Commit

Permalink
Adding ability to truncate output
Browse files Browse the repository at this point in the history
If there are too many tcp connections then the top doesn't work well as it scrolls the shell window. This `-o` option lets you limit the output to however many lines you want.
  • Loading branch information
ShawnTuatara authored Sep 14, 2024
1 parent 9f3d0df commit 71bfdf7
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tools/tcptop.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ def range_check(string):
help="skip system summary line")
parser.add_argument("-p", "--pid",
help="trace this PID only")
parser.add_argument("-o", "--outputlines", default=-1, type=range_check,
help="Number of lines to output per interval")
parser.add_argument("interval", nargs="?", default=1, type=range_check,
help="output interval, in seconds (default 1)")
parser.add_argument("count", nargs="?", default=-1, type=range_check,
Expand Down Expand Up @@ -367,9 +369,10 @@ def get_ipv6_session_key(k):
"LADDR6", "RADDR6", "RX_KB", "TX_KB"))

# output
for k, (send_bytes, recv_bytes) in sorted(ipv6_throughput.items(),
key=lambda kv: sum(kv[1]),
reverse=True):
outputElements = sorted(ipv6_throughput.items(),key=lambda kv: sum(kv[1]),reverse=True)
if args.outputlines > 0:
del outputElements[args.outputlines:]
for k, (send_bytes, recv_bytes) in outputElements:
print("%-7d %-12.12s %-32s %-32s %6d %6d" % (k.pid,
k.name,
k.laddr + ":" + str(k.lport),
Expand Down

0 comments on commit 71bfdf7

Please sign in to comment.