profileName option

This commit is contained in:
Hem Brahmbhatt
2017-08-22 12:31:22 +01:00
parent 3e1d094289
commit 00b4fa42a6
3 changed files with 15 additions and 11 deletions

View File

@@ -90,6 +90,7 @@ module.exports = function (original, length, options) {
conf = {
original: original,
memoized: memoized,
profileName: options.profileName,
get: function (args) {
if (resolve) args = resolve(args);
if (get) return get(args);

View File

@@ -5,6 +5,7 @@
var partial = require('es5-ext/function/#/partial')
, forEach = require('es5-ext/object/for-each')
, pad = require('es5-ext/string/#/pad')
, compact = require('es5-ext/array/#/compact')
, d = require('d')
, memoize = require('./plain')
@@ -12,17 +13,18 @@ var partial = require('es5-ext/function/#/partial')
, stats = exports.statistics = {};
Object.defineProperty(memoize, '__profiler__', d(function (conf) {
var id, stack, data;
var id, source, data, stack;
stack = (new Error()).stack;
if (!stack || !stack.split('\n').slice(3).some(function (line) {
if ((line.indexOf('/memoizee/') === -1) &&
(line.indexOf(' (native)') === -1)) {
id = line.replace(/\n/g, "\\n").trim();
return true;
}
})) {
id = 'unknown';
}
if (!stack || !stack.split('\n').slice(3).some(function (line) {
if ((line.indexOf('/memoizee/') === -1) &&
(line.indexOf(' (native)') === -1)) {
source = line.replace(/\n/g, "\\n").trim();
return true;
}
})) {
source = 'unknown';
}
id = compact.call([conf.profileName, source]).join(', ');
if (!stats[id]) stats[id] = { initial: 0, cached: 0 };
data = stats[id];

View File

@@ -4,8 +4,9 @@ var memoize = require('../plain');
module.exports = function (t, a) {
memoize(function () {})();
memoize(function () {}, { profileName: 'test' })();
a(typeof t.statistics, 'object', "Access to statistics");
a(Object.keys(t.statistics).length > 0, true, "Statistics collected");
a(Object.keys(t.statistics).length, 2, "Statistics collected including named function");
a(typeof t.log, 'function', "Access to log function");
a(typeof t.log(), 'string', "Log outputs string");
};