summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/testing/profiling.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2019-07-11 11:56:54 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2019-07-11 12:19:38 -0400
commit81b68ac3e491bfc57218c60d6f44a4ad8123279a (patch)
tree9fc8303abe1e844481f17ca4d2fd74946939543e /lib/sqlalchemy/testing/profiling.py
parentfa5db637dc93b3e2ec09506735833f2e764f3a0f (diff)
downloadsqlalchemy-81b68ac3e491bfc57218c60d6f44a4ad8123279a.tar.gz
profiling plugin fixes
support that we have pytest-xdist arguments now, as well as allow force-write to reset the list of callcounts which seem to accumulate commas for some reason Change-Id: I54dd164c21ffbb9139937d5c3ffb1df7e9598594
Diffstat (limited to 'lib/sqlalchemy/testing/profiling.py')
-rw-r--r--lib/sqlalchemy/testing/profiling.py47
1 files changed, 41 insertions, 6 deletions
diff --git a/lib/sqlalchemy/testing/profiling.py b/lib/sqlalchemy/testing/profiling.py
index 7ec39ffc9..a75549027 100644
--- a/lib/sqlalchemy/testing/profiling.py
+++ b/lib/sqlalchemy/testing/profiling.py
@@ -31,17 +31,37 @@ try:
except ImportError:
cProfile = None
+_profile_stats = None
+"""global ProfileStatsFileInstance.
+
+plugin_base assigns this at the start of all tests.
+
+"""
+
+
_current_test = None
+"""String id of current test.
-# ProfileStatsFile instance, set up in plugin_base
-_profile_stats = None
+plugin_base assigns this at the start of each test using
+_start_current_test.
+
+"""
+
+
+def _start_current_test(id_):
+ global _current_test
+ _current_test = id_
+
+ if _profile_stats.force_write:
+ _profile_stats.reset_count()
class ProfileStatsFile(object):
""""Store per-platform/fn profiling results in a file.
- We're still targeting Py2.5, 2.4 on 0.7 with no dependencies,
- so no json lib :( need to roll something silly
+ There was no json module available when this was written, but now
+ the file format which is very deterministically line oriented is kind of
+ handy in any case for diffs and merges.
"""
@@ -121,6 +141,19 @@ class ProfileStatsFile(object):
per_platform["current_count"] += 1
return result
+ def reset_count(self):
+ test_key = _current_test
+ # since self.data is a defaultdict, don't access a key
+ # if we don't know it's there first.
+ if test_key not in self.data:
+ return
+ per_fn = self.data[test_key]
+ if self.platform_key not in per_fn:
+ return
+ per_platform = per_fn[self.platform_key]
+ if "counts" in per_platform:
+ per_platform["counts"][:] = []
+
def replace(self, callcount):
test_key = _current_test
per_fn = self.data[test_key]
@@ -247,11 +280,13 @@ def count_functions(variance=0.05):
stats.sort_stats("cumulative")
stats.print_stats()
- if expected_count:
+ if _profile_stats.force_write:
+ _profile_stats.replace(callcount)
+ elif expected_count:
deviance = int(callcount * variance)
failed = abs(callcount - expected_count) > deviance
- if failed or _profile_stats.force_write:
+ if failed:
if _profile_stats.write:
_profile_stats.replace(callcount)
else: