summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/testing/profiling.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2014-01-21 20:10:23 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2014-01-21 20:10:23 -0500
commit07fb90c6cc14de6d02cf4be592c57d56831f59f7 (patch)
tree050ef65db988559c60f7aa40f2d0bfe24947e548 /lib/sqlalchemy/testing/profiling.py
parent560fd1d5ed643a1b0f95296f3b840c1963bbe67f (diff)
parentee1f4d21037690ad996c5eacf7e1200e92f2fbaa (diff)
downloadsqlalchemy-ticket_2501.tar.gz
Merge branch 'master' into ticket_2501ticket_2501
Conflicts: lib/sqlalchemy/orm/mapper.py
Diffstat (limited to 'lib/sqlalchemy/testing/profiling.py')
-rw-r--r--lib/sqlalchemy/testing/profiling.py47
1 files changed, 31 insertions, 16 deletions
diff --git a/lib/sqlalchemy/testing/profiling.py b/lib/sqlalchemy/testing/profiling.py
index bda44d80c..fa2490649 100644
--- a/lib/sqlalchemy/testing/profiling.py
+++ b/lib/sqlalchemy/testing/profiling.py
@@ -1,3 +1,9 @@
+# testing/profiling.py
+# Copyright (C) 2005-2014 the SQLAlchemy authors and contributors <see AUTHORS file>
+#
+# This module is part of SQLAlchemy and is released under
+# the MIT License: http://www.opensource.org/licenses/mit-license.php
+
"""Profiling support for unit and performance tests.
These are special purpose profiling methods which operate
@@ -45,12 +51,10 @@ def profiled(target=None, **target_opts):
if target is None:
target = 'anonymous_target'
- filename = "%s.prof" % target
-
@decorator
def decorate(fn, *args, **kw):
elapsed, load_stats, result = _profile(
- filename, fn, *args, **kw)
+ fn, *args, **kw)
graphic = target_opts.get('graphic', profile_config['graphic'])
if graphic:
@@ -60,8 +64,8 @@ def profiled(target=None, **target_opts):
if report:
sort_ = target_opts.get('sort', profile_config['sort'])
limit = target_opts.get('limit', profile_config['limit'])
- print(("Profile report for target '%s' (%s)" % (
- target, filename)
+ print(("Profile report for target '%s'" % (
+ target, )
))
stats = load_stats()
@@ -81,7 +85,6 @@ def profiled(target=None, **target_opts):
if print_callees:
stats.print_callees()
- os.unlink(filename)
return result
return decorate
@@ -162,6 +165,15 @@ class ProfileStatsFile(object):
per_platform['current_count'] += 1
return result
+ def replace(self, callcount):
+ test_key = _current_test
+ per_fn = self.data[test_key]
+ per_platform = per_fn[self.platform_key]
+ counts = per_platform['counts']
+ counts[-1] = callcount
+ if self.write:
+ self._write()
+
def _header(self):
return \
"# %s\n"\
@@ -263,16 +275,19 @@ def function_call_count(variance=0.05):
if expected_count:
deviance = int(callcount * variance)
- if abs(callcount - expected_count) > deviance:
- raise AssertionError(
- "Adjusted function call count %s not within %s%% "
- "of expected %s. (Delete line %d of file %s to "
- "regenerate this callcount, when tests are run "
- "with --write-profiles.)"
- % (
- callcount, (variance * 100),
- expected_count, line_no,
- _profile_stats.fname))
+ failed = abs(callcount - expected_count) > deviance
+
+ if failed:
+ if _profile_stats.write:
+ _profile_stats.replace(callcount)
+ else:
+ raise AssertionError(
+ "Adjusted function call count %s not within %s%% "
+ "of expected %s. Rerun with --write-profiles to "
+ "regenerate this callcount."
+ % (
+ callcount, (variance * 100),
+ expected_count))
return fn_result
return update_wrapper(wrap, fn)
return decorate