Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bcc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
bcc
Commits
8e86b9e9
Commit
8e86b9e9
authored
Jul 27, 2017
by
Benjamin Poirier
Committed by
Brenden Blanco
Aug 11, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tcptop: Cleanup argument parsing
parent
890c76ab
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
16 deletions
+15
-16
tools/tcptop.py
tools/tcptop.py
+15
-16
No files found.
tools/tcptop.py
View file @
8e86b9e9
...
@@ -34,6 +34,13 @@ from subprocess import call
...
@@ -34,6 +34,13 @@ from subprocess import call
import
ctypes
as
ct
import
ctypes
as
ct
# arguments
# arguments
def
range_check
(
string
):
value
=
int
(
string
)
if
value
<
1
:
msg
=
"value must be stricly positive, got %d"
%
(
value
,)
raise
argparse
.
ArgumentTypeError
(
msg
)
return
value
examples
=
"""examples:
examples
=
"""examples:
./tcptop # trace TCP send/recv by host
./tcptop # trace TCP send/recv by host
./tcptop -C # don't clear the screen
./tcptop -C # don't clear the screen
...
@@ -49,15 +56,11 @@ parser.add_argument("-S", "--nosummary", action="store_true",
...
@@ -49,15 +56,11 @@ parser.add_argument("-S", "--nosummary", action="store_true",
help
=
"skip system summary line"
)
help
=
"skip system summary line"
)
parser
.
add_argument
(
"-p"
,
"--pid"
,
parser
.
add_argument
(
"-p"
,
"--pid"
,
help
=
"trace this PID only"
)
help
=
"trace this PID only"
)
parser
.
add_argument
(
"interval"
,
nargs
=
"?"
,
default
=
1
,
parser
.
add_argument
(
"interval"
,
nargs
=
"?"
,
default
=
1
,
type
=
range_check
,
help
=
"output interval, in seconds (default 1)"
)
help
=
"output interval, in seconds (default 1)"
)
parser
.
add_argument
(
"count"
,
nargs
=
"?"
,
default
=
99999999
,
parser
.
add_argument
(
"count"
,
nargs
=
"?"
,
default
=
-
1
,
type
=
range_check
,
help
=
"number of outputs"
)
help
=
"number of outputs"
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
countdown
=
int
(
args
.
count
)
if
args
.
interval
and
int
(
args
.
interval
)
==
0
:
print
(
"ERROR: interval 0. Exiting."
)
exit
()
debug
=
0
debug
=
0
# linux stats
# linux stats
...
@@ -204,15 +207,13 @@ ipv6_recv_bytes = b["ipv6_recv_bytes"]
...
@@ -204,15 +207,13 @@ ipv6_recv_bytes = b["ipv6_recv_bytes"]
print
(
'Tracing... Output every %s secs. Hit Ctrl-C to end'
%
args
.
interval
)
print
(
'Tracing... Output every %s secs. Hit Ctrl-C to end'
%
args
.
interval
)
# output
# output
exiting
=
0
i
=
0
while
(
1
):
exiting
=
False
while
i
!=
args
.
count
and
not
exiting
:
try
:
try
:
if
args
.
interval
:
sleep
(
args
.
interval
)
sleep
(
int
(
args
.
interval
))
else
:
sleep
(
99999999
)
except
KeyboardInterrupt
:
except
KeyboardInterrupt
:
exiting
=
1
exiting
=
True
# header
# header
if
args
.
noclear
:
if
args
.
noclear
:
...
@@ -282,6 +283,4 @@ while (1):
...
@@ -282,6 +283,4 @@ while (1):
ipv6_send_bytes
.
clear
()
ipv6_send_bytes
.
clear
()
ipv6_recv_bytes
.
clear
()
ipv6_recv_bytes
.
clear
()
countdown
-=
1
i
+=
1
if
exiting
or
countdown
==
0
:
exit
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment