本文整理汇总了Python中pstats.Stats.dump_stats方法的典型用法代码示例。如果您正苦于以下问题:Python Stats.dump_stats方法的具体用法?Python Stats.dump_stats怎么用?Python Stats.dump_stats使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pstats.Stats
的用法示例。
在下文中一共展示了Stats.dump_stats方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import dump_stats [as 别名]
def handle(self, *args, **options):
profile_file = options.pop('profile', None)
if profile_file:
profiler = Profile()
profiler.runcall(self._handle, *args, **options)
stats = Stats(profiler)
stats.dump_stats(profile_file)
else:
self._handle(*args, **options)
示例2: concat
# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import dump_stats [as 别名]
def concat(pattern, outfile, mpi=None):
if mpi:
from mpi4py import MPI
pattern = pattern % MPI.COMM_WORLD.rank
outfile = outfile % MPI.COMM_WORLD.rank
files = glob(pattern)
if files:
s = Stats(files[0])
for f in files[1:]: s.add(f)
s.dump_stats(outfile)
for f in files:
os.remove(f)
示例3: profiler
# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import dump_stats [as 别名]
def profiler(enable, outfile):
try:
if enable:
profiler = Profile()
profiler.enable()
yield
finally:
if enable:
profiler.disable()
stats = Stats(profiler)
stats.sort_stats('tottime')
stats.dump_stats(outfile)
示例4: process_view
# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import dump_stats [as 别名]
def process_view(self, request, view_func, view_args, view_kwargs):
from cProfile import Profile
from pstats import Stats
full_name = "{v.__module__}.{v.func_name}".format(v=view_func)
if self.regex.match(full_name):
profile = Profile()
response = profile.runcall(view_func, request, *view_args,
**view_kwargs)
stats = Stats(profile)
if os.path.exists(self.filename):
stats.add(self.filename)
stats.strip_dirs()
stats.dump_stats(self.filename)
return response
示例5: Profiler
# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import dump_stats [as 别名]
class Profiler(object):
def __init__(self, name=None):
self._lock = RLock()
self._name = name or settings.PROFILE_DEFAULT_NAME
self._location = settings.PROFILE_FILENAME_TEMPLATE % self._name
self._stats = None
self._local = ProfilerLocal()
self._notch = time() - 1
self._updates = False
def _set_status(self, value):
settings.PROFILING = value
status = property(lambda self: settings.PROFILING, _set_status)
def __enter__(self):
if not settings.PROFILING:
return self
if not self._local.counter:
self._local.profile = Profile()
self._local.profile.enable()
self._local.counter += 1
return self
def __exit__(self, extype, exvalue, extraceback):
if not settings.PROFILING:
return
self._local.counter -= 1
if not self._local.counter:
self._local.profile.disable()
self.aggregate(self._local.profile)
self._local.profile = None
def aggregate(self, profile_or_stats):
with self._lock:
if self._stats is None:
self._stats = Stats(profile_or_stats)
else:
self._stats.add(profile_or_stats)
self._updates = True
def clear(self):
with self._lock:
if self._stats is not None:
self._stats = None
@contextmanager
def hold(self, location=None):
if not settings.PROFILING:
yield None
else:
if location is None:
location = self._location
with self._lock:
self.save(location=location, force=True)
yield location
def load(self, location=None):
if not settings.PROFILING:
return None
if location is None:
location = self._location
with self._lock:
self.save(location=location, force=True)
try:
with open(location, "rb") as file:
return file.read()
except Exception as error:
if isinstance(error, IOError) and error.errno == errno.ENOENT:
return None
else:
raise
def save(self, location=None, force=False):
if not (settings.PROFILING and self._updates):
return
now = time()
if not force and now < self._notch:
return
if location is None:
location = self._location
with self._lock:
if self._stats:
self._stats.dump_stats(location)
if not force:
server_log.write("Save profiling statistics to \"%s\"" % os.path.basename(location))
self._notch = now + settings.PROFILING_SAVE_PERIODICITY
self._updates = False
#.........这里部分代码省略.........
示例6: __init__
# 需要导入模块: from pstats import Stats [as 别名]
# 或者: from pstats.Stats import dump_stats [as 别名]
class Stat:
"""manage interface between pstat data and GUI item"""
def __init__(self, pstat=None, path=None):
# pStat profile statistics instance
self.pstat = None
self.load(pstat, path)
self.itemArray = {}
self.itemArray[TAB_FUNCTIONSTAT] = {}
self.itemArray[TAB_SOURCE] = {}
# Reference from pstat key to Qt object in the GUI
self.pStatArray = {}
self.pStatArray[TAB_FUNCTIONSTAT] = {}
self.pStatArray[TAB_SOURCE] = {}
def getTotalTime(self):
if self.pstat:
return self.pstat.total_tt
else:
return 0
def getCallNumber(self):
if self.pstat:
return self.pstat.total_calls
else:
return 0
def getPrimitiveCallRatio(self):
if self.pstat:
return 100.0 * float(self.pstat.prim_calls) / float(
self.pstat.total_calls)
else:
return 0
def getStatNumber(self):
if self.pstat:
return len(self.pstat.stats)
else:
return 0
def getStatItems(self):
if self.pstat:
return list(self.pstat.stats.items())
def getStatKeys(self):
if self.pstat:
return list(self.pstat.stats.keys())
def getCalleesItems(self):
if self.pstat:
return list(self.pstat.all_callees.items())
def getStatTotalTime(self, pstatTriplet):
if self.pstat:
try:
return self.pstat.stats[pstatTriplet][2]
except KeyError:
return 0
else:
return 0
def getStatCumulativeTime(self, pstatTriplet):
if self.pstat:
try:
return self.pstat.stats[pstatTriplet][3]
except KeyError:
return 0
else:
return 0
def load(self, pstat=None, path=None):
if pstat and path:
print('''' Warning : both pstat and path parameter given.
path override pstat !''')
if pstat:
self.pstat = pstat
if path:
self.pstat = Stats(str(path))
if self.pstat:
self.pstat.calc_callees()
def save(self, path):
try:
self.pstat.dump_stats(path)
except:
pass
def setStatLink(self, guiItem, pstatTriplet, target):
self.itemArray[target][guiItem] = pstatTriplet
self.pStatArray[target][pstatTriplet] = guiItem
def getPstatFromGui(self, guiItem, target):
try:
return self.itemArray[target][guiItem]
except KeyError:
return None
def getGuiFromPstat(self, pStatTtriplet, target):
try:
return self.pStatArray[target][pStatTtriplet]
except KeyError:
#.........这里部分代码省略.........