本文整理汇总了Python中hotshot.stats.load方法的典型用法代码示例。如果您正苦于以下问题:Python stats.load方法的具体用法?Python stats.load怎么用?Python stats.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hotshot.stats
的用法示例。
在下文中一共展示了stats.load方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: gather_stats
# 需要导入模块: from hotshot import stats [as 别名]
# 或者: from hotshot.stats import load [as 别名]
def gather_stats(p):
profiles = {}
for f in os.listdir(p):
if f.endswith('.agg.prof'):
path = f[:-9]
prof = pstats.Stats(os.path.join(p, f))
elif f.endswith('.prof'):
bits = f.split('.')
path = ".".join(bits[:-3])
prof = stats.load(os.path.join(p, f))
else:
continue
print("Processing %s" % f)
if path in profiles:
profiles[path].add(prof)
else:
profiles[path] = prof
os.unlink(os.path.join(p, f))
for (path, prof) in profiles.items():
prof.dump_stats(os.path.join(p, "%s.agg.prof" % path))
示例2: runProfiler
# 需要导入模块: from hotshot import stats [as 别名]
# 或者: from hotshot.stats import load [as 别名]
def runProfiler(logger, func, args=tuple(), kw={}, verbose=True, nb_func=25, sort_by=('cumulative', 'calls')):
profile_filename = "/tmp/profiler"
prof = Profile(profile_filename)
try:
logger.warning("Run profiler")
result = prof.runcall(func, *args, **kw)
prof.close()
logger.error("Profiler: Process data...")
stat = loadStats(profile_filename)
stat.strip_dirs()
stat.sort_stats(*sort_by)
logger.error("Profiler: Result:")
log = StringIO()
stat.stream = log
stat.print_stats(nb_func)
log.seek(0)
for line in log:
logger.error(line.rstrip())
return result
finally:
unlink(profile_filename)
示例3: test_load_stats
# 需要导入模块: from hotshot import stats [as 别名]
# 或者: from hotshot.stats import load [as 别名]
def test_load_stats(self):
def start(prof):
prof.start()
# Make sure stats can be loaded when start and stop of profiler
# are not executed in the same stack frame.
profiler = self.new_profiler()
start(profiler)
profiler.stop()
profiler.close()
stats.load(self.logfn)
os.unlink(self.logfn)
示例4: begin
# 需要导入模块: from hotshot import stats [as 别名]
# 或者: from hotshot.stats import load [as 别名]
def begin(self):
"""Create profile stats file and load profiler.
"""
if not self.available():
return
self._create_pfile()
self.prof = hotshot.Profile(self.pfile)
示例5: report
# 需要导入模块: from hotshot import stats [as 别名]
# 或者: from hotshot.stats import load [as 别名]
def report(self, stream):
"""Output profiler report.
"""
log.debug('printing profiler report')
self.prof.close()
prof_stats = stats.load(self.pfile)
prof_stats.sort_stats(self.sort)
# 2.5 has completely different stream handling from 2.4 and earlier.
# Before 2.5, stats objects have no stream attribute; in 2.5 and later
# a reference sys.stdout is stored before we can tweak it.
compat_25 = hasattr(prof_stats, 'stream')
if compat_25:
tmp = prof_stats.stream
prof_stats.stream = stream
else:
tmp = sys.stdout
sys.stdout = stream
try:
if self.restrict:
log.debug('setting profiler restriction to %s', self.restrict)
prof_stats.print_stats(*self.restrict)
else:
prof_stats.print_stats()
finally:
if compat_25:
prof_stats.stream = tmp
else:
sys.stdout = tmp
示例6: runProfiler
# 需要导入模块: from hotshot import stats [as 别名]
# 或者: from hotshot.stats import load [as 别名]
def runProfiler(func, args=tuple(), kw={}, verbose=True, nb_func=25, sort_by=('cumulative', 'calls')):
profile_filename = "/tmp/profiler"
prof = Profile(profile_filename)
try:
if verbose:
print "[+] Run profiler"
result = prof.runcall(func, *args, **kw)
prof.close()
if verbose:
print "[+] Stop profiler"
print "[+] Process data..."
stat = loadStats(profile_filename)
if verbose:
print "[+] Strip..."
stat.strip_dirs()
if verbose:
print "[+] Sort data..."
stat.sort_stats(*sort_by)
if verbose:
print
print "[+] Display statistics"
print
stat.print_stats(nb_func)
return result
finally:
unlink(profile_filename)