From 00a9eb2b03f79baf03dcf2750cbbb84eff036163 Mon Sep 17 00:00:00 2001 From: arvidn Date: Sat, 14 May 2022 15:42:00 +0200 Subject: [PATCH] fix checking benchmark --- examples/connection_tester.cpp | 2 +- tools/benchmark_checking.py | 38 ++++++++++++++++++++-------------- 2 files changed, 23 insertions(+), 17 deletions(-) mode change 100755 => 100644 tools/benchmark_checking.py diff --git a/examples/connection_tester.cpp b/examples/connection_tester.cpp index b470eaa5072..6bddbf7dfd0 100644 --- a/examples/connection_tester.cpp +++ b/examples/connection_tester.cpp @@ -916,7 +916,7 @@ void write_handler(file_storage const& fs disk.submit_jobs(); } -void generate_data(char const* path, torrent_info const& ti) +void generate_data(std::string const path, torrent_info const& ti) { io_context ios; counters stats_counters; diff --git a/tools/benchmark_checking.py b/tools/benchmark_checking.py old mode 100755 new mode 100644 index 2f40336e62d..1a3ac2da4c0 --- a/tools/benchmark_checking.py +++ b/tools/benchmark_checking.py @@ -9,16 +9,18 @@ import sys import time -from linux_vmstat import capture_sample -from linux_vmstat import plot_output -from linux_vmstat import print_output_to_file +from vmstat import capture_sample +from vmstat import plot_output +from vmstat import print_output_to_file def main(): args = parse_args() - ret = os.system('cd ../examples && b2 release %s stage_client_test stage_connection_tester' - % args.toolset) + ret = os.system(f"cd ../examples && b2 release {args.toolset} stage_client_test stage_connection_tester") + save_dir = args.directory + print(f"save dir: {save_dir}") + if ret != 0: print('ERROR: build failed: %d' % ret) sys.exit(1) @@ -32,17 +34,21 @@ def main(): print('ERROR: connection_tester failed: %d' % ret) sys.exit(1) - if not os.path.exists("checking_benchmark.torrent"): - ret = os.system('../examples/connection_tester gen-data -t checking_benchmark.torrent -p .') + if not os.path.exists(f"{save_dir}/checking_benchmark"): + cmd_line = f'../examples/connection_tester gen-data -t checking_benchmark.torrent -P {save_dir}' + print(cmd_line) + ret = os.system(cmd_line) if ret != 0: print('ERROR: connection_tester failed: %d' % ret) sys.exit(1) - for threads in [4, 8, 16, 32, 64]: - run_test('%d' % threads, '--hashing_threads=%d' % threads) + for threads in [1, 2, 4, 8, 16, 32, 64]: + print("drop caches now. e.g. \"echo 1 | sudo tee /proc/sys/vm/drop_caches\"") + input("Press Enter to continue...") + run_test(f"{threads}", f"--hashing_threads={threads}", save_dir) -def run_test(name, client_arg): +def run_test(name, client_arg, save_dir: str): output_dir = 'logs_checking_%s' % name timing_path = os.path.join(output_dir, 'timing.txt') @@ -56,22 +62,21 @@ def run_test(name, client_arg): except Exception: pass - rm_file_or_dir(".resume") + rm_file_or_dir(f"{save_dir}/.resume") client_cmd = ('../examples/client_test checking_benchmark.torrent ' - '--enable_dht=0 --enable_lsd=0 --enable_upnp=0 --enable_natpmp=0 ' - '-1 %s -s . -f %s/events.log --alert_mask=all' - ) % (client_arg, output_dir) + '--enable_dht=0 --enable_lsd=0 --enable_upnp=0 --enable_natpmp=0 ' + f'-1 {client_arg} -s {save_dir} -f {output_dir}/events.log --alert_mask=all') client_out = open('%s/client.out' % output_dir, 'w+') print('client_cmd: "{cmd}"'.format(cmd=client_cmd)) c = subprocess.Popen(client_cmd.split(' '), stdout=client_out, stderr=client_out, stdin=subprocess.PIPE) - start_time = time.time() + start = time.monotonic() if platform.system() == "Linux": out = {} while c.returncode is None: - capture_sample(c.pid, start_time, out) + capture_sample(c.pid, start, out) time.sleep(0.1) c.poll() @@ -115,6 +120,7 @@ def rm_file_or_dir(path): def parse_args(): p = argparse.ArgumentParser() p.add_argument('--toolset', default="") + p.add_argument('--directory', default=".") return p.parse_args()