-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Supports microsecond precision by employing process.hrtime
This uses the same approach as Brave does, except using process.hrtime instead of Java's `System.nanoTime`. Here's the approach in summary: When creating a tracer or a span, save off the relative time and make timestamps based on an high-precision offset from there. In browsers, microsecond precision requires installing a shim like this: ``` // use higher-precision time than milliseconds process.hrtime = require('browser-process-hrtime'); ``` See https://nodejs.org/api/process.html#process_process_hrtime_time See https://github.com/kumavis/browser-process-hrtime Fixes #29 Fixes #3
- Loading branch information
Adrian Cole
committed
Oct 12, 2016
1 parent
7f3efe8
commit b938e77
Showing
11 changed files
with
133 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"lerna": "2.0.0-beta.9", | ||
"lerna": "2.0.0-beta.30", | ||
"version": "0.3.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,12 @@ | ||
// Returns the current time in epoch microseconds | ||
module.exports.now = function now() { | ||
return new Date().getTime() * 1000; | ||
// if startTimestamp and startTick are present, process.hrtime is used | ||
// See https://nodejs.org/api/process.html#process_process_hrtime_time | ||
module.exports.now = function now(startTimestamp, startTick) { | ||
if (startTimestamp && startTick && process && process.hrtime) { | ||
const hrtime = process.hrtime(startTick); | ||
const elapsedMicros = Math.floor(hrtime[0] * 1000000 + hrtime[1] / 1000); | ||
return startTimestamp + elapsedMicros; | ||
} else { | ||
return new Date().getTime() * 1000; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters