Esempio n. 1
0
  def testHistogram(self):
    page0 = self.pages[0]
    page1 = self.pages[1]

    results = page_test_results.PageTestResults()
    results.WillRunPage(page0)
    v0 = histogram.HistogramValue(
        page0, 'a', 'units',
        raw_value_json='{"buckets": [{"low": 1, "high": 2, "count": 1}]}',
        important=False)
    results.AddValue(v0)
    results.DidRunPage(page0)

    results.WillRunPage(page1)
    v1 = histogram.HistogramValue(
        page1, 'a', 'units',
        raw_value_json='{"buckets": [{"low": 2, "high": 3, "count": 1}]}',
        important=False)
    results.AddValue(v1)
    results.DidRunPage(page1)

    summary = summary_module.Summary(results.all_page_specific_values)
    values = summary.interleaved_computed_per_page_values_and_summaries

    self.assertEquals(2, len(values))
    self.assertIn(v0, values)
    self.assertIn(v1, values)
Esempio n. 2
0
    def test_histogram(self):
        results = page_test_results.PageTestResults()
        results.WillRunPage(self._page_set[0])
        results.AddValue(
            histogram.HistogramValue(
                self._page_set[0],
                'a',
                '',
                raw_value_json=
                '{"buckets": [{"low": 1, "high": 2, "count": 1}]}'))
        results.DidRunPage(self._page_set[0])

        results.WillRunPage(self._page_set[1])
        results.AddValue(
            histogram.HistogramValue(
                self._page_set[1],
                'a',
                '',
                raw_value_json=
                '{"buckets": [{"low": 2, "high": 3, "count": 1}]}'))
        results.DidRunPage(self._page_set[1])

        self._formatter.Format(results)

        self.assertEqual(self.output_header_row, ['page_name', 'a ()'])
        self.assertEqual(self.output_data_rows,
                         [[self._page_set[0].display_name, '1.5'],
                          [self._page_set[1].display_name, '2.5']])
def ConvertOldCallingConventionToValue(page, trace_name, units,
                                       value, chart_name, data_type):
  value_name = value_module.ValueNameFromTraceAndChartName(
      trace_name, chart_name)
  if data_type == 'default':
    if isinstance(value, list):
      return list_of_scalar_values.ListOfScalarValues(
          page, value_name, units, value, important=True)
    else:
      return scalar.ScalarValue(page, value_name, units,
                                value, important=True)
  elif data_type == 'unimportant':
    if isinstance(value, list):
      return list_of_scalar_values.ListOfScalarValues(
          page, value_name, units, value, important=False)
    else:
      return scalar.ScalarValue(page, value_name, units,
                                value, important=False)
  elif data_type == 'histogram':
    assert isinstance(value, basestring)
    return histogram.HistogramValue(
        page, value_name, units, raw_value_json=value, important=True)
  elif data_type == 'unimportant-histogram':
    assert isinstance(value, basestring)
    return histogram.HistogramValue(
        page, value_name, units, raw_value_json=value, important=False)
  elif data_type == 'informational':
    raise NotImplementedError()
  else:
    raise ValueError('Unrecognized data type %s', data_type)
  def AddResults(self, tab, results, trace_name=None):
    """Add results for this page to the results object."""
    assert self._histogram_delta, 'Must call Stop() first'
    for h in _HISTOGRAMS:
      # Histogram data may not be available
      if h['name'] not in self._histogram_start:
        continue
      results.AddValue(histogram.HistogramValue(
          results.current_page, h['display_name'], h['units'],
          raw_value_json=self._histogram_delta[h['name']], important=False,
          description=h.get('description')))
    self._memory_stats = self._browser.memory_stats
    if not self._memory_stats['Browser']:
      return
    AddResultsForProcesses(results, self._memory_stats,
                           metric_trace_name=trace_name)

    if self._start_commit_charge:
      end_commit_charge = self._memory_stats['SystemCommitCharge']
      commit_charge_difference = end_commit_charge - self._start_commit_charge
      results.AddValue(scalar.ScalarValue(
          results.current_page,
          'commit_charge.' + (trace_name or 'commit_charge'),
          'kb', commit_charge_difference, important=False,
          description='System commit charge (committed memory pages).'))
    results.AddValue(scalar.ScalarValue(
        results.current_page, 'processes.' + (trace_name or 'processes'),
        'count', self._memory_stats['ProcessCount'], important=False,
        description='Number of processes used by Chrome.'))
Esempio n. 5
0
    def testMergeLikeValuesFromSamePage(self):
        v0 = histogram_module.HistogramValue(
            None,
            'x',
            'counts',
            raw_value_json='{"buckets": [{"low": 1, "high": 3, "count": 1}]}',
            description='histogram-based metric')
        v1 = histogram_module.HistogramValue(
            None,
            'x',
            'counts',
            raw_value_json='{"buckets": [{"low": 2, "high": 4, "count": 1}]}',
            description='histogram-based metric')

        vM = histogram_module.HistogramValue.MergeLikeValuesFromSamePage(
            [v0, v1])
        self.assertTrue(isinstance(vM, histogram_module.HistogramValue))
        self.assertEquals('histogram-based metric', vM.description)
Esempio n. 6
0
  def testAsDict(self):
    histogram = histogram_module.HistogramValue(
        None, 'x', 'counts',
        raw_value_json='{"buckets": [{"low": 1, "high": 2, "count": 1}]}',
        important=False)
    d = histogram.AsDictWithoutBaseClassEntries()

    self.assertEquals(['buckets'], d.keys())
    self.assertTrue(isinstance(d['buckets'], list))
    self.assertEquals(len(d['buckets']), 1)
Esempio n. 7
0
 def AddResults(self, tab, results):
   assert self._histogram_delta, 'Must call Stop() first'
   for h in HISTOGRAMS_TO_RECORD:
     # Histogram data may not be available
     if h['name'] not in self._histogram_delta:
       continue
     results.AddValue(histogram.HistogramValue(
         results.current_page, h['display_name'], h['units'],
         raw_value_json=self._histogram_delta[h['name']], important=False,
         description=h.get('description')))
Esempio n. 8
0
  def ValidateAndMeasurePage(self, page, tab, results):
    """On the last tab, cycle through each tab that was opened and then record
    a single histogram for the tab switching metric."""
    browser = tab.browser
    if len(browser.tabs) != len(page.story_set.stories):
      return

    if browser.tabs < 2:
      raise Exception('Should have at least two tabs for tab switching')

    # Measure power usage of tabs after quiescence.
    util.WaitFor(tab.HasReachedQuiescence, 60)

    if browser.platform.CanMonitorPower():
      self._power_metric.Start(page, tab)
      time.sleep(TabSwitching.SAMPLE_TIME)
      self._power_metric.Stop(page, tab)
      self._power_metric.AddResults(tab, results,)

    histogram_name = 'MPArch.RWH_TabSwitchPaintDuration'
    histogram_type = histogram_util.BROWSER_HISTOGRAM
    display_name = 'MPArch_RWH_TabSwitchPaintDuration'
    first_histogram = histogram_util.GetHistogram(
        histogram_type, histogram_name, tab)
    prev_histogram = first_histogram

    for tab_to_switch in browser.tabs:
      tab_to_switch.Activate()
      def _IsDone():
        # pylint: disable=W0640
        cur_histogram = histogram_util.GetHistogram(
            histogram_type, histogram_name, tab_to_switch)
        diff_histogram = histogram_util.SubtractHistogram(
            cur_histogram, prev_histogram)
        # TODO(deanliao): Add SubtractHistogramRawValue to process histogram
        #     object instead of JSON string.
        diff_histogram_count = json.loads(diff_histogram).get('count', 0)
        return diff_histogram_count > 0
      util.WaitFor(_IsDone, 30)

      # We need to get histogram again instead of getting cur_histogram as
      # variables modified inside inner function cannot be retrieved. However,
      # inner function can see external scope's variables.
      prev_histogram = histogram_util.GetHistogram(
          histogram_type, histogram_name, tab_to_switch)

    last_histogram = prev_histogram
    total_diff_histogram = histogram_util.SubtractHistogram(last_histogram,
                                                            first_histogram)
    results.AddSummaryValue(
        histogram.HistogramValue(None, display_name, 'ms',
                                 raw_value_json=total_diff_histogram,
                                 important=False))

    keychain_metric.KeychainMetric().AddResults(tab, results)
Esempio n. 9
0
  def test_type_change(self):
    results = page_test_results.PageTestResults()
    results.WillRunPage(self.pages[0])
    results.AddValue(scalar.ScalarValue(self.pages[0], 'a', 'seconds', 3))
    results.DidRunPage(self.pages[0])

    results.WillRunPage(self.pages[1])
    self.assertRaises(
      AssertionError,
      lambda: results.AddValue(histogram.HistogramValue(
          self.pages[1], 'a', 'seconds',
          raw_value_json='{"buckets": [{"low": 1, "high": 2, "count": 1}]}')))
Esempio n. 10
0
    def ValidateAndMeasurePage(self, page, tab, results):
        """On the last tab, cycle through each tab that was opened and then record
    a single histogram for the tab switching metric."""
        if len(tab.browser.tabs) != len(page.page_set.pages):
            return

        # Measure power usage of tabs after quiescence.
        util.WaitFor(tab.HasReachedQuiescence, 60)

        if tab.browser.platform.CanMonitorPower():
            self._power_metric.Start(page, tab)
            time.sleep(TabSwitching.SAMPLE_TIME)
            self._power_metric.Stop(page, tab)
            self._power_metric.AddResults(
                tab,
                results,
            )

        histogram_name = 'MPArch.RWH_TabSwitchPaintDuration'
        histogram_type = histogram_util.BROWSER_HISTOGRAM
        display_name = 'MPArch_RWH_TabSwitchPaintDuration'
        first_histogram = histogram_util.GetHistogram(histogram_type,
                                                      histogram_name, tab)
        prev_histogram = first_histogram

        for i in xrange(len(tab.browser.tabs)):
            t = tab.browser.tabs[i]
            t.Activate()

            def _IsDone():
                cur_histogram = histogram_util.GetHistogram(
                    histogram_type, histogram_name, tab)
                diff_histogram = histogram_util.SubtractHistogram(
                    cur_histogram, prev_histogram)
                return diff_histogram

            util.WaitFor(_IsDone, 30)
            prev_histogram = histogram_util.GetHistogram(
                histogram_type, histogram_name, tab)

        last_histogram = histogram_util.GetHistogram(histogram_type,
                                                     histogram_name, tab)
        diff_histogram = histogram_util.SubtractHistogram(
            last_histogram, first_histogram)

        results.AddSummaryValue(
            histogram.HistogramValue(None,
                                     display_name,
                                     'ms',
                                     raw_value_json=diff_histogram,
                                     important=False))

        keychain_metric.KeychainMetric().AddResults(tab, results)
Esempio n. 11
0
    def test_histogram(self):
        test_page_set = _MakePageSet()

        measurement_results = page_test_results.PageTestResults()
        measurement_results.WillRunPage(test_page_set.pages[0])
        measurement_results.AddValue(
            histogram.HistogramValue(
                test_page_set.pages[0],
                'a',
                'units',
                raw_value_json=
                '{"buckets": [{"low": 1, "high": 2, "count": 1}]}',
                important=False))
        measurement_results.DidRunPage(test_page_set.pages[0])

        measurement_results.WillRunPage(test_page_set.pages[1])
        measurement_results.AddValue(
            histogram.HistogramValue(
                test_page_set.pages[1],
                'a',
                'units',
                raw_value_json=
                '{"buckets": [{"low": 2, "high": 3, "count": 1}]}',
                important=False))
        measurement_results.DidRunPage(test_page_set.pages[1])

        formatter = buildbot_output_formatter.BuildbotOutputFormatter(
            self._test_output_stream)
        formatter.Format(measurement_results)

        expected = [
            'HISTOGRAM a: http___www.bar.com_= ' +
            '{"buckets": [{"low": 2, "high": 3, "count": 1}]} units\n' +
            'Avg a: 2.500000units\n', 'HISTOGRAM a: http___www.foo.com_= ' +
            '{"buckets": [{"low": 1, "high": 2, "count": 1}]} units\n' +
            'Avg a: 1.500000units\n',
            'RESULT telemetry_page_measurement_results: num_failed= 0 count\n',
            'RESULT telemetry_page_measurement_results: num_errored= 0 count\n'
        ]
        self.assertEquals(expected, self._test_output_stream.output_data)
    def ValidateAndMeasurePage(self, page, tab, results):
        """Record the ending histogram for the tab switching metric."""
        last_histogram = cros_utils.GetTabSwitchHistogramRetry(tab.browser)
        total_diff_histogram = histogram_util.SubtractHistogram(
            last_histogram, self._first_histogram)

        display_name = 'MPArch_RWH_TabSwitchPaintDuration'
        results.AddSummaryValue(
            histogram.HistogramValue(None,
                                     display_name,
                                     'ms',
                                     raw_value_json=total_diff_histogram,
                                     important=False))
Esempio n. 13
0
    def testAsDict(self):
        histogram = histogram_module.HistogramValue(
            None,
            'x',
            'counts',
            raw_value_json='{"buckets": [{"low": 1, "high": 2, "count": 1}]}',
            important=False,
            improvement_direction=improvement_direction.DOWN)
        d = histogram.AsDict()

        self.assertIn('buckets', d.keys())
        self.assertTrue(isinstance(d['buckets'], list))
        self.assertEquals(len(d['buckets']), 1)
  def testRepr(self):
    page = self.pages[0]
    v = histogram_module.HistogramValue(
            page, 'x', 'counts',
           raw_value_json='{"buckets": [{"low": 1, "high": 2, "count": 1}]}',
           important=True, description='desc', tir_label='my_ir',
           improvement_direction=improvement_direction.UP)
    expected = ('HistogramValue(http://www.bar.com/, x, counts, '
                'raw_json_string={"buckets": [{"low": 1, "high": 2, "count": '
                '1}]}, important=True, description=desc, tir_label=my_ir, '
                'improvement_direction=up)')

    self.assertEquals(expected, str(v))
Esempio n. 15
0
  def testTypeChange(self):
    results = self.getPageTestResults()
    results.WillRunPage(self.pages[0])
    results.AddValue(scalar.ScalarValue(
        self.pages[0], 'a', 'seconds', 3,
        improvement_direction=improvement_direction.UP))
    results.DidRunPage(self.pages[0])

    results.WillRunPage(self.pages[1])
    self.assertRaises(
        AssertionError,
        lambda: results.AddValue(histogram.HistogramValue(
            self.pages[1], 'a', 'seconds',
            raw_value_json='{"buckets": [{"low": 1, "high": 2, "count": 1}]}',
            improvement_direction=improvement_direction.UP)))
Esempio n. 16
0
    def ValidateAndMeasurePage(self, page, tab, results):
        tab.WaitForDocumentReadyStateToBeComplete()
        super(SessionRestore, self).ValidateAndMeasurePage(page, tab, results)

        # Record CPU usage from browser start to when the foreground page is loaded.
        self._cpu_metric.Stop(None, None)
        self._cpu_metric.AddResults(tab, results, 'cpu_utilization')

        for h in _HISTOGRAMS:
            histogram_data = histogram_util.GetHistogram(
                histogram_util.BROWSER_HISTOGRAM, h['name'], tab)

            results.AddValue(
                histogram.HistogramValue(page,
                                         h['display_name'],
                                         'ms',
                                         raw_value_json=histogram_data,
                                         important=False))
Esempio n. 17
0
    def testHistogramBasic(self):
        page0 = self.pages[0]
        histogram = histogram_module.HistogramValue(
            page0,
            'x',
            'counts',
            raw_value_json='{"buckets": [{"low": 1, "high": 2, "count": 1}]}',
            important=False)
        self.assertEquals(['{"buckets": [{"low": 1, "high": 2, "count": 1}]}'],
                          histogram.GetBuildbotValue())
        self.assertEquals(1.5, histogram.GetRepresentativeNumber())
        self.assertEquals(['{"buckets": [{"low": 1, "high": 2, "count": 1}]}'],
                          histogram.GetBuildbotValue())

        self.assertEquals(
            'unimportant-histogram',
            histogram.GetBuildbotDataType(value.SUMMARY_RESULT_OUTPUT_CONTEXT))
        histogram.important = True
        self.assertEquals(
            'histogram',
            histogram.GetBuildbotDataType(value.SUMMARY_RESULT_OUTPUT_CONTEXT))