Skip to content

Instantly share code, notes, and snippets.

@egonelbre
Created March 13, 2015 09:53
Show Gist options
  • Save egonelbre/4cd61cb4d49229943512 to your computer and use it in GitHub Desktop.
Save egonelbre/4cd61cb4d49229943512 to your computer and use it in GitHub Desktop.
Fix for nanoseconds
From 0ad0fd6f3c2b00e9ce80e5b699aa61d97aa55805 Mon Sep 17 00:00:00 2001
From: Egon Elbre <egonelbre@gmail.com>
Date: Fri, 13 Mar 2015 11:51:19 +0200
Subject: [PATCH 1/2] Fixes for nanosecond precision.
---
trace_viewer/core/analysis/single_slice_sub_view_test.html | 4 ++--
trace_viewer/core/analysis/util.html | 12 +++++++++++-
trace_viewer/core/draw_helpers.html | 2 +-
trace_viewer/core/location.html | 4 ++--
trace_viewer/core/trace_model/timed_event.html | 6 +++---
trace_viewer/core/tracks/ruler_track.html | 14 +++++++++++---
6 files changed, 30 insertions(+), 12 deletions(-)
diff --git a/trace_viewer/core/analysis/single_slice_sub_view_test.html b/trace_viewer/core/analysis/single_slice_sub_view_test.html
index aa67efb..32c78b7 100644
--- a/trace_viewer/core/analysis/single_slice_sub_view_test.html
+++ b/trace_viewer/core/analysis/single_slice_sub_view_test.html
@@ -150,7 +150,7 @@ tv.b.unittest.testSuite(function() {
assertEquals(3, table.tableRows.length);
assertEquals('b', table.tableRows[0].value);
assertEquals('0 ms', table.tableRows[1].value);
- assertEquals('0.002 ms', table.tableRows[2].value);
+ assertEquals('2 ns', table.tableRows[2].value);
});
test('analyzeSelectionWithSingleSliceCategory', function() {
@@ -163,7 +163,7 @@ tv.b.unittest.testSuite(function() {
assertEquals('b', table.tableRows[0].value);
assertEquals('foo', table.tableRows[1].value);
assertEquals('0 ms', table.tableRows[2].value);
- assertEquals('0.002 ms', table.tableRows[3].value);
+ assertEquals('2 ns', table.tableRows[3].value);
});
test('instantiate_withSingleSliceContainingIDRef', function() {
diff --git a/trace_viewer/core/analysis/util.html b/trace_viewer/core/analysis/util.html
index 8fb952a..6c5b2a8 100644
--- a/trace_viewer/core/analysis/util.html
+++ b/trace_viewer/core/analysis/util.html
@@ -13,13 +13,23 @@ found in the LICENSE file.
*/
tv.exportTo('tv.c.analysis', function() {
function tsString(ts) {
- return Number(parseFloat(tsRound(ts)).toFixed(3)).toLocaleString() + ' ms';
+ if(ts == 0){
+ return '0 ms';
+ } else if (ts < 1) {
+ return Number(parseFloat(tsRoundNS(ts)).toFixed(3)).toLocaleString() + ' ns';
+ } else {
+ return Number(parseFloat(tsRound(ts)).toFixed(3)).toLocaleString() + ' ms';
+ }
}
function tsRound(ts) {
return Math.round(ts * 1000.0) / 1000.0;
}
+ function tsRoundNS(ts) {
+ return Math.round(ts * 1000000.0) / 1000.0;
+ }
+
return {
tsString: tsString,
tsRound: tsRound
diff --git a/trace_viewer/core/draw_helpers.html b/trace_viewer/core/draw_helpers.html
index e15af3a..9c8c18d 100644
--- a/trace_viewer/core/draw_helpers.html
+++ b/trace_viewer/core/draw_helpers.html
@@ -173,7 +173,7 @@ tv.exportTo('tv.c', function() {
var w = pixWidth;
if (slice.duration > 0) {
- w = Math.max(slice.duration, 0.001);
+ w = Math.max(slice.duration, 0.000001);
if (w < pixWidth)
w = pixWidth;
}
diff --git a/trace_viewer/core/location.html b/trace_viewer/core/location.html
index 30303a2..1df1e60 100644
--- a/trace_viewer/core/location.html
+++ b/trace_viewer/core/location.html
@@ -54,7 +54,7 @@ tv.exportTo('tv.c', function() {
Location.prototype = {
fromViewCoordinates: function(viewX, viewY) {
var dt = this.viewport_.currentDisplayTransform;
- this.xWorld_ = Math.round(dt.xViewToWorld(viewX));
+ this.xWorld_ = dt.xViewToWorld(viewX);
// Build yComponents by calculating percentage offset with respect to
// each parent track.
@@ -75,7 +75,7 @@ tv.exportTo('tv.c', function() {
toViewCoordinates: function() {
var dt = this.viewport_.currentDisplayTransform;
var containerToTrack = this.viewport_.containerToTrackObj;
- var viewX = Math.round(dt.xWorldToView(this.xWorld_));
+ var viewX = dt.xWorldToView(this.xWorld_);
var viewY = -1;
for (var index in this.yComponents_) {
diff --git a/trace_viewer/core/trace_model/timed_event.html b/trace_viewer/core/trace_model/timed_event.html
index 48695bc..971f1c6 100644
--- a/trace_viewer/core/trace_model/timed_event.html
+++ b/trace_viewer/core/trace_model/timed_event.html
@@ -45,9 +45,9 @@ tv.exportTo('tv.c.trace_model', function() {
// and an X event (whose end = start + duration) at the same time may
// become not equal. Round back to micros (which is the source data
// precision) to ensure equality below.
- var this_end_micros = Math.round(this.end * 1000);
- var that_end_micros = Math.round(that.end * 1000);
- return this.start <= that.start && this_end_micros >= that_end_micros;
+ var this_end_nanos = Math.round(this.end * 10000000);
+ var that_end_nanos = Math.round(that.end * 10000000);
+ return this.start <= that.start && this_end_nanos >= that_end_nanos;
}
};
diff --git a/trace_viewer/core/tracks/ruler_track.html b/trace_viewer/core/tracks/ruler_track.html
index 410dbcc..33a3c3d 100644
--- a/trace_viewer/core/tracks/ruler_track.html
+++ b/trace_viewer/core/tracks/ruler_track.html
@@ -37,6 +37,7 @@ tv.exportTo('tv.c.tracks', function() {
this.classList.add('ruler-track');
this.strings_secs_ = [];
this.strings_msecs_ = [];
+ this.strings_nsecs_ = [];
this.viewportChange_ = this.viewportChange_.bind(this);
viewport.addEventListener('change', this.viewportChange_);
@@ -110,7 +111,11 @@ tv.exportTo('tv.c.tracks', function() {
var unit;
var unitDivisor;
var tickLabels = undefined;
- if (majorMarkDistanceWorld < 100) {
+ if (majorMarkDistanceWorld < 0.1) {
+ unit = 'ns';
+ unitDivisor = 0.001;
+ tickLabels = this.strings_nsecs_;
+ } else if (majorMarkDistanceWorld < 100) {
unit = 'ms';
unitDivisor = 1;
tickLabels = this.strings_msecs_;
@@ -162,7 +167,7 @@ tv.exportTo('tv.c.tracks', function() {
var curXView = Math.floor(dt.xWorldToView(curX));
var unitValue = curX / unitDivisor;
- var roundedUnitValue = Math.floor(unitValue * 100000) / 100000;
+ var roundedUnitValue = Math.round(unitValue * 100000) / 100000;
if (!tickLabels[roundedUnitValue])
tickLabels[roundedUnitValue] = roundedUnitValue + ' ' + unit;
@@ -247,7 +252,10 @@ tv.exportTo('tv.c.tracks', function() {
leftMarkerView + (distanceBetweenMarkersView / 2);
// Determine units.
- if (distanceBetweenMarkers < 100) {
+ if (distanceBetweenMarkers < 0.1) {
+ unit = 'ns';
+ unitDivisor = 0.001;
+ } else if (distanceBetweenMarkers < 100) {
unit = 'ms';
unitDivisor = 1;
} else {
--
1.9.5.msysgit.0
From 2c7ca8f91dcedbb90d6384d7e6acaeca2b27bcb9 Mon Sep 17 00:00:00 2001
From: Egon Elbre <egonelbre@gmail.com>
Date: Fri, 13 Mar 2015 11:52:23 +0200
Subject: [PATCH 2/2] Added nanoseconds test file.
---
test_data/nanoseconds.json | 10 ++++++++++
1 file changed, 10 insertions(+)
create mode 100644 test_data/nanoseconds.json
diff --git a/test_data/nanoseconds.json b/test_data/nanoseconds.json
new file mode 100644
index 0000000..30ea58f
--- /dev/null
+++ b/test_data/nanoseconds.json
@@ -0,0 +1,10 @@
+{"traceEvents": [
+{"name": "X1", "ph": "B", "pid": 1, "tid": 1, "ts": 0},
+{"name": "X1", "ph": "E", "pid": 1, "tid": 1, "ts": 1.1},
+{"name": "X2", "ph": "B", "pid": 1, "tid": 1, "ts": 1.1},
+{"name": "X2", "ph": "E", "pid": 1, "tid": 1, "ts": 1.3},
+{"name": "X3", "ph": "B", "pid": 1, "tid": 1, "ts": 1.3},
+{"name": "X3", "ph": "E", "pid": 1, "tid": 1, "ts": 1.6},
+{"name": "X4", "ph": "B", "pid": 1, "tid": 1, "ts": 1.7},
+{"name": "X4", "ph": "E", "pid": 1, "tid": 1, "ts": 2.1},
+{}]}
\ No newline at end of file
--
1.9.5.msysgit.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment