From ec602d0695e50475cf27cbae2ac2040cb7ef2a6f Mon Sep 17 00:00:00 2001 From: Slava Kim Date: Mon, 2 Feb 2015 20:12:26 -0800 Subject: [PATCH] Make tools profiler Fibers-aware --- tools/tiny-profile.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tools/tiny-profile.js b/tools/tiny-profile.js index b1262808c9..eb607bfcf4 100644 --- a/tools/tiny-profile.js +++ b/tools/tiny-profile.js @@ -162,6 +162,7 @@ // In both reports the grand total is 600ms. var _ = require('underscore'); +var Fiber = require('fibers'); var enabled = !! process.env['METEOR_PROFILE']; @@ -170,11 +171,11 @@ var bucketTimes = {}; var spaces = function (x) { var s = ''; for (var i = 0; i < x; ++i) - s += ' '; + s += ' '; return s; }; -var currentEntry = []; +var globalEntry = []; var running = false; @@ -198,8 +199,14 @@ var Profile = function (bucketName, f) { else name = bucketName; - var parent = currentEntry; - currentEntry = _.clone(currentEntry); + var currentEntry; + if (Fiber.current) { + currentEntry = + Fiber.current.profilerEntry || (Fiber.current.profilerEntry = []); + } else { + currentEntry = globalEntry; + } + currentEntry.push(name); var key = JSON.stringify(currentEntry); var start = process.hrtime(); @@ -214,7 +221,7 @@ var Profile = function (bucketName, f) { var elapsed = process.hrtime(start); bucketTimes[key] = (bucketTimes[key] || 0) + (elapsed[0] * 1000 + elapsed[1] / 1000000); - currentEntry = parent; + currentEntry.pop(); } if (err) throw err;