forked from bfar/node-dtrace-provider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dtrace_provider.h
230 lines (182 loc) · 4.3 KB
/
dtrace_provider.h
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#include <node.h>
#include <node_object_wrap.h>
#include <v8.h>
#ifdef _HAVE_DTRACE
#include <sys/dtrace.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#ifndef __APPLE__
#include <stdlib.h>
#include <malloc.h>
#endif
#ifdef __APPLE__
#define FUNC_SIZE 32
#define IS_ENABLED_FUNC_LEN 12
#else
#define FUNC_SIZE 96
#define IS_ENABLED_FUNC_LEN 32
#endif
#define ARGTYPE_INT 1
#define ARGTYPE_CHAR 2
namespace node {
using namespace v8;
class DTraceProbe {
public:
dof_stridx_t name;
dof_stridx_t func;
dof_stridx_t nargv;
dof_stridx_t xargv;
uint16_t noffs;
uint32_t enoffidx;
uint32_t argidx;
uint16_t nenoffs;
uint32_t offidx;
uint8_t nargc;
uint8_t xargc;
void *addr;
DTraceProbe *next;
int types[6];
DTraceProbe() {
next = NULL;
}
~DTraceProbe() {
free(addr);
}
void *Dof();
uint32_t ProbeOffset(char *dof, uint8_t argc);
uint32_t IsEnabledOffset(char *dof);
void CreateTracepoints();
void Fire(Local<Array> a);
};
class DTraceProbeDef {
public:
char *function;
char *types[7];
char *name;
DTraceProbe *probe;
DTraceProbeDef *next;
DTraceProbeDef() {
next = NULL;
name = NULL;
function = NULL;
probe = NULL;
}
uint8_t Argc();
~DTraceProbeDef() {
delete probe;
delete next;
free(name);
for (int i = 0; (types[i] != NULL && i < 7); i++)
free(types[i]);
}
private:
};
class DOFSection {
public:
dof_secidx_t index;
uint32_t type;
uint32_t flags;
uint32_t align;
uint64_t offset;
uint64_t size;
uint32_t entsize;
size_t pad;
DOFSection *next;
char *data;
DOFSection(uint32_t type, dof_secidx_t index) {
this->type = type;
this->index = index;
this->flags = DOF_SECF_LOAD;
this->offset = 0;
this->size = 0;
this->entsize = 0;
this->pad = 0;
this->next = NULL;
this->data = NULL;
switch(type) {
case DOF_SECT_COMMENTS: this->align = 1; break;
case DOF_SECT_STRTAB: this->align = 1; break;
case DOF_SECT_PROBES: this->align = 8; break;
case DOF_SECT_PRARGS: this->align = 1; break;
case DOF_SECT_PROFFS: this->align = 4; break;
case DOF_SECT_PRENOFFS: this->align = 4; break;
case DOF_SECT_PROVIDER: this->align = 4; break;
case DOF_SECT_UTSNAME: this->align = 1; break;
}
}
void AddData(void *data, size_t length);
void *Header();
~DOFSection() {
free(data);
delete(next);
}
private:
};
class DOFFile {
public:
char *dof;
DOFFile(size_t size) {
sections = NULL;
this->size = size;
dof = (char *) malloc(size);
}
void AppendSection(DOFSection *);
void Generate();
void Load();
~DOFFile() {
free(dof);
delete(sections);
}
private:
int gen;
size_t size;
DOFSection *sections;
};
class DOFStrtab : public DOFSection {
public:
DOFStrtab(int index) : DOFSection(DOF_SECT_STRTAB, index) {
data = NULL;
}
int Add(char *string);
~DOFStrtab() {
// data freed by superclass
}
private:
int strindex;
};
class DTraceProvider : ObjectWrap {
public:
static void Initialize(v8::Handle<v8::Object> target);
char *name;
int enabled;
DTraceProbeDef *probe_defs;
DTraceProbe *probes;
DOFFile *file;
static v8::Handle<v8::Value> New(const v8::Arguments& args);
static v8::Handle<v8::Value> AddProbe(const v8::Arguments& args);
static v8::Handle<v8::Value> Enable(const v8::Arguments& args);
static v8::Handle<v8::Value> Fire(const v8::Arguments& args);
DTraceProvider() : ObjectWrap() {
name = NULL;
probe_defs = NULL;
probes = NULL;
file = NULL;
enabled = 0;
}
~DTraceProvider() {
// disable provider first!
free(name);
delete(file);
delete(probe_defs);
}
private:
void AppendProbe(DTraceProbe *);
size_t DofSize(DOFStrtab *);
};
void InitDTraceProvider(v8::Handle<v8::Object> target);
}
#endif // _HAVE_DTRACE