本文整理汇总了Python中sys.setprofile函数的典型用法代码示例。如果您正苦于以下问题:Python setprofile函数的具体用法?Python setprofile怎么用?Python setprofile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setprofile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: profiler
def profiler(self,frame,event,arg):
"""
This is the profile routine. It creates the instances of ForthonTimings for each
routine called and starts and stops the timers.
"""
# --- Get the name of the routine
name = frame.f_code.co_name
# --- If name is not known, this could mean that this was called from
# --- inside the sys.setprofile routine, or from some other odd place,
# --- like from fortran. Skip those cases.
if name == '?': return
# --- Turn the profiler off during these operations (though this is
# --- probably unecessary since the sys package should already do this).
sys.setprofile(None)
# --- Create an instance of the timer for the toplevel if it hasn't
# --- already been done.
if self.root is None:
self.root = ForthonTimings(0,"toplevel")
self.timer = self.root
if event == 'return' and self.level > 0:
self.level = self.level - 1
self.timer = self.timer.stoptimer()
if self.trace:
if self.tracelevel is None or self.tracelevel > self.level:
# --- The flush is added so that anything that was printed to stdout
# --- or stderr get outputed now so that the print outs occur
# --- at the proper time relative to the trace.
sys.stdout.flush()
sys.stderr.flush()
print "%s %s %s"%(self.level*' ',event,name)
if event == 'call':
self.level = self.level + 1
self.timer = self.timer.newtimer(name)
# --- Turn the profiler back on
sys.setprofile(self.profiler)
示例2: stop
def stop():
"""
Turn off memory profiling.
"""
global _out_stream
sys.setprofile(None)
_out_stream.close()
示例3: __call__
def __call__(self, func, *args, **kwargs):
global _converting
if _converting:
return func(*args, **kwargs) # skip
else:
# clean start
sys.setprofile(None)
from myhdl import _traceSignals
if _traceSignals._tracing:
raise ToVerilogError("Cannot use toVerilog while tracing signals")
if not callable(func):
raise ToVerilogError(_error.FirstArgType, "got %s" % type(func))
_converting = 1
if self.name is None:
name = func.func_name
else:
name = str(self.name)
try:
h = _HierExtr(name, func, *args, **kwargs)
finally:
_converting = 0
vpath = name + ".v"
vfile = open(vpath, 'w')
### initialize properly ###
_genUniqueSuffix.reset()
arglist = _flatten(h.top)
# print h.top
_checkArgs(arglist)
genlist = _analyzeGens(arglist, h.absnames)
siglist, memlist = _analyzeSigs(h.hierarchy)
_annotateTypes(genlist)
top_inst = h.hierarchy[0]
intf = _analyzeTopFunc(top_inst, func, *args, **kwargs)
doc = _makeDoc(inspect.getdoc(func))
self._convert_filter(h, intf, siglist, memlist, genlist)
_writeFileHeader(vfile, vpath, self.timescale)
_writeModuleHeader(vfile, intf, doc)
_writeSigDecls(vfile, intf, siglist, memlist)
_convertGens(genlist, vfile)
_writeModuleFooter(vfile)
vfile.close()
# don't write testbench if module has no ports
if len(intf.argnames) > 0 and not toVerilog.no_testbench:
tbpath = "tb_" + vpath
tbfile = open(tbpath, 'w')
_writeTestBench(tbfile, intf)
tbfile.close()
### clean-up properly ###
self._cleanup(siglist)
return h.top
示例4: runctx
def runctx(self, cmd, globals, locals):
self.set_cmd(cmd)
sys.setprofile(self.dispatcher)
try:
exec cmd in globals, locals
finally:
sys.setprofile(None)
示例5: start
def start(self, name = 'start'):
if getattr(self, 'running', False):
return
self._setup()
self.simulate_call('start')
self.running = True
sys.setprofile(self.dispatcher)
示例6: set_profile
def set_profile(active=False):
if active:
log_start("Profiling init", bookmark=True)
sys.setprofile(_profile)
else:
sys.setprofile(None)
log_endok("Profiling exit")
示例7: run
def run(self, profiler):
profile = functools.partial(self._profile, profiler)
sys.setprofile(profile)
threading.setprofile(profile)
yield
threading.setprofile(None)
sys.setprofile(None)
示例8: Tasklet
def Tasklet(self, do_profile=False, do_trace=False, disable_trace_after_schedule=False):
if do_profile:
sys.setprofile(self.Callback)
self.addCleanup(sys.setprofile, None)
if do_trace:
sys.settrace(self.Callback)
self.addCleanup(sys.settrace, None)
self.foo()
n = len(self.trace)
self.foo()
n2 = len(self.trace)
if do_profile or do_trace:
self.assertGreater(n2, n)
else:
self.assertEqual(n2, n)
schedule()
self.foo()
n = len(self.trace)
self.foo()
n2 = len(self.trace)
if (do_profile or do_trace) and not disable_trace_after_schedule:
self.assertGreater(n2, n)
else:
self.assertEqual(n2, n)
示例9: runctx
def runctx(self, cmd, globals, locals):
self.set_cmd(cmd)
sys.setprofile(self.trace_dispatch)
try:
exec(cmd, globals, locals)
finally:
sys.setprofile(None)
示例10: run_toplevel
def run_toplevel(f, *fargs, **fkwds):
"""Calls f() and handles all OperationErrors.
Intended use is to run the main program or one interactive statement.
run_protected() handles details like forwarding exceptions to
sys.excepthook(), catching SystemExit, printing a newline after
sys.stdout if needed, etc.
"""
try:
# run it
try:
f(*fargs, **fkwds)
finally:
sys.settrace(None)
sys.setprofile(None)
# we arrive here if no exception is raised. stdout cosmetics...
try:
stdout = sys.stdout
softspace = stdout.softspace
except AttributeError:
pass
# Don't crash if user defined stdout doesn't have softspace
else:
if softspace:
stdout.write('\n')
except SystemExit as e:
handle_sys_exit(e)
except BaseException as e:
display_exception(e)
return False
return True # success
示例11: runcall
def runcall(self, func, *args):
self.set_cmd(`func`)
sys.setprofile(self.dispatcher)
try:
return apply(func, args)
finally:
sys.setprofile(None)
示例12: attachThread
def attachThread(self, target=None, args=None, kwargs=None, mainThread=0):
"""
Public method to setup a thread for DebugClient to debug.
If mainThread is non-zero, then we are attaching to the already
started mainthread of the app and the rest of the args are ignored.
@param target the start function of the target thread (i.e. the
user code)
@param args arguments to pass to target
@param kwargs keyword arguments to pass to target
@param mainThread non-zero, if we are attaching to the already
started mainthread of the app
@return The identifier of the created thread
"""
try:
self.lockClient()
newThread = DebugThread(self, target, args, kwargs, mainThread)
ident = -1
if mainThread:
ident = thread.get_ident()
self.mainThread = newThread
if self.debugging:
sys.setprofile(newThread.profile)
else:
ident = _original_start_thread(newThread.bootstrap, ())
if self.mainThread is not None:
self.tracePython = self.mainThread.tracePython
newThread.set_ident(ident)
self.threads[newThread.get_ident()] = newThread
finally:
self.unlockClient()
return ident
示例13: get_info_on_next_invocation
def get_info_on_next_invocation(self, func, callback, needed):
"""
func is a tuple (filename, funcname)
needed is a list/tuple of NeededInfo objects
"""
if isinstance(needed, NeededInfo):
needed = (needed,)
request = WatchRequest(needed, {}, callback)
if func in self.watching_funcs:
self.watching_funcs[func].requests.append(request)
else:
self.watching_funcs[func] = FuncWatchStatus(func, requests=[request])
fws = self.watching_funcs[func]
for ni in needed:
hsh = 0
for i in range(ni.stmt_idx+1):
hsh += hash(ni.stmt_sequence[i])
#cprint ("adding to hash %s: %i"%(str(ni.stmt_sequence[i]), hsh), 'green')
if hsh in fws.ni_hashmap:
fws.ni_hashmap[hsh].append((request,ni))
else:
fws.ni_hashmap[hsh] = [(request,ni)]
cprint("finishing up get_info_on_next_invocation", 'red')
# XXX Why do I need to use both settrace and setprofile? settrace doesn't
# XXX trigger on return events, and setprofile doesn't trigger on line events...
self.old_trace, self.old_profile = sys.gettrace(), sys.getprofile()
sys.settrace(self.trace_cb)
sys.setprofile(self.profile_cb)
示例14: trace_dispatch
def trace_dispatch(self, frame, event, arg):
"""
Public method wrapping the trace_dispatch of bdb.py.
It wraps the call to dispatch tracing into
bdb to make sure we have locked the client to prevent multiple
threads from entering the client event loop.
@param frame The current stack frame.
@param event The trace event (string)
@param arg The arguments
@return local trace function
"""
try:
self._dbgClient.lockClient()
# if this thread came out of a lock, and we are quitting
# and we are still running, then get rid of tracing for this thread
if self.quitting and self._threadRunning:
sys.settrace(None)
sys.setprofile(None)
import threading
self.__name = threading.currentThread().getName()
retval = DebugBase.trace_dispatch(self, frame, event, arg)
finally:
self._dbgClient.unlockClient()
return retval
示例15: __bootstrap
def __bootstrap(self):
try:
self._set_ident()
self._Thread__started.set()
threading._active_limbo_lock.acquire()
threading._active[self._Thread__ident] = self
del threading._limbo[self]
threading._active_limbo_lock.release()
if threading._trace_hook:
sys.settrace(threading._trace_hook)
if threading._profile_hook:
sys.setprofile(threading._profile_hook)
try:
self.run()
finally:
self._Thread__exc_clear()
finally:
with threading._active_limbo_lock:
self._Thread__stop()
try:
del threading._active[threading._get_ident()]
except:
pass