Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
asteriskperf-python-wrapper
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
s_doering
asteriskperf-python-wrapper
Commits
62f109f0
Commit
62f109f0
authored
Jul 11, 2015
by
Deathcrow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- added legacy option
- code restructuring
parent
a26951ca
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
79 additions
and
56 deletions
+79
-56
wrapper.py
wrapper.py
+79
-56
No files found.
wrapper.py
100644 → 100755
View file @
62f109f0
#!/usr/bin/env python3
# vim: expandtab shiftwidth=4 softtabstop=4
#iperf -V -Z cubic -t 30 -c fdb2:f689:4248:2bc8::3 -p 12345
import
argparse
...
...
@@ -57,28 +60,53 @@ def process_raw_tcpprobe_file(tcpprobe_file, sender):
for
key
,
i
in
enumerate
(
sender
):
if
line_split
[
1
]
==
r
"["
+
i
[
'src'
]
+
r
"]:"
+
i
[
'src_port'
]:
# and line_split[2][:-5] == r"["+i['dst']+r"]:":
tcpprobe_sender_file
=
open
(
args
.
tmp_folder
+
"/tcpprobe_"
+
i
[
'congestion'
]
+
"_"
+
str
(
key
),
'a'
)
tcpprobe_sender_file
.
write
(
line
)
tcpprobe_sender_file
.
close
()
if
not
i
.
get
(
'tcpprobe_time'
):
i
[
'tcpprobe_time'
]
=
float
(
line_split
[
0
])
i
[
'tcpprobe_seq'
]
=
int
(
line_split
[
4
],
0
)
if
float
(
line_split
[
0
])
-
i
[
'tcpprobe_time'
]
>
bandwith_interval
:
bandwith_file
=
open
(
args
.
tmp_folder
+
"/bw_"
+
i
[
'congestion'
]
+
"_"
+
str
(
key
),
'a'
)
i
[
'tcpprobe_file'
].
write
(
line
)
# i['tcpprobe_file'].close()
# if not i.get('tcpprobe_time'):
# i['tcpprobe_time'] = float(line_split[0])
# i['tcpprobe_seq'] = int(line_split[4], 0)
# if float(line_split[0]) - i['tcpprobe_time'] > bandwith_interval:
# bandwidth_file = open(args.tmp_folder+"/bw_"+i['congestion']+"_"+str(key), 'a')
# write Mbps to file
bandwi
th_file
.
write
(
" "
.
join
(
line_split
[:
3
]
+
[
str
(
abs
(
int
(
line_split
[
4
],
0
)
-
i
[
'tcpprobe_seq'
])
/
bandwith_interval
*
8
/
1000
/
1000
)]
)
+
"
\n
"
)
bandwi
th_file
.
close
()
# bandwid
th_file.write(" ".join(line_split[:3]+[str(abs(int(line_split[4], 0) - i['tcpprobe_seq']) / bandwith_interval * 8 / 1000 / 1000 )] )+"\n" )
# bandwid
th_file.close()
i
[
'tcpprobe_time'
]
=
float
(
line_split
[
0
])
i
[
'tcpprobe_seq'
]
=
int
(
line_split
[
4
],
0
)
# i['tcpprobe_time'] = float(line_split[0])
# i['tcpprobe_seq'] = int(line_split[4], 0)
tcpprobe_file
.
close
()
def
process_proc_tcpprobe
(
sender
):
#sampling
tcpprobe_proc
=
open
(
"/proc/net/tcpprobe"
,
"r"
)
unprocessed_senders
=
sender
.
copy
()
# collect line from tcpprobe and write to file if it belongs to a
# unprocessed (one that didn't have a line written yet) sender
while
len
(
unprocessed_senders
)
>
0
:
line
=
tcpprobe_proc
.
readline
()
time_dif
=
time
.
perf_counter
()
-
start_time
line_split
=
line
.
split
(
" "
)
# try to match current tcpprobe line against all unprocessed senders
for
key
,
i
in
enumerate
(
unprocessed_senders
):
if
(
line_split
[
1
]
==
r
"["
+
i
[
'src'
]
+
r
"]:"
+
i
[
'src_port'
]
and
line_split
[
2
]
==
r
"["
+
i
[
'dst'
]
+
r
"]:"
+
i
[
'port'
]):
# write time + current tcpprobe line to file for this sender
unprocessed_senders
.
pop
(
key
)[
'tcpprobe_file'
].
write
(
str
(
time_dif
)
+
" "
+
" "
.
join
(
line_split
[
1
:]))
break
else
:
# no break occured
if
line
==
""
:
# this shouldn't happen. Try to continue anyway
print
(
"CRITICAL ERROR!"
)
unprocessed_senders
=
{}
tcpprobe_proc
.
close
()
def
signal_handler
(
signum
,
frame
):
clean_up
()
raise
SystemExit
def
clean_up
():
# Clean up
# tcpprobe.terminate()
if
args
.
legacy
:
tcpprobe
.
terminate
()
if
args
.
tcpdump
==
"1"
:
tcpdump
.
terminate
()
# cpunetlog.terminate()
...
...
@@ -116,6 +144,10 @@ parser.add_argument('-D', '--tcpdump', default="1", \
help
=
"Enable/Disable tcpdump (Default: enabled"
)
parser
.
add_argument
(
'-S'
,
'--samplerate'
,
default
=
"0.1"
,
\
help
=
"Samplerate for measurements"
)
parser
.
add_argument
(
'--legacy'
,
action
=
'store_true'
,
\
help
=
"Record entire tcp_probe output instead of samples by samplerate.
\
Can be less CPU intensive for certain samplerates.
\
Consider using full=0 for tcp_probe module"
)
args
=
parser
.
parse_args
()
...
...
@@ -161,8 +193,9 @@ else:
print
(
"Utility not supported"
)
raise
SystemExit
tcpprobe_file
=
tempfile
.
TemporaryFile
(
'w+'
)
#tcpprobe = subprocess.Popen(["cat", "/proc/net/tcpprobe"],stdout=tcpprobe_file)
if
args
.
legacy
:
tcpprobe_file
=
tempfile
.
TemporaryFile
(
'w+'
)
tcpprobe
=
subprocess
.
Popen
([
"cat"
,
"/proc/net/tcpprobe"
],
stdout
=
tcpprobe_file
)
if
args
.
tcpdump
==
"1"
:
tcpdump
=
subprocess
.
Popen
([
"tcpdump"
,
"-iany"
,
"-w"
+
args
.
tmp_folder
+
"/tcpdump_"
+
str
(
mypid
),
"-s100"
])
...
...
@@ -230,43 +263,29 @@ if args.utility != "netperf":
# ss_file.close()
# time.sleep(0.1)
if
not
args
.
legacy
:
while
time
.
perf_counter
()
-
start_time
<
float
(
args
.
time
):
while_start
=
time
.
perf_counter
()
# remember beginning of this loop
process_proc_tcpprobe
(
sender
)
#heavy lifting here
try
:
# sleep samplerate minus time spent in loop
time
.
sleep
(
float
(
args
.
samplerate
)
-
(
time
.
perf_counter
()
-
while_start
))
except
ValueError
:
# negative sleep
pass
while
time
.
perf_counter
()
-
start_time
<
float
(
args
.
time
):
while_start
=
time
.
perf_counter
()
# remember beginning of this loop
tcpprobe_proc
=
open
(
"/proc/net/tcpprobe"
,
"r"
)
unprocessed_senders
=
sender
.
copy
()
# collect line from tcpprobe and write to file if it belongs to a
# unprocessed (one that didn't have a line written yet) sender
while
len
(
unprocessed_senders
)
>
0
:
line
=
tcpprobe_proc
.
readline
()
time_dif
=
time
.
perf_counter
()
-
start_time
line_split
=
line
.
split
(
" "
)
# try to match current tcpprobe line against all unprocessed senders
for
key
,
i
in
enumerate
(
unprocessed_senders
):
if
(
line_split
[
1
]
==
r
"["
+
i
[
'src'
]
+
r
"]:"
+
i
[
'src_port'
]
and
line_split
[
2
]
==
r
"["
+
i
[
'dst'
]
+
r
"]:"
+
i
[
'port'
]):
# write time + current tcpprobe line to file for this sender
unprocessed_senders
.
pop
(
key
)[
'tcpprobe_file'
].
write
(
str
(
time_dif
)
+
" "
+
" "
.
join
(
line_split
[
1
:]))
break
else
:
# no break occured
if
line
==
""
:
unprocessed_senders
=
{}
# fly, you fools!
tcpprobe_proc
.
close
()
#print(abs(time.perf_counter() - while_start))
try
:
# sleep samplerate minus time spent in loop
time
.
sleep
(
float
(
args
.
samplerate
)
-
(
time
.
perf_counter
()
-
while_start
))
except
ValueError
:
# negative sleep
pass
else
:
time
.
sleep
(
float
(
args
.
time
))
for
i
in
sender
:
i
[
'utility'
].
wait
()
clean_up
()
if
args
.
legacy
:
process_raw_tcpprobe_file
(
tcpprobe_file
,
sender
)
#calculate bandwidth for each sender:
for
key
,
i
in
enumerate
(
sender
):
last_timestamp
=
0
...
...
@@ -278,16 +297,20 @@ for key, i in enumerate(sender):
last_timestamp
=
float
(
line_split
[
0
])
last_seq
=
int
(
line_split
[
4
],
0
)
#convert from hex-string
else
:
bandwith_file
=
open
(
args
.
tmp_folder
+
"/bw_"
+
i
[
'congestion'
]
+
"_"
+
str
(
key
),
'a'
)
# print bw for current time interval, convert to Mbps
# pay attention to seq number wrap-around
bw
=
(
int
(
line_split
[
4
],
0
)
-
last_seq
)
if
(
int
(
line_split
[
4
],
0
)
-
last_seq
)
>=
0
else
(
int
(
"0xffffffff"
,
0
)
-
last_seq
+
int
(
line_split
[
4
],
0
))
bw
=
bw
/
abs
(
float
(
line_split
[
0
])
-
last_timestamp
)
# byte/s
bw
=
bw
*
8
/
1000
/
1000
# Mbps
bandwith_file
.
write
(
" "
.
join
(
line_split
[:
3
]
+
[
str
(
bw
)]
)
+
"
\n
"
)
bandwith_file
.
close
()
last_timestamp
=
float
(
line_split
[
0
])
last_seq
=
int
(
line_split
[
4
],
0
)
if
abs
(
float
(
line_split
[
0
])
-
last_timestamp
)
>=
float
(
args
.
samplerate
):
bandwidth_file
=
open
(
args
.
tmp_folder
+
"/bw_"
+
i
[
'congestion'
]
+
"_"
+
str
(
key
),
'a'
)
# print bw for current time interval, convert to Mbps
# pay attention to seq number wrap-around
bw
=
(
int
(
line_split
[
4
],
0
)
-
last_seq
)
if
(
int
(
line_split
[
4
],
0
)
-
last_seq
)
>=
0
\
else
(
int
(
"0xffffffff"
,
0
)
-
last_seq
+
int
(
line_split
[
4
],
0
))
bw
=
bw
/
abs
(
float
(
line_split
[
0
])
-
last_timestamp
)
# byte/s
bw
=
bw
*
8
/
1000
/
1000
# Mbps
bandwidth_file
.
write
(
" "
.
join
(
line_split
[:
3
]
+
[
str
(
bw
)]
)
+
"
\n
"
)
bandwidth_file
.
close
()
last_timestamp
=
float
(
line_split
[
0
])
last_seq
=
int
(
line_split
[
4
],
0
)
else
:
pass
for
i
in
sender
:
i
[
'tcpprobe_file'
].
close
()
...
...
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