LearnBoost/mongoose — pull request #2074 by Avnerus (2014-05-14 15:16:47+00:00)
Title: Add DTrace to mongoose queries

Hi!
I was wondering if you can review my attempt to add DTrace probes to mongoose queries.
Inspired by the node-restify DTrace probes, I tried to add probing at key query functions in mongoose so I can profile my DB queries.
I'm using the following DTrace script to track both mongoose and restify to profile my server:

```
#!/usr/sbin/dtrace -s
#pragma D option quiet
#pragma D option dynvarsize=128m

restify*:::route-start
{
track[arg2] = timestamp;
}

restify*:::handler-start
/track[arg3]/
{
h[arg3, copyinstr(arg2)] = timestamp;
}

restify*:::handler-done
/track[arg3] && h[arg3, copyinstr(arg2)]/
{
@[copyinstr(arg2)] = quantize((timestamp - h[arg3, copyinstr(arg2)]) / 1000000);
h[arg3, copyinstr(arg2)] = 0;
}

restify*:::route-done
/track[arg2]/
{
@[copyinstr(arg1)] = quantize((timestamp - track[arg2]) / 1000000);
track[arg2] = 0;
}

mongoose*:::query-start
{
mongotrack[arg2] = timestamp;
}

mongoose*:::query-done
/mongotrack[arg2]/
{
@[strjoin(strjoin(copyinstr(arg0),"-"),copyinstr(arg1))] = quantize((timestamp - mongotrack[arg2]) / 1000000);
mongotrack[arg2] = 0;
}
```
The output show a histogram of the execution time of queries such as -
{modelName}-save
{modelName}-findOne
{modelName}-update

etc

Thank you!

- Avner