Skip to content

Commit

Permalink
Moving duration to primary argument for tcpconnlat. Also updating doc…
Browse files Browse the repository at this point in the history
…s for tcpconnlat to match.
  • Loading branch information
dpayne committed Jan 18, 2018
1 parent 7b7e34a commit fc50799
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
13 changes: 5 additions & 8 deletions man/man8/tcpconnlat.8
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.SH NAME
tcpconnlat \- Trace TCP active connection latency. Uses Linux eBPF/bcc.
.SH SYNOPSIS
.B tcpconnlat [\-h] [\-t] [\-p PID] [-m MIN_MS] [-u MIN_US] [-v]
.B tcpconnlat [\-h] [\-t] [\-p PID] [-v] [min_ms]
.SH DESCRIPTION
This tool traces active TCP connections
(eg, via a connect() syscall), and shows the latency (time) for the connection
Expand Down Expand Up @@ -31,14 +31,11 @@ Include a timestamp column.
\-p PID
Trace this process ID only (filtered in-kernel).
.TP
\-m MIN_NS
Minimum duration to trace, in milliseconds.
.TP
\-u MIN_US
Minimum duration to trace, in microseconds.
.TP
\-v
Print the resulting BPF program, for debugging purposes.
.TP
min_ns
Minimum duration to trace, in milliseconds.
.SH EXAMPLES
.TP
Trace all active TCP connections, and show connection latency (SYN->response round trip):
Expand All @@ -55,7 +52,7 @@ Trace PID 181 only:
.TP
Trace connects with latency longer than 10 ms:
#
.B tcpconnlat \-m 10
.B tcpconnlat 10
.TP
Print the BPF program:
#
Expand Down
29 changes: 19 additions & 10 deletions tools/tcpconnlat.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,22 @@
import argparse
import ctypes as ct

# arg validation
def positive_float(val):
try:
ival = float(val)
except ValueError:
raise argparse.ArgumentTypeError("must be a float")

if ival < 0:
raise argparse.ArgumentTypeError("must be positive")
return ival

# arguments
examples = """examples:
./tcpconnlat # trace all TCP connect()s
./tcpconnlat -m 1 # only show results slower than 1 ms
./tcpconnlat -u 100 # only show results slower than 100 microseconds
./tcpconnlat 1 # trace connection latency slower than 1 ms
./tcpconnlat 0.1 # trace connection latency slower than 100 us
./tcpconnlat -t # include timestamps
./tcpconnlat -p 181 # only trace PID 181
"""
Expand All @@ -37,18 +48,16 @@
help="include timestamp on output")
parser.add_argument("-p", "--pid",
help="trace this PID only")
parser.add_argument("-m", "--min-ms", type=float, dest="min_ms",
help="minimum latency filter (ms)")
parser.add_argument("-u", "--min-us", type=float, dest="min_us",
help="minimum latency filter (us)")
parser.add_argument("duration_ms", nargs="?", default=0,
type=positive_float,
help="minimum duration to trace (ms)")
parser.add_argument("-v", "--verbose", action="store_true",
help="print the BPF program for debugging purposes")
args = parser.parse_args()

if args.min_ms:
duration_us = int(args.min_ms * 1000)
elif args.min_us:
duration_us = int(args.min_us)
if args.duration_ms:
# support fractions but round to nearest microsecond
duration_us = int(args.duration_ms * 1000)
else:
duration_us = 0 # default is show all

Expand Down
4 changes: 2 additions & 2 deletions tools/tcpconnlat_example.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ examples:
./tcpconnlat # trace all TCP connect()s
./tcpconnlat -t # include timestamps
./tcpconnlat -p 181 # only trace PID 181
./tcpconnlat -m 1 # only show connects longer than 1 ms
./tcpconnlat -u 100 # only show connects longer than 100 us
./tcpconnlat 1 # only show connects longer than 1 ms
./tcpconnlat 0.1 # only show connects longer than 100 us
./tcpconnlat -v # Show the BPF program

0 comments on commit fc50799

Please sign in to comment.