blob: 7287d679940226bc829616628fe5c558150c21e6 [file] [log] [blame]
<!DOCTYPE html>
<!--
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.
-->
<!--
Include all Diagnostic subclasses here so that DiagnosticMap.addDicts() and
DiagnosticMap.fromDict() always have access to all subclasses in the
Diagnostic registry.
-->
<link rel="import" href="/tracing/value/diagnostics/breakdown.html">
<link rel="import" href="/tracing/value/diagnostics/generic.html">
<link rel="import" href="/tracing/value/diagnostics/iteration_info.html">
<link rel="import" href="/tracing/value/diagnostics/related_event_set.html">
<link rel="import" href="/tracing/value/diagnostics/related_histogram_breakdown.html">
<link rel="import" href="/tracing/value/diagnostics/related_value_map.html">
<link rel="import" href="/tracing/value/diagnostics/related_value_set.html">
<script>
'use strict';
tr.exportTo('tr.v.d', function() {
class DiagnosticMap extends Map {
/**
* Add a new Diagnostic to this map.
*
* @param {string} name
* @param {!tr.v.d.Diagnostic} diagnostic
*/
set(name, diagnostic) {
if (typeof(name) !== 'string')
throw new Error('name must be string, not ' + name);
if (!(diagnostic instanceof tr.v.d.Diagnostic))
throw new Error('Must be instanceof Diagnostic: ' + diagnostic);
Map.prototype.set.call(this, name, diagnostic);
}
/**
* Add Diagnostics from a dictionary of dictionaries.
*
* @param {Object} dict
*/
addDicts(dict) {
tr.b.iterItems(dict, function(name, diagnosticDict) {
this.set(name, tr.v.d.Diagnostic.fromDict(diagnosticDict));
}, this);
}
asDict() {
var dict = {};
for (var [name, diagnostic] of this) {
dict[name] = diagnostic.asDict();
}
return dict;
}
static fromDict(d) {
var diagnostics = new DiagnosticMap();
diagnostics.addDicts(d);
return diagnostics;
}
static fromObject(obj) {
var diagnostics = new DiagnosticMap();
tr.b.iterItems(obj, function(name, diagnostic) {
diagnostics.set(name, diagnostic);
});
return diagnostics;
}
}
return {
DiagnosticMap: DiagnosticMap
};
});
</script>