How to use the pprofile.StatisticProfile function in pprofile

To help you get started, we’ve selected a few pprofile examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vpelletier / pprofile / pprofile.py View on Github external
if options.script is not None:
            args.append(options.script)
        args.extend(options.argv)
        runner_method_kw = {
            'module': options.module,
            'argv': args,
        }
        runner_method_id = 'runmodule'
    if options.format is None:
        if _isCallgrindName(options.out):
            options.format = 'callgrind'
        else:
            options.format = 'text'
    relative_path = options.format == 'callgrind' and options.zipfile
    if options.statistic:
        prof = StatisticalProfile()
        runner = StatisticalThread(
            profiler=prof,
            period=options.statistic,
            single=not options.threads,
        )
    else:
        if options.threads:
            klass = ThreadProfile
        else:
            klass = Profile
        prof = runner = klass(verbose=options.verbose)
    try:
        getattr(runner, runner_method_id)(**runner_method_kw)
    finally:
        if options.out == '-':
            out = EncodeOrReplaceWriter(sys.stdout)
github vpelletier / pprofile / pprofile.py View on Github external
profiler (None or StatisticProfile instance)
          Available on instances as the "profiler" read-only property.
          If None, a new profiler instance will be created.
        period (float)
          How many seconds to wait between consecutive samples.
          The smaller, the more profiling overhead, but the faster results
          become meaningful.
          The larger, the less profiling overhead, but requires long profiling
          session to get meaningful results.
        single (bool)
          Profile only the thread which created this instance.
        group, name
          See Python's threading.Thread API.
        """
        if profiler is None:
            profiler = StatisticProfile()
        if single:
            self._test = lambda x, ident=threading.current_thread().ident: ident == x
        else:
            self._test = None
        super(StatisticThread, self).__init__(
            group=group,
            name=name,
        )
        self._stop_event = threading.Event()
        self._period = period
        self._profiler = profiler
        profiler.total_time = 0
        self.daemon = True
        self.clean_exit = False
github vpelletier / pprofile / pprofile.py View on Github external
def __init__(self):
        super(StatisticProfile, self).__init__()
        self.total_time = 1
github vpelletier / pprofile / pprofile.py View on Github external
>>> s_profile = StatisticProfile()
        >>> with s_profile(single=False):
        >>>    # Code to profile
        Is equivalent to:
        >>> s_profile = StatisticProfile()
        >>> s_thread = StatisticThread(profiler=s_profile, single=False)
        >>> with s_thread:
        >>>    # Code to profile
        """
        return StatisticThread(
            profiler=self, period=period, single=single, group=group,
            name=name,
        )

# BBB
StatisticalProfile = StatisticProfile

class StatisticThread(threading.Thread, ProfileRunnerBase):
    """
    Usage in a nutshell:
      with StatisticThread() as profiler_thread:
        # do stuff
      profiler_thread.profiler.print_stats()
    """
    __slots__ = (
        '_test',
        '_start_time',
        'clean_exit',
    )

    def __init__(self, profiler=None, period=.001, single=True, group=None, name=None):
        """