def __init__(self,
                 system_facade,
                 cfm_facade,
                 writer_function,
                 additional_system_metrics=[]):
        """
        Constructor.

        @param system_facade facade object to access system utils.
        @param cfm_facade facade object to access cfm utils.
        @param writer_function function called to collected metrics.
        @param additional_system_metrics Additional metrics to collect.
        """
        metric_set = system_metrics_collector.create_default_metric_set(
            system_facade)
        for metric in additional_system_metrics:
            metric_set.append(metric)
        self._system_metrics_collector = (
            system_metrics_collector.SystemMetricsCollector(
                system_facade, metric_set))
        # Media metrics
        data_point_collector = media_metrics_collector.DataPointCollector(
            cfm_facade)
        self._media_metrics_collector = (
            media_metrics_collector.MetricsCollector(data_point_collector))

        self._writer_function = writer_function
        # Collector thread.
        self._collector_thread = threading.Thread(
            target=self._collect_snapshots_until_stopped)
        self._stop = threading.Event()
 def test_collector_default_set_of_metrics_no_error(self):
     # Only verify no errors are thrown when collecting using
     # the default metric set.
     collector = system_metrics_collector.SystemMetricsCollector(
         FakeSystemFacade())
     collector.collect_snapshot()
     collector.collect_snapshot()
     collector.write_metrics(lambda **kwargs: None)
    def test_collector(self):
        collector = system_metrics_collector.SystemMetricsCollector(
            FakeSystemFacade(), [TestMetric()])
        collector.collect_snapshot()
        d = {}

        def _write_func(**kwargs):
            d.update(kwargs)

        collector.write_metrics(_write_func)
        self.assertEquals('test_description', d['description'])
        self.assertEquals([1], d['value'])
        self.assertEquals(False, d['higher_is_better'])
        self.assertEquals('test_unit', d['units'])
예제 #4
0
    def __init__(
            self,
            title,
            own_script,
            common_script,
            bindir,
            tmpdir,
            debugdir,
            timeout = 70,
            test_runtime_seconds = 60,
            num_peer_connections = 5,
            iteration_delay_millis = 500,
            before_start_hook = None):

          def perf_before_start_hook(tab):
              """
              Before start hook to disable cpu overuse detection.
              """
              if before_start_hook:
                  before_start_hook(tab)
              tab.EvaluateJavaScript('cpuOveruseDetection = false')

          super(WebRtcPeerConnectionPerformanceTest, self).__init__(
                  title,
                  own_script,
                  common_script,
                  bindir,
                  tmpdir,
                  debugdir,
                  timeout,
                  test_runtime_seconds,
                  num_peer_connections,
                  iteration_delay_millis,
                  perf_before_start_hook)
          self.collector = system_metrics_collector.SystemMetricsCollector(
                system_facade_native.SystemFacadeNative())
          # TODO(crbug/784365): If this proves to work fine, move to a separate
          # module and make more generic.
          delay = 5
          iterations = self.test_runtime_seconds / delay + 1
          utils.BgJob('top -b -d %d -n %d -w 512 -c > %s/top_output.txt'
                      % (delay, iterations, self.debugdir))
          utils.BgJob('iostat -x %d %d > %s/iostat_output.txt'
                      % (delay, iterations, self.debugdir))
          utils.BgJob('for i in $(seq %d);'
                      'do netstat -s >> %s/netstat_output.txt'
                      ';sleep %d;done'
                      % (delay, self.debugdir, iterations))