当前位置: 首页>>代码示例>>Python>>正文


Python Dispatcher.dispatchStapLabModuleAll方法代码示例

本文整理汇总了Python中dispatcher.Dispatcher.dispatchStapLabModuleAll方法的典型用法代码示例。如果您正苦于以下问题:Python Dispatcher.dispatchStapLabModuleAll方法的具体用法?Python Dispatcher.dispatchStapLabModuleAll怎么用?Python Dispatcher.dispatchStapLabModuleAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dispatcher.Dispatcher的用法示例。


在下文中一共展示了Dispatcher.dispatchStapLabModuleAll方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: stapLab

# 需要导入模块: from dispatcher import Dispatcher [as 别名]
# 或者: from dispatcher.Dispatcher import dispatchStapLabModuleAll [as 别名]
class stapLab():
	def __init__(self,
				logStream	= (lambda _: None)
		):
		self.log		= logStream
		self.options		= self.parseargs()
		if self.options['verbose']:
			self.log	= print
		self.log(self.options)
		self.dispatcher		= Dispatcher(	registerCallbackFunc	= self.registerGUIcallback,
							args			= {
											'target-pid' 	: self.options['target-pid'],	
											'logStream'	: self.log,
											'hardFail'	: True,
											'followChildren': self.options['follow_children']
										}
						)
		self.timers		= []
		self.start()

	def parseargs(self):
		# parse args
		#TODO:
		# subargument structure so we can set individual options to each module, e.g.:
		# stapLab tid moduleA optionA1 optionB1 moduleB optionA2 optionB2
		# stapLab [-f] tid [module [option]]
		# -> Theoretically this could also be done by just simply copying an existing module and quickly modifiying the sourcecode
		# the advantage of this would be that we keep program complexity lower and it is more powerful to do it in code, 
		# compared to using switches and the cli parameters.
		parser = argparse.ArgumentParser(description='staplab - systemtap module dispatcher and data visualizer')
		parser.add_argument('target-pid', type=int, metavar="target_pid",
					help='target process ID. Must be greater than zero.')
		parser.add_argument('modules', type=str, nargs="+", metavar="module",default=['dummy'], 
					help='module to be dispatched')
		parser.add_argument('-f','--follow-children', action='store_true',
					help='if a process forks, include children to the tapset')
		parser.add_argument('-d','--hardFail', action='store_true',
					help='fail hard if Module cannot be loaded, i.e. quit and don\'t continue loading other modules')
		parser.add_argument('-v','--verbose', action='store_true',
					help='be verbose about what is going on internally')

		args = vars(parser.parse_args())
		return args

	def registerGUIcallback(self,func,timerInterval=20):
		fig	= pl.figure()
		self.log("set timer for %s" % str(func))
		def guiCallBack(func,figure):
			try:
				func(figure)
				#manager = pl.get_current_fig_manager()
				#manager.canvas.draw()
			except KeyboardInterrupt:
				self.stop()
		timer	= fig.canvas.new_timer(interval = timerInterval)
		timer.add_callback(guiCallBack,func,fig)
		timer.start()
		self.timers	+= [timer]

	def start(self):
		try:
			self.dispatcher.dispatchStapLabModuleAll(modules=self.options['modules'], target=self.options['target-pid'])
		except ImportError as err:
			self.log("error while loading a module: %s" % str(err))
			raise
		self.log("entering stapLab mainLoop")
		
		# wait for dispatcher to launch at least one module
		while self.dispatcher.stapLabModules == 0:
			sleep(1)
		
		# now run until we have no modules left to process
		while len(self.dispatcher.stapLabModules) > 0:
			try:
				# we do this so we can catch KeyboardInterrupts better
				pl.show()
				sleep(0.1)
			except KeyboardInterrupt:
				self.stop()
			except:
				self.log("error in stapLab mainLoop")
				raise
		self.log("leaving stapLab mainLoop")

	def stop(self):
		self.log("stapLab.stop()")
		self.dispatcher.stop()
		sys.exit(0)
开发者ID:psychophoniac,项目名称:staplab,代码行数:90,代码来源:staplab.py


注:本文中的dispatcher.Dispatcher.dispatchStapLabModuleAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。