joyent/node — pull request #3074 by seebees (2012-04-08 04:39:37+00:00)
Title: proccess.tick should the current turn of the event loop

This depends on libuv:[373](https://github.com/joyent/libuv/pull/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.

```javascript
// process.tick === 0
process.nextTick(function() {
// 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.