Example #1
0
    def SetEnableProfiling(self,
                           enable_profiling,
                           profiling_sample_rate=1000,
                           profiling_type=u'all'):
        """Enables or disables profiling.

    Args:
      enable_profiling: boolean value to indicate if profiling should
                        be enabled.
      profiling_sample_rate: optional integer indicating the profiling sample
                             rate. The value contains the number of files
                             processed. The default value is 1000.
      profiling_type: optional profiling type.
    """
        self._enable_profiling = enable_profiling
        self._profiling_sample_rate = profiling_sample_rate

        if self._enable_profiling:
            if profiling_type in [u'all', u'memory'
                                  ] and not self._memory_profiler:
                self._memory_profiler = profiler.GuppyMemoryProfiler(
                    self._identifier)

            if profiling_type in [u'all', u'parsers'
                                  ] and not self._parsers_profiler:
                self._parsers_profiler = profiler.ParsersProfiler(
                    self._identifier)
Example #2
0
  def _StartProfiling(self):
    """Starts profiling."""
    if not self._processing_configuration:
      return

    if self._processing_configuration.profiling.HaveProfileMemory():
      identifier = u'{0:s}-memory'.format(self._name)
      self._memory_profiler = profiler.GuppyMemoryProfiler(
          identifier, path=self._processing_configuration.profiling.directory,
          profiling_sample_rate=(
              self._processing_configuration.profiling.sample_rate))
      self._memory_profiler.Start()

    if self._processing_configuration.profiling.HaveProfileParsers():
      identifier = u'{0:s}-parsers'.format(self._name)
      self._parsers_profiler = profiler.ParsersProfiler(
          identifier, path=self._processing_configuration.profiling.directory)
      self._extraction_worker.SetParsersProfiler(self._parsers_profiler)

    if self._processing_configuration.profiling.HaveProfileProcessing():
      identifier = u'{0:s}-processing'.format(self._name)
      self._processing_profiler = profiler.ProcessingProfiler(
          identifier, path=self._processing_configuration.profiling.directory)
      self._extraction_worker.SetProcessingProfiler(self._processing_profiler)

    if self._processing_configuration.profiling.HaveProfileSerializers():
      identifier = u'{0:s}-serializers'.format(self._name)
      self._serializers_profiler = profiler.SerializersProfiler(
          identifier, path=self._processing_configuration.profiling.directory)
Example #3
0
    def _StartProfiling(self):
        """Starts profiling."""
        if not self._enable_profiling:
            return

        if self._profiling_type in (u'all', u'memory'):
            identifier = u'{0:s}-memory'.format(self._name)
            self._memory_profiler = profiler.GuppyMemoryProfiler(
                identifier,
                path=self._profiling_directory,
                profiling_sample_rate=self._profiling_sample_rate)
            self._memory_profiler.Start()

        if self._profiling_type in (u'all', u'parsers'):
            identifier = u'{0:s}-parsers'.format(self._name)
            self._parsers_profiler = profiler.ParsersProfiler(
                identifier, path=self._profiling_directory)
            self._extraction_worker.SetParsersProfiler(self._parsers_profiler)

        if self._profiling_type in (u'all', u'processing'):
            identifier = u'{0:s}-processing'.format(self._name)
            self._processing_profiler = profiler.ProcessingProfiler(
                identifier, path=self._profiling_directory)
            self._extraction_worker.SetProcessingProfiler(
                self._processing_profiler)

        if self._profiling_type in (u'all', u'serializers'):
            identifier = u'{0:s}-serializers'.format(self._name)
            self._serializers_profiler = profiler.SerializersProfiler(
                identifier, path=self._profiling_directory)
Example #4
0
    def testGuppyMemoryProfiler(self):
        """Tests the Start, Sample and Stop functions."""
        self.assertTrue(profiler.GuppyMemoryProfiler.IsSupported())

        with shared_test_lib.TempDirectory() as temp_directory:
            test_profiler = profiler.GuppyMemoryProfiler('unittest',
                                                         path=temp_directory)

            test_profiler.Start()

            for _ in range(5):
                test_profiler.Sample()
                time.sleep(0.01)

            test_profiler.Stop()