本文整理汇总了Python中cProfile.run方法的典型用法代码示例。如果您正苦于以下问题:Python cProfile.run方法的具体用法?Python cProfile.run怎么用?Python cProfile.run使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cProfile
的用法示例。
在下文中一共展示了cProfile.run方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: profile_main
# 需要导入模块: import cProfile [as 别名]
# 或者: from cProfile import run [as 别名]
def profile_main():
"""
:return:
"""
log.info("Profiling: ENABLED")
# Enable memory usage profiling at the line level
tracemalloc.start()
# Enable CPU usage/function call timing/rate at the function level
# Automatigically dumps profile to `filename` for further analysis
cProfile.run("main()", filename=(CWD + "/chimay-red.cprof"))
# Take snapshot of traced malloc profile
snapshot = tracemalloc.take_snapshot()
# Print snapshot statistics filtering for only `tracefiles`
display_top(snapshot, limit=20, modpaths=TRACEFILES)
return 0
示例2: main
# 需要导入模块: import cProfile [as 别名]
# 或者: from cProfile import run [as 别名]
def main():
""" DocstringNotImplemented """
# set pwntools context for binary file
if TARGET.binary:
context.binary = TARGET.binary
if TARGET.debug:
# Setup pwnlib context for tmux debug automation
context.terminal = ['tmux', '-L', 'chimay-red', 'splitw', '-v', '-p', '50']
# run remote gdbserver attached to `www` PID on TARGET
run_new_remote_gdbserver(TARGET.rhost, TARGET.gdbport)
# attach and connect to remote gdbserver on TARGET
attach_gdb_server(TARGET.rhost, TARGET.gdbport, TARGET.binary, TARGET.breakpoints.split(","))
if TARGET.shellcommand:
Command(TARGET.vector, TARGET.rhost, TARGET.lhost, TARGET.shellcommand, command="custom_shell_command")
else:
Command(TARGET.vector, TARGET.rhost, TARGET.lhost, command=TARGET.command)
# Run the script
示例3: __init__
# 需要导入模块: import cProfile [as 别名]
# 或者: from cProfile import run [as 别名]
def __init__(self, name, run=True, end_prompt=True, **kwargs):
kwargs['agent'] = core.Agent
print 'ran init'
self._name = name
self._end_prompt = end_prompt
#create the environment
start = time.clock()
self.world = universe.create_world(name,
defaults=self._defaults,
ignore_world_agent=True,
**kwargs)
end = time.clock()
print name, end - start, '???'
self.lag = end-start
示例4: main
# 需要导入模块: import cProfile [as 别名]
# 或者: from cProfile import run [as 别名]
def main():
if sys.argv[1] == '-d':
del sys.argv[1]
import pdb
pdb.set_trace()
my_module_gen()
else:
import os
if "PYBINDGEN_ENABLE_PROFILING" in os.environ:
try:
import cProfile as profile
except ImportError:
my_module_gen()
else:
print("** running under profiler", file=sys.stderr)
profile.run('my_module_gen()', 'foomodulegen-auto.pstat')
else:
my_module_gen()
示例5: run
# 需要导入模块: import cProfile [as 别名]
# 或者: from cProfile import run [as 别名]
def run():
print('\nLoading JSON...')
input_fn = 'benchmark.json'
output_fn = 'panflute.json'
with open(input_fn, encoding='utf-8') as f:
doc = pf.load(f)
print('\nApplying trivial filter...')
doc = doc.walk(action=empty_test, doc=doc)
print('Dumping JSON...')
with open(output_fn, mode='w', encoding='utf-8') as f:
pf.dump(doc, f)
f.write('\n')
print(' - Done!')
示例6: profile
# 需要导入模块: import cProfile [as 别名]
# 或者: from cProfile import run [as 别名]
def profile(profileOutputFile=None, dotOutputFile=None, imageOutputFile=None):
"""
This will run the program and present profiling data in a nice looking graph
"""
try:
from thirdparty.gprof2dot import gprof2dot
from thirdparty.xdot import xdot
import gobject
import gtk
import pydot
except ImportError, e:
errMsg = "profiling requires third-party libraries (%s). " % getUnicode(e, UNICODE_ENCODING)
errMsg += "Quick steps:%s" % os.linesep
errMsg += "1) sudo apt-get install python-pydot python-pyparsing python-profiler graphviz"
logger.error(errMsg)
return
示例7: get_result_n
# 需要导入模块: import cProfile [as 别名]
# 或者: from cProfile import run [as 别名]
def get_result_n(att_trees, data, type_alg, k=DEFAULT_K, n=10):
"""
run clustering_based_k_anon for n time, with k=10
"""
print "K=%d" % k
data_back = copy.deepcopy(data)
n_ncp = 0.0
n_time = 0.0
for i in range(n):
_, eval_result = clustering_based_k_anon(att_trees, data, type_alg, k)
data = copy.deepcopy(data_back)
n_ncp += eval_result[0]
n_time += eval_result[1]
n_ncp = n_ncp / n
n_time = n_ncp / n
print "Run %d times" % n
print "NCP %0.2f" % n_ncp + "%"
print "Running time %0.2f" % n_time + " seconds"
示例8: timeout
# 需要导入模块: import cProfile [as 别名]
# 或者: from cProfile import run [as 别名]
def timeout(func, args=(), timeout_duration=2, default=None, **kwargs):
"""This will spwan a thread and run the given function using the args, kwargs and
return the given default value if the timeout_duration is exceeded
"""
import threading
class InterruptableThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.result = default
def run(self):
try:
self.result = func(*args, **kwargs)
except:
pass
it = InterruptableThread()
it.start()
it.join(timeout_duration)
return it.result
示例9: profiler
# 需要导入模块: import cProfile [as 别名]
# 或者: from cProfile import run [as 别名]
def profiler(command, filename="profile.stats", n_stats=10):
"""Profiler for a python program
Runs cProfile and outputs ordered statistics that describe
how often and for how long various parts of the program are executed.
Stats can be visualized with `!snakeviz profile.stats`.
Parameters
----------
command: str
Command string to be executed.
filename: str
Name under which to store the stats.
n_stats: int or None
Number of top stats to show.
"""
import cProfile, pstats
cProfile.run(command, filename)
stats = pstats.Stats(filename).strip_dirs().sort_stats("time")
return stats.print_stats(n_stats or {})
示例10: command
# 需要导入模块: import cProfile [as 别名]
# 或者: from cProfile import run [as 别名]
def command(self):
with warnings.catch_warnings():
try:
from sqlalchemy import exc
except ImportError:
pass
else:
warnings.simplefilter("ignore", category=exc.SAWarning)
self.basic_setup()
request = webob.Request.blank('--script--', environ={
'paste.registry': self.registry})
tg.request_local.context.request = request
if self.options.pdb:
base.log.info('Installing exception hook')
sys.excepthook = utils.postmortem_hook
with open(self.args[1]) as fp:
ns = dict(__name__='__main__')
sys.argv = self.args[1:]
if self.options.profile:
cProfile.run(fp, '%s.profile' %
os.path.basename(self.args[1]))
else:
exec(fp.read(), ns)
示例11: profile
# 需要导入模块: import cProfile [as 别名]
# 或者: from cProfile import run [as 别名]
def profile(profileOutputFile=None, dotOutputFile=None, imageOutputFile=None):
"""
This will run the program and present profiling data in a nice looking graph
"""
try:
__import__("gobject")
from thirdparty.gprof2dot import gprof2dot
from thirdparty.xdot import xdot
import gtk
import pydot
except ImportError, e:
errMsg = "profiling requires third-party libraries ('%s') " % getUnicode(e, UNICODE_ENCODING)
errMsg += "(Hint: 'sudo apt-get install python-pydot python-pyparsing python-profiler graphviz')"
logger.error(errMsg)
return
示例12: main
# 需要导入模块: import cProfile [as 别名]
# 或者: from cProfile import run [as 别名]
def main():
""" Main function to invoke for profiling """
import cProfile as profile
import pstats
global _PROFILING
_PROFILING = True
filename = "Processor.profile"
profile.run("_main()", filename)
stats = pstats.Stats(filename)
# Clean up filenames for the report
stats.strip_dirs()
# Sort the statistics by the total time spent in the function itself
stats.sort_stats("tottime")
stats.print_stats(100) # Print 100 most significant lines
示例13: profile
# 需要导入模块: import cProfile [as 别名]
# 或者: from cProfile import run [as 别名]
def profile(code, name='profile_run', sort='cumulative', num=30):
"""Common-use for cProfile"""
cProfile.run(code, name)
stats = pstats.Stats(name)
stats.sort_stats(sort)
stats.print_stats(num)
return stats
#### Code for listing (nearly) all objects in the known universe
#### http://utcc.utoronto.ca/~cks/space/blog/python/GetAllObjects
# Recursively expand slist's objects
# into olist, using seen to track
# already processed objects.
示例14: findNew
# 需要导入模块: import cProfile [as 别名]
# 或者: from cProfile import run [as 别名]
def findNew(self, regex):
"""Return all objects matching regex that were considered 'new' when the last diff() was run."""
return self.findTypes(self.newRefs, regex)
示例15: findPersistent
# 需要导入模块: import cProfile [as 别名]
# 或者: from cProfile import run [as 别名]
def findPersistent(self, regex):
"""Return all objects matching regex that were considered 'persistent' when the last diff() was run."""
return self.findTypes(self.persistentRefs, regex)