dest="profilesort",
help="Type of sort for profiling standard output",
)
+ make_option(
+ "--profile-dump",
+ type="string",
+ dest="profiledump",
+ help="Filename where a single profile run will be dumped",
+ )
make_option(
"--postgresql-templatedb",
type="string",
profiling._profile_stats = profiling.ProfileStatsFile(
file_config.get("sqla_testing", "profile_file"),
sort=options.profilesort,
+ dump=options.profiledump,
)
import os
import platform
import pstats
+import re
import sys
from . import config
"""
- def __init__(self, filename, sort="cumulative"):
+ def __init__(self, filename, sort="cumulative", dump=None):
self.force_write = (
config.options is not None and config.options.force_write_profiles
)
self.data = collections.defaultdict(
lambda: collections.defaultdict(dict)
)
+ self.dump = dump
self.sort = sort
self._read()
if self.write:
line_no, expected_count = expected
print(("Pstats calls: %d Expected %s" % (callcount, expected_count)))
- stats.sort_stats(_profile_stats.sort)
+ stats.sort_stats(*re.split(r"[, ]", _profile_stats.sort))
stats.print_stats()
+ if _profile_stats.dump:
+ base, ext = os.path.splitext(_profile_stats.dump)
+ test_name = _current_test.split(".")[-1]
+ dumpfile = "%s_%s%s" % (base, test_name, ext or ".profile")
+ stats.dump_stats(dumpfile)
+ print("Dumped stats to file %s" % dumpfile)
# stats.print_callers()
if _profile_stats.force_write:
_profile_stats.replace(callcount)