This depends on libuv:373
I've been thinking about long stack traces for a long time now. The performance hit of trying to calculate the entire trace in production is unacceptable. However in a production system it is often desirable to unwind a transaction to determine just what happend. In some cases this may mean a long stack trace of the offending transaction, in others it may be sufficient to be able to trace through the log.
Given that asynchronous events produce logs that are... challenging for humans to read I wanted to come up with something that could help. Given the non-opinionated nature of core it needs to be small and non-invasive.
It is at this time that I will point out that I do not claim to be wise, nor do I know if this problem has already been solved sufficiently in userland. I would also like to be clear that I believe the proper domain for a complete solution is going to be userland. However I do think that a little help is in order.
The problem with unwinding an asynchronous log is order. To that end I am proposing to expose a monotonically increasing counter or tick count on the process object. Every turn of the event loop will increase the counter. Any non-blocking function like process.nextTick will also increase this value.
I have not done so in this pull, but I would also like to discuss the possibility of exposing the value of tick when a given callback was "primed" or a tock value e.g.
// process.tick === 0
// process.tick === 1
// process.tock === 0
If you've read all the way to the end of this, I thank you for your time, I'm sure we are all lovers of wisdom as it were, so comments are not just welcomed, but desired. Really, what I'm after is: If you know where you are, and where you were, that should be enough to draw a line into the past to find out what happend.
Implement uv tick count in node
Can one of the admins verify this patch?
Hi, thanks for interest, a monotonic counter is an interesting idea but I'm not sure if it provides the benefit you're looking for. As far as long stack traces and transaction tracing is concerned we've landed async listener which was designed specifically for that.
That being said, I've toyed with the idea of process.on('turn-start') and process.on('turn-stop') and I think it's a worth while concept to expose, though its use is somewhat suspect at the moment.