Quellcode durchsuchen

simplebench/bench-backup: add --drop-caches argument

Add an option to drop caches before each test run. It may probably
improve reliability of results when testing in cached mode.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Vladimir Sementsov-Ogievskiy vor 4 Jahren
Ursprung
Commit
8c8407fe45
2 geänderte Dateien mit 15 neuen und 2 gelöschten Zeilen
  1. 5 1
      scripts/simplebench/bench-backup.py
  2. 10 1
      scripts/simplebench/simplebench.py

+ 5 - 1
scripts/simplebench/bench-backup.py

@@ -156,7 +156,8 @@ def bench(args):
             })
 
     result = simplebench.bench(bench_func, test_envs, test_cases,
-                               count=args.count, initial_run=args.initial_run)
+                               count=args.count, initial_run=args.initial_run,
+                               drop_caches=args.drop_caches)
     with open('results.json', 'w') as f:
         json.dump(result, f, indent=4)
     print(results_to_text(result))
@@ -221,4 +222,7 @@ def __call__(self, parser, namespace, values, option_string=None):
 Do additional initial run per cell which doesn't count in result,
 default true''')
 
+    p.add_argument('--drop-caches', action='store_true', help='''\
+Do "sync; echo 3 > /proc/sys/vm/drop_caches" before each test run''')
+
     bench(p.parse_args())

+ 10 - 1
scripts/simplebench/simplebench.py

@@ -19,11 +19,17 @@
 #
 
 import statistics
+import subprocess
 import time
 
 
+def do_drop_caches():
+    subprocess.run('sync; echo 3 > /proc/sys/vm/drop_caches', shell=True,
+                   check=True)
+
+
 def bench_one(test_func, test_env, test_case, count=5, initial_run=True,
-              slow_limit=100):
+              slow_limit=100, drop_caches=False):
     """Benchmark one test-case
 
     test_func   -- benchmarking function with prototype
@@ -40,6 +46,7 @@ def bench_one(test_func, test_env, test_case, count=5, initial_run=True,
     initial_run -- do initial run of test_func, which don't get into result
     slow_limit  -- stop at slow run (that exceedes the slow_limit by seconds).
                    (initial run is not measured)
+    drop_caches -- drop caches before each run
 
     Returns dict with the following fields:
         'runs':     list of test_func results
@@ -53,6 +60,7 @@ def bench_one(test_func, test_env, test_case, count=5, initial_run=True,
     """
     if initial_run:
         print('  #initial run:')
+        do_drop_caches()
         print('   ', test_func(test_env, test_case))
 
     runs = []
@@ -60,6 +68,7 @@ def bench_one(test_func, test_env, test_case, count=5, initial_run=True,
         t = time.time()
 
         print('  #run {}'.format(i+1))
+        do_drop_caches()
         res = test_func(test_env, test_case)
         print('   ', res)
         runs.append(res)