From c08083e9dfd38f93eb67d234e85b47efa211045c Mon Sep 17 00:00:00 2001 From: drebs Date: Tue, 25 Apr 2017 17:57:25 +0200 Subject: [test] measure cpu percentage during benchmark --- testing/tests/benchmarks/conftest.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'testing/tests/benchmarks/conftest.py') 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 -- cgit v1.2.3