Skip to content

perf_hooks: emit user timing marks, measures and timerify to trace events - #18789

Closed
jasnell wants to merge 3 commits into
nodejs:masterfrom
jasnell:perf_trace_event
Closed

perf_hooks: emit user timing marks, measures and timerify to trace events#18789
jasnell wants to merge 3 commits into
nodejs:masterfrom
jasnell:perf_trace_event

Conversation

@jasnell

Copy link
Copy Markdown
Member

Emit user timing marks/measures and performance.timerify() measures to trace events.

image

/cc @nodejs/diagnostics @mcollina

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

perf_hooks, trace_events

@jasnelljasnell added trace_events Issues and PRs related to V8, Node.js core, and userspace code trace events. perf_hooks Issues and PRs related to the implementation of the Performance Timing API. labels Feb 14, 2018
@nodejs-github-botnodejs-github-bot added the c++ Issues and PRs that require attention from people who are familiar with C++. label Feb 14, 2018
@AndreasMadsen

Copy link
Copy Markdown
Member

Didn’t review closely but tests are missing.

Comment threadsrc/node_perf.cc Outdated

@ofrobotsofrobotsFeb 15, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, this is doing a floating point divide which is more expensive than an integer divide. 1000 would be an integral constant.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yeah, good point :-)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed. Floating point divide + 2 conversions between integer and floating point.

#include<stdint.h>uint64_tfoo(uint64_t nanos) {
return nanos / 1e3;
}
// clang -O3 -mllvm --x86-asm-syntax=intel -S foo.c
movqxmm0,rdipunpckldqxmm0, xmmword ptr [rip+ LCPI0_0] ## xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]subpdxmm0, xmmword ptr [rip+ LCPI0_1]haddpdxmm0,xmm0divsdxmm0, qword ptr [rip+ LCPI0_2]movsdxmm1, qword ptr [rip+ LCPI0_3] ## xmm1 = mem[0],zeromovapdxmm2,xmm0subsdxmm2,xmm1cvttsd2sirax,xmm2	movabs	rcx,-9223372036854775808xorrcx,raxcvttsd2sirax,xmm0ucomisdxmm0,xmm1	cmovae	rax,rcxpoprbpret

@jasnell

Copy link
Copy Markdown
MemberAuthor

@ofrobots ... nit fixed!
@AndreasMadsen ... test added.

Comment threadsrc/node_perf.cc Outdated

@ofrobotsofrobotsFeb 16, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: what would the the correct context here? To me it seems that an AsyncResource or async_context be created when the observer is constructed, and that should be used on the callback. Do you agree?

Aside: Do our compilers support async_context{0,0} syntax yet?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still thinking about that. PerformanceObserver currently is not an AsyncResource and only actually exists on the JS side. Making it an AsyncResource would be a minor divergence from the spec but is certainly not out of the question.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I don't know about the compilers question.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't want to inherit from AsyncResource, you can attache an async_context to the PerformanceObserver instances for the same effect.

I'm okay if you want to do this in a follow-on, as the issue existed before this PR, and is orthogonal.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added example to #18810 in case it is useful. If the CI passes there, then that would answer the compiler question :).

@jasnell

Copy link
Copy Markdown
MemberAuthor

@ofrobots ... just went ahead and made PerformanceObserver an AsyncResource.

@jasnell

Copy link
Copy Markdown
MemberAuthor

@jasnell

Copy link
Copy Markdown
MemberAuthor

@jasnell

Copy link
Copy Markdown
MemberAuthor

CI is looking good with one unrelated failure.

@BridgeARBridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Feb 17, 2018
Comment threadsrc/tracing/trace_event.h Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is a sync with upstream?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In sync with upstream? Nope, not yet. But that reminds me...

@ofrobots ... ^^ To implement this I needed this macro implemented also.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasnell created https://chromium-review.googlesource.com/c/v8/v8/+/924507 that adds the same macro upstream.

Note that for the trace-event macros, a sync with upstream is no longer a necessity. Our copy of trace_event.h is derived from upstream, but has a slightly different implementation. It is okay for them to pick up features at a different pace. Please do continue to ping if we add more macros locally. There is no need to block on upstream.

@mcollinamcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a nit

Comment threaddoc/api/tracing.md Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The flag should be named --trace-events-categories for consistency.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This flag already exists and is not introduced by this PR

Adds the `node.perf.usertiming` trace events category for recording
usertiming marks and measures (e.g. `perf_hooks.performance.mark()`)
in the trace events timeline.
Adds the `node.perf.function` trace events category for recording
`perf_hooks.performance.timerify()` durations in the trace events
timeline.
@jasnelljasnell added the semver-minor PRs that contain new features and should be released in the next minor version. label Feb 26, 2018
jasnell added a commit that referenced this pull request Feb 26, 2018
PR-URL: #18789
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
jasnell added a commit that referenced this pull request Feb 26, 2018
Adds the `node.perf.usertiming` trace events category for recording
usertiming marks and measures (e.g. `perf_hooks.performance.mark()`)
in the trace events timeline.
Adds the `node.perf.function` trace events category for recording
`perf_hooks.performance.timerify()` durations in the trace events
timeline.
PR-URL: #18789
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
jasnell added a commit that referenced this pull request Feb 26, 2018
PR-URL: #18789
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
@jasnell

Copy link
Copy Markdown
MemberAuthor

Landed in aca8e76, 9e509b6, and 009e418

@jasnelljasnell closed this Feb 26, 2018
@MylesBorins

Copy link
Copy Markdown
Contributor

Should this be backported to v9.x-staging? If yes please follow the guide and raise a backport PR, if not let me know or add the dont-land-on label.

@targos

Copy link
Copy Markdown
Member

This depends on #17640 which can't go in v9.x.

@targostargos added dont-land-on-v9.x and removed author ready PRs that have at least one approval, no pending requests for changes, and a CI started. backport-requested-v9.x labels Apr 2, 2018
MayaLekova pushed a commit to MayaLekova/node that referenced this pull request May 8, 2018
PR-URL: nodejs#18789
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
MayaLekova pushed a commit to MayaLekova/node that referenced this pull request May 8, 2018
Adds the `node.perf.usertiming` trace events category for recording
usertiming marks and measures (e.g. `perf_hooks.performance.mark()`)
in the trace events timeline.
Adds the `node.perf.function` trace events category for recording
`perf_hooks.performance.timerify()` durations in the trace events
timeline.
PR-URL: nodejs#18789
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
MayaLekova pushed a commit to MayaLekova/node that referenced this pull request May 8, 2018
PR-URL: nodejs#18789
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Trott pushed a commit to ZauberNerd/node that referenced this pull request Dec 11, 2020
This reverts commit 009e418.
AFAIU the discussion at [1], PerformanceObserver had been made to
inherit from AsyncResource more or less as a band-aid in lack of a
better async_context candidate to invoke it in. In order to enable
access to AsyncLocalStores from PerformanceObservers invoked
synchronously through e.g. measure() or mark(), the current
async_context, if any, should be retained.
Note that this is a breaking change, but
- as has been commented at [1], PerformanceObserver being derived from
AsyncResource is a "minor divergence from the spec" anyway,
- to my knowledge this is an internal implementation detail which has
never been documented and
- I can't think of a good reason why existing PerformanceObserver
implementations would possibly rely on it.
OTOH, it's probably worthwhile to not potentially invoke before() and
after() async_hooks for each and every PerformanceObserver notification.
[1] nodejs#18789
Co-Authored-By: ZauberNerd <zaubernerd@zaubernerd.de>
PR-URL: nodejs#36343
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
targos pushed a commit that referenced this pull request Dec 21, 2020
This reverts commit 009e418.
AFAIU the discussion at [1], PerformanceObserver had been made to
inherit from AsyncResource more or less as a band-aid in lack of a
better async_context candidate to invoke it in. In order to enable
access to AsyncLocalStores from PerformanceObservers invoked
synchronously through e.g. measure() or mark(), the current
async_context, if any, should be retained.
Note that this is a breaking change, but
- as has been commented at [1], PerformanceObserver being derived from
AsyncResource is a "minor divergence from the spec" anyway,
- to my knowledge this is an internal implementation detail which has
never been documented and
- I can't think of a good reason why existing PerformanceObserver
implementations would possibly rely on it.
OTOH, it's probably worthwhile to not potentially invoke before() and
after() async_hooks for each and every PerformanceObserver notification.
[1] #18789
Co-Authored-By: ZauberNerd <zaubernerd@zaubernerd.de>
PR-URL: #36343
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++Issues and PRs that require attention from people who are familiar with C++.perf_hooksIssues and PRs related to the implementation of the Performance Timing API.semver-minorPRs that contain new features and should be released in the next minor version.trace_eventsIssues and PRs related to V8, Node.js core, and userspace code trace events.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants

@jasnell@AndreasMadsen@MylesBorins@targos@mcollina@ofrobots@BridgeAR@nodejs-github-bot