Skip to content

Commit

Permalink
Fix initialization of profiler
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed May 12, 2014
1 parent c341f4c commit 824668e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
var partial = require('es5-ext/function/#/partial')
, forEach = require('es5-ext/object/for-each')
, pad = require('es5-ext/string/#/pad')
, d = require('d')
, memoize = require('./plain')

, max = Math.max
, stats = exports.statistics = {};

Object.defineProperty(memoize, '__profiler__', function (conf) {
Object.defineProperty(memoize, '__profiler__', d(function (conf) {
var id, stack, data;
stack = (new Error()).stack;
if (!stack || !stack.split('\n').slice(3).some(function (line) {
Expand All @@ -28,7 +29,7 @@ Object.defineProperty(memoize, '__profiler__', function (conf) {

conf.on('set', function () { ++data.initial; });
conf.on('get', function () { ++data.cached; });
});
}));

exports.log = function () {
var initial, cached, ordered, ipad, cpad, ppad, toPrc, log;
Expand Down
4 changes: 4 additions & 0 deletions test/profile.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
'use strict';

var memoize = require('../plain');

module.exports = function (t, a) {
memoize(function () {})();
a(typeof t.statistics, 'object', "Access to statistics");
a(Object.keys(t.statistics).length > 0, true, "Statistics collected");
a(typeof t.log, 'function', "Access to log function");
a(typeof t.log(), 'string', "Log outputs string");
};

0 comments on commit 824668e

Please sign in to comment.