Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Commit

Permalink
Add intrinsic time unit to Model.
Browse files Browse the repository at this point in the history
BUG=#624
R=nduca@chromium.org

Review URL: https://codereview.appspot.com/248870043

Change-Id: I9ad83391f01d3abd74c08cea67a13c848eccffa3
  • Loading branch information
egonelbre committed Jun 26, 2015
1 parent 71eafbe commit 04dd8b1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
20 changes: 20 additions & 0 deletions trace_viewer/model/model.html
Expand Up @@ -9,6 +9,7 @@
<link rel="import" href="/base/interval_tree.html">
<link rel="import" href="/base/range.html">
<link rel="import" href="/base/task.html">
<link rel="import" href="/base/units/time.html">
<link rel="import" href="/ui/base/overlay.html">
<link rel="import" href="/core/filter.html">
<link rel="import" href="/core/auditor.html">
Expand Down Expand Up @@ -122,6 +123,7 @@
this.instantEvents = [];
this.flowEvents = [];
this.clockSyncRecords = [];
this.intrinsicTimeUnit_ = undefined;

this.stackFrames = {};
this.samples = [];
Expand Down Expand Up @@ -705,6 +707,24 @@
this.reportedImportWarnings_[data.type] = true;
},

/**
* Returns a time unit that is used to format values and determines the
* precision of the timestamp values.
*/
get intrinsicTimeUnit() {
if (this.intrinsicTimeUnit_ === undefined)
return tr.b.units.Time.supportedUnits.ms;
return this.intrinsicTimeUnit_;
},

set intrinsicTimeUnit(value) {
if (this.intrinsicTimeUnit_ === value)
return;
if (this.intrinsicTimeUnit_ !== undefined)
throw new Error('Intrinsic time unit already set');
this.intrinsicTimeUnit_ = value;
},

get hasImportWarnings() {
return (this.importWarnings_.length > 0);
},
Expand Down
18 changes: 18 additions & 0 deletions trace_viewer/model/model_test.html
Expand Up @@ -5,6 +5,7 @@
found in the LICENSE file.
-->

<link rel="import" href="/base/units/time.html">
<link rel="import" href="/core/test_utils.html">
<link rel="import" href="/extras/full_config.html">
<link rel="import" href="/model/annotation.html">
Expand Down Expand Up @@ -409,5 +410,22 @@
assert.equal(m.getAnnotationByGUID(a2.guid), a2);
assert.equal(m.getAllAnnotations().length, 1);
});

test('model_intrinsicTimeUnit', function() {
var unit = tr.b.units.Time.supportedUnits;
var m = new tr.Model();

// by default it should be milliseconds
assert.equal(m.intrinsicTimeUnit, unit.ms);

m.intrinsicTimeUnit = unit.ns;
assert.equal(m.intrinsicTimeUnit, unit.ns);
// should be able to set to the same
m.intrinsicTimeUnit = unit.ns;
assert.equal(m.intrinsicTimeUnit, unit.ns);
// should not be able to change it after fixing it
assert.throw(function() { m.intrinsicTimeUnit = unit.ms; });
assert.equal(m.intrinsicTimeUnit, unit.ns);
});
});
</script>

0 comments on commit 04dd8b1

Please sign in to comment.