You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add trace_events Clock Sync Event for Date.now() and hrtime() #17349
trace_events has an internal clock, this makes it very difficult to correlate the data with other external data. I would suggest that we emit a Clock Sync Event on startup for synchronizing with Date.now() and process.hrtime().
/cc @nodejs/v8 - as we currently lack a trace_events specialist.
Definitely +1 on this. @bnoordhuis ... the trace events implementation in core was never completed and has quite a bit that has not been implemented yet. Specifically, none of the _WITH_TIMESTAMP macro variations have any implementation at all.
@matthewloring moved on to a different role within Google. @ofrobots@JustinBeckwith ... has there been any progress in identifying who will be following up on the trace events impl in core?
Hi Folks! 👋 Sorry for the late reply @matthewloring was previously working on trace events, but since he is no longer working on the same team, @kjin and I are ramping up on the trace event implementation.
There have been some changes made upstream to make it easier for embedders to reuse the libplatform implementation of tracing controller rather than having to duplicate. See changes on this bug: https://bugs.chromium.org/p/v8/issues/detail?id=6511. @kjin and I are presently digesting this to understand how this could be utilized over in node.
For now, I would recommend to just sync the trace_event_common.h file as that macro does not require any changes on the back-end since it uses an existing internal macro.
Meanwhile, I will check with @ofrobots if we can reuse the existing file from V8 directly now since some parts have already been exposed.
Hi Folks. I have been doing some research, and here are my findings based on the Trace Event Clock Sync design document. As far as I understand the TRACE_EVENT_CLOCK_SYNC_ISSUER and *_RECEIVER macros are for the scenario where one has multiple individual trace event agents, each writing their logs separately. In the Node use-case, both Node and V8 write to the same agent, and the same IO sink (log file at present), so those macros wouldn't actually help.
trace_events has an internal clock, this makes it very difficult to correlate the data with other external data.
Can you elaborate a little bit more on where/how you saw the timestamps to differ? Trace events timestamps are based on the V8 TimeTicks class. Specifically we use the HighResolutionNow. At least on linux, I think the time source is the same as uv_hrtime, but other platforms I see this as possibly differing. Can you confirm which environment you saw the time domain differing?
There are a few ways I can think we can fix things:
Change the implementation of trace event in Node.js so that it uses a Platform provided hrtime function which we can back using uv_hrtime. This would require some API changes in the V8 platform to allow an embedder to provide a clock source. (/cc @hashseed)
Add a normal event (but not a .._CLOCK_SYNC_ISSUER) to allow trace log readers to correlate V8 TimerTicks timestamps to process.hrtime (and possibly Date.now) timestamps.
Note that on my system the difference between process.hrtime and trace event internal timestamps is the units – nano seconds vs micro seconds.
I'm going to mull over these options and evaluate feasibility, but if anyone has opinions, or if I have understood something incorrectly, please do share your thoughts.
Another thing to consider here is that at least @jasnell has expressed a desire to be able to use the TRACE_EVENT_*_WITH_TIMESTAMP macros which suggests that we want to provide our own timestamps anyway. I think this suggests a preference for option 1.
@jasnell can you elaborate on your use-case for providing own timestamps while I am thinking this over?
Hi Folks. I have been doing some research, and here are my findings based on the Trace Event Clock Sync design document. As far as I understand the TRACE_EVENT_CLOCK_SYNC_ISSUER and *_RECEIVER macros are for the scenario where one has multiple individual trace event agents, each writing their logs separately. In the Node use-case, both Node and V8 write to the same agent, and the same IO sink (log file at present), so those macros wouldn't actually help.
That is the primary use case. As I understand it, the reason why the CLOCK_SYNC is so complicated is to compensate for the small amount of time it takes to get the timestamp and call the macro. By making it a two way protocol, the delay can be messaured and compensated for later. In my opinion, this is over engineered.
Can you elaborate a little bit more on where/how you saw the timestamps to differ? Trace events timestamps are based on the V8 TimeTicks class. Specifically we use the HighResolutionNow. At least on linux, I think the time source is the same as uv_hrtime, but other platforms I see this as possibly differing. Can you confirm which environment you saw the time domain differing?
Oh, they do appear to match. I confirmed this on Mac. The big issues are then that it is not documented, nor gaurantteed to always align. I could be that they are the same, at least uv_hrtime on windows appears to use QueryPerformanceCounter too.
There are a few ways I can think we can fix things.
I'm fine with both options, with a slight preference for the first option.
With the preference for the first option, here's a proposed V8 change that allows embedders (i.e. Node) to provide the backing time source for the trace event timestamps: https://chromium-review.googlesource.com/c/v8/v8/+/847690. Once that is in place, it should be a fairly simple change in Node to start using uv_hrtime.
Activity
bnoordhuis commentedon Nov 27, 2017
You mean adding a
TRACE_EVENT_CLOCK_SYNC_ISSUER()in the right place? Seems fine to me, I'd say go for it.AndreasMadsen commentedon Nov 27, 2017
Oh, brilliant. I was looking to see if we had the macro but I couldn't find it. This makes it much easier.
AndreasMadsen commentedon Nov 27, 2017
As suspected it is not implemented:
node/src/tracing/trace_event.h
Line 213 in 212b12c
bnoordhuis commentedon Nov 27, 2017
Curious, it exists in deps/v8/base:
node/deps/v8/base/trace_event/common/trace_event_common.h
Lines 922 to 926 in 4ca4db0
Time to sync up again, I suppose?
cc @matthewloring - do you still work on tracing?
targos commentedon Nov 27, 2017
should I add something to
update-v8that syncs this file?AndreasMadsen commentedon Nov 27, 2017
@bnoordhuis It is
INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMPthat isn't implemented.jasnell commentedon Nov 27, 2017
Definitely +1 on this. @bnoordhuis ... the trace events implementation in core was never completed and has quite a bit that has not been implemented yet. Specifically, none of the
_WITH_TIMESTAMPmacro variations have any implementation at all.@matthewloring moved on to a different role within Google.
@ofrobots @JustinBeckwith ... has there been any progress in identifying who will be following up on the trace events impl in core?
ofrobots commentedon Nov 29, 2017
Hi Folks! 👋 Sorry for the late reply @matthewloring was previously working on trace events, but since he is no longer working on the same team, @kjin and I are ramping up on the trace event implementation.
There have been some changes made upstream to make it easier for embedders to reuse the libplatform implementation of tracing controller rather than having to duplicate. See changes on this bug: https://bugs.chromium.org/p/v8/issues/detail?id=6511. @kjin and I are presently digesting this to understand how this could be utilized over in node.
fmeawad commentedon Nov 29, 2017
For now, I would recommend to just sync the trace_event_common.h file as that macro does not require any changes on the back-end since it uses an existing internal macro.
Meanwhile, I will check with @ofrobots if we can reuse the existing file from V8 directly now since some parts have already been exposed.
ofrobots commentedon Dec 27, 2017
Hi Folks. I have been doing some research, and here are my findings based on the Trace Event Clock Sync design document. As far as I understand the
TRACE_EVENT_CLOCK_SYNC_ISSUERand*_RECEIVERmacros are for the scenario where one has multiple individual trace event agents, each writing their logs separately. In the Node use-case, both Node and V8 write to the same agent, and the same IO sink (log file at present), so those macros wouldn't actually help.@AndreasMadsen
Can you elaborate a little bit more on where/how you saw the timestamps to differ? Trace events timestamps are based on the V8
TimeTicksclass. Specifically we use theHighResolutionNow. At least on linux, I think the time source is the same asuv_hrtime, but other platforms I see this as possibly differing. Can you confirm which environment you saw the time domain differing?There are a few ways I can think we can fix things:
hrtimefunction which we can back usinguv_hrtime. This would require some API changes in the V8 platform to allow an embedder to provide a clock source. (/cc @hashseed).._CLOCK_SYNC_ISSUER) to allow trace log readers to correlate V8 TimerTicks timestamps toprocess.hrtime(and possiblyDate.now) timestamps.The latter would be something along the lines of:
Note that on my system the difference between
process.hrtimeand trace event internal timestamps is the units – nano seconds vs micro seconds.I'm going to mull over these options and evaluate feasibility, but if anyone has opinions, or if I have understood something incorrectly, please do share your thoughts.
ofrobots commentedon Dec 27, 2017
Another thing to consider here is that at least @jasnell has expressed a desire to be able to use the
TRACE_EVENT_*_WITH_TIMESTAMPmacros which suggests that we want to provide our own timestamps anyway. I think this suggests a preference for option 1.@jasnell can you elaborate on your use-case for providing own timestamps while I am thinking this over?
AndreasMadsen commentedon Dec 28, 2017
That is the primary use case. As I understand it, the reason why the
CLOCK_SYNCis so complicated is to compensate for the small amount of time it takes to get the timestamp and call the macro. By making it a two way protocol, the delay can be messaured and compensated for later. In my opinion, this is over engineered.Oh, they do appear to match. I confirmed this on Mac. The big issues are then that it is not documented, nor gaurantteed to always align. I could be that they are the same, at least uv_hrtime on windows appears to use
QueryPerformanceCountertoo.I'm fine with both options, with a slight preference for the first option.
ofrobots commentedon Jan 2, 2018
With the preference for the first option, here's a proposed V8 change that allows embedders (i.e. Node) to provide the backing time source for the trace event timestamps: https://chromium-review.googlesource.com/c/v8/v8/+/847690. Once that is in place, it should be a fairly simple change in Node to start using
uv_hrtime.Assigning issue to self.
18 remaining items
deps: cherry-pick 814577e from upstream V8
deps: cherry-pick c3bb73f from upstream V8
src: use uv_hrtime as tracing timestamp
deps: cherry-pick 814577e from upstream V8
deps: cherry-pick c3bb73f from upstream V8