예제 #1
0
 def testRoundtrip(self):
     dr = histogram.DateRange(1496693745000)
     dr.AddDiagnostic(histogram.DateRange(1496693746000))
     self.assertEqual(time.mktime(dr.min_date.timetuple()), 1496693745)
     self.assertEqual(time.mktime(dr.max_date.timetuple()), 1496693746)
     clone = diagnostic.Diagnostic.FromDict(dr.AsDict())
     self.assertEqual(clone.min_date, dr.min_date)
     self.assertEqual(clone.max_date, dr.max_date)
예제 #2
0
 def testDisallowReservedNames(self):
   diagnostics = histogram.DiagnosticMap()
   with self.assertRaises(TypeError):
     diagnostics[None] = generic_set.GenericSet(())
   with self.assertRaises(TypeError):
     diagnostics['generic'] = None
   diagnostics[reserved_infos.TRACE_URLS.name] = histogram.DateRange(0)
   diagnostics.DisallowReservedNames()
   diagnostics[reserved_infos.TRACE_URLS.name] = generic_set.GenericSet(())
   with self.assertRaises(TypeError):
     diagnostics[reserved_infos.TRACE_URLS.name] = histogram.DateRange(0)
예제 #3
0
 def DiagnosticValue(value):
   if isinstance(value, (int, long)):
     return histogram.DateRange(value)
   elif isinstance(value, list):
     return generic_set.GenericSet(value)
   else:
     raise NotImplementedError(type(value))
예제 #4
0
 def testGetSharedDiagnosticsOfType(self):
     d0 = generic_set.GenericSet(['foo'])
     d1 = histogram.DateRange(0)
     hs = histogram_set.HistogramSet()
     hs.AddSharedDiagnostic('generic', d0)
     hs.AddSharedDiagnostic('generic', d1)
     diagnostics = hs.GetSharedDiagnosticsOfType(generic_set.GenericSet)
     self.assertEqual(len(diagnostics), 1)
     self.assertIsInstance(diagnostics[0], generic_set.GenericSet)
예제 #5
0
 def AddDurationHistogram(self, duration_in_milliseconds):
   hist = histogram.Histogram(
       'benchmark_total_duration', 'ms_smallerIsBetter')
   hist.AddSample(duration_in_milliseconds)
   # TODO(#4244): Do this generally.
   if self.telemetry_info.label:
     hist.diagnostics[reserved_infos.LABELS.name] = generic_set.GenericSet(
         [self.telemetry_info.label])
   hist.diagnostics[reserved_infos.BENCHMARKS.name] = generic_set.GenericSet(
       [self.telemetry_info.benchmark_name])
   hist.diagnostics[reserved_infos.BENCHMARK_START.name] = histogram.DateRange(
       self.telemetry_info.benchmark_start_epoch * 1000)
   if self.telemetry_info.benchmark_descriptions:
     hist.diagnostics[
         reserved_infos.BENCHMARK_DESCRIPTIONS.name] = generic_set.GenericSet([
             self.telemetry_info.benchmark_descriptions])
   self._histograms.AddHistogram(hist)
예제 #6
0
    def testDeduplicateDiagnostics(self):
        generic_a = generic_set.GenericSet(['A'])
        generic_b = generic_set.GenericSet(['B'])
        date_a = histogram.DateRange(42)
        date_b = histogram.DateRange(57)

        a_hist = histogram.Histogram('a', 'unitless')
        generic0 = generic_set.GenericSet.FromDict(generic_a.AsDict())
        generic0.AddDiagnostic(generic_b)
        a_hist.diagnostics['generic'] = generic0
        date0 = histogram.DateRange.FromDict(date_a.AsDict())
        date0.AddDiagnostic(date_b)
        a_hist.diagnostics['date'] = date0

        b_hist = histogram.Histogram('b', 'unitless')
        generic1 = generic_set.GenericSet.FromDict(generic_a.AsDict())
        generic1.AddDiagnostic(generic_b)
        b_hist.diagnostics['generic'] = generic1
        date1 = histogram.DateRange.FromDict(date_a.AsDict())
        date1.AddDiagnostic(date_b)
        b_hist.diagnostics['date'] = date1

        c_hist = histogram.Histogram('c', 'unitless')
        c_hist.diagnostics['generic'] = generic1

        histograms = histogram_set.HistogramSet([a_hist, b_hist, c_hist])
        self.assertNotEqual(a_hist.diagnostics['generic'].guid,
                            b_hist.diagnostics['generic'].guid)
        self.assertEqual(b_hist.diagnostics['generic'].guid,
                         c_hist.diagnostics['generic'].guid)
        self.assertEqual(a_hist.diagnostics['generic'],
                         b_hist.diagnostics['generic'])
        self.assertNotEqual(a_hist.diagnostics['date'].guid,
                            b_hist.diagnostics['date'].guid)
        self.assertEqual(a_hist.diagnostics['date'],
                         b_hist.diagnostics['date'])

        histograms.DeduplicateDiagnostics()

        self.assertEqual(a_hist.diagnostics['generic'].guid,
                         b_hist.diagnostics['generic'].guid)
        self.assertEqual(b_hist.diagnostics['generic'].guid,
                         c_hist.diagnostics['generic'].guid)
        self.assertEqual(a_hist.diagnostics['generic'],
                         b_hist.diagnostics['generic'])
        self.assertEqual(a_hist.diagnostics['date'].guid,
                         b_hist.diagnostics['date'].guid)
        self.assertEqual(a_hist.diagnostics['date'],
                         b_hist.diagnostics['date'])

        histogram_dicts = histograms.AsDicts()

        # All diagnostics should have been serialized as DiagnosticRefs.
        for d in histogram_dicts:
            if 'type' not in d:
                for diagnostic_dict in d['diagnostics'].itervalues():
                    self.assertIsInstance(diagnostic_dict, str)

        histograms2 = histogram_set.HistogramSet()
        histograms2.ImportDicts(histograms.AsDicts())
        histograms2.ResolveRelatedHistograms()
        a_hists = histograms2.GetHistogramsNamed('a')
        self.assertEqual(len(a_hists), 1)
        a_hist2 = a_hists[0]
        b_hists = histograms2.GetHistogramsNamed('b')
        self.assertEqual(len(b_hists), 1)
        b_hist2 = b_hists[0]

        self.assertEqual(a_hist2.diagnostics['generic'].guid,
                         b_hist2.diagnostics['generic'].guid)
        self.assertEqual(a_hist2.diagnostics['generic'],
                         b_hist2.diagnostics['generic'])
        self.assertEqual(a_hist2.diagnostics['date'].guid,
                         b_hist2.diagnostics['date'].guid)
        self.assertEqual(a_hist2.diagnostics['date'],
                         b_hist2.diagnostics['date'])
 def testDateRange(self):
   grouping = histogram_grouping.DateRangeGrouping('foo')
   hist = histogram.Histogram('', 'count')
   self.assertEqual(grouping.callback(hist), '')
   hist.diagnostics['foo'] = histogram.DateRange(15e11)
   self.assertEqual(grouping.callback(hist), str(hist.diagnostics['foo']))
예제 #8
0
 def testMaxTimestamp(self):
     dr = histogram.DateRange(1496693745123)
     dr.AddDiagnostic(histogram.DateRange(1496693746123))
     self.assertEqual(dr.max_timestamp, 1496693746123)