2015-07-11 07:51:30 +02:00
|
|
|
#!/usr/bin/env python
|
2018-06-16 16:12:18 +02:00
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
2015-07-11 07:51:30 +02:00
|
|
|
|
2013-09-10 07:48:38 +02:00
|
|
|
import os
|
|
|
|
import time
|
|
|
|
import shutil
|
|
|
|
import subprocess
|
|
|
|
import sys
|
2019-09-13 15:22:15 +02:00
|
|
|
import multiprocessing
|
2013-09-10 07:48:38 +02:00
|
|
|
|
2018-06-12 11:43:13 +02:00
|
|
|
cache_size = 300 # in MiB
|
2013-09-22 15:23:47 +02:00
|
|
|
|
2013-09-10 07:48:38 +02:00
|
|
|
toolset = ''
|
|
|
|
if len(sys.argv) > 1:
|
2018-06-12 11:43:13 +02:00
|
|
|
toolset = sys.argv[1]
|
2013-09-10 07:48:38 +02:00
|
|
|
|
2019-09-13 15:22:15 +02:00
|
|
|
ret = os.system('cd ../examples && b2 -j %d profile %s stage_client_test'
|
|
|
|
% (multiprocessing.cpu_count(), toolset))
|
2013-10-08 07:10:23 +02:00
|
|
|
if ret != 0:
|
2018-06-12 11:43:13 +02:00
|
|
|
print('ERROR: build failed: %d' % ret)
|
|
|
|
sys.exit(1)
|
2013-09-10 07:48:38 +02:00
|
|
|
|
2019-09-13 15:22:15 +02:00
|
|
|
ret = os.system('cd ../examples && b2 -j %d release %s stage_connection_tester'
|
|
|
|
% (multiprocessing.cpu_count(), toolset))
|
2013-09-10 07:48:38 +02:00
|
|
|
if ret != 0:
|
2018-06-12 11:43:13 +02:00
|
|
|
print('ERROR: build failed: %d' % ret)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
try:
|
|
|
|
os.remove('.ses_state')
|
2019-09-13 15:22:15 +02:00
|
|
|
except Exception:
|
|
|
|
pass
|
2018-06-12 11:43:13 +02:00
|
|
|
try:
|
|
|
|
shutil.rmtree('.resume')
|
2019-09-13 15:22:15 +02:00
|
|
|
except Exception:
|
|
|
|
pass
|
2018-06-12 11:43:13 +02:00
|
|
|
try:
|
|
|
|
shutil.rmtree('cpu_benchmark')
|
2019-09-13 15:22:15 +02:00
|
|
|
except Exception:
|
|
|
|
pass
|
2013-10-08 07:10:23 +02:00
|
|
|
|
2013-09-10 07:48:38 +02:00
|
|
|
if not os.path.exists('cpu_benchmark.torrent'):
|
2018-06-12 11:43:13 +02:00
|
|
|
ret = os.system('../examples/connection_tester gen-torrent -s 10000 -n 15 -t cpu_benchmark.torrent')
|
|
|
|
if ret != 0:
|
|
|
|
print('ERROR: connection_tester failed: %d' % ret)
|
|
|
|
sys.exit(1)
|
2013-09-10 07:48:38 +02:00
|
|
|
|
2018-06-12 11:43:13 +02:00
|
|
|
try:
|
|
|
|
shutil.rmtree('t')
|
2018-10-19 14:35:19 +02:00
|
|
|
except Exception:
|
2018-06-12 11:43:13 +02:00
|
|
|
pass
|
2013-09-10 07:48:38 +02:00
|
|
|
|
|
|
|
|
2018-06-12 11:43:13 +02:00
|
|
|
def run_test(name, test_cmd, client_arg, num_peers):
|
|
|
|
output_dir = 'logs_%s' % name
|
|
|
|
|
|
|
|
try:
|
|
|
|
shutil.rmtree(output_dir)
|
2018-10-19 14:35:19 +02:00
|
|
|
except Exception:
|
2018-06-12 11:43:13 +02:00
|
|
|
pass
|
|
|
|
try:
|
|
|
|
os.mkdir(output_dir)
|
2018-10-19 14:35:19 +02:00
|
|
|
except Exception:
|
2018-06-12 11:43:13 +02:00
|
|
|
pass
|
|
|
|
|
|
|
|
port = (int(time.time()) % 50000) + 2000
|
|
|
|
|
|
|
|
try:
|
|
|
|
shutil.rmtree('session_stats')
|
2018-10-19 14:35:19 +02:00
|
|
|
except Exception:
|
2018-06-12 11:43:13 +02:00
|
|
|
pass
|
|
|
|
try:
|
|
|
|
shutil.rmtree('session_stats_report')
|
2018-10-19 14:35:19 +02:00
|
|
|
except Exception:
|
2018-06-12 11:43:13 +02:00
|
|
|
pass
|
|
|
|
|
|
|
|
start = time.time()
|
2019-09-13 15:22:15 +02:00
|
|
|
client_cmd = '../examples/client_test -k --listen_interfaces=127.0.0.1:%d cpu_benchmark.torrent ' \
|
|
|
|
'--disable_hash_checks=1 --enable_dht=0 --enable_lsd=0 --enable_upnp=0 --enable_natpmp=0 ' \
|
|
|
|
'-e 120 %s -O --allow_multiple_connections_per_ip=1 --connections_limit=%d -T %d ' \
|
|
|
|
'--cache_size=%d -f %s/events.log --alert_mask=8747' \
|
|
|
|
% (port, client_arg, num_peers * 2, num_peers * 2, cache_size * 16, output_dir)
|
2018-06-12 11:43:13 +02:00
|
|
|
test_cmd = '../examples/connection_tester %s -c %d -d 127.0.0.1 -p %d -t cpu_benchmark.torrent' % (
|
|
|
|
test_cmd, num_peers, port)
|
|
|
|
|
|
|
|
client_out = open('%s/client.out' % output_dir, 'w+')
|
|
|
|
test_out = open('%s/test.out' % output_dir, 'w+')
|
|
|
|
print(client_cmd)
|
|
|
|
c = subprocess.Popen(client_cmd.split(' '), stdout=client_out, stderr=client_out, stdin=subprocess.PIPE)
|
|
|
|
time.sleep(2)
|
|
|
|
print(test_cmd)
|
|
|
|
t = subprocess.Popen(test_cmd.split(' '), stdout=test_out, stderr=test_out)
|
|
|
|
|
|
|
|
t.wait()
|
|
|
|
|
|
|
|
end = time.time()
|
|
|
|
|
|
|
|
try:
|
|
|
|
c.communicate('q')
|
2018-10-19 14:35:19 +02:00
|
|
|
except Exception:
|
2018-06-12 11:43:13 +02:00
|
|
|
pass
|
|
|
|
c.wait()
|
|
|
|
|
|
|
|
client_out.close()
|
|
|
|
test_out.close()
|
|
|
|
|
|
|
|
print('runtime %d seconds' % (end - start))
|
|
|
|
print('analyzing proile...')
|
|
|
|
os.system('gprof ../examples/client_test >%s/gprof.out' % output_dir)
|
|
|
|
print('generating profile graph...')
|
|
|
|
try:
|
2019-09-13 15:22:15 +02:00
|
|
|
os.system('gprof2dot --strip <%s/gprof.out | dot -Tpng -o %s/cpu_profile.png' % (output_dir, output_dir))
|
2018-10-19 14:35:19 +02:00
|
|
|
except Exception:
|
2019-09-13 15:22:15 +02:00
|
|
|
print('please install gprof2dot and dot:\nsudo pip install gprof2dot\nsudo apt install graphviz')
|
|
|
|
|
|
|
|
os.system('python parse_session_stats.py %s/events.log' % output_dir)
|
|
|
|
|
2018-06-12 11:43:13 +02:00
|
|
|
try:
|
2019-09-13 15:22:15 +02:00
|
|
|
shutil.move('session_stats_report', '%s/session_stats_report' % output_dir)
|
2018-10-19 14:35:19 +02:00
|
|
|
except Exception:
|
2018-06-12 11:43:13 +02:00
|
|
|
pass
|
2013-09-10 23:04:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
run_test('download', 'upload', '', 50)
|
2013-09-22 15:23:47 +02:00
|
|
|
run_test('upload', 'download', '-G', 20)
|