Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: tracing/tracing/value/histogram.py

Issue 2998043002: Remove RelatedHistogramSet. (Closed)
Patch Set: Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tracing/tracing/value/histogram.html ('k') | tracing/tracing/value/histogram_set.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 datetime 5 import datetime
6 import json 6 import json
7 import math 7 import math
8 import random 8 import random
9 import uuid 9 import uuid
10 10
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 class HistogramRef(object): 489 class HistogramRef(object):
490 490
491 def __init__(self, guid): 491 def __init__(self, guid):
492 self._guid = guid 492 self._guid = guid
493 493
494 @property 494 @property
495 def guid(self): 495 def guid(self):
496 return self._guid 496 return self._guid
497 497
498 498
499 class RelatedHistogramSet(diagnostic.Diagnostic):
500
501 def __init__(self, histograms=()):
502 super(RelatedHistogramSet, self).__init__()
503 self._histograms_by_guid = {}
504 for hist in histograms:
505 self.Add(hist)
506
507 def Add(self, hist):
508 assert isinstance(hist, (Histogram, HistogramRef))
509 assert not self.Has(hist)
510 self._histograms_by_guid[hist.guid] = hist
511
512 def Has(self, hist):
513 return hist.guid in self._histograms_by_guid
514
515 def __len__(self):
516 return len(self._histograms_by_guid)
517
518 def __iter__(self):
519 for hist in self._histograms_by_guid.itervalues():
520 yield hist
521
522 def Resolve(self, histograms, required=False):
523 for hist in self:
524 if isinstance(hist, Histogram):
525 continue
526 guid = hist.guid
527 hist = histograms.LookupHistogram(guid)
528 if isinstance(hist, Histogram):
529 self._histograms_by_guid[guid] = hist
530 else:
531 assert not required, guid
532
533 def _AsDictInto(self, d):
534 d['guids'] = []
535 for hist in self:
536 d['guids'].append(hist.guid)
537
538 @staticmethod
539 def FromDict(d):
540 return RelatedHistogramSet(HistogramRef(guid) for guid in d['guids'])
541
542
543 class RelatedHistogramMap(diagnostic.Diagnostic): 499 class RelatedHistogramMap(diagnostic.Diagnostic):
544 500
545 def __init__(self): 501 def __init__(self):
546 super(RelatedHistogramMap, self).__init__() 502 super(RelatedHistogramMap, self).__init__()
547 self._histograms_by_name = {} 503 self._histograms_by_name = {}
548 504
549 def Get(self, name): 505 def Get(self, name):
550 return self._histograms_by_name.get(name) 506 return self._histograms_by_name.get(name)
551 507
552 def Set(self, name, hist): 508 def Set(self, name, hist):
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 903
948 def AsDict(self): 904 def AsDict(self):
949 dct = {} 905 dct = {}
950 for name, diag in self.iteritems(): 906 for name, diag in self.iteritems():
951 dct[name] = diag.AsDictOrReference() 907 dct[name] = diag.AsDictOrReference()
952 return dct 908 return dct
953 909
954 def Merge(self, other, parent_hist, other_parent_hist): 910 def Merge(self, other, parent_hist, other_parent_hist):
955 merged_from = self.get(reserved_infos.MERGED_FROM.name) 911 merged_from = self.get(reserved_infos.MERGED_FROM.name)
956 if merged_from is None: 912 if merged_from is None:
957 merged_from = RelatedHistogramSet() 913 merged_from = RelatedHistogramMap()
958 self[reserved_infos.MERGED_FROM.name] = merged_from 914 self[reserved_infos.MERGED_FROM.name] = merged_from
959 merged_from.Add(other_parent_hist) 915 merged_from.Set(len(merged_from), other_parent_hist)
960 916
961 for name, other_diagnostic in other.iteritems(): 917 for name, other_diagnostic in other.iteritems():
962 if name not in self: 918 if name not in self:
963 self[name] = other_diagnostic 919 self[name] = other_diagnostic
964 continue 920 continue
965 my_diagnostic = self[name] 921 my_diagnostic = self[name]
966 if my_diagnostic.CanAddDiagnostic( 922 if my_diagnostic.CanAddDiagnostic(
967 other_diagnostic, name, parent_hist, other_parent_hist): 923 other_diagnostic, name, parent_hist, other_parent_hist):
968 my_diagnostic.AddDiagnostic( 924 my_diagnostic.AddDiagnostic(
969 other_diagnostic, name, parent_hist, other_parent_hist) 925 other_diagnostic, name, parent_hist, other_parent_hist)
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
1577 'W': HistogramBinBoundaries.CreateExponential(1e-3, 1, 50), 1533 'W': HistogramBinBoundaries.CreateExponential(1e-3, 1, 50),
1578 'unitless': HistogramBinBoundaries.CreateExponential(1e-3, 1e3, 50), 1534 'unitless': HistogramBinBoundaries.CreateExponential(1e-3, 1e3, 50),
1579 'count': HistogramBinBoundaries.CreateExponential(1, 1e3, 20), 1535 'count': HistogramBinBoundaries.CreateExponential(1, 1e3, 20),
1580 'sigma': HistogramBinBoundaries.CreateLinear(-5, 5, 50), 1536 'sigma': HistogramBinBoundaries.CreateLinear(-5, 5, 50),
1581 } 1537 }
1582 1538
1583 1539
1584 all_diagnostics.DIAGNOSTICS_BY_NAME.update({ 1540 all_diagnostics.DIAGNOSTICS_BY_NAME.update({
1585 'Breakdown': Breakdown, 1541 'Breakdown': Breakdown,
1586 'GenericSet': GenericSet, 1542 'GenericSet': GenericSet,
1587 'RelatedHistogramSet': RelatedHistogramSet,
1588 'UnmergeableDiagnosticSet': UnmergeableDiagnosticSet, 1543 'UnmergeableDiagnosticSet': UnmergeableDiagnosticSet,
1589 'RelatedEventSet': RelatedEventSet, 1544 'RelatedEventSet': RelatedEventSet,
1590 'BuildbotInfo': BuildbotInfo, 1545 'BuildbotInfo': BuildbotInfo,
1591 'DateRange': DateRange, 1546 'DateRange': DateRange,
1592 'TagMap': TagMap, 1547 'TagMap': TagMap,
1593 'RelatedHistogramBreakdown': RelatedHistogramBreakdown, 1548 'RelatedHistogramBreakdown': RelatedHistogramBreakdown,
1594 'TelemetryInfo': TelemetryInfo, 1549 'TelemetryInfo': TelemetryInfo,
1595 'RelatedHistogramMap': RelatedHistogramMap, 1550 'RelatedHistogramMap': RelatedHistogramMap,
1596 }) 1551 })
OLDNEW
« no previous file with comments | « tracing/tracing/value/histogram.html ('k') | tracing/tracing/value/histogram_set.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698