mirror of
https://github.com/hanzoai/node-dtrace-provider.git
synced 2026-09-23 23:48:45 +00:00
Revert "Expose DTraceProbeDef objects into JS as probe holders."
This reverts commit 3c0cffd412.
This commit is contained in:
+59
-110
@@ -8,33 +8,25 @@
|
||||
namespace node {
|
||||
|
||||
using namespace v8;
|
||||
|
||||
Persistent<FunctionTemplate> DTraceProvider::constructor_template;
|
||||
Persistent<FunctionTemplate> DTraceProbeDef::constructor_template;
|
||||
|
||||
void DTraceProvider::Initialize(Handle<Object> target) {
|
||||
HandleScope scope;
|
||||
|
||||
Local<FunctionTemplate> t = FunctionTemplate::New(DTraceProvider::New);
|
||||
constructor_template = Persistent<FunctionTemplate>::New(t);
|
||||
constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
constructor_template->SetClassName(String::NewSymbol("DTraceProvider"));
|
||||
t->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
t->SetClassName(String::NewSymbol("DTraceProvider"));
|
||||
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor_template, "addProbe", DTraceProvider::AddProbe);
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor_template, "enable", DTraceProvider::Enable);
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor_template, "fire", DTraceProvider::Fire);
|
||||
NODE_SET_PROTOTYPE_METHOD(t, "addProbe", DTraceProvider::AddProbe);
|
||||
NODE_SET_PROTOTYPE_METHOD(t, "enable", DTraceProvider::Enable);
|
||||
NODE_SET_PROTOTYPE_METHOD(t, "fire", DTraceProvider::Fire);
|
||||
|
||||
target->Set(String::NewSymbol("DTraceProvider"), constructor_template->GetFunction());
|
||||
|
||||
DTraceProbeDef::Initialize(target);
|
||||
target->Set(String::NewSymbol("DTraceProvider"), t->GetFunction());
|
||||
}
|
||||
|
||||
Handle<Value> DTraceProvider::New(const Arguments& args) {
|
||||
HandleScope scope;
|
||||
DTraceProvider *p = new DTraceProvider();
|
||||
|
||||
p->Wrap(args.This());
|
||||
|
||||
if (args.Length() != 1 || !args[0]->IsString()) {
|
||||
return ThrowException(Exception::Error(String::New(
|
||||
"Must give provider name as argument")));
|
||||
@@ -43,6 +35,7 @@ namespace node {
|
||||
String::AsciiValue name(args[0]->ToString());
|
||||
p->name = strdup(*name);
|
||||
|
||||
p->Wrap(args.Holder());
|
||||
return args.This();
|
||||
}
|
||||
|
||||
@@ -50,15 +43,28 @@ namespace node {
|
||||
HandleScope scope;
|
||||
DTraceProvider *provider = ObjectWrap::Unwrap<DTraceProvider>(args.Holder());
|
||||
|
||||
// create a DTraceProbeDef object - hateful, what's the right way?
|
||||
Handle<Function> klass = DTraceProbeDef::constructor_template->GetFunction();
|
||||
v8::Handle<v8::Value> args2[] = {
|
||||
args[0], args[1], args[2], args[3], args[4], args[5], args[6]
|
||||
};
|
||||
Handle<Value> pd = klass->NewInstance(7, args2);
|
||||
if (!args[0]->IsString()) {
|
||||
return ThrowException(Exception::Error(String::New(
|
||||
"Must give probe name as first argument")));
|
||||
}
|
||||
|
||||
DTraceProbeDef *probe = new DTraceProbeDef();
|
||||
probe->next = NULL;
|
||||
|
||||
// init argument types
|
||||
int i;
|
||||
for (i = 0; (args[i+1]->IsString() && i < 6); i++) {
|
||||
String::AsciiValue type(args[i+1]->ToString());
|
||||
probe->types[i] = strdup(*type);
|
||||
}
|
||||
probe->types[i] = NULL;
|
||||
|
||||
// init name and function
|
||||
String::AsciiValue name(args[0]->ToString());
|
||||
probe->name = strdup(*name);
|
||||
probe->function = (char *) "func";
|
||||
|
||||
// append to probe list
|
||||
DTraceProbeDef *probe = ObjectWrap::Unwrap<DTraceProbeDef>(pd->ToObject());
|
||||
if (provider->probe_defs == NULL)
|
||||
provider->probe_defs = probe;
|
||||
else {
|
||||
@@ -66,7 +72,8 @@ namespace node {
|
||||
for (p = provider->probe_defs; (p->next != NULL); p = p->next) ;
|
||||
p->next = probe;
|
||||
}
|
||||
return pd;
|
||||
|
||||
return Undefined();
|
||||
}
|
||||
|
||||
Handle<Value> DTraceProvider::Enable(const Arguments& args) {
|
||||
@@ -222,7 +229,35 @@ namespace node {
|
||||
return Undefined();
|
||||
}
|
||||
|
||||
pd->_fire(args[1]);
|
||||
// perform is-enabled check
|
||||
DTraceProbe *p = pd->probe;
|
||||
void *(*isfunc)() = (void* (*)())(p->addr);
|
||||
long isenabled = (long)(*isfunc)();
|
||||
if (isenabled == 0) {
|
||||
return Undefined();
|
||||
}
|
||||
|
||||
// invoke fire callback
|
||||
TryCatch try_catch;
|
||||
|
||||
Local<Function> cb = Local<Function>::Cast(args[1]);
|
||||
Local<Value> probe_args = cb->Call(provider->handle_, 0, NULL);
|
||||
|
||||
// exception in args callback?
|
||||
if (try_catch.HasCaught()) {
|
||||
FatalException(try_catch);
|
||||
return Undefined();
|
||||
}
|
||||
|
||||
// check return
|
||||
if (!probe_args->IsArray()) {
|
||||
return Undefined();
|
||||
}
|
||||
|
||||
Local<Array> a = Local<Array>::Cast(probe_args);
|
||||
p->Fire(a);
|
||||
|
||||
return Undefined();
|
||||
}
|
||||
|
||||
void DTraceProvider::AppendProbe(DTraceProbe *probe) {
|
||||
@@ -327,97 +362,11 @@ namespace node {
|
||||
return argc;
|
||||
}
|
||||
|
||||
void DTraceProbeDef::Initialize(Handle<Object> target) {
|
||||
HandleScope scope;
|
||||
|
||||
Local<FunctionTemplate> t = FunctionTemplate::New(DTraceProbeDef::New);
|
||||
constructor_template = Persistent<FunctionTemplate>::New(t);
|
||||
constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
constructor_template->SetClassName(String::NewSymbol("DTraceProbeDef"));
|
||||
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor_template, "fire", DTraceProbeDef::Fire);
|
||||
|
||||
target->Set(String::NewSymbol("DTraceProbeDef"), constructor_template->GetFunction());
|
||||
}
|
||||
|
||||
Handle<Value> DTraceProbeDef::New(const Arguments& args) {
|
||||
HandleScope scope;
|
||||
DTraceProbeDef *probe = new DTraceProbeDef();
|
||||
probe->Wrap(args.This());
|
||||
|
||||
if (!args[0]->IsString()) {
|
||||
return ThrowException(Exception::Error(String::New(
|
||||
"Must give probe name as first argument")));
|
||||
}
|
||||
|
||||
probe->next = NULL;
|
||||
|
||||
// init argument types
|
||||
int i;
|
||||
for (i = 0; (args[i+1]->IsString() && i < 6); i++) {
|
||||
String::AsciiValue type(args[i+1]->ToString());
|
||||
probe->types[i] = strdup(*type);
|
||||
}
|
||||
probe->types[i] = NULL;
|
||||
|
||||
// init name and function
|
||||
String::AsciiValue name(args[0]->ToString());
|
||||
probe->name = strdup(*name);
|
||||
probe->function = (char *) "func";
|
||||
|
||||
return args.This();
|
||||
}
|
||||
|
||||
Handle<Value> DTraceProbeDef::Fire(const Arguments& args) {
|
||||
HandleScope scope;
|
||||
DTraceProbeDef *pd = ObjectWrap::Unwrap<DTraceProbeDef>(args.Holder());
|
||||
|
||||
return pd->_fire(args[0]);
|
||||
}
|
||||
|
||||
Handle<Value> DTraceProbeDef::_fire(v8::Local<v8::Value> argsfn) {
|
||||
|
||||
// perform is-enabled check
|
||||
DTraceProbe *p = this->probe;
|
||||
void *(*isfunc)() = (void* (*)())(p->addr);
|
||||
long isenabled = (long)(*isfunc)();
|
||||
if (isenabled == 0) {
|
||||
return Undefined();
|
||||
}
|
||||
|
||||
// invoke fire callback
|
||||
TryCatch try_catch;
|
||||
|
||||
if (!argsfn->IsFunction()) {
|
||||
return ThrowException(Exception::Error(String::New(
|
||||
"Must give probe value callback as argument")));
|
||||
}
|
||||
|
||||
Local<Function> cb = Local<Function>::Cast(argsfn);
|
||||
Local<Value> probe_args = cb->Call(this->handle_, 0, NULL);
|
||||
|
||||
// exception in args callback?
|
||||
if (try_catch.HasCaught()) {
|
||||
FatalException(try_catch);
|
||||
return Undefined();
|
||||
}
|
||||
|
||||
// check return
|
||||
if (!probe_args->IsArray()) {
|
||||
return Undefined();
|
||||
}
|
||||
|
||||
Local<Array> a = Local<Array>::Cast(probe_args);
|
||||
p->Fire(a);
|
||||
|
||||
return Undefined();
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
init(Handle<Object> target) {
|
||||
DTraceProvider::Initialize(target);
|
||||
}
|
||||
|
||||
|
||||
} // namespace node
|
||||
|
||||
#endif // _HAVE_DTRACE
|
||||
|
||||
+2
-11
@@ -66,24 +66,16 @@ namespace node {
|
||||
void Fire(Local<Array> a);
|
||||
};
|
||||
|
||||
class DTraceProbeDef : ObjectWrap {
|
||||
class DTraceProbeDef {
|
||||
|
||||
public:
|
||||
static void Initialize(v8::Handle<v8::Object> target);
|
||||
char *function;
|
||||
char *types[7];
|
||||
char *name;
|
||||
DTraceProbe *probe;
|
||||
DTraceProbeDef *next;
|
||||
|
||||
static v8::Handle<v8::Value> New(const v8::Arguments& args);
|
||||
static v8::Handle<v8::Value> Fire(const v8::Arguments& args);
|
||||
|
||||
Handle<Value> _fire(v8::Local<v8::Value>);
|
||||
|
||||
static Persistent<FunctionTemplate> constructor_template;
|
||||
|
||||
DTraceProbeDef() : ObjectWrap() {
|
||||
DTraceProbeDef() {
|
||||
next = NULL;
|
||||
name = NULL;
|
||||
function = NULL;
|
||||
@@ -226,7 +218,6 @@ namespace node {
|
||||
}
|
||||
|
||||
private:
|
||||
static Persistent<FunctionTemplate> constructor_template;
|
||||
void AppendProbe(DTraceProbe *);
|
||||
size_t DofSize(DOFStrtab *);
|
||||
};
|
||||
|
||||
+3
-5
@@ -1,10 +1,8 @@
|
||||
var d = require('../dtrace-provider');
|
||||
var dtp = d.createDTraceProvider("nodeapp");
|
||||
var p1 = dtp.addProbe("probe1", "int", "int", "int", "int", "int", "int");
|
||||
var p2 = dtp.addProbe("probe2", "char *", "char *", "char *", "char *", "char *", "char *");
|
||||
dtp.addProbe("probe1", "int", "int", "int", "int", "int", "int");
|
||||
dtp.addProbe("probe2", "char *", "char *", "char *", "char *", "char *", "char *");
|
||||
dtp.enable();
|
||||
p1.fire(function(p) { return [1, 2, 3, 4, 5, 6]; });
|
||||
p2.fire(function(p) { return ["hello, dtrace via probe", "foo", "bar", "baz", "fred", "barney"]; });
|
||||
dtp.fire("probe1", function(p) { return [1, 2, 3, 4, 5, 6]; });
|
||||
dtp.fire("probe2", function(p) { return ["hello, dtrace via provider", "foo", "bar", "baz", "fred", "barney"]; });
|
||||
dtp.fire("probe2", function(p) { return ["hello, dtrace", "foo", "bar", "baz", "fred", "barney"]; });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user