本文整理汇总了Python中profile.run方法的典型用法代码示例。如果您正苦于以下问题:Python profile.run方法的具体用法?Python profile.run怎么用?Python profile.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类profile
的用法示例。
在下文中一共展示了profile.run方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: runMain
# 需要导入模块: import profile [as 别名]
# 或者: from profile import run [as 别名]
def runMain(main, options, args):
if options.profile:
if True:
import hotshot
profile = hotshot.Profile(options.profile)
profile.runcall(main, options, args)
profile.close()
import hotshot.stats
stats = hotshot.stats.load(options.profile)
else:
import profile
profile.run('main(options, args)', options.profile)
import pstats
stats = pstats.Stats(options.profile)
stats.strip_dirs()
stats.sort_stats('time', 'calls')
stats.print_stats(20)
elif options.psyco:
import psyco
psyco.full()
status = main(options, args)
else:
status = main(options, args)
return status
示例2: runtests
# 需要导入模块: import profile [as 别名]
# 或者: from profile import run [as 别名]
def runtests(xmlrunner=False):
''' Run unit tests '''
import sys
if '--profile' in sys.argv:
import profile
import pstats
sys.argv = [x for x in sys.argv if x != '--profile']
if xmlrunner:
import xmlrunner as xr
profile.run("unittest.main(testRunner=xr.XMLTestRunner(output='test-reports', verbosity=2))", '_stats.txt')
else:
profile.run('unittest.main()', '_stats.txt')
stats = pstats.Stats('_stats.txt')
#stats.strip_dirs()
stats.sort_stats('cumulative', 'calls')
stats.print_stats(25)
stats.sort_stats('time', 'calls')
stats.print_stats(25)
elif xmlrunner:
import xmlrunner as xr
unittest.main(testRunner=xr.XMLTestRunner(output='test-reports', verbosity=2))
else:
unittest.main()
示例3: run_profile
# 需要导入模块: import profile [as 别名]
# 或者: from profile import run [as 别名]
def run_profile():
import profile
profile.run('for i in range(10): demo()', '/tmp/profile.out')
import pstats
p = pstats.Stats('/tmp/profile.out')
p.strip_dirs().sort_stats('time', 'cum').print_stats(60)
p.strip_dirs().sort_stats('cum', 'time').print_stats(60)
示例4: run_profile
# 需要导入模块: import profile [as 别名]
# 或者: from profile import run [as 别名]
def run_profile():
import profile
profile.run('for i in range(1): demo()', '/tmp/profile.out')
import pstats
p = pstats.Stats('/tmp/profile.out')
p.strip_dirs().sort_stats('time', 'cum').print_stats(60)
p.strip_dirs().sort_stats('cum', 'time').print_stats(60)
示例5: main
# 需要导入模块: import profile [as 别名]
# 或者: from profile import run [as 别名]
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--profile", default=False)
args = parser.parse_args()
if args.profile:
profile.run("test_perf()")
profile.run("test_perf_data()")
else:
test_perf()
test_perf_data()
示例6: main
# 需要导入模块: import profile [as 别名]
# 或者: from profile import run [as 别名]
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--profile", default=False)
parser.add_argument("--evm", default=False)
args = parser.parse_args()
if args.profile:
profile.run("test_perf()")
else:
if args.evm:
test_perf_evm()
else:
test_perf()
示例7: __exit
# 需要导入模块: import profile [as 别名]
# 或者: from profile import run [as 别名]
def __exit(memory,code):
if memory:
from exaddos.leak import objgraph
print "memory utilisation"
print
print objgraph.show_most_common_types(limit=20)
print
print
print "generating memory utilisation graph"
print
obj = objgraph.by_type('run')
objgraph.show_backrefs([obj], max_depth=10)
sys.exit(code)
示例8: run
# 需要导入模块: import profile [as 别名]
# 或者: from profile import run [as 别名]
def run (function):
eval(function)
示例9: __init__
# 需要导入模块: import profile [as 别名]
# 或者: from profile import run [as 别名]
def __init__(self, shell):
super(ExecutionMagics, self).__init__(shell)
if profile is None:
self.prun = self.profile_missing_notice
# Default execution function used to actually run user code.
self.default_runner = None
示例10: _run_with_timing
# 需要导入模块: import profile [as 别名]
# 或者: from profile import run [as 别名]
def _run_with_timing(run, nruns):
"""
Run function `run` and print timing information.
Parameters
----------
run : callable
Any callable object which takes no argument.
nruns : int
Number of times to execute `run`.
"""
twall0 = time.time()
if nruns == 1:
t0 = clock2()
run()
t1 = clock2()
t_usr = t1[0] - t0[0]
t_sys = t1[1] - t0[1]
print "\nIPython CPU timings (estimated):"
print " User : %10.2f s." % t_usr
print " System : %10.2f s." % t_sys
else:
runs = range(nruns)
t0 = clock2()
for nr in runs:
run()
t1 = clock2()
t_usr = t1[0] - t0[0]
t_sys = t1[1] - t0[1]
print "\nIPython CPU timings (estimated):"
print "Total runs performed:", nruns
print " Times : %10s %10s" % ('Total', 'Per run')
print " User : %10.2f s, %10.2f s." % (t_usr, t_usr / nruns)
print " System : %10.2f s, %10.2f s." % (t_sys, t_sys / nruns)
twall1 = time.time()
print "Wall time: %10.2f s." % (twall1 - twall0)
示例11: capture
# 需要导入模块: import profile [as 别名]
# 或者: from profile import run [as 别名]
def capture(self, line, cell):
"""run the cell, capturing stdout/err"""
args = magic_arguments.parse_argstring(self.capture, line)
out = not args.no_stdout
err = not args.no_stderr
with capture_output(out, err) as io:
self.shell.run_cell(cell)
if args.output:
self.shell.user_ns[args.output] = io
示例12: run
# 需要导入模块: import profile [as 别名]
# 或者: from profile import run [as 别名]
def run(main, options, args):
import sys
if options.tempdir:
import tempfile, os
if os.path.isdir(options.tempdir):
tempfile.tempdir = options.tempdir
else:
raise ValueError('path does not exist', options.tempdir)
if options.resource_usage:
import datetime, time
startTime = datetime.datetime.now()
startClock = time.clock()
try:
status = runMain(main, options, args)
except UsageError:
status = 1
print("Try '%s --help'" % sys.argv[0], file=sys.stdout)
if options.resource_usage:
stopTime = datetime.datetime.now()
stopClock = time.clock()
print('elapsed time: ', stopTime - startTime, file=sys.stderr)
print('processor time: ', datetime.timedelta(seconds=stopClock - startClock), file=sys.stderr)
sys.exit(status)
示例13: test5
# 需要导入模块: import profile [as 别名]
# 或者: from profile import run [as 别名]
def test5():
import profile
profile.run("test4()", "prof.txt")
import pstats
p = pstats.Stats("prof.txt")
p.sort_stats("time").print_stats()
示例14: main
# 需要导入模块: import profile [as 别名]
# 或者: from profile import run [as 别名]
def main(filename):
profile.run('dostuff()', filename)
示例15: ThirdTest
# 需要导入模块: import profile [as 别名]
# 或者: from profile import run [as 别名]
def ThirdTest():
print "Doing old profiler test"
import profile
import pstats
benchtime = profile.run('Tester()', 'fooprof')
stats = pstats.Stats('fooprof')
stats.strip_dirs()
stats.sort_stats('time', 'calls')
stats.print_stats(20)