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

Unified Diff: tools/telemetry/telemetry/core/timeline/bounds.py

Issue 19772005: [telemetry] Timeline model cleanups (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: tools/telemetry/telemetry/core/timeline/bounds.py
diff --git a/tools/telemetry/telemetry/core/timeline/bounds.py b/tools/telemetry/telemetry/core/timeline/bounds.py
new file mode 100644
index 0000000000000000000000000000000000000000..9bbe1badb3fdba08ca1b09cbf384b60ffa10e4fe
--- /dev/null
+++ b/tools/telemetry/telemetry/core/timeline/bounds.py
@@ -0,0 +1,71 @@
+# Copyright (c) 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+class Bounds(object):
+ """Represents a min-max bounds."""
+ def __init__(self):
+ self.is_empty_ = True
+ self.min_ = None
+ self.max_ = None
+
+ @property
+ def is_empty(self):
+ return self.is_empty_
+
+ @property
+ def min(self):
+ if self.is_empty_:
+ return None
+ return self.min_
+
+ @property
+ def max(self):
+ if self.is_empty_:
+ return None
+ return self.max_
+
+ @property
+ def bounds(self):
+ if self.is_empty_:
+ return None
+ return self.max_ - self.min_
+
+ @property
+ def center(self):
+ return (self.min_ + self.max_) * 0.5
+
+
+ def Reset(self):
+ self.is_empty_ = True
+ self.min_ = None
+ self.max_ = None
+
+ def AddBounds(self, bounds):
+ if bounds.isEmpty:
+ return
+ self.AddValue(bounds.min_)
+ self.AddValue(bounds.max_)
+
+ def AddValue(self, value):
+ if self.is_empty_:
+ self.max_ = value
+ self.min_ = value
+ self.is_empty_ = False
+ return
+
+ self.max_ = max(self.max_, value)
+ self.min_ = min(self.min_, value)
+
+ @staticmethod
+ def CompareByMinTimes(a, b):
+ if not a.is_empty and not b.is_empty:
+ return a.min_ - b.min_
+
+ if a.is_empty and not b.is_empty:
+ return -1
+
+ if not a.is_empty and b.is_empty:
+ return 1
+
+ return 0
« no previous file with comments | « tools/telemetry/telemetry/core/timeline/async_slice.py ('k') | tools/telemetry/telemetry/core/timeline/counter.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698