forked from nodejs/node-v0.x-archive
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_dtrace.cc
More file actions
113 lines (84 loc) · 2.88 KB
/
node_dtrace.cc
File metadata and controls
113 lines (84 loc) · 2.88 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include <node_dtrace.h>
#ifdef HAVE_DTRACE
#include "node_provider.h"
#else
#define NODE_HTTP_SERVER_REQUEST(arg0, arg1)
#define NODE_HTTP_SERVER_REQUEST_ENABLED() (0)
#define NODE_HTTP_SERVER_RESPONSE(arg0)
#define NODE_HTTP_SERVER_RESPONSE_ENABLED() (0)
#define NODE_NET_SERVER_CONNECTION(arg0)
#define NODE_NET_SERVER_CONNECTION_ENABLED() (0)
#define NODE_NET_STREAM_END(arg0)
#define NODE_NET_STREAM_END_ENABLED() (0)
#endif
namespace node {
using namespace v8;
#define SLURP_STRING(obj, member, valp) \
String::Utf8Value _##member(obj->Get(String::New(#member))->ToString()); \
if ((*(const char **)valp = *_##member) == NULL) \
*(const char **)valp = "<unknown>";
#define SLURP_INT(obj, member, valp) \
*valp = obj->Get(String::New(#member))->ToInteger()->Value();
#define SLURP_CONNECTION(arg, conn) \
node_dtrace_connection_t conn; \
Local<Object> _##conn = Local<Object>::Cast(arg); \
SLURP_INT(_##conn, fd, &conn.fd); \
SLURP_STRING(_##conn, remoteAddress, &conn.remote); \
SLURP_INT(_##conn, remotePort, &conn.port);
Handle<Value> DTRACE_NET_SERVER_CONNECTION(const Arguments& args) {
if (!NODE_NET_SERVER_CONNECTION_ENABLED())
return Undefined();
HandleScope scope;
SLURP_CONNECTION(args[0], conn);
NODE_NET_SERVER_CONNECTION(&conn);
return Undefined();
}
Handle<Value> DTRACE_NET_STREAM_END(const Arguments& args) {
if (!NODE_NET_STREAM_END_ENABLED())
return Undefined();
HandleScope scope;
SLURP_CONNECTION(args[0], conn);
NODE_NET_STREAM_END(&conn);
return Undefined();
}
Handle<Value> DTRACE_HTTP_SERVER_REQUEST(const Arguments& args) {
node_dtrace_http_request_t req;
if (!NODE_HTTP_SERVER_REQUEST_ENABLED())
return Undefined();
HandleScope scope;
Local<Object> arg0 = Local<Object>::Cast(args[0]);
Local<Object> arg1 = Local<Object>::Cast(args[1]);
SLURP_STRING(arg0, url, &req.url);
SLURP_STRING(arg0, method, &req.method);
SLURP_CONNECTION(args[1], conn);
NODE_HTTP_SERVER_REQUEST(&req, &conn);
return Undefined();
}
Handle<Value> DTRACE_HTTP_SERVER_RESPONSE(const Arguments& args) {
if (!NODE_HTTP_SERVER_RESPONSE_ENABLED())
return Undefined();
HandleScope scope;
SLURP_CONNECTION(args[0], conn);
NODE_HTTP_SERVER_RESPONSE(&conn);
return Undefined();
}
#define NODE_PROBE(name) #name, name
void InitDTrace(Handle<Object> target) {
static struct {
const char *name;
Handle<Value> (*func)(const Arguments&);
Persistent<FunctionTemplate> templ;
} tab[] = {
{ NODE_PROBE(DTRACE_NET_SERVER_CONNECTION) },
{ NODE_PROBE(DTRACE_NET_STREAM_END) },
{ NODE_PROBE(DTRACE_HTTP_SERVER_REQUEST) },
{ NODE_PROBE(DTRACE_HTTP_SERVER_RESPONSE) },
{ NULL }
};
for (int i = 0; tab[i].name != NULL; i++) {
tab[i].templ = Persistent<FunctionTemplate>::New(
FunctionTemplate::New(tab[i].func));
target->Set(String::NewSymbol(tab[i].name), tab[i].templ->GetFunction());
}
}
}