Пример #1
0
def enableProfiler(signum, config):
    """
    Enables the profiler on specified signal
    """
    try:
        # If the profiler is available on the system then enable it
        import gevent_profiler
        
        if config.has_key('summaryOutput'):
            gevent_profiler.set_summary_output(config['summaryOutput'])

        if config.has_key('statsOutput'):
            gevent_profiler.set_stats_output(config['statsOutput'])

        if config.has_key('traceOutput'):
            gevent_profiler.set_trace_output(config['traceOutput'])

        if config.has_key('printPercentage'):
            gevent_profiler.print_percentages(config['printPercentage'])

        if config.has_key('countTimeBlocking'):
            gevent_profiler.time_blocking(config['countTimeBlocking'])

        gevent_profiler.attach_on_signal(signum=signum, duration=config['duration'])
        logging.getLogger().info("The profiler is enabled and waiting on signal %s." % signum)

    except Exception as ex:
        logging.getLogger().warn("Failed enabling the profiler: %s" % ex)
Пример #2
0
def profile(duration=60, pf=None, trace_obj=None):
    """ profile """
    import gevent_profiler

    if gevent_profiler._attach_expiration is not None:
        return False, 'profile has running!\n'

    start_time = strftime('%y%m%d-%H%M%S')
    if pf is None:
        save_path = os.environ.get('LOG_PATH', None)
        if not save_path:
            save_path = os.path.join(os.environ['ROOT_PATH'], 'log')
        pf = os.path.join(save_path, 'profile-%s.profile' % start_time)
    gevent_profiler.set_summary_output(pf)
    gevent_profiler._attach_duration = duration

    if trace_obj:
        gevent_profiler.set_trace_output(trace_obj)
        gevent_profiler.enable_trace_output(True)
    else:
        gevent_profiler.set_trace_output(None)
        gevent_profiler.enable_trace_output(False)

    gevent_profiler.attach()
    return True, 'profile start:%s\n' % start_time
Пример #3
0
    def begin(self):
        ts = time.time()

        gevent_profiler.set_stats_output("nose-gevent-profiler-%s-stats.txt" %
                                         ts)
        gevent_profiler.set_summary_output(
            "nose-gevent-profiler-%s-summary.txt" % ts)
        gevent_profiler.set_trace_output(None)
Пример #4
0
def start_profiler(prefix, pcts=False):
    """
    Start the gevent-profiler, outputting to the passed prefix-stats and prefix-summary.txt.

    You must call stop_profiler at a later point. The profiler is not safe to run twice at once
    as it keeps global state internally.

    @param  prefix      The prefix to use when naming the output files.
    @param  pcts        Whether the profiler should add percentages as well.
    """
    gevent_profiler.set_stats_output('%s-stats.txt' % prefix)
    gevent_profiler.set_summary_output('%s-summary.txt' % prefix)
    gevent_profiler.print_percentages(pcts)

    gevent_profiler.set_trace_output(None)  #'%s-trace.txt' % prefix)   @TODO make optional
    gevent_profiler.attach()
Пример #5
0
    def __init__(self, datadir: str) -> None:
        # create a new file every time instead of overwritting the latest profiling
        summary_file = "{:%Y%m%d_%H%M}_profile_summary".format(datetime.now())
        stats_file = "{:%Y%m%d_%H%M}_profile_stats".format(datetime.now())

        summary_path = os.path.join(datadir, summary_file)
        stats_path = os.path.join(datadir, stats_file)

        gevent_profiler.set_trace_output(None)
        gevent_profiler.set_summary_output(summary_path)
        gevent_profiler.set_stats_output(stats_path)

        GreenletProfiler.set_clock_type("cpu")
        GreenletProfiler.start()
        # gevent_profiler.attach()

        self.datadir = datadir
Пример #6
0
def start_profiler(prefix, pcts=False):
    """
    Start the gevent-profiler, outputting to the passed prefix-stats and prefix-summary.txt.

    You must call stop_profiler at a later point. The profiler is not safe to run twice at once
    as it keeps global state internally.

    @param  prefix      The prefix to use when naming the output files.
    @param  pcts        Whether the profiler should add percentages as well.
    """
    gevent_profiler.set_stats_output('%s-stats.txt' % prefix)
    gevent_profiler.set_summary_output('%s-summary.txt' % prefix)
    gevent_profiler.print_percentages(pcts)

    gevent_profiler.set_trace_output(
        None)  #'%s-trace.txt' % prefix)   @TODO make optional
    gevent_profiler.attach()
Пример #7
0
    def start(self):
        if self.profiling:
            return

        # create a new file every time instead of overwritting the latest profiling
        summary_file = '{:%Y%m%d_%H%M}_profile_summary'.format(datetime.now())
        stats_file = '{:%Y%m%d_%H%M}_profile_stats'.format(datetime.now())

        summary_path = os.path.join(self.datadir, summary_file)
        stats_path = os.path.join(self.datadir, stats_file)

        gevent_profiler.set_trace_output(None)
        gevent_profiler.set_summary_output(summary_path)
        gevent_profiler.set_stats_output(stats_path)

        GreenletProfiler.set_clock_type('cpu')
        GreenletProfiler.start()
        # gevent_profiler.attach()

        self.profiling = True
Пример #8
0
    def start(self):
        if self.profiling:
            return

        # create a new file every time instead of overwritting the latest profiling
        summary_file = '{:%Y%m%d_%H%M}_profile_summary'.format(datetime.now())
        stats_file = '{:%Y%m%d_%H%M}_profile_stats'.format(datetime.now())

        summary_path = os.path.join(self.datadir, summary_file)
        stats_path = os.path.join(self.datadir, stats_file)

        gevent_profiler.set_trace_output(None)
        gevent_profiler.set_summary_output(summary_path)
        gevent_profiler.set_stats_output(stats_path)

        GreenletProfiler.set_clock_type('cpu')
        GreenletProfiler.start()
        # gevent_profiler.attach()

        self.profiling = True
Пример #9
0
Файл: main.py Проект: fcua/x8623
    from session.regions import run_region_reloader
    gevent.spawn(run_region_reloader)


try:
    from uwsgidecorators import postfork
except ImportError:
    import gevent.monkey
    gevent.monkey.patch_all()
    init()
else:
    init = postfork(init)

from .app import application

if __name__ == '__main__':
    import settings
    import gevent_profiler
    import signal
    from gevent.pywsgi import WSGIServer

    gevent_profiler.attach_on_signal(signum=signal.SIGUSR1, duration=30)
    gevent_profiler.set_stats_output('stats.txt')
    gevent_profiler.set_summary_output('summary.txt')
    gevent_profiler.set_trace_output('trace.txt')

    logger.info('listening %s:%d', settings.SESSION['host'],
                settings.SESSION['port'])
    WSGIServer((settings.SESSION['host'], settings.SESSION['port']),
               application).serve_forever()
Пример #10
0
 def __enter__(self):
     gevent_profiler.set_stats_output(self.stats)
     gevent_profiler.set_summary_output(self.summary)
     gevent_profiler.set_trace_output(None)
     gevent_profiler.attach()
Пример #11
0
    def begin(self):
        ts = time.time()

        gevent_profiler.set_stats_output("nose-gevent-profiler-%s-stats.txt" % ts)
        gevent_profiler.set_summary_output("nose-gevent-profiler-%s-summary.txt" % ts)
        gevent_profiler.set_trace_output(None)