Exemplo n.º 1
0
    def __call__(self, *args, **kwargs):

        if settings.PROFILING_RATE > 0 and random.random() < settings.PROFILING_RATE / 100:
            profiler = cProfile.Profile()
            profiler.enable()
            t0 = time.perf_counter()
            ret = super().__call__(*args, **kwargs)
            tottime = time.perf_counter() - t0
            profiler.disable()
            profiler.dump_stats(os.path.join(settings.PROFILE_DIR, '{time:.0f}_{tottime:.3f}_celery_{t}.pstat'.format(
                t=self.name, tottime=tottime, time=time.time()
            )))
        else:
            t0 = time.perf_counter()
            ret = super().__call__(*args, **kwargs)
            tottime = time.perf_counter() - t0

        if settings.METRICS_ENABLED:
            pretix_task_duration_seconds.observe(tottime, task_name=self.name)
        return ret
Exemplo n.º 2
0
    def __call__(self, *args, **kwargs):

        if settings.PROFILING_RATE > 0 and random.random(
        ) < settings.PROFILING_RATE / 100:
            profiler = cProfile.Profile()
            profiler.enable()
            t0 = time.perf_counter()
            ret = super().__call__(*args, **kwargs)
            tottime = time.perf_counter() - t0
            profiler.disable()
            profiler.dump_stats(
                os.path.join(
                    settings.PROFILE_DIR,
                    '{time:.0f}_{tottime:.3f}_celery_{t}.pstat'.format(
                        t=self.name, tottime=tottime, time=time.time())))
        else:
            t0 = time.perf_counter()
            ret = super().__call__(*args, **kwargs)
            tottime = time.perf_counter() - t0

        if settings.METRICS_ENABLED:
            pretix_task_duration_seconds.observe(tottime, task_name=self.name)
        return ret