Skip to content

Commit

Permalink
Fix dtrace implementation
Browse files Browse the repository at this point in the history
Now it's at least in a running state.
But we should update it though. A bit rought.
  • Loading branch information
JonGretar committed Nov 2, 2016
1 parent 2c34eab commit f15bb0d
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 9 deletions.
8 changes: 7 additions & 1 deletion doc/debugging/dtrace.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# DTrace

*TODO: Describe the DTrace capabilities.*

$ sudo dtrace -l -P resource*
ID PROVIDER MODULE FUNCTION NAME
4525 resource-machine89061 mod-0x103904cb0 req-start req-start
4526 resource-machine89061 mod-0x103904cb0 req-end req-end
4527 resource-machine89061 mod-0x103904cb0 decision-start decision-start
4528 resource-machine89061 mod-0x103904cb0 decision-end decision-end
22 changes: 22 additions & 0 deletions examples/demo/tracer.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/sbin/dtrace -s
#pragma D option quiet

resource-machine*:::req-start
{
printf("%s#%i - %s %s \n", copyinstr(arg0), arg1, copyinstr(arg2), copyinstr(arg3));
}

resource-machine*:::decision-start
{
printf("%s#%i - > %s(%s)\n", copyinstr(arg0), arg1, copyinstr(arg2), copyinstr(arg3));
}

resource-machine*:::decision-end
{
printf("%s#%i - < %s\n", copyinstr(arg0), arg1, copyinstr(arg2));
}

resource-machine*:::req-end
{
printf("%s#%i - Finished: %i\n", copyinstr(arg0), arg1, arg2);
}
7 changes: 1 addition & 6 deletions lib/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports.reqStart = function (req, res) {
req.serverName,
req.requestId,
req.method,
req.path,
req.route,
req.headers
]);
req.decisionTrace = [];
Expand Down Expand Up @@ -42,11 +42,6 @@ module.exports.reqEnd = function (req, res) {
} else {
req.log.info(payload, 'Successful request to ' + req.url);
}

dtrace.easyFire('decision-end', [
req.serverName,
req.requestId
]);
};

module.exports.decisionStart = function (req, res, decision) {
Expand Down
2 changes: 1 addition & 1 deletion lib/decision_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports.handleRequest = function handleRequest(req, res) {
}

// Ensure bodyStream has finished before closing up.
if (res._bodyStream) {
if (res._bodyStream && !res._bodyStream._writableState.ended) {
res._bodyStream.once('end', suspend(function* () {
yield tree.finish(req, res, suspend.resume());
res.end();
Expand Down
3 changes: 2 additions & 1 deletion lib/decision_tree/v3/titles.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ var decisions = {
'v3o14' : 'Conflict?',
'v3o16' : 'PUT?',
'v3o18' : 'Multiple representations?',
'v3o18b' : 'Multiple representations?(B)',
'v3o20' : 'Response includes an entity?',
'v3p3' : 'Conflict?',
'v3p11' : 'New resource?',
'finish' : 'Finish request'
};
module.exports.decisionTitles = decisions;
module.exports = decisions;
2 changes: 2 additions & 0 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ function Server(options) {
requestId: req.requestId
});

req.serverName = self.name;

decisionCore.handleRequest(req, res);
});
}
Expand Down

0 comments on commit f15bb0d

Please sign in to comment.