Пример #1
0
    def _dump(self):
        """
        Dumps the profiling stats.
        Also manages clearing stats if clearing each interval.

        """
        # If clearing each interval, stop profiler
        if self._config.clear_each_interval:
            profiler.stop()
            self._ended = utils.utc_seconds()

        # Dump the stats
        stats = profiler.get_func_stats()
        ctx = ProfilingContext(
            started=self._started, ended=utils.utc_seconds(),
            topic=self._topic
        )
        for o in self._outputs:
            try:
                o.write(ctx, stats)
            except Exception:
                # @TODO - Possibly do something with logging
                pass

        # If clearing each interval, clear stats and restart profiler
        if self._config.clear_each_interval:
            profiler.clear_stats()
            profiler.start()
            self.started = utils.utc_seconds()
Пример #2
0
 def __call__(self, req):
     taskid = req.headers['X-Neutron-Profiler-taskid']
     action = req.headers['X-Neutron-Profiler-Action']
     if action == 'start':
         # (anilvenkata): save self.taskid, helpful in throwing error
         # if stop called without start
         GreenletProfiler.set_clock_type('cpu')
         GreenletProfiler.start()
         LOG.debug("Trace Profiler.start profiling %s ", os.getpid())
     elif action == 'stop':
         GreenletProfiler.stop()
         LOG.debug("Trace Profiler.stop profiling %s ", os.getpid())
         stats = GreenletProfiler.get_func_stats()
         trace_path = os.path.join(cfg.CONF.trace_profiler.trace_path,
                                   taskid)
         utils.ensure_dir(trace_path)
         trace_file = os.path.join(trace_path, str(os.getpid()))
         LOG.debug("Trace Profiler.writing to trace file %s ", trace_file)
         stats.save(trace_file, cfg.CONF.trace_profiler.trace_format)
         GreenletProfiler.clear_stats()
     else:
         LOG.info(
             "Invalid profiler action %(action)s with "
             " taskid %(taskid)s", {
                 "action": action,
                 "taskid": taskid
             })
Пример #3
0
 def __call__(self, req):
     filename = req.headers['X-Neutron-Profiler-Filename']
     action = req.headers['X-Neutron-Profiler-Action']
     if action == 'start_trace':
         GreenletProfiler.set_clock_type('cpu')
         GreenletProfiler.start()
     else:
         GreenletProfiler.stop()
         stats = GreenletProfiler.get_func_stats()
         stats.save(filename, 'pstat')
         GreenletProfiler.clear_stats()
 def setUpClass(cls):
     # Measure the CPU cost of spin() as a baseline.
     GreenletProfiler.set_clock_type("cpu")
     GreenletProfiler.start()
     for _ in range(10):
         spin(1)
     GreenletProfiler.stop()
     f_stats = GreenletProfiler.get_func_stats()
     spin_stat = find_func(f_stats, "spin")
     GreenletTest.spin_cost = spin_stat.ttot / 10.0
     GreenletProfiler.clear_stats()
 def setUpClass(cls):
     # Measure the CPU cost of spin() as a baseline.
     GreenletProfiler.set_clock_type('cpu')
     GreenletProfiler.start()
     for _ in range(10):
         spin(1)
     GreenletProfiler.stop()
     f_stats = GreenletProfiler.get_func_stats()
     spin_stat = find_func(f_stats, 'spin')
     GreenletTest.spin_cost = spin_stat.ttot / 10.0
     GreenletProfiler.clear_stats()
 def tearDown(self):
     GreenletProfiler.stop()
     GreenletProfiler.clear_stats()
 def __call__(self, req):
     taskid = req.headers['X-Neutron-Profiler-taskid']
     action = req.headers['X-Neutron-Profiler-Action']
     iteration = req.headers.get('X-Neutron-Profiler-Iteration')
     profiler_type = req.headers.get('X-Neutron-Profiler-Type')
     obj_graph = True if profiler_type == 'objgraph' else False
     objcount = (True if
                 (profiler_type in ['objcount', 'objgraph']) else False)
     calltrace = (True if (not profiler_type
                           or profiler_type == 'calltrace') else False)
     trace_path = os.path.join(cfg.CONF.trace_profiler.trace_path, taskid)
     ensure_dir(trace_path)
     LOG.info(
         "Trace Profiler pid %s taskid %s action %s iteration %s"
         " profiler_type %s", os.getpid(), taskid, action, iteration,
         profiler_type)
     if action == 'start':
         if calltrace:
             GreenletProfiler.set_clock_type('cpu')
             GreenletProfiler.start()
         if objcount and iteration:
             objcount_dict[iteration] = len(gc.get_objects())
         if obj_graph:
             objgraph.get_new_ids()
         LOG.info("Trace Profiler.start profiling %s ", os.getpid())
     elif action == 'snapshot':
         if iteration:
             if objcount:
                 objcount_dict[iteration] = len(gc.get_objects())
             if obj_graph:
                 objgraph_file = os.path.join(
                     trace_path,
                     "{}-{}-{}-objgraph.dot".format(socket.gethostname(),
                                                    os.getpid(), iteration))
                 dump_objgrpah(objgraph_file)
     elif action == 'stop':
         LOG.info("Trace Profiler.stop profiling %s ", os.getpid())
         if calltrace:
             trace_file = os.path.join(
                 trace_path, "{}-{}".format(socket.gethostname(),
                                            os.getpid()))
             GreenletProfiler.stop()
             stats = GreenletProfiler.get_func_stats()
             LOG.info("Trace Profiler.writing to trace file %s ",
                      trace_file)
             stats.save(trace_file, cfg.CONF.trace_profiler.trace_format)
             GreenletProfiler.clear_stats()
         if objcount:
             objcount_file = os.path.join(
                 trace_path,
                 "{}-{}-objcount".format(socket.gethostname(), os.getpid()))
             if iteration:
                 objcount_dict[iteration] = len(gc.get_objects())
             with open(objcount_file, 'w') as fp:
                 json.dump(objcount_dict, fp)
             objcount_dict.clear()
         if obj_graph:
             objgraph_file = os.path.join(
                 trace_path,
                 "{}-{}-objgraph.dot".format(socket.gethostname(),
                                             os.getpid()))
             dump_objgrpah(objgraph_file)
     else:
         LOG.warning(
             "Invalid profiler action %(action)s with "
             " taskid %(taskid)s", {
                 "action": action,
                 "taskid": taskid
             })
 def tearDown(self):
     GreenletProfiler.stop()
     GreenletProfiler.clear_stats()