summaryrefslogtreecommitdiff
path: root/testing/tests/benchmarks/conftest.py
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2017-04-25 17:57:25 +0200
committerdrebs <drebs@leap.se>2017-04-27 10:02:20 +0200
commitc08083e9dfd38f93eb67d234e85b47efa211045c (patch)
tree7c2a9f1316c6622bb2882c796f0adb0caee59938 /testing/tests/benchmarks/conftest.py
parent48dd87ab8ad077e5913c0cddd5bfb9badd9dcc35 (diff)
[test] measure cpu percentage during benchmark
Diffstat (limited to 'testing/tests/benchmarks/conftest.py')
-rw-r--r--testing/tests/benchmarks/conftest.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/testing/tests/benchmarks/conftest.py b/testing/tests/benchmarks/conftest.py
index bec5d7ab..543f06b8 100644
--- a/testing/tests/benchmarks/conftest.py
+++ b/testing/tests/benchmarks/conftest.py
@@ -1,4 +1,6 @@
import base64
+import os
+import psutil
import pytest
import random
@@ -73,3 +75,24 @@ def txbenchmark_with_setup(benchmark):
rounds=4, warmup_rounds=1)
return threads.deferToThread(bench)
return blockOnThreadWithSetup
+
+
+#
+# resource monitoring
+#
+
+@pytest.fixture
+def monitored_benchmark(benchmark, request):
+
+ def _monitored_benchmark(fun, *args, **kwargs):
+ process = psutil.Process(os.getpid())
+ process.cpu_percent()
+ benchmark.pedantic(
+ fun, args=args, kwargs=kwargs,
+ rounds=1, iterations=1, warmup_rounds=0)
+ percent = process.cpu_percent()
+ # store value in benchmark session, so json output can be updated
+ bs = request.config._benchmarksession
+ bs.benchmarks[0].stats.cpu_percent = percent
+
+ return _monitored_benchmark