Exemple #1
0
def _GetMaxDetachedContextAge(tab, data_start):
    data = histogram_util.GetHistogram(_TYPE, _NAME, tab)
    delta = histogram_util.SubtractHistogram(data, data_start)
    if not 'buckets' in delta:
        return
    buckets = json.loads(delta)['buckets']
    if buckets:
        return max(x.get('high', x['low']) for x in buckets)
Exemple #2
0
    def _IsDone():
        cur_histogram = _GetTabSwitchHistogram(browser)
        if not cur_histogram:
            return False

        diff_histogram = histogram_util.SubtractHistogram(
            cur_histogram, prev_histogram)
        diff_histogram_count = json.loads(diff_histogram).get('count', 0)
        return diff_histogram_count > 0
 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
  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)
Exemple #5
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)
Exemple #6
0
  def Stop(self, page, tab):
    assert self._started, 'Must call Start() first'
    for h in HISTOGRAMS_TO_RECORD:
      # Histogram data may not be available
      if h['name'] not in self._histogram_start:
        continue
      histogram_data = histogram_util.GetHistogram(
          h['type'], h['name'], tab)

      if not histogram_data:
        continue
      self._histogram_delta[h['name']] = histogram_util.SubtractHistogram(
          histogram_data, self._histogram_start[h['name']])
    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))
  def Stop(self, page, tab):
    """Prepare the results for this page.

    The results are the differences between the current histogram values
    and the values when Start() was called.
    """
    assert self._histogram_start, 'Must call Start() first'
    for h in _HISTOGRAMS:
      # Histogram data may not be available
      if h['name'] not in self._histogram_start:
        continue
      histogram_data = histogram_util.GetHistogram(
          h['type'], h['name'], tab)
      self._histogram_delta[h['name']] = histogram_util.SubtractHistogram(
          histogram_data, self._histogram_start[h['name']])
  def testSubtractHistogram(self):
    baseline_histogram = """{"count": 3, "buckets": [
        {"low": 1, "high": 2, "count": 1},
        {"low": 2, "high": 3, "count": 2}]}"""

    later_histogram = """{"count": 14, "buckets": [
        {"low": 1, "high": 2, "count": 1},
        {"low": 2, "high": 3, "count": 3},
        {"low": 3, "high": 4, "count": 10}]}"""

    new_histogram = json.loads(
        histogram_util.SubtractHistogram(later_histogram, baseline_histogram))
    new_buckets = dict()
    for b in new_histogram['buckets']:
      new_buckets[b['low']] = b['count']
    self.assertFalse(1 in new_buckets)
    self.assertEquals(1, new_buckets[2])
    self.assertEquals(10, new_buckets[3])
Exemple #10
0
 def _IsDone():
   cur_histogram = histogram_util.GetHistogram(
       histogram_type, histogram_name, tab)
   diff_histogram = histogram_util.SubtractHistogram(
       cur_histogram, prev_histogram)
   return diff_histogram