Index: tools/telemetry/telemetry/value/value_backcompat.py |
diff --git a/tools/telemetry/telemetry/value/value_backcompat.py b/tools/telemetry/telemetry/value/value_backcompat.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b7318bcaa2108e36d945a654a1a74f234bf59982 |
--- /dev/null |
+++ b/tools/telemetry/telemetry/value/value_backcompat.py |
@@ -0,0 +1,46 @@ |
+# 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. |
+"""Backward compatibility for old results API. |
+ |
+This module helps convert the old PageMeasurementResults API into the new |
+style one. This exists as a bridging solution so we can change the underlying |
+implementation and update the PageMeasurementResults API once we know the |
+underlying implementation is solid. |
+""" |
+from telemetry import value as value_module |
+from telemetry.value.histogram import HistogramValue |
+from telemetry.value.list_of_scalar_values import ListOfScalarValues |
+from telemetry.value.scalar import ScalarValue |
+ |
+ |
+def ConvertOldCallingConventionToValue(page, trace_name, units, |
+ value, chart_name, data_type): |
+ value_name = value_module.ValueNameFromTraceAndChartName( |
+ trace_name, chart_name) |
+ if data_type == 'default': |
+ if isinstance(value, list): |
+ return ListOfScalarValues(page, value_name, units, |
+ value, important=True) |
+ else: |
+ return ScalarValue(page, value_name, units, |
+ value, important=True) |
+ elif data_type == 'unimportant': |
+ if isinstance(value, list): |
+ return ListOfScalarValues(page, value_name, units, |
+ value, important=False) |
+ else: |
+ return ScalarValue(page, value_name, units, |
+ value, important=False) |
+ elif data_type == 'histogram': |
+ assert isinstance(value, basestring) |
+ return HistogramValue(page, value_name, units, |
+ raw_value_json=value, important=True) |
+ elif data_type == 'unimportant-histogram': |
+ assert isinstance(value, basestring) |
+ return HistogramValue(page, value_name, units, |
+ raw_value_json=value, important=False) |
+ elif data_type == 'informational': |
+ raise NotImplementedError() |
+ else: |
+ raise ValueError('Unrecognized data type %s', data_type) |