本文整理汇总了Python中sys.setprofile函数的典型用法代码示例。如果您正苦于以下问题:Python setprofile函数的具体用法?Python setprofile怎么用?Python setprofile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setprofile函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:arunpersaud,项目名称:Forthon,代码行数:35,代码来源:ForthonTimer.py
示例2: stop
def stop():
"""
Turn off memory profiling.
"""
global _out_stream
sys.setprofile(None)
_out_stream.close()
开发者ID:OpenMDAO,项目名称:OpenMDAO,代码行数:7,代码来源:iprof_mem.py
示例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
开发者ID:forrestv,项目名称:myhdl,代码行数:60,代码来源:_toVerilog.py
示例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)
开发者ID:asottile,项目名称:ancient-pythons,代码行数:7,代码来源:profile.py
示例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)
开发者ID:connoryang,项目名称:dec-eve-serenity,代码行数:7,代码来源:slprofile.py
示例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")
开发者ID:shish,项目名称:context-apis,代码行数:7,代码来源:api.py
示例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)
开发者ID:qbektrix,项目名称:profiling,代码行数:7,代码来源:samplers.py
示例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)
开发者ID:dev-alex-alex2006hw,项目名称:tools,代码行数:27,代码来源:test_tstate.py
示例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)
开发者ID:asottile,项目名称:ancient-pythons,代码行数:7,代码来源:profile.py
示例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
开发者ID:mozillazg,项目名称:pypy,代码行数:32,代码来源:app_main.py
示例11: runcall
def runcall(self, func, *args):
self.set_cmd(`func`)
sys.setprofile(self.dispatcher)
try:
return apply(func, args)
finally:
sys.setprofile(None)
开发者ID:AngusGeek,项目名称:org.aspectj,代码行数:7,代码来源:profile.py
示例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
开发者ID:testmana2,项目名称:test,代码行数:33,代码来源:DebugClientThreads.py
示例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)
开发者ID:RichardWarfield,项目名称:heimdall,代码行数:33,代码来源:watcher.py
示例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
开发者ID:Darriall,项目名称:eric,代码行数:27,代码来源:DebugThread.py
示例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
开发者ID:0xmilk,项目名称:appscale,代码行数:25,代码来源:background_thread.py
示例16: capture_events
def capture_events(callable, p=None):
if p is None:
p = HookWatcher()
sys.setprofile(p.callback)
protect(callable, p)
sys.setprofile(None)
return p.get_events()[1:-1]
开发者ID:mancoast,项目名称:CPythonPyc_test,代码行数:7,代码来源:220_test_profilehooks.py
示例17: platform_specific
def platform_specific(self, context, *args, **kwargs):
def tracer(frame, event, arg):
if event == 'return':
self._locals = frame.f_locals.copy()
# tracer is activated on next call, return or exception
sys.setprofile(tracer)
try:
# trace the function call
self.func(context, *args, **kwargs)
finally:
# disable tracer and replace with old one
sys.setprofile(None)
if hasattr(context, 'browser') and 'browser' in self._locals:
return self._locals['browser'](context, *args, **kwargs)
elif hasattr(context, 'device'):
if context.device.capabilities['platformName'] == 'iOS' and 'ios' in self._locals:
return self._locals['ios'](context, *args, **kwargs)
elif context.device.capabilities['platformName'] == 'Android' and 'android' in self._locals:
return self._locals['android'](context, *args, **kwargs)
elif 'mobile' in self._locals:
return self._locals['mobile'](context, *args, **kwargs)
raise MultiplatformException(
"Function %s was decorated with @multiplatform but could not find appropriate context" % self.func)
开发者ID:galuszkak,项目名称:behaving,代码行数:27,代码来源:multiplatform.py
示例18: run
def run(self):
if _settrace_func:
_sys.settrace(_settrace_func)
if _setprofile_func:
_sys.setprofile(_setprofile_func)
self.__target(*self.__args, **self.__kwargs)
开发者ID:CJT-Jackton,项目名称:panda3d,代码行数:7,代码来源:threading.py
示例19: run
def run(self, cmd):
sys.setprofile(self.profile)
try:
exec(cmd)
finally:
sys.setprofile(None)
return self
开发者ID:pympler,项目名称:pympler,代码行数:7,代码来源:mprofile.py
示例20: notify_event
def notify_event(self, frame, event, arg):
if event in ["call", "return"]:
fname = self._getfilename(frame)
func = frame.f_code.co_name
if event == "return":
self.frameno -= 1
if not self.enabled and self.frameno == self.depth:
self.enabled = True
if self.frameno < 0:
sys.setprofile(None)
return
if self.enabled:
lineno = frame.f_lineno
prefix = " " * self.frameno
buff = "%s%s %s:%d:%s()\n" % (prefix,event,fname,lineno,func)
sys.stderr.write(buff)
if event == "call":
if self.enabled and fname.startswith("logging/"):
self.enabled = False
self.depth = self.frameno
self.frameno += 1
开发者ID:ClaudioArtusio,项目名称:neubot,代码行数:25,代码来源:__init__.py
注:本文中的sys.setprofile函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论