Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

debugging with http timers

  • Loading branch information...
commit 6475038f15e81b0b8d37ae474693b499bf7ae0b0 1 parent bab59f3
isaacs authored
Showing with 31 additions and 2 deletions.
  1. +31 −2 lib/http.js
33 lib/http.js
View
@@ -55,6 +55,8 @@ var parsers = new FreeList('parsers', 1000, function() {
parser._headers = parser._headers.concat(headers);
}
parser._url += url;
+ var req = parser.req;
+ if (req && req.times) req.times.header = Date.now();
};
// info.headers and info.url are set only if .onHeaders()
@@ -63,6 +65,8 @@ var parsers = new FreeList('parsers', 1000, function() {
// info.url is not set for response parsers but that's not
// applicable here since all our parsers are request parsers.
parser.onHeadersComplete = function(info) {
+ var req = parser.req;
+ if (req && req.times) req.times.headerEnd = Date.now();
var headers = info.headers;
var url = info.url;
@@ -119,6 +123,9 @@ var parsers = new FreeList('parsers', 1000, function() {
};
parser.onBody = function(b, start, len) {
+ var req = parser.req;
+ if (req && req.times) req.times.body = Date.now();
+
// TODO body encoding?
var slice = b.slice(start, start + len);
if (parser.incoming._paused || parser.incoming._pendings.length) {
@@ -1192,9 +1199,15 @@ function createHangUpError() {
ClientRequest.prototype.onSocket = function(socket) {
+ if (!this.times) this.times = {};
+ if (this.times) this.times.onSocket1 = Date.now();
var req = this;
- process.nextTick(function() {
+ // process.nextTick(onSocket);
+ onSocket();
+ function onSocket() {
+ if (req.times) req.times.onSocket2 = Date.now();
var parser = parsers.alloc();
+ parser.req = req;
req.socket = socket;
req.connection = socket;
parser.reinitialize(HTTPParser.RESPONSE);
@@ -1236,7 +1249,10 @@ ClientRequest.prototype.onSocket = function(socket) {
socket.on('error', errorListener);
socket.ondata = function(d, start, end) {
+ var req = parser.req;
+ if (req && req.times) req.times.ondata = Date.now();
var ret = parser.execute(d, start, end - start);
+
if (ret instanceof Error) {
debug('parse error');
freeParser();
@@ -1275,6 +1291,11 @@ ClientRequest.prototype.onSocket = function(socket) {
// send a final response after this client sends a request
// body. So, we must not free the parser.
parser.incoming.statusCode !== 100) {
+ var req = parser.req;
+ if (req) {
+ if (req.times) req.times.pcomp = Date.now();
+ parser.req = null;
+ }
freeParser();
}
};
@@ -1313,6 +1334,8 @@ ClientRequest.prototype.onSocket = function(socket) {
parser.onIncoming = function(res, shouldKeepAlive) {
debug('AGENT incoming response!');
+ if (req.times) req.times.inc = Date.now();
+
if (req.res) {
// We already have a response object, this means the server
// sent a double response.
@@ -1320,6 +1343,7 @@ ClientRequest.prototype.onSocket = function(socket) {
return;
}
req.res = res;
+ if (req.times) req.times.preResp = Date.now();
// Responses to CONNECT request is handled as Upgrade.
if (req.method === 'CONNECT') {
@@ -1350,6 +1374,7 @@ ClientRequest.prototype.onSocket = function(socket) {
}
res.addListener('end', function() {
+ if (req.times) req.times.respEnd = Date.now();
if (!req.shouldKeepAlive) {
if (socket.writable) {
debug('AGENT socket.destroySoon()');
@@ -1362,7 +1387,9 @@ ClientRequest.prototype.onSocket = function(socket) {
});
DTRACE_HTTP_CLIENT_RESPONSE(socket, req);
+ if (req.times) req.times.resp = Date.now();
req.emit('response', res);
+ if (req.times) req.times.postResp = Date.now();
res.on('end', function() {
if (req.shouldKeepAlive) {
@@ -1374,8 +1401,10 @@ ClientRequest.prototype.onSocket = function(socket) {
return isHeadResponse;
};
+ if (req.times) req.times.onSocket3 = Date.now();
req.emit('socket', socket);
- });
+ if (req.times) req.times.onSocket4 = Date.now();
+ }
};
ClientRequest.prototype._deferToConnect = function(method, arguments_, cb) {
Please sign in to comment.
Something went wrong with that request. Please try again.