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

Unified Diff: tools/telemetry/telemetry/value/__init__.py

Issue 381723002: Refactor Telemetry value system to support AsDict() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Nat's Comments Created 6 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
« no previous file with comments | « no previous file | tools/telemetry/telemetry/value/histogram.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/telemetry/telemetry/value/__init__.py
diff --git a/tools/telemetry/telemetry/value/__init__.py b/tools/telemetry/telemetry/value/__init__.py
index 99d35717b15cf032320e22e22b2f7504c813be76..57f0a226d0766ec6113ca97fb02146b10527572e 100644
--- a/tools/telemetry/telemetry/value/__init__.py
+++ b/tools/telemetry/telemetry/value/__init__.py
@@ -150,6 +150,37 @@ class Value(object):
"""
raise NotImplementedError()
+ @classmethod
+ def GetJSONTypeName(cls):
+ """Gets the typename for serialization to JSON using AsDict."""
+ raise NotImplementedError()
+
+ def AsDict(self):
+ """Gets a representation of this value as a dict for eventual
+ serialization to JSON.
+ """
+ return self._AsDictImpl()
+
+ def _AsDictImpl(self):
+ d = {
+ 'name': self.name,
+ 'type': self.GetJSONTypeName(),
+ 'unit': self.units,
+ }
+
+ if self.page:
+ d['page_id'] = self.page.id
+
+ return d
+
+ def AsDictWithoutBaseClassEntries(self):
+ full_dict = self.AsDict()
+ base_dict_keys = set(self._AsDictImpl().keys())
+
+ # Exctracts only entries added by the subclass.
+ return dict([(k, v) for (k, v) in full_dict.iteritems()
+ if k not in base_dict_keys])
+
def ValueNameFromTraceAndChartName(trace_name, chart_name=None):
"""Mangles a trace name plus optional chart name into a standard string.
« no previous file with comments | « no previous file | tools/telemetry/telemetry/value/histogram.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698