mirror of
https://github.com/hanzoai/node-dtrace-provider.git
synced 2026-09-23 23:48:45 +00:00
Prevent attempted re-enabling of providers breaking existing probes.
It was possible to call enable() on a provider more than once, which would simply attempt to repeat the work required - creating stubs and the appropriate DOF. However the kernel will in most cases ignore new DOF, leaving the old provider in place, while the newly-created stubs are elsewhere. This change simply no-ops subsequent calls to enable() on a provider, which still doesn't allow changes to be made, but does prevent inadvertent breaking of existing probes.
This commit is contained in:
@@ -90,6 +90,10 @@ namespace node {
|
||||
return Undefined();
|
||||
}
|
||||
|
||||
if (provider->enabled == 1) {
|
||||
return Undefined();
|
||||
}
|
||||
|
||||
DOFSection *probes = new DOFSection(DOF_SECT_PROBES, 1);
|
||||
|
||||
// PROBES SECTION
|
||||
@@ -198,6 +202,7 @@ namespace node {
|
||||
|
||||
provider->file = file;
|
||||
|
||||
provider->enabled = 1;
|
||||
return Undefined();
|
||||
}
|
||||
|
||||
|
||||
@@ -193,6 +193,7 @@ namespace node {
|
||||
public:
|
||||
static void Initialize(v8::Handle<v8::Object> target);
|
||||
char *name;
|
||||
int enabled;
|
||||
DTraceProbeDef *probe_defs;
|
||||
DTraceProbe *probes;
|
||||
DOFFile *file;
|
||||
@@ -207,6 +208,7 @@ namespace node {
|
||||
probe_defs = NULL;
|
||||
probes = NULL;
|
||||
file = NULL;
|
||||
enabled = 0;
|
||||
}
|
||||
|
||||
~DTraceProvider() {
|
||||
|
||||
+14
-1
@@ -1,8 +1,21 @@
|
||||
// expected output:
|
||||
//
|
||||
// $ sudo dtrace -Z -n 'nodeapp*:::probe1{ printf("%i %i %i %i %i %i", arg0, arg1, arg2, arg3, arg4, arg5); }' \
|
||||
// -n 'nodeapp*:::probe2{ printf("%s %s %s %s %s %s", copyinstr(arg0), copyinstr(arg1), copyinstr(arg2), copyinstr(arg3), copyinstr(arg4), copyinstr(arg5)) }' \
|
||||
// -c 'node test/dtp.js'
|
||||
//
|
||||
// dtrace: description 'nodeapp*:::probe1' matched 0 probes
|
||||
// dtrace: description 'nodeapp*:::probe2' matched 0 probes
|
||||
// CPU ID FUNCTION:NAME
|
||||
// 1 3421 func:probe1 1 2 3 4 5 6
|
||||
// 1 3422 func:probe2 a b c d e f
|
||||
|
||||
var d = require('../dtrace-provider');
|
||||
var dtp = d.createDTraceProvider("nodeapp");
|
||||
dtp.addProbe("probe1", "int", "int", "int", "int", "int", "int");
|
||||
dtp.addProbe("probe2", "char *", "char *", "char *", "char *", "char *", "char *");
|
||||
dtp.enable();
|
||||
dtp.fire("probe1", function(p) { return [1, 2, 3, 4, 5, 6]; });
|
||||
dtp.fire("probe2", function(p) { return ["hello, dtrace", "foo", "bar", "baz", "fred", "barney"]; });
|
||||
dtp.fire("probe2", function(p) { return ["a", "b", "c", "d", "e", "f"]; });
|
||||
|
||||
setTimeout(function() { }, 1000);
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
// expected output:
|
||||
//
|
||||
// $ sudo dtrace -Zn 'nodeapp*:::{ trace(arg0); }' -c 'node test/enabled_again.js'
|
||||
// dtrace: description 'nodeapp*:::' matched 0 probes
|
||||
// CPU ID FUNCTION:NAME
|
||||
// 1 5456 func:probe1 1
|
||||
// 1 5456 func:probe1 2
|
||||
|
||||
var d = require('../dtrace-provider');
|
||||
var dtp = d.createDTraceProvider("nodeapp");
|
||||
dtp.addProbe("probe1", "int");
|
||||
dtp.enable();
|
||||
dtp.fire("probe1", function(p) { return [1]; });
|
||||
|
||||
for (var i = 0; i<100; i++) {
|
||||
dtp.enable();
|
||||
}
|
||||
dtp.fire("probe1", function(p) { return [2]; });
|
||||
setTimeout(function() { }, 1000);
|
||||
Reference in New Issue
Block a user