def GetValue(self, page, tab, results): data = self._GetHistogramFromDomAutomation(tab) if not data: return new_histogram = histogram_util.SubtractHistogram( data, self._start_values[page.url + self.name]) results.Add(self.name, self.units, new_histogram, data_type='unimportant-histogram')
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, '', raw_value_json=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])
def MeasurePage(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 self._cpu_metric.Start(page, tab) time.sleep(.5) self._cpu_metric.Stop(page, tab) # Calculate the idle cpu load before any actions are done. self._cpu_metric.AddResults(tab, results, 'idle_cpu_utilization') histogram_name = 'MPArch.RWH_TabSwitchPaintDuration' histogram_type = histogram_util.BROWSER_HISTOGRAM 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.AddSummary(histogram_name, '', diff_histogram, data_type='unimportant-histogram')
def _IsDone(): cur_histogram = histogram_util.GetHistogram( histogram_type, histogram_name, tab) diff_histogram = histogram_util.SubtractHistogram( cur_histogram, prev_histogram) return diff_histogram