def run(globalOptions: dict): global pyProc signal.signal(signal.SIGINT, handler) signal.signal(signal.SIGTERM, handler) options = globalOptions if options.get('cmdline_args').get('bypass', False): cmd = options.get('control').get('cmd') logging.info("Bypass vaitrace, just run cmd") pyCmd = options.get('control').get('cmd') pyRunCtx(pyCmd) exit(0) """Preparing""" tracer.prepare(options) tracer.start() """requirememt format: ["tracerName", "tracerName1", "hwInfo", ...]""" collector.prepare(options, tracer.getSourceRequirement()) collector.start() """Start Running""" pyCmd = options.get('control').get('cmd') timeout = options.get('control').get('timeout') # pyRunCtx(pyCmd) pyProc = Thread(target=pyRunCtx, args=(pyCmd,)) pyProc.start() options['control']['launcher'] = "python" options['control']['pid'] = os.getpid() options['control']['time'] = time.strftime( "%Y-%m-%d %H:%M:%S", time.localtime()) if timeout <= 0: pyProc.join() else: while timeout > 0: time.sleep(1) timeout -= 1 p = pyProc.is_alive() if p == False: break logging.info("vaitrace timeout, waiting for Python thread terminated") pyProc.join() collector.stop() tracer.stop() tracer.process(collector.getData())
def run(globalOptions: dict): signal.signal(signal.SIGINT, handler) signal.signal(signal.SIGTERM, handler) options = globalOptions """Help find the path of cmd in PATH""" cmd = options.get('control').get('cmd')[0] options['control']['cmd'][0] = shell_find_exec_path(cmd) if options.get('cmdline_args').get('bypass', False): cmd = options.get('control').get('cmd') logging.info("Bypass vaitrace, just run cmd") proc = Popen(cmd) proc.wait() exit(0) """Preparing""" tracer.prepare(options) tracer.start() """requirememt format: ["tracerName", "tracerName1", "hwInfo", ...]""" collector.prepare(options, tracer.getSourceRequirement()) collector.start() """Start Running""" cmd = options.get('control').get('cmd') timeout = options.get('control').get('timeout') proc = Popen(cmd) options['control']['launcher'] = "cpp" options['control']['pid'] = proc.pid options['control']['time'] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) if timeout <= 0: proc.wait() else: while timeout > 0: time.sleep(1) timeout -= 1 p = proc.poll() if p is not None: break logging.info("vaitrace time out, stopping process...") proc.send_signal(signal.SIGINT) proc.wait() collector.stop() tracer.stop() tracer.process(collector.getData())