Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf_hooks/trace_events - nested measurements don't work as expected #32281

Open
bmacnaughton opened this issue Mar 15, 2020 · 1 comment
Open
Labels
trace_events Issues and PRs related to V8, Node.js core, and userspace code trace events.

Comments

@bmacnaughton
Copy link
Contributor

'use strict';

const trace_events = require('trace_events');
const {performance: perf} = require('perf_hooks');
const fs = require('fs');

const tracing = trace_events.createTracing({
  categories: ['node.perf.usertiming'],
});

tracing.enable();
fs.readdirSync('.');
perf.mark('A');
fs.readdirSync('.');
perf.mark('B');
fs.readdirSync('.');
perf.mark('C');
perf.measure('B => C', 'B', 'C');
fs.readdirSync('.');
perf.mark('D');
perf.measure('A => D', 'A', 'D');
fs.readdirSync('.');
tracing.disable();

How often does it reproduce? Is there a required condition?

It reproduces every time.

What is the expected behavior?

i expect that A => D be shorter than JavaScriptMainThread and that A => D would be selectable in chrome://tracing. It's possible that it's just an omission from the documentation or that I missed a note that measurements cannot be nested.

What do you see instead?

image

node_trace.1.log:

{"traceEvents":[{"pid":29578,"tid":29578,"ts":1819702786241,"tts":22090,"ph":"M","cat":"__metadata","name":"process_name","dur":0,"tdur":0,"args":{"name":"node"}},{"pid":29578,"tid":29578,"ts":1819702786243,"tts":22092,"ph":"M","cat":"__metadata","name":"version","dur":0,"tdur":0,"args":{"node":"12.16.1"}},{"pid":29578,"tid":29578,"ts":1819702786245,"tts":22094,"ph":"M","cat":"__metadata","name":"thread_name","dur":0,"tdur":0,"args":{"name":"JavaScriptMainThread"}},{"pid":29578,"tid":29578,"ts":1819702786252,"tts":22101,"ph":"M","cat":"__metadata","name":"node","dur":0,"tdur":0,"args":{"process":{"versions":{"node":"12.16.1","v8":"7.8.279.23-node.31","uv":"1.34.0","zlib":"1.2.11","brotli":"1.0.7","ares":"1.15.0","modules":"72","nghttp2":"1.40.0","napi":"5","llhttp":"2.0.4","http_parser":"2.9.3","openssl":"1.1.1d","cldr":"35.1","icu":"64.2","tz":"2019c","unicode":"12.1"},"arch":"x64","platform":"linux","release":{"name":"node","lts":"Erbium"}}}},{"pid":29578,"tid":29578,"ts":1819702786241,"tts":22090,"ph":"M","cat":"__metadata","name":"process_name","dur":0,"tdur":0,"args":{"name":"node"}},{"pid":29578,"tid":29578,"ts":1819702786243,"tts":22092,"ph":"M","cat":"__metadata","name":"version","dur":0,"tdur":0,"args":{"node":"12.16.1"}},{"pid":29578,"tid":29578,"ts":1819702786245,"tts":22094,"ph":"M","cat":"__metadata","name":"thread_name","dur":0,"tdur":0,"args":{"name":"JavaScriptMainThread"}},{"pid":29578,"tid":29578,"ts":1819702786252,"tts":22101,"ph":"M","cat":"__metadata","name":"node","dur":0,"tdur":0,"args":{"process":{"versions":{"node":"12.16.1","v8":"7.8.279.23-node.31","uv":"1.34.0","zlib":"1.2.11","brotli":"1.0.7","ares":"1.15.0","modules":"72","nghttp2":"1.40.0","napi":"5","llhttp":"2.0.4","http_parser":"2.9.3","openssl":"1.1.1d","cldr":"35.1","icu":"64.2","tz":"2019c","unicode":"12.1"},"arch":"x64","platform":"linux","release":{"name":"node","lts":"Erbium"}}}},{"pid":29578,"tid":29578,"ts":1819702786664,"tts":22261,"ph":"R","cat":"node,node.perf,node.perf.usertiming","name":"A","dur":0,"tdur":0,"args":{}},{"pid":29578,"tid":29578,"ts":1819702786702,"tts":22295,"ph":"R","cat":"node,node.perf,node.perf.usertiming","name":"B","dur":0,"tdur":0,"args":{}},{"pid":29578,"tid":29578,"ts":1819702786720,"tts":22313,"ph":"R","cat":"node,node.perf,node.perf.usertiming","name":"C","dur":0,"tdur":0,"args":{}},{"pid":29578,"tid":29578,"ts":1819702786702,"tts":22350,"ph":"b","cat":"node,node.perf,node.perf.usertiming","name":"B => C","dur":0,"tdur":0,"id":"0x7ffd671fc568","args":{}},{"pid":29578,"tid":29578,"ts":1819702786720,"tts":22352,"ph":"e","cat":"node,node.perf,node.perf.usertiming","name":"B => C","dur":0,"tdur":0,"id":"0x7ffd671fc568","args":{}},{"pid":29578,"tid":29578,"ts":1819702786782,"tts":22375,"ph":"R","cat":"node,node.perf,node.perf.usertiming","name":"D","dur":0,"tdur":0,"args":{}},{"pid":29578,"tid":29578,"ts":1819702786664,"tts":22379,"ph":"b","cat":"node,node.perf,node.perf.usertiming","name":"A => D","dur":0,"tdur":0,"id":"0x7ffd671fc568","args":{}},{"pid":29578,"tid":29578,"ts":1819702786782,"tts":22381,"ph":"e","cat":"node,node.perf,node.perf.usertiming","name":"A => D","dur":0,"tdur":0,"id":"0x7ffd671fc568","args":{}},{"pid":29578,"tid":29578,"ts":1819702786241,"tts":22090,"ph":"M","cat":"__metadata","name":"process_name","dur":0,"tdur":0,"args":{"name":"node"}},{"pid":29578,"tid":29578,"ts":1819702786243,"tts":22092,"ph":"M","cat":"__metadata","name":"version","dur":0,"tdur":0,"args":{"node":"12.16.1"}},{"pid":29578,"tid":29578,"ts":1819702786245,"tts":22094,"ph":"M","cat":"__metadata","name":"thread_name","dur":0,"tdur":0,"args":{"name":"JavaScriptMainThread"}},{"pid":29578,"tid":29578,"ts":1819702786252,"tts":22101,"ph":"M","cat":"__metadata","name":"node","dur":0,"tdur":0,"args":{"process":{"versions":{"node":"12.16.1","v8":"7.8.279.23-node.31","uv":"1.34.0","zlib":"1.2.11","brotli":"1.0.7","ares":"1.15.0","modules":"72","nghttp2":"1.40.0","napi":"5","llhttp":"2.0.4","http_parser":"2.9.3","openssl":"1.1.1d","cldr":"35.1","icu":"64.2","tz":"2019c","unicode":"12.1"},"arch":"x64","platform":"linux","release":{"name":"node","lts":"Erbium"}}}},{"pid":29578,"tid":29578,"ts":1819702786241,"tts":22090,"ph":"M","cat":"__metadata","name":"process_name","dur":0,"tdur":0,"args":{"name":"node"}},{"pid":29578,"tid":29578,"ts":1819702786243,"tts":22092,"ph":"M","cat":"__metadata","name":"version","dur":0,"tdur":0,"args":{"node":"12.16.1"}},{"pid":29578,"tid":29578,"ts":1819702786245,"tts":22094,"ph":"M","cat":"__metadata","name":"thread_name","dur":0,"tdur":0,"args":{"name":"JavaScriptMainThread"}},{"pid":29578,"tid":29578,"ts":1819702786252,"tts":22101,"ph":"M","cat":"__metadata","name":"node","dur":0,"tdur":0,"args":{"process":{"versions":{"node":"12.16.1","v8":"7.8.279.23-node.31","uv":"1.34.0","zlib":"1.2.11","brotli":"1.0.7","ares":"1.15.0","modules":"72","nghttp2":"1.40.0","napi":"5","llhttp":"2.0.4","http_parser":"2.9.3","openssl":"1.1.1d","cldr":"35.1","icu":"64.2","tz":"2019c","unicode":"12.1"},"arch":"x64","platform":"linux","release":{"name":"node","lts":"Erbium"}}}},{"pid":29578,"tid":29578,"ts":1819702786241,"tts":22090,"ph":"M","cat":"__metadata","name":"process_name","dur":0,"tdur":0,"args":{"name":"node"}},{"pid":29578,"tid":29578,"ts":1819702786243,"tts":22092,"ph":"M","cat":"__metadata","name":"version","dur":0,"tdur":0,"args":{"node":"12.16.1"}},{"pid":29578,"tid":29578,"ts":1819702786245,"tts":22094,"ph":"M","cat":"__metadata","name":"thread_name","dur":0,"tdur":0,"args":{"name":"JavaScriptMainThread"}},{"pid":29578,"tid":29578,"ts":1819702786252,"tts":22101,"ph":"M","cat":"__metadata","name":"node","dur":0,"tdur":0,"args":{"process":{"versions":{"node":"12.16.1","v8":"7.8.279.23-node.31","uv":"1.34.0","zlib":"1.2.11","brotli":"1.0.7","ares":"1.15.0","modules":"72","nghttp2":"1.40.0","napi":"5","llhttp":"2.0.4","http_parser":"2.9.3","openssl":"1.1.1d","cldr":"35.1","icu":"64.2","tz":"2019c","unicode":"12.1"},"arch":"x64","platform":"linux","release":{"name":"node","lts":"Erbium"}}}},{"pid":29578,"tid":29578,"ts":1819702786241,"tts":22090,"ph":"M","cat":"__metadata","name":"process_name","dur":0,"tdur":0,"args":{"name":"node"}},{"pid":29578,"tid":29578,"ts":1819702786243,"tts":22092,"ph":"M","cat":"__metadata","name":"version","dur":0,"tdur":0,"args":{"node":"12.16.1"}},{"pid":29578,"tid":29578,"ts":1819702786245,"tts":22094,"ph":"M","cat":"__metadata","name":"thread_name","dur":0,"tdur":0,"args":{"name":"JavaScriptMainThread"}},{"pid":29578,"tid":29578,"ts":1819702786252,"tts":22101,"ph":"M","cat":"__metadata","name":"node","dur":0,"tdur":0,"args":{"process":{"versions":{"node":"12.16.1","v8":"7.8.279.23-node.31","uv":"1.34.0","zlib":"1.2.11","brotli":"1.0.7","ares":"1.15.0","modules":"72","nghttp2":"1.40.0","napi":"5","llhttp":"2.0.4","http_parser":"2.9.3","openssl":"1.1.1d","cldr":"35.1","icu":"64.2","tz":"2019c","unicode":"12.1"},"arch":"x64","platform":"linux","release":{"name":"node","lts":"Erbium"}}}}]}

Additional information

@legendecas legendecas added the trace_events Issues and PRs related to V8, Node.js core, and userspace code trace events. label Mar 15, 2020
@jeluard
Copy link

jeluard commented May 5, 2024

I can't make this example generate traces for node.perf.usertiming with recent node releases. Is it still supported?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
trace_events Issues and PRs related to V8, Node.js core, and userspace code trace events.
Projects
None yet
Development

No branches or pull requests

3 participants