| 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 testRelatedHistogramSet(self): | |
| 15 a = histogram.Histogram('a', 'unitless') | |
| 16 b = histogram.Histogram('b', 'unitless') | |
| 17 c = histogram.Histogram('c', 'unitless') | |
| 18 a.diagnostics['rhs'] = histogram.RelatedHistogramSet([b, c]) | |
| 19 | |
| 20 # Don't serialize c yet. | |
| 21 hists = histogram_set.HistogramSet([a, b]) | |
| 22 hists2 = histogram_set.HistogramSet() | |
| 23 hists2.ImportDicts(hists.AsDicts()) | |
| 24 hists2.ResolveRelatedHistograms() | |
| 25 a2 = hists2.GetHistogramsNamed('a') | |
| 26 self.assertEqual(len(a2), 1) | |
| 27 a2 = a2[0] | |
| 28 self.assertEqual(a2.guid, a.guid) | |
| 29 self.assertIsInstance(a2, histogram.Histogram) | |
| 30 self.assertIsNot(a2, a) | |
| 31 b2 = hists2.GetHistogramsNamed('b') | |
| 32 self.assertEqual(len(b2), 1) | |
| 33 b2 = b2[0] | |
| 34 self.assertEqual(b2.guid, b.guid) | |
| 35 self.assertIsInstance(b2, histogram.Histogram) | |
| 36 self.assertIsNot(b2, b) | |
| 37 rhs2 = a2.diagnostics['rhs'] | |
| 38 self.assertIsInstance(rhs2, histogram.RelatedHistogramSet) | |
| 39 self.assertEqual(len(rhs2), 2) | |
| 40 | |
| 41 # Assert that b and c are in a2's RelatedHistogramSet, rhs2. | |
| 42 rhs2hs = list(rhs2) | |
| 43 rhs2guids = [h.guid for h in rhs2hs] | |
| 44 b2i = rhs2guids.index(b.guid) | |
| 45 self.assertIs(rhs2hs[b2i], b2) | |
| 46 | |
| 47 c2i = rhs2guids.index(c.guid) | |
| 48 self.assertIsInstance(rhs2hs[c2i], histogram.HistogramRef) | |
| 49 | |
| 50 # Now serialize c and add it to hists2. | |
| 51 hists2.ImportDicts([c.AsDict()]) | |
| 52 hists2.ResolveRelatedHistograms() | |
| 53 | |
| 54 c2 = hists2.GetHistogramsNamed('c') | |
| 55 self.assertEqual(len(c2), 1) | |
| 56 c2 = c2[0] | |
| 57 self.assertEqual(c2.guid, c.guid) | |
| 58 self.assertIsNot(c2, c) | |
| 59 | |
| 60 rhs2hs = list(rhs2) | |
| 61 rhs2guids = [h.guid for h in rhs2hs] | |
| 62 b2i = rhs2guids.index(b.guid) | |
| 63 c2i = rhs2guids.index(c.guid) | |
| 64 self.assertIs(b2, rhs2hs[b2i]) | |
| 65 self.assertIs(c2, rhs2hs[c2i]) | |
| 66 | |
| 67 def testRelatedHistogramMap(self): | 14 def testRelatedHistogramMap(self): |
| 68 a = histogram.Histogram('a', 'unitless') | 15 a = histogram.Histogram('a', 'unitless') |
| 69 b = histogram.Histogram('b', 'unitless') | 16 b = histogram.Histogram('b', 'unitless') |
| 70 c = histogram.Histogram('c', 'unitless') | 17 c = histogram.Histogram('c', 'unitless') |
| 71 rhm = histogram.RelatedHistogramMap() | 18 rhm = histogram.RelatedHistogramMap() |
| 72 rhm.Set('y', b) | 19 rhm.Set('y', b) |
| 73 rhm.Set('z', c) | 20 rhm.Set('z', c) |
| 74 a.diagnostics['rhm'] = rhm | 21 a.diagnostics['rhm'] = rhm |
| 75 | 22 |
| 76 # Don't serialize c yet. | 23 # Don't serialize c yet. |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 diag0 = histogram.GenericSet(['shared0']) | 140 diag0 = histogram.GenericSet(['shared0']) |
| 194 diag1 = histogram.GenericSet(['shared1']) | 141 diag1 = histogram.GenericSet(['shared1']) |
| 195 hists.AddSharedDiagnostic('generic0', diag0) | 142 hists.AddSharedDiagnostic('generic0', diag0) |
| 196 | 143 |
| 197 guid0 = diag0.guid | 144 guid0 = diag0.guid |
| 198 guid1 = diag1.guid | 145 guid1 = diag1.guid |
| 199 | 146 |
| 200 hists.ReplaceSharedDiagnostic(guid0, diag1) | 147 hists.ReplaceSharedDiagnostic(guid0, diag1) |
| 201 | 148 |
| 202 self.assertIsNotNone(hists.LookupDiagnostic(guid1)) | 149 self.assertIsNotNone(hists.LookupDiagnostic(guid1)) |
| OLD | NEW |