-
Notifications
You must be signed in to change notification settings - Fork 983
/
Copy pathdtrace.js
80 lines (61 loc) · 2.09 KB
/
dtrace.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright 2012 Mark Cavage, Inc. All rights reserved.
///--- Globals
'use strict';
var ID = 0;
var MAX_INT = Math.pow(2, 32) - 1;
var PROBES = {
// server_name, route_name, id, method, url, headers (json)
'route-start': ['char *', 'char *', 'int', 'char *', 'char *', 'json'],
// server_name, route_name, handler_name, id
'handler-start': ['char *', 'char *', 'char *', 'int'],
// server_name, route_name, handler_name, id
'handler-done': ['char *', 'char *', 'char *', 'int'],
// server_name, route_name, id, statusCode, headers (json)
'route-done': ['char *', 'char *', 'int', 'int', 'json'],
// Client probes
// method, url, headers, id
'client-request': ['char *', 'char *', 'json', 'int'],
// id, statusCode, headers
'client-response': ['int', 'int', 'json'],
// id, Error.toString()
'client-error': ['id', 'char *']
};
var PROVIDER;
///--- API
// eslint-disable-next-line wrap-iife
module.exports = (function exportStaticProvider() {
if (!PROVIDER) {
try {
var dtrace = require('dtrace-provider');
PROVIDER = dtrace.createDTraceProvider('restify');
} catch (e) {
PROVIDER = {
fire: function fire() {},
enable: function enable() {},
addProbe: function addProbe() {
var p = {
fire: function fire() {}
};
return p;
},
removeProbe: function removeProbe() {},
disable: function disable() {}
};
}
PROVIDER._rstfy_probes = {};
Object.keys(PROBES).forEach(function forEach(p) {
var args = PROBES[p].splice(0);
args.unshift(p);
var probe = PROVIDER.addProbe.apply(PROVIDER, args);
PROVIDER._rstfy_probes[p] = probe;
});
PROVIDER.enable();
PROVIDER.nextId = function nextId() {
if (++ID >= MAX_INT) {
ID = 1;
}
return ID;
};
}
return PROVIDER;
})();