Ejemplo n.º 1
0
    def add_signal_handlers(self):
        try:
            if self._should_profiler_be_enabled(
            ) and self.signal_helper.can_usr_signals_be_used():
                from viztracer import VizTracer
                tracer = VizTracer(
                    output_file=constants.CODE_PROFILER_TRACE_NAME,
                    ignore_c_function=True,
                    plugins=[
                        'vizplugins.cpu_usage', 'vizplugins.memory_usage'
                    ],
                    max_stack_depth=20)
                self.logger.info(
                    "Attempting to install the default code profiler.")
                tracer.install()
                self.logger.info("Successfully installed code profiler.")
                self._set_signal_handler_not_initialized_env = False
                self.is_profiler_enabled = True
            else:
                self._disable_code_profiler()

        except Exception as e:
            self.logger.exception(e)
            self._disable_code_profiler()

        finally:
            self.shut_down()
Ejemplo n.º 2
0
 def test_install(self):
     tracer = VizTracer(output_file="remote.json")
     tracer.install()
     os.kill(os.getpid(), signal.SIGUSR1)
     time.sleep(0.1)
     os.kill(os.getpid(), signal.SIGUSR2)
     self.assertTrue(os.path.exists("remote.json"))
     os.remove("remote.json")
Ejemplo n.º 3
0
    def test_windows(self):
        tracer = VizTracer(output_file="remote.json")
        with self.assertRaises(SystemExit):
            tracer.install()

        self.template(["viztracer", "--attach", "1234"], success=False)