| OLD | NEW |
| 1 # Copyright 2017 The Chromium Authors. All rights reserved. | 1 # Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import unittest | 5 import unittest |
| 6 | 6 |
| 7 from tracing.value import histogram | 7 from tracing.value import histogram |
| 8 from tracing.value import histogram_set | 8 from tracing.value import histogram_set |
| 9 from tracing.value.diagnostics import diagnostic_ref | 9 from tracing.value.diagnostics import diagnostic_ref |
| 10 | 10 |
| 11 | 11 |
| 12 class HistogramSetUnittest(unittest.TestCase): | 12 class HistogramSetUnittest(unittest.TestCase): |
| 13 | 13 |
| 14 def testRelatedHistogramMap(self): | |
| 15 a = histogram.Histogram('a', 'unitless') | |
| 16 b = histogram.Histogram('b', 'unitless') | |
| 17 c = histogram.Histogram('c', 'unitless') | |
| 18 rhm = histogram.RelatedHistogramMap() | |
| 19 rhm.Set('y', b) | |
| 20 rhm.Set('z', c) | |
| 21 a.diagnostics['rhm'] = rhm | |
| 22 | |
| 23 # Don't serialize c yet. | |
| 24 hists = histogram_set.HistogramSet([a, b]) | |
| 25 hists2 = histogram_set.HistogramSet() | |
| 26 hists2.ImportDicts(hists.AsDicts()) | |
| 27 hists2.ResolveRelatedHistograms() | |
| 28 a2 = hists2.GetHistogramsNamed('a') | |
| 29 self.assertEqual(len(a2), 1) | |
| 30 a2 = a2[0] | |
| 31 self.assertEqual(a2.guid, a.guid) | |
| 32 self.assertIsInstance(a2, histogram.Histogram) | |
| 33 self.assertIsNot(a2, a) | |
| 34 b2 = hists2.GetHistogramsNamed('b') | |
| 35 self.assertEqual(len(b2), 1) | |
| 36 b2 = b2[0] | |
| 37 self.assertEqual(b2.guid, b.guid) | |
| 38 self.assertIsInstance(b2, histogram.Histogram) | |
| 39 self.assertIsNot(b2, b) | |
| 40 rhm2 = a2.diagnostics['rhm'] | |
| 41 self.assertIsInstance(rhm2, histogram.RelatedHistogramMap) | |
| 42 self.assertEqual(len(rhm2), 2) | |
| 43 | |
| 44 # Assert that b and c are in a2's RelatedHistogramMap, rhm2. | |
| 45 self.assertIs(b2, rhm2.Get('y')) | |
| 46 self.assertIsInstance(rhm2.Get('z'), histogram.HistogramRef) | |
| 47 | |
| 48 # Now serialize c and add it to hists2. | |
| 49 hists2.ImportDicts([c.AsDict()]) | |
| 50 hists2.ResolveRelatedHistograms() | |
| 51 | |
| 52 c2 = hists2.GetHistogramsNamed('c') | |
| 53 self.assertEqual(len(c2), 1) | |
| 54 c2 = c2[0] | |
| 55 self.assertEqual(c2.guid, c.guid) | |
| 56 self.assertIsNot(c2, c) | |
| 57 | |
| 58 self.assertIs(b2, rhm2.Get('y')) | |
| 59 self.assertIs(c2, rhm2.Get('z')) | |
| 60 | |
| 61 def testGetSharedDiagnosticsOfType(self): | 14 def testGetSharedDiagnosticsOfType(self): |
| 62 d0 = histogram.GenericSet(['foo']) | 15 d0 = histogram.GenericSet(['foo']) |
| 63 d1 = histogram.DateRange(0) | 16 d1 = histogram.DateRange(0) |
| 64 hs = histogram_set.HistogramSet() | 17 hs = histogram_set.HistogramSet() |
| 65 hs.AddSharedDiagnostic('generic', d0) | 18 hs.AddSharedDiagnostic('generic', d0) |
| 66 hs.AddSharedDiagnostic('generic', d1) | 19 hs.AddSharedDiagnostic('generic', d1) |
| 67 diagnostics = hs.GetSharedDiagnosticsOfType(histogram.GenericSet) | 20 diagnostics = hs.GetSharedDiagnosticsOfType(histogram.GenericSet) |
| 68 self.assertEqual(len(diagnostics), 1) | 21 self.assertEqual(len(diagnostics), 1) |
| 69 self.assertIsInstance(diagnostics[0], histogram.GenericSet) | 22 self.assertIsInstance(diagnostics[0], histogram.GenericSet) |
| 70 | 23 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 diag0 = histogram.GenericSet(['shared0']) | 93 diag0 = histogram.GenericSet(['shared0']) |
| 141 diag1 = histogram.GenericSet(['shared1']) | 94 diag1 = histogram.GenericSet(['shared1']) |
| 142 hists.AddSharedDiagnostic('generic0', diag0) | 95 hists.AddSharedDiagnostic('generic0', diag0) |
| 143 | 96 |
| 144 guid0 = diag0.guid | 97 guid0 = diag0.guid |
| 145 guid1 = diag1.guid | 98 guid1 = diag1.guid |
| 146 | 99 |
| 147 hists.ReplaceSharedDiagnostic(guid0, diag1) | 100 hists.ReplaceSharedDiagnostic(guid0, diag1) |
| 148 | 101 |
| 149 self.assertIsNotNone(hists.LookupDiagnostic(guid1)) | 102 self.assertIsNotNone(hists.LookupDiagnostic(guid1)) |
| OLD | NEW |