Example #1
0
 def test_module_stress(self):
     self.assertEqual(yappi.is_running(), False)
     
     yappi.start()
     yappi.clear_stats()
     self.assertRaises(_yappi.error, yappi.set_clock_type, "wall")
     
     yappi.stop()
     yappi.clear_stats()
     yappi.set_clock_type("cpu")
     self.assertRaises(yappi.YappiError, yappi.set_clock_type, "dummy")
     self.assertEqual(yappi.is_running(), False)
     yappi.clear_stats()
     yappi.clear_stats()
Example #2
0
 def _start_profiling(self, clock):
     with lock:
         if yappi.is_running():
             raise HTTPBadRequest("profile is already running")
         log.info("Starting profiling using %r clock", clock)
         yappi.set_clock_type(clock)
         yappi.start(builtins=True, profile_threads=True)
 def stop():
     pages.require("/admin/settings.edit", noautoreturn=True)
     pages.postOnly()
     import yappi
     if yappi.is_running():
         yappi.stop()
     raise cherrypy.HTTPRedirect("/settings/profiler")
Example #4
0
def injection_unload(**kwargs):
    try:
        import yappi
        if yappi.is_running():
            yappi.stop()
    except:
        pass
Example #5
0
 def stop():
     pages.require("/admin/settings.edit",  noautoreturn=True)
     pages.postOnly()
     import yappi
     if yappi.is_running():
         yappi.stop()
     raise cherrypy.HTTPRedirect("/settings/profiler")
Example #6
0
def _stop_profiling(filename, format):
    logging.debug("Stopping profiling")
    with _lock:
        if yappi.is_running():
            yappi.stop()
            stats = yappi.get_func_stats()
            stats.save(filename, format)
            yappi.clear_stats()
Example #7
0
def injection_load(**kwargs):
    import threading
    try:
        import yappi
        if not yappi.is_running():
            yappi.start()
    except:
        pass
Example #8
0
def _stop_profiling(filename, format):
    logging.debug("Stopping CPU profiling")
    with _lock:
        if yappi.is_running():
            yappi.stop()
            stats = yappi.get_func_stats()
            stats.save(filename, format)
            yappi.clear_stats()
Example #9
0
 def start():
     pages.require("/admin/settings.edit")
     import yappi
     if not yappi.is_running():
         yappi.start()
     time.sleep(0.5)
     messagebus.postMessage("/system/settings/activatedprofiler",pages.getAcessingUser())
     raise cherrypy.HTTPRedirect("/settings/profiler")
Example #10
0
 def start():
     pages.require("/admin/settings.edit", noautoreturn=True)
     pages.postOnly()
     import yappi
     if not yappi.is_running():
         yappi.start()
     time.sleep(0.5)
     messagebus.postMessage("/system/settings/activatedprofiler",pages.getAcessingUser())
     raise cherrypy.HTTPRedirect("/settings/profiler")
Example #11
0
    def _start_profiling(self, clock):
        with lock:
            if yappi.is_running():
                raise http.Error(http.BAD_REQUEST,
                                 "profile is already running")

            log.info("Starting profiling using %r clock", clock)
            yappi.set_clock_type(clock)
            yappi.start(builtins=True, profile_threads=True)
Example #12
0
File: cpu.py Project: EdDev/vdsm
    def stop(self):
        if not yappi.is_running():
            raise UsageError("CPU profiler is not running")

        logging.info("Stopping CPU profiling")
        yappi.stop()
        stats = yappi.get_func_stats()
        stats.save(self.filename, self.format)
        yappi.clear_stats()
Example #13
0
    def _start_profiling(self, clock):
        with lock:
            if yappi.is_running():
                raise http.Error(
                    http.BAD_REQUEST, "profile is already running")

            log.info("Starting profiling using %r clock", clock)
            yappi.set_clock_type(clock)
            yappi.start(builtins=True, profile_threads=True)
Example #14
0
    def stop(self):
        if not yappi.is_running():
            raise UsageError("CPU profiler is not running")

        logging.info("Stopping CPU profiling")
        yappi.stop()
        stats = yappi.get_func_stats()
        stats.save(self.filename, self.format)
        yappi.clear_stats()
Example #15
0
    def update(self, config, current_time=None):
        """
            Updates the state of the profiler - either enabling or disabling it, based on
            the current time and whether or not the current profiling interval has started/stopped
        """
        # no profiling if the profiler isn't available
        if yappi is None:
            return

        if current_time is None:
            current_time = time.time()

        try:
            # check if profiling is enabled in the config and turn it on/off if necessary
            if config.enable_profiling:
                if not self._is_enabled:
                    self._update_start_interval(config, current_time)
                    self._is_enabled = True
            else:
                if yappi.is_running():
                    self._stop(config, current_time)
                self._is_enabled = False

            # only do profiling if we are still enabled
            if not self._is_enabled:
                return

            # check if the current profiling interval needs to start or stop
            if yappi.is_running():
                if current_time > self._profile_end:
                    self._stop(config, current_time)
                    self._update_start_interval(config, current_time)

            else:
                if current_time > self._profile_start:
                    self._start(config, current_time)
        except Exception, e:
            global_log.log(
                scalyr_logging.DEBUG_LEVEL_0,
                "Failed to update profiler: %s, %s" %
                (str(e), traceback.format_exc()),
                limit_once_per_x_secs=300,
                limit_key="profiler-update",
            )
Example #16
0
File: ctl.py Project: skripkar/noc
 def prof_start(self):
     """
     Start service profiling
     """
     import yappi
     if yappi.is_running():
         return "Already running"
     else:
         yappi.start()
         return "Profiling started"
Example #17
0
 def _stop_profiling(self):
     with lock:
         if not yappi.is_running():
             raise HTTPBadRequest("profile is not running")
         log.info("Stopping profiling, writing profile to %r",
                  self.config.profile.filename)
         yappi.stop()
         stats = yappi.get_func_stats()
         stats.save(self.config.profile.filename, type="pstat")
         yappi.clear_stats()
Example #18
0
def _start_profiling():
    global yappi
    logging.debug("Starting profiling")
    with _lock:
        import yappi
        # yappi start semantics are a bit too liberal, returning success if
        # yappi is already started, happily having too different code paths
        # that thinks they own the single process profiler.
        if yappi.is_running():
            raise Error('Profiler is already running')
        yappi.start()
Example #19
0
    def _stop_profiling(self):
        with lock:
            if not yappi.is_running():
                raise http.Error(http.BAD_REQUEST, "profile is not running")

            log.info("Stopping profiling, writing profile to %r",
                     self.config.profile.filename)
            yappi.stop()
            stats = yappi.get_func_stats()
            stats.save(self.config.profile.filename, type="pstat")
            yappi.clear_stats()
Example #20
0
async def start_prof():
    """
    Start code profiling
    :return:
    """
    import yappi

    if yappi.is_running():
        return "Already running"
    yappi.start()
    return "Profiling started"
Example #21
0
    def _stop_profiling(self):
        with lock:
            if not yappi.is_running():
                raise http.Error(http.BAD_REQUEST, "profile is not running")

            log.info("Stopping profiling, writing profile to %r",
                     self.config.profile.filename)
            yappi.stop()
            stats = yappi.get_func_stats()
            stats.save(self.config.profile.filename, type="pstat")
            yappi.clear_stats()
Example #22
0
async def stop_prof():
    """
    Stop code profiling
    :return:
    """
    import yappi

    if not yappi.is_running():
        return "Not running"

    return "Profiling stopped"
Example #23
0
def injection(cmd=None, **kwargs):
    import yappi
    if cmd == 'reset':
        yappi.clear_stats()
        return True
    else:
        if not yappi.is_running():
            yappi.start()
        result = []
        for f in yappi.get_func_stats():
            result.append((f.name, f.ncall, f.nactualcall, f.ttot, f.tsub,
                           f.tavg, f.module, f.lineno, f.builtin))
        return result
Example #24
0
def impl():
    out = '''
    <p> Profile is{0}running. 
    <a href='start'>Start</a> <a href='stop'>Stop</a> <a href='clear_stats'>Clear stats</a>
    '''.format(
        ' ' if yappi.is_running() else ' not '
    )
    fkeys = 'index module lineno name ncall nactualcall builtin ttot tsub tavg'.split()
    out += '<table><tr>{0}</tr>'.format(''.join(map('<th>{0}</th>'.format, fkeys)))
    fmt = '<tr>{0}</tr>'.format(''.join('<td>{0.%s}</td>' % (k, ) for k in fkeys))
    out += ''.join(map(fmt.format, yappi.get_func_stats()))
    out += '</table>'
    return out
Example #25
0
def injection(thread_stack_info=None, **kwargs):
    import threading
    import sys
    result = []
    if thread_stack_info is None:
        import inspect
        yi = {}
        try:
            import yappi
            if not yappi.is_running():
                yappi.start()
            for d in yappi.get_thread_stats():
                yi[d[2]] = (d[3], d[4])
        except:
            pass
        for t in threading.enumerate():
            if not t.name.startswith('__pptop_injection'):
                try:
                    target = '{}.{}'.format(
                        t._target.__module__,
                        t._target.__qualname__ if hasattr(
                            t._target, '__qualname__') else t._target.__name__)
                except:
                    target = None
                y = yi.get(t.ident)
                r = (t.ident, t.daemon, t.name, target, y[0] if y else 0,
                     y[1] if y else 0)
                try:
                    x = inspect.getframeinfo(sys._current_frames()[t.ident])
                    r += (' '.join(x.code_context).strip(),
                          '{}:{}'.format(x.filename, x.lineno))
                except:
                    # from pptop.logger import log_traceback
                    # log_traceback()
                    r += (None, None)
                result.append(r)
    else:
        try:
            import traceback
            import linecache
            for fi in traceback.extract_stack(
                    sys._current_frames()[thread_stack_info]):
                f = fi.filename
                ln = fi.lineno
                cmd = linecache.getline(f, ln).strip()
                result.append((cmd, '{}:{}'.format(f, ln)))
        except Exception:
            e = sys.exc_info()
            result.append((e[0].__name__, str(e[1])))
    return result
Example #26
0
File: cpu.py Project: kripper/vdsm
def _start_profiling(clock, builtins, threads):
    global yappi
    logging.debug("Starting profiling")

    import yappi

    with _lock:
        # yappi start semantics are a bit too liberal, returning success if
        # yappi is already started, happily having too different code paths
        # that thinks they own the single process profiler.
        if yappi.is_running():
            raise Error('Profiler is already running')
        yappi.set_clock_type(clock)
        yappi.start(builtins=builtins, profile_threads=threads)
Example #27
0
def _start_profiling(clock, builtins, threads):
    global yappi
    logging.debug("Starting CPU profiling")

    import yappi

    with _lock:
        # yappi start semantics are a bit too liberal, returning success if
        # yappi is already started, happily having too different code paths
        # that thinks they own the single process profiler.
        if yappi.is_running():
            raise UsageError('CPU profiler is already running')
        yappi.set_clock_type(clock)
        yappi.start(builtins=builtins, profile_threads=threads)
        def start():
            pages.require("/admin/settings.edit", noautoreturn=True)
            pages.postOnly()
            import yappi
            if not yappi.is_running():
                yappi.start()
                try:
                    yappi.set_clock_type("cpu")
                except:
                    logging.exception("CPU time profiling not supported")

            time.sleep(0.5)
            messagebus.postMessage("/system/settings/activatedprofiler",
                                   pages.getAcessingUser())
            raise cherrypy.HTTPRedirect("/settings/profiler")
Example #29
0
    def start(self):
        # Lazy import so we do not effect runtime environment if profiling is
        # not used.
        global yappi
        import yappi  # pylint: disable=import-error

        # yappi start semantics are a bit too liberal, returning success if
        # yappi is already started, happily having two different code paths
        # that thinks they own the single process profiler.
        if yappi.is_running():
            raise UsageError('CPU profiler is already running')

        logging.info("Starting CPU profiling")
        yappi.set_clock_type(self.clock)
        yappi.start(builtins=self.builtins, profile_threads=self.threads)
Example #30
0
File: cpu.py Project: EdDev/vdsm
    def start(self):
        # Lazy import so we do not effect runtime environment if profiling is
        # not used.
        global yappi
        import yappi

        # yappi start semantics are a bit too liberal, returning success if
        # yappi is already started, happily having two different code paths
        # that thinks they own the single process profiler.
        if yappi.is_running():
            raise UsageError('CPU profiler is already running')

        logging.info("Starting CPU profiling")
        yappi.set_clock_type(self.clock)
        yappi.start(builtins=self.builtins, profile_threads=self.threads)
Example #31
0
def profile():
    import yappi, cStringIO
    if not yappi.is_running():
        yappi.start()
    s = yappi.get_func_stats()
    s = s.sort(flask.request.args.get('sort', 'tsub'))
    f = cStringIO.StringIO()
    s.print_all(f,
                columns={
                    0: ('name', 80),
                    1: ('ncall', 20),
                    2: ('tsub', 8),
                    3: ('ttot', 8)
                })
    if flask.request.args.get('clear', 'N').lower() \
       in {'y', 'yes', 'true', 'on'}:
        yappi.clear_stats()
    return '<pre>\n' + f.getvalue() + '</pre>\n'
    def index(self, start=None, stop=None, clear=None, show=None):
        start = yappi.is_running() or start
        self.stop()
        result = None
        try:
            if show:
                stats = self.get_stats()
            else:
                stats = None
            if clear:
                self.clear()

            result = GenericView('profiler', {'stats': stats}).render()
        finally:
            if start:
                self.start()

        return result
Example #33
0
 def index(self, start=None, stop=None, clear=None, show=None):
     start = yappi.is_running() or start
     self.stop()
     result = None
     try:
         if show:
             stats = self.get_stats()
         else:
             stats = None
         if clear:
             self.clear()
         
         result = GenericView('profiler', {'stats': stats}).render()
     finally:
         if start:
             self.start()
     
     return result
Example #34
0
File: debug.py Project: DaveQB/salt
def _handle_sigusr2(sig, stack):
    '''
    Signal handler for SIGUSR2, only available on Unix-like systems
    '''
    try:
        import yappi
    except ImportError:
        return
    if yappi.is_running():
        yappi.stop()
        filename = 'callgrind.salt-{0}-{1}'.format(int(time.time()), os.getpid())
        destfile = os.path.join(tempfile.gettempdir(), filename)
        yappi.get_func_stats().save(destfile, type='CALLGRIND')
        if sys.stderr.isatty():
            sys.stderr.write('Saved profiling data to: {0}\n'.format(destfile))
        yappi.clear_stats()
    else:
        if sys.stderr.isatty():
            sys.stderr.write('Profiling started\n')
        yappi.start()
Example #35
0
def _handle_sigusr2(sig, stack):
    """
    Signal handler for SIGUSR2, only available on Unix-like systems
    """
    try:
        import yappi
    except ImportError:
        return
    if yappi.is_running():
        yappi.stop()
        filename = "callgrind.salt-{0}-{1}".format(int(time.time()), os.getpid())
        destfile = os.path.join(tempfile.gettempdir(), filename)
        yappi.get_func_stats().save(destfile, type="CALLGRIND")
        if sys.stderr.isatty():
            sys.stderr.write("Saved profiling data to: {0}\n".format(destfile))
        yappi.clear_stats()
    else:
        if sys.stderr.isatty():
            sys.stderr.write("Profiling started\n")
        yappi.start()
Example #36
0
File: utils.py Project: nirs/yappi
 def setUp(self):
     if yappi.is_running():
         yappi.stop()
     yappi.clear_stats()
     yappi.set_clock_type('cpu')  # reset to default clock type
Example #37
0
 def is_running(self):
     return yappi.is_running()
Example #38
0
 def __enter__(self):
     """ Start the yappi profiler if it is not running.
     """
     if  not yappi.is_running():
         yappi.start(self._builtins)
Example #39
0
 def setUp(self):
     if yappi.is_running():
         yappi.stop()
     yappi.clear_stats()
     yappi.set_clock_type('cpu') # reset to default clock type
Example #40
0
def is_profiler_running():
    """Return True if the profiler is running."""
    # GET /profiler
    return yappi.is_running()
Example #41
0
File: cpu.py Project: EdDev/vdsm
def is_running():
    with _lock:
        return yappi and yappi.is_running()
Example #42
0
 def is_running(self):
     return yappi.is_running()
Example #43
0
 def __enter__(self):
     """ Start the yappi profiler if it is not running.
     """
     if not yappi.is_running():
         yappi.start(self._builtins)
Example #44
0
def is_running():
    with _lock:
        return yappi and yappi.is_running()
Example #45
0
    def get(self, req, resp):
        if yappi is None:
            raise http.Error(http.NOT_FOUND, "yappi is not installed")

        msg = {"running": yappi.is_running()}
        resp.send_json(msg)