UNPKG

1.98 kBJavaScriptView Raw
1/*
2 * Copyright (c) 2012 Dmitri Melikyan
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to permit
9 * persons to whom the Software is furnished to do so, subject to the
10 * following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
18 * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23
24
25var nt;
26
27exports.init = function() {
28 nt = global.nodetime;
29 // trying to initialize dtrace provider
30 var dtp = undefined;
31 try {
32 var d = require("dtrace-provider");
33 dtp = d.createDTraceProvider("nodetime");
34 dtp.addProbe("api-call-start", "int", "char *", "char *");
35 dtp.addProbe("api-call-done", "int", "char *", "char *");
36 dtp.enable();
37 }
38 catch(err) {
39 this.error(err)
40 }
41
42
43 // firing dtrace events on calls
44 if(dtp) {
45 nt.on('call', function(point, time) {
46 try {
47 var scope = time.scope.replace(/\s/g, '-').toLowerCase();
48 var command = time.command.replace(/\s/g, '-').toLowerCase();
49 dtp.fire('api-call-' + point, function() {
50 return [time.id, scope, command];
51 });
52 }
53 catch(err) {
54 nt.error(err)
55 }
56 });
57 }
58};
59
60