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

Unified Diff: tracing/tracing/value/add_shared_diagnostics.py

Issue 3000643002: [Tracing] Add add_shared_diagnostics.AddValueDiagnostics (Closed)
Patch Set: fix test Created 3 years, 3 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: tracing/tracing/value/add_shared_diagnostics.py
diff --git a/tracing/tracing/value/add_shared_diagnostics.py b/tracing/tracing/value/add_shared_diagnostics.py
new file mode 100644
index 0000000000000000000000000000000000000000..a9945f3774008cd5cd837a5604a94c6395ac57a7
--- /dev/null
+++ b/tracing/tracing/value/add_shared_diagnostics.py
@@ -0,0 +1,54 @@
+# Copyright 2016 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.
+
+import json
+
+from tracing.value import histogram
+from tracing.value import histogram_set
+from tracing.value.diagnostics import diagnostic
+
+
+def AddSharedDiagnostics(
+ histograms_json_filename, diagnostic_names_to_filenames):
+ """Add shared Diagnostics to a set of histograms.
+
+ Args:
+ histograms_json_filename: path to a histograms JSON file.
+ diagnostic_names_to_filenames: dict mapping names to filenames of
+ serialized Diagnostics.
+
+ Returns:
+ The new histograms JSON with added shared diagnostic.
+ """
+ histogram_dicts = json.load(open(histograms_json_filename))
+ histograms = histogram_set.HistogramSet()
+ histograms.ImportDicts(histogram_dicts)
+
+ for name, filename in diagnostic_names_to_filenames.iteritems():
+ diag = diagnostic.Diagnostic.FromDict(json.load(open(filename)))
+ histograms.AddSharedDiagnostic(name, diag)
+
+ return json.dumps(histograms.AsDicts())
+
+
+def AddValueDiagnostic(
+ histograms_json_filename, diagnostic_names_to_values):
+ """Adds shared GenericSets containing values to a set of histograms.
+
+ Args:
+ histograms_json_filename: path to a histograms JSON file.
+ diagnostic_names_to_values: dict mapping names to JSONizable values.
+
+ Returns:
+ The new histograms JSON with added GenericSets.
+ """
+ histogram_dicts = json.load(open(histograms_json_filename))
+ histograms = histogram_set.HistogramSet()
+ histograms.ImportDicts(histogram_dicts)
+
+ for name, value in diagnostic_names_to_values.iteritems():
+ diag = histogram.GenericSet([value])
+ histograms.AddSharedDiagnostic(name, diag)
+
+ return json.dumps(histograms.AsDicts())
« no previous file with comments | « tracing/tracing/value/add_shared_diagnostic_unittest.py ('k') | tracing/tracing/value/add_shared_diagnostics_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698