Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
c943cd0
test: fix repl-tab-complete --without-ssl
danbev Dec 26, 2017
9510540
doc: lowercase primitives in test/common/README.md
vsemozhetbyt Feb 19, 2018
e74e422
crypto: add cert.fingerprint256 as SHA256 fingerprint
bjori Dec 14, 2017
ef8f90f
http2: fix condition where data is lost
mcollina Feb 19, 2018
28a5362
build: fix lint-md-build dependency
joyeecheung Feb 24, 2018
71d09ec
doc: make the background section concise and improve its formality
Feb 22, 2018
4d5cd5c
src: fix error message in async_hooks constructor
danbev Feb 26, 2018
44d80c5
build: fix coverage after gcovr update
killagu Feb 23, 2018
59547cc
loader: fix --inspect-brk
devsnek Feb 23, 2018
ae4d83f
http: prevent aborted event when already completed
billywhizz Feb 17, 2018
0789eec
http: prevent aborted event when already completed
billywhizz Feb 17, 2018
eca333a
test: refactor test after review
billywhizz Feb 27, 2018
fd27165
test: specify 'dir' for directory symlinks
kfarnung Feb 27, 2018
68c1337
doc: add RegExp Unicode Property Escapes to intl
vsemozhetbyt Feb 28, 2018
12856b0
lib: change hook -> hooks in code comment
danbev Feb 28, 2018
4471369
http2: send error text in case of ALPN mismatch
addaleax Feb 25, 2018
a455006
test: allow running with `NODE_PENDING_DEPRECATION`
addaleax Feb 25, 2018
aa0fca9
http2: use original error for cancelling pending streams
addaleax Feb 25, 2018
8bc930c
http2: fix endless loop when writing empty string
addaleax Feb 22, 2018
8d595bb
test: check endless loop while writing empty string
XadillaX Feb 11, 2018
08b83ee
src: refactor setting JS properties on WriteWrap
addaleax Feb 23, 2018
1b32fc3
n-api: fix object test
Feb 27, 2018
459f209
doc: Readable unpipe on Writable error event
GeorgeSapkin Feb 8, 2018
77154cd
doc: update list of re-exported symbols
richardlau Feb 26, 2018
cc90bbd
test: fix flaky inspector-stop-profile-after-done
Trott Mar 2, 2018
551d975
http2: fix flaky test-http2-https-fallback
mcollina Mar 2, 2018
bfa894c
doc: add MoonBall to collaborators
MoonBall Mar 3, 2018
a4462b7
doc: fix n-api asynchronous threading docs
ebickle Mar 1, 2018
6d17383
buffer: fix typo in lib/buffer.js
ryzokuken Mar 4, 2018
23107ba
test: remove assert message and add block scope
wuweiweiwu Feb 28, 2018
d883376
test: refactor test-async-wrap-getasyncid
santigimeno Feb 12, 2018
cab6c8e
doc: add URL.format() example
zeke Feb 20, 2018
f864509
test,benchmark: use new Buffer API where appropriate
ChALkeR Feb 24, 2018
a938e52
build: disable openssl build warnings on macos
bnoordhuis Feb 27, 2018
db8d197
lib,test: remove yoda statements
BridgeAR Mar 2, 2018
5b8c97f
events: show throw stack trace for uncaught exception
addaleax Feb 26, 2018
5c4f703
n-api: update reference test
Mar 2, 2018
96f0bec
repl: make last error available as `_error`
addaleax Feb 21, 2018
e584113
lib: re-fix v8_prof_processor
addaleax Feb 28, 2018
479b622
tls,http2: handle writes after SSL destroy more gracefully
addaleax Feb 25, 2018
4ecf5bb
doc: fix a typo in util.isDeepStrictEqual
Feb 14, 2018
e42600f
doc: add missing `Returns` in fs & util
Feb 14, 2018
3d4cda3
trace_events: add file pattern cli option
AndreasMadsen Jan 31, 2018
6ae2caf
buffer: coerce offset to integer
BridgeAR Jan 17, 2018
5bbf009
test: check symbols in shared lib
yhwang Feb 15, 2018
89edbae
src: clean up process.dlopen()
bnoordhuis Feb 22, 2018
4fae6e3
src: make process.dlopen() load well-known symbol
bnoordhuis Feb 22, 2018
4b34b2e
build: fix gocvr version used for coverage
mhdawson Mar 2, 2018
95f6467
module: fix cyclical dynamic import
bmeck Feb 23, 2018
0e4f426
doc: add simple example to rename function
punteek Feb 16, 2018
ae2dabb
doc: new team for bundlers or delivery of Node.js
mhdawson Mar 2, 2018
056001d
deps: cherry-pick 0bcb1d6f from upstream V8
jakobkummerow Dec 5, 2017
9d2de16
doc: add introduced_in metadata to _toc.md
Trott Mar 4, 2018
f03079f
doc: update cc list
BridgeAR Mar 2, 2018
d3a70e9
doc: remove tentativeness in pull-requests.md
Trott Mar 4, 2018
6852461
doc: remove subsystem from pull request template
Trott Mar 4, 2018
f10470c
src: refactor GetPeerCertificate
danbev Mar 2, 2018
2f17c52
src: use std::unique_ptr for STACK_OF(X509)
bnoordhuis Mar 2, 2018
ee653ec
test: move require http2 to after crypto check
danbev Mar 3, 2018
cc52dae
src: #include <stdio.h>" to iculslocs
srl295 Mar 5, 2018
28880cf
perf_hooks: fix timing
TimothyGu Feb 25, 2018
6787913
test: add more information to assert.strictEqual
ryzokuken Mar 6, 2018
08bcdde
src: handle exceptions in env->SetImmediates
jasnell Jan 26, 2018
67a9742
src: prevent persistent handle resource leaks
bnoordhuis Feb 21, 2018
f89f659
src: remove unnecessary Reset() calls
bnoordhuis Feb 21, 2018
420d56c
src: don't touch js object in Http2Session dtor
bnoordhuis Feb 21, 2018
50d1233
http2: no stream destroy while its data is on the wire
addaleax Feb 26, 2018
f3e3429
module: support main w/o extension, pjson cache
guybedford Feb 12, 2018
39e032f
module: fix main lookup regression from #18728
guybedford Feb 14, 2018
3e8e152
util: use blue on non-windows systems for number
devsnek Feb 22, 2018
1fadb2e
doc: fix/add link to Android info
vsemozhetbyt Feb 26, 2018
ef4714c
net: inline and simplify onSocketEnd
addaleax Feb 6, 2018
27ba6e2
2018-03-07, Version 9.8.0 (Current)
MylesBorins Mar 6, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
perf_hooks: fix timing
Fixes: #17892
Fixes: #17893
Fixes: #18992

PR-URL: #18993
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
  • Loading branch information
TimothyGu authored and MylesBorins committed Mar 7, 2018
commit 28880cf89d5a5c1be19d5c7260bba88d600cff49
31 changes: 20 additions & 11 deletions doc/api/perf_hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ added: v8.5.0

* Returns: {number}

Returns the current high resolution millisecond timestamp.
Returns the current high resolution millisecond timestamp, where 0 represents
the start of the current `node` process.

### performance.timeOrigin
<!-- YAML
Expand All @@ -190,8 +191,8 @@ added: v8.5.0

* {number}

The [`timeOrigin`][] specifies the high resolution millisecond timestamp from
which all performance metric durations are measured.
The [`timeOrigin`][] specifies the high resolution millisecond timestamp at
which the current `node` process began, measured in Unix time.

### performance.timerify(fn)
<!-- YAML
Expand Down Expand Up @@ -302,7 +303,8 @@ added: v8.5.0
* {number}

The high resolution millisecond timestamp at which the Node.js process
completed bootstrap.
completed bootstrapping. If bootstrapping has not yet finished, the property
has the value of -1.

### performanceNodeTiming.clusterSetupEnd
<!-- YAML
Expand All @@ -311,7 +313,8 @@ added: v8.5.0

* {number}

The high resolution millisecond timestamp at which cluster processing ended.
The high resolution millisecond timestamp at which cluster processing ended. If
cluster processing has not yet ended, the property has the value of -1.

### performanceNodeTiming.clusterSetupStart
<!-- YAML
Expand All @@ -321,6 +324,7 @@ added: v8.5.0
* {number}

The high resolution millisecond timestamp at which cluster processing started.
If cluster processing has not yet started, the property has the value of -1.

### performanceNodeTiming.loopExit
<!-- YAML
Expand All @@ -330,7 +334,8 @@ added: v8.5.0
* {number}

The high resolution millisecond timestamp at which the Node.js event loop
exited.
exited. If the event loop has not yet exited, the property has the value of -1.
It can only have a value of not -1 in a handler of the [`'exit'`][] event.

### performanceNodeTiming.loopStart
<!-- YAML
Expand All @@ -340,7 +345,8 @@ added: v8.5.0
* {number}

The high resolution millisecond timestamp at which the Node.js event loop
started.
started. If the event loop has not yet started (e.g., in the first tick of the
main script), the property has the value of -1.

### performanceNodeTiming.moduleLoadEnd
<!-- YAML
Expand Down Expand Up @@ -395,8 +401,9 @@ added: v8.5.0

* {number}

The high resolution millisecond timestamp at which third_party_main processing
ended.
The high resolution millisecond timestamp at which third\_party\_main
processing ended. If third\_party\_main processing has not yet ended, the
property has the value of -1.

### performanceNodeTiming.thirdPartyMainStart
<!-- YAML
Expand All @@ -405,8 +412,9 @@ added: v8.5.0

* {number}

The high resolution millisecond timestamp at which third_party_main processing
started.
The high resolution millisecond timestamp at which third\_party\_main
processing started. If third\_party\_main processing has not yet started, the
property has the value of -1.

### performanceNodeTiming.v8Start
<!-- YAML
Expand Down Expand Up @@ -642,6 +650,7 @@ obs.observe({ entryTypes: ['function'], buffered: true });
require('some-module');
```

[`'exit'`]: process.html#process_event_exit
[`timeOrigin`]: https://w3c.github.io/hr-time/#dom-performance-timeorigin
[Async Hooks]: async_hooks.html
[W3C Performance Timeline]: https://w3c.github.io/performance-timeline/
52 changes: 33 additions & 19 deletions lib/perf_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const {
observerCounts,
setupObservers,
timeOrigin,
timeOriginTimestamp,
timerify,
constants
} = process.binding('performance');
Expand Down Expand Up @@ -145,6 +146,13 @@ function now() {
return hr[0] * 1000 + hr[1] / 1e6;
}

function getMilestoneTimestamp(milestoneIdx) {
const ns = milestones[milestoneIdx];
if (ns === -1)
return ns;
return ns / 1e6 - timeOrigin;
}

class PerformanceNodeTiming {
constructor() {}

Expand All @@ -157,67 +165,72 @@ class PerformanceNodeTiming {
}

get startTime() {
return timeOrigin;
return 0;
}

get duration() {
return now() - timeOrigin;
}

get nodeStart() {
return milestones[NODE_PERFORMANCE_MILESTONE_NODE_START];
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_NODE_START);
}

get v8Start() {
return milestones[NODE_PERFORMANCE_MILESTONE_V8_START];
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_V8_START);
}

get environment() {
return milestones[NODE_PERFORMANCE_MILESTONE_ENVIRONMENT];
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_ENVIRONMENT);
}

get loopStart() {
return milestones[NODE_PERFORMANCE_MILESTONE_LOOP_START];
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_LOOP_START);
}

get loopExit() {
return milestones[NODE_PERFORMANCE_MILESTONE_LOOP_EXIT];
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_LOOP_EXIT);
}

get bootstrapComplete() {
return milestones[NODE_PERFORMANCE_MILESTONE_BOOTSTRAP_COMPLETE];
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_BOOTSTRAP_COMPLETE);
}

get thirdPartyMainStart() {
return milestones[NODE_PERFORMANCE_MILESTONE_THIRD_PARTY_MAIN_START];
return getMilestoneTimestamp(
NODE_PERFORMANCE_MILESTONE_THIRD_PARTY_MAIN_START);
}

get thirdPartyMainEnd() {
return milestones[NODE_PERFORMANCE_MILESTONE_THIRD_PARTY_MAIN_END];
return getMilestoneTimestamp(
NODE_PERFORMANCE_MILESTONE_THIRD_PARTY_MAIN_END);
}

get clusterSetupStart() {
return milestones[NODE_PERFORMANCE_MILESTONE_CLUSTER_SETUP_START];
return getMilestoneTimestamp(
NODE_PERFORMANCE_MILESTONE_CLUSTER_SETUP_START);
}

get clusterSetupEnd() {
return milestones[NODE_PERFORMANCE_MILESTONE_CLUSTER_SETUP_END];
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_CLUSTER_SETUP_END);
}

get moduleLoadStart() {
return milestones[NODE_PERFORMANCE_MILESTONE_MODULE_LOAD_START];
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_MODULE_LOAD_START);
}

get moduleLoadEnd() {
return milestones[NODE_PERFORMANCE_MILESTONE_MODULE_LOAD_END];
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_MODULE_LOAD_END);
}

get preloadModuleLoadStart() {
return milestones[NODE_PERFORMANCE_MILESTONE_PRELOAD_MODULE_LOAD_START];
return getMilestoneTimestamp(
NODE_PERFORMANCE_MILESTONE_PRELOAD_MODULE_LOAD_START);
}

get preloadModuleLoadEnd() {
return milestones[NODE_PERFORMANCE_MILESTONE_PRELOAD_MODULE_LOAD_END];
return getMilestoneTimestamp(
NODE_PERFORMANCE_MILESTONE_PRELOAD_MODULE_LOAD_END);
}

[kInspect]() {
Expand Down Expand Up @@ -466,11 +479,11 @@ class Performance extends PerformanceObserverEntryList {
}

get timeOrigin() {
return timeOrigin;
return timeOriginTimestamp;
}

now() {
return now();
return now() - timeOrigin;
}

mark(name) {
Expand Down Expand Up @@ -549,8 +562,9 @@ class Performance extends PerformanceObserverEntryList {

[kInspect]() {
return {
timeOrigin,
nodeTiming
maxEntries: this.maxEntries,
nodeTiming: this.nodeTiming,
timeOrigin: this.timeOrigin
};
}
}
Expand Down
35 changes: 35 additions & 0 deletions src/node_perf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

#include <vector>

#ifdef __POSIX__
#include <sys/time.h> // gettimeofday
#endif

namespace node {
namespace performance {

Expand All @@ -21,13 +25,38 @@ using v8::Object;
using v8::String;
using v8::Value;

// Microseconds in a second, as a float.
#define MICROS_PER_SEC 1e6
// Microseconds in a millisecond, as a float.
#define MICROS_PER_MILLIS 1e3

// https://w3c.github.io/hr-time/#dfn-time-origin
const uint64_t timeOrigin = PERFORMANCE_NOW();
// https://w3c.github.io/hr-time/#dfn-time-origin-timestamp
const double timeOriginTimestamp = GetCurrentTimeInMicroseconds();
uint64_t performance_node_start;
uint64_t performance_v8_start;

uint64_t performance_last_gc_start_mark_ = 0;
v8::GCType performance_last_gc_type_ = v8::GCType::kGCTypeAll;

double GetCurrentTimeInMicroseconds() {
#ifdef _WIN32
// The difference between the Unix Epoch and the Windows Epoch in 100-ns ticks.
#define TICKS_TO_UNIX_EPOCH 116444736000000000LL
FILETIME ft;
GetSystemTimeAsFileTime(&ft);
uint64_t filetime_int = static_cast<uint64_t>(ft.dwHighDateTime) << 32 |
ft.dwLowDateTime;
// FILETIME is measured in terms of 100 ns. Convert that to 1 us (1000 ns).
return (filetime_int - TICKS_TO_UNIX_EPOCH) / 10.;
#else
struct timeval tp;
gettimeofday(&tp, nullptr);
return MICROS_PER_SEC * tp.tv_sec + tp.tv_usec;
#endif
}

// Initialize the performance entry object properties
inline void InitObject(const PerformanceEntry& entry, Local<Object> obj) {
Environment* env = entry.env();
Expand Down Expand Up @@ -372,6 +401,12 @@ void Init(Local<Object> target,
v8::Number::New(isolate, timeOrigin / 1e6),
attr).ToChecked();

target->DefineOwnProperty(
context,
FIXED_ONE_BYTE_STRING(isolate, "timeOriginTimestamp"),
v8::Number::New(isolate, timeOriginTimestamp / MICROS_PER_MILLIS),
attr).ToChecked();

target->DefineOwnProperty(context,
env->constants_string(),
constants,
Expand Down
8 changes: 6 additions & 2 deletions src/node_perf.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ using v8::Local;
using v8::Object;
using v8::Value;

extern const uint64_t timeOrigin;

double GetCurrentTimeInMicroseconds();

static inline PerformanceMilestone ToPerformanceMilestoneEnum(const char* str) {
#define V(name, label) \
if (strcmp(str, label) == 0) return NODE_PERFORMANCE_MILESTONE_##name;
Expand Down Expand Up @@ -77,11 +81,11 @@ class PerformanceEntry {
return ToPerformanceEntryTypeEnum(type().c_str());
}

double startTime() const { return startTime_ / 1e6; }
double startTime() const { return startTimeNano() / 1e6; }

double duration() const { return durationNano() / 1e6; }

uint64_t startTimeNano() const { return startTime_; }
uint64_t startTimeNano() const { return startTime_ - timeOrigin; }

uint64_t durationNano() const { return endTime_ - startTime_; }

Expand Down
6 changes: 5 additions & 1 deletion src/node_perf_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "node.h"
#include "v8.h"

#include <algorithm>
#include <map>
#include <string>

Expand Down Expand Up @@ -76,7 +77,10 @@ class performance_state {
isolate,
offsetof(performance_state_internal, observers),
NODE_PERFORMANCE_ENTRY_TYPE_INVALID,
root) {}
root) {
for (size_t i = 0; i < milestones.Length(); i++)
milestones[i] = -1.;
}

AliasedBuffer<uint8_t, v8::Uint8Array> root;
AliasedBuffer<double, v8::Float64Array> milestones;
Expand Down
Loading