Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Range cache must be invalidated before going out of scope

  • Loading branch information...
commit 658b724ab670b9b8e8ccc44407b8308882c5273c 1 parent 0cc7500
@bcantrill authored
Showing with 58 additions and 1 deletion.
  1. +11 −1 libdtrace.cc
  2. +47 −0 tests/test-sched.js
View
12 libdtrace.cc
@@ -653,6 +653,7 @@ DTraceConsumer::Aggwalk(const Arguments& args)
HandleScope scope;
DTraceConsumer *dtc = ObjectWrap::Unwrap<DTraceConsumer>(args.Holder());
dtrace_hdl_t *dtp = dtc->dtc_handle;
+ int rval;
if (!args[0]->IsFunction())
return (dtc->badarg("expected function as argument"));
@@ -671,7 +672,16 @@ DTraceConsumer::Aggwalk(const Arguments& args)
dtrace_errmsg(dtp, dtrace_errno(dtp))));
}
- if (dtrace_aggregate_walk(dtp, DTraceConsumer::aggwalk, dtc) == -1) {
+ rval = dtrace_aggregate_walk(dtp, DTraceConsumer::aggwalk, dtc);
+
+ /*
+ * Flush the ranges cache; the ranges will go out of scope when the
+ * destructor for our HandleScope is called, and we cannot be left
+ * holding references.
+ */
+ dtc->ranges_cache(DTRACE_AGGVARIDNONE, NULL);
+
+ if (rval == -1) {
if (!dtc->dtc_error->IsNull())
return (dtc->dtc_error);
View
47 tests/test-sched.js
@@ -0,0 +1,47 @@
+var util = require('util');
+var libdtrace = require('libdtrace');
+var i;
+
+dtp = new libdtrace.Consumer();
+
+prog =
+ 'sched:::on-cpu\n' +
+ '{\n' +
+ ' self->on = timestamp;\n' +
+ '}\n' +
+ '\n' +
+ 'sched:::off-cpu\n' +
+ '/self->on/\n' +
+ '{\n' +
+ ' @ = lquantize((timestamp - self->on) / 1000, \n' +
+ ' 0, 10000, 100);\n' +
+ '}\n' +
+ '\n';
+
+util.puts(prog);
+
+dtp.setopt('aggrate', '10ms');
+dtp.strcompile(prog);
+dtp.go();
+data = [];
+
+var start = new Date();
+
+setInterval(function () {
+
+ var delta = (new Date()).valueOf() - start.valueOf();
+
+ if (delta >= 5000)
+ process.exit(0);
+
+ dtp.aggwalk(function (varid, key, val) {
+ data.push(val);
+
+ if (data.length >= 50)
+ return;
+
+ for (i = data.length - 1; i >= 0 && i >= data.length - 5; i--)
+ util.puts(util.inspect(data[i], false, null));
+ });
+}, 10);
+
Please sign in to comment.
Something went wrong with that request. Please try again.