Skip to content

Commit

Permalink
Adding dtrace probes for insight
Browse files Browse the repository at this point in the history
  • Loading branch information
avoidwork committed Feb 18, 2019
1 parent 32be1ff commit 0dee54a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
7 changes: 7 additions & 0 deletions benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"use strict";

const http = require("http"),
router = require("./index")();

router.use("/", (req, res) => res.json("Hello World!"));
http.createServer(router.route).listen(8000);
16 changes: 12 additions & 4 deletions lib/woodland.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ const path = require("path"),
precise = require("precise"),
methods = http.METHODS,
Base = require(path.join(__dirname, "base.js")),
dtrace = require(path.join(__dirname, "dtrace.js")),
{all, clone, each, http2Normalize, http2Send, next, ms, params, parse, partial, pipeable, last, reduce, wrapped, writeHead} = require(path.join(__dirname, "utility.js")),
delimiter = ":";

class Woodland extends Base {
constructor (defaultHeaders, cacheSize, http2, cacheTTL, dtrace) {
constructor (defaultHeaders, cacheSize, http2, cacheTTL, dtp) {
super();
this.blacklisted = new Set();
this.cache = fifo(cacheSize, cacheTTL);
this.defaultHeaders = Object.keys(defaultHeaders).map(key => [key.toLowerCase(), defaultHeaders[key]]);
this.dtp = dtrace === true ? dtrace("woodland") : null;
this.dtrace = dtp === true;
this.dtp = this.dtrace ? dtrace("woodland") : null;
this.http2 = http2;
this.permissions = fifo(cacheSize, cacheTTL);
this.methods = [];
Expand Down Expand Up @@ -329,7 +331,10 @@ class Woodland extends Base {

res.on("finish", () => {
if (this.dtrace) {
timer.stop();
if (timer.stopped.length === 0) {
timer.stop();
}

this.dtp.fire("route", () => [req.parsed.href, ms(timer.diff()), "finish"]);
}

Expand All @@ -340,7 +345,10 @@ class Woodland extends Base {
this.onclose(req, res);

if (this.dtrace) {
timer.stop();
if (timer.stopped.length === 0) {
timer.stop();
}

this.dtp.fire("route", () => [req.parsed.href, ms(timer.diff()), "close"]);
}

Expand Down
2 changes: 1 addition & 1 deletion sample.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const http = require("http"),
router = require("./index")({defaultHeaders: {"Cache-Control": "no-cache", "Content-Type": "text/plain"}});
router = require("./index")({defaultHeaders: {"Cache-Control": "no-cache", "Content-Type": "text/plain"}, dtrace: true});

router.use("/", (req, res) => res.send("Hello World!"));
router.use("/", (req, res) => res.send("Make a GET request to retrieve the representation"), "options");
Expand Down

0 comments on commit 0dee54a

Please sign in to comment.