| Index: tracing/tracing/value/value.html
|
| diff --git a/tracing/tracing/value/value.html b/tracing/tracing/value/value.html
|
| index a57b404138cdd7d4fe4d14ec8b4def9207ed1a89..bea2450169f7187d9c557aead25304a781d0101f 100644
|
| --- a/tracing/tracing/value/value.html
|
| +++ b/tracing/tracing/value/value.html
|
| @@ -8,15 +8,18 @@ found in the LICENSE file.
|
| <link rel="import" href="/tracing/base/guid.html">
|
| <link rel="import" href="/tracing/base/iteration_helpers.html">
|
| <link rel="import" href="/tracing/base/utils.html">
|
| +<link rel="import" href="/tracing/value/diagnostics/diagnostic_map.html">
|
|
|
| <script>
|
| 'use strict';
|
|
|
| tr.exportTo('tr.v', function() {
|
| - function Value(canonicalUrl, name, opt_options, opt_groupingKeys,
|
| - opt_diagnostics) {
|
| + /** @constructor */
|
| + function Value(name, opt_options) {
|
| if (typeof(name) !== 'string')
|
| - throw new Error('Expected value_name grouping key to be provided');
|
| + throw new Error('name must be a string');
|
| +
|
| + this.name_ = name;
|
|
|
| // If this Value is being deserialized, then its guid will be set by
|
| // fromDict().
|
| @@ -24,18 +27,7 @@ tr.exportTo('tr.v', function() {
|
| // allocated the first time the guid is gotten by asDict().
|
| this.guid_ = undefined;
|
|
|
| - // Allow callers to re-use groupingKeys dictionaries.
|
| - this.groupingKeys = {name: name};
|
| - if (opt_groupingKeys) {
|
| - for (var keyName in opt_groupingKeys) {
|
| - this.addGroupingKey(keyName, opt_groupingKeys[keyName]);
|
| - }
|
| - }
|
| -
|
| - this.diagnostics = opt_diagnostics || {};
|
| -
|
| - // May be undefined
|
| - this.diagnostics.canonical_url = canonicalUrl;
|
| + this.diagnostics = new tr.v.d.DiagnosticMap();
|
|
|
| var options = opt_options || {};
|
| this.description = options.description;
|
| @@ -44,19 +36,31 @@ tr.exportTo('tr.v', function() {
|
| }
|
|
|
| Value.fromDict = function(d) {
|
| - if (d.type === 'numeric')
|
| - return NumericValue.fromDict(d);
|
| -
|
| - if (d.type === 'dict')
|
| - return DictValue.fromDict(d);
|
| -
|
| - if (d.type == 'failure')
|
| - return FailureValue.fromDict(d);
|
| -
|
| - if (d.type === 'skip')
|
| - return SkipValue.fromDict(d);
|
| + var value = undefined;
|
| + switch (d.type) {
|
| + case 'numeric':
|
| + value = NumericValue.fromDict(d);
|
| + break;
|
| +
|
| + case 'dict':
|
| + value = DictValue.fromDict(d);
|
| + break;
|
| +
|
| + case 'failure':
|
| + value = FailureValue.fromDict(d);
|
| + break;
|
| +
|
| + case 'skip':
|
| + value = SkipValue.fromDict(d);
|
| + break;
|
| +
|
| + default:
|
| + throw new Error('Not implemented');
|
| + }
|
|
|
| - throw new Error('Not implemented');
|
| + value.guid = d.guid;
|
| + value.diagnostics.addDicts(d.diagnostics);
|
| + return value;
|
| };
|
|
|
| Value.prototype = {
|
| @@ -75,21 +79,7 @@ tr.exportTo('tr.v', function() {
|
| },
|
|
|
| get name() {
|
| - return this.groupingKeys.name;
|
| - },
|
| -
|
| - get canonicalUrl() {
|
| - return this.diagnostics.canonical_url;
|
| - },
|
| -
|
| - addGroupingKey: function(keyName, key) {
|
| - if (keyName === 'name')
|
| - throw new Error('Invalid groupingKey name "name"');
|
| -
|
| - if (this.groupingKeys.hasOwnProperty(keyName))
|
| - throw new Error('Tried to redefine grouping key ' + keyName);
|
| -
|
| - this.groupingKeys[keyName] = key;
|
| + return this.name_;
|
| },
|
|
|
| asDict: function() {
|
| @@ -99,10 +89,10 @@ tr.exportTo('tr.v', function() {
|
| asJSON: function() {
|
| var d = {
|
| guid: this.guid,
|
| - grouping_keys: tr.b.cloneDictionary(this.groupingKeys),
|
| + name: this.name_,
|
| description: this.description,
|
| important: this.important,
|
| - diagnostics: this.diagnostics
|
| + diagnostics: this.diagnostics.asDict()
|
| };
|
|
|
| this._asDictInto(d);
|
| @@ -116,13 +106,12 @@ tr.exportTo('tr.v', function() {
|
| }
|
| };
|
|
|
| - function NumericValue(canonicalUrl, name, numeric, opt_options,
|
| - opt_groupingKeys, opt_diagnostics) {
|
| + /** @constructor */
|
| + function NumericValue(name, numeric, opt_options) {
|
| if (!(numeric instanceof tr.v.NumericBase))
|
| throw new Error('Expected numeric to be instance of tr.v.NumericBase');
|
|
|
| - Value.call(this, canonicalUrl, name, opt_options, opt_groupingKeys,
|
| - opt_diagnostics);
|
| + Value.call(this, name, opt_options);
|
| this.numeric = numeric;
|
| }
|
|
|
| @@ -130,12 +119,7 @@ tr.exportTo('tr.v', function() {
|
| if (d.numeric === undefined)
|
| throw new Error('Expected numeric to be provided');
|
| var numeric = tr.v.NumericBase.fromDict(d.numeric);
|
| - var name = d.grouping_keys.name;
|
| - d.grouping_keys = tr.b.cloneDictionary(d.groupingKeys);
|
| - delete d.grouping_keys.name;
|
| - var value = new NumericValue(d.diagnostics.canonical_url, name,
|
| - numeric, d, d.grouping_keys, d.diagnostics);
|
| - value.guid = d.guid;
|
| + var value = new NumericValue(d.name, numeric, d);
|
| return value;
|
| };
|
|
|
| @@ -148,10 +132,9 @@ tr.exportTo('tr.v', function() {
|
| }
|
| };
|
|
|
| - function DictValue(canonicalUrl, name, value, opt_options, opt_groupingKeys,
|
| - opt_diagnostics) {
|
| - Value.call(this, canonicalUrl, name, opt_options, opt_groupingKeys,
|
| - opt_diagnostics);
|
| + /** @constructor */
|
| + function DictValue(name, value, opt_options) {
|
| + Value.call(this, name, opt_options);
|
| this.value = value;
|
| }
|
|
|
| @@ -160,12 +143,7 @@ tr.exportTo('tr.v', function() {
|
| throw new Error('Expected units to be undefined');
|
| if (d.value === undefined)
|
| throw new Error('Expected value to be provided');
|
| - var name = d.grouping_keys.name;
|
| - d.grouping_keys = tr.b.cloneDictionary(d.groupingKeys);
|
| - delete d.grouping_keys.name;
|
| - var value = new DictValue(d.diagnostics.canonical_url, name,
|
| - d.value, d, d.groupingKeys, d.diagnostics);
|
| - value.guid = d.guid;
|
| + var value = new DictValue(d.name, d.value, d);
|
| return value;
|
| };
|
|
|
| @@ -178,9 +156,8 @@ tr.exportTo('tr.v', function() {
|
| }
|
| };
|
|
|
| -
|
| - function FailureValue(canonicalUrl, name, opt_options, opt_groupingKeys,
|
| - opt_diagnostics) {
|
| + /** @constructor */
|
| + function FailureValue(name, opt_options) {
|
| var options = opt_options || {};
|
|
|
| var stack;
|
| @@ -197,21 +174,14 @@ tr.exportTo('tr.v', function() {
|
| if (typeof stack !== 'string')
|
| throw new Error('stack must be provided as a string');
|
|
|
| - if (canonicalUrl === undefined) {
|
| - throw new Error('FailureValue must provide canonicalUrl');
|
| - }
|
| -
|
| - Value.call(this, canonicalUrl, name, options, opt_groupingKeys,
|
| - opt_diagnostics);
|
| + Value.call(this, name, options);
|
| this.stack = stack;
|
| }
|
|
|
| - FailureValue.fromError = function(canonicalUrl, e) {
|
| + FailureValue.fromError = function(e) {
|
| var ex = tr.b.normalizeException(e);
|
| - return new FailureValue(canonicalUrl, ex.typeName,
|
| - {description: ex.message,
|
| - stack: ex.stack});
|
| -
|
| + return new FailureValue(ex.typeName, {
|
| + description: ex.message, stack: ex.stack});
|
| };
|
|
|
| FailureValue.fromDict = function(d) {
|
| @@ -219,13 +189,7 @@ tr.exportTo('tr.v', function() {
|
| throw new Error('Expected units to be undefined');
|
| if (d.stack_str === undefined)
|
| throw new Error('Expected stack_str to be provided');
|
| - var name = d.grouping_keys.name;
|
| - d.grouping_keys = tr.b.cloneDictionary(d.groupingKeys);
|
| - delete d.grouping_keys.name;
|
| - var value = new FailureValue(d.diagnostics.canonical_url, name,
|
| - d, d.grouping_keys, d.diagnostics);
|
| - value.guid = d.guid;
|
| - return value;
|
| + return new FailureValue(d.name, d);
|
| };
|
|
|
| FailureValue.prototype = {
|
| @@ -237,23 +201,15 @@ tr.exportTo('tr.v', function() {
|
| }
|
| };
|
|
|
| -
|
| - function SkipValue(canonicalUrl, name, opt_options, opt_groupingKeys,
|
| - opt_diagnostics) {
|
| - Value.call(this, canonicalUrl, name, opt_options, opt_groupingKeys,
|
| - opt_diagnostics);
|
| + /** @constructor */
|
| + function SkipValue(name, opt_options) {
|
| + Value.call(this, name, opt_options);
|
| }
|
|
|
| SkipValue.fromDict = function(d) {
|
| if (d.units !== undefined)
|
| throw new Error('Expected units to be undefined');
|
| - var name = d.grouping_keys.name;
|
| - d.grouping_keys = tr.b.cloneDictionary(d.groupingKeys);
|
| - delete d.grouping_keys.name;
|
| - var value = new SkipValue(d.diagnostics.canonical_url, name,
|
| - d, d.grouping_keys, d.diagnostics);
|
| - value.guid = d.guid;
|
| - return value;
|
| + return new SkipValue(d.name, d);
|
| };
|
|
|
| SkipValue.prototype = {
|
|
|