Cleaned up probe code a little.

This commit is contained in:
Robin Ward 2013-03-11 11:13:28 -04:00
parent 37cf8b7d38
commit 4360d1bd61
4 changed files with 1565 additions and 1572 deletions
app/assets/javascripts/discourse/components
config/locales

View file

@ -29,50 +29,44 @@ Discourse.Development = {
}, },
after: function(data, owner, args) { after: function(data, owner, args) {
var ary, f, n, v, _ref;
if (typeof console === "undefined") return;
if (console === null) return;
var f, n, v;
if (owner && data.time > 10) { if (owner && data.time > 10) {
f = function(name, data) { f = function(name, data) {
if (data && data.count) return name + " - " + data.count + " calls " + ((data.time + 0.0).toFixed(2)) + "ms"; if (data && data.count) return name + " - " + data.count + " calls " + ((data.time + 0.0).toFixed(2)) + "ms";
}; };
if (console && console.group) { if (console.group) {
console.group(f(name, data)); console.group(f(name, data));
} else { } else {
console.log(""); console.log("");
console.log(f(name, data)); console.log(f(name, data));
} }
ary = []; var ary = [];
_ref = window.probes; for (n in window.probes) {
for (n in _ref) { v = window.probes[n];
v = _ref[n]; if (n === name || v.time < 1) continue;
if (n === name || v.time < 1) { ary.push({ k: n, v: v });
continue;
}
ary.push({
k: n,
v: v
});
} }
ary.sortBy(function(item) { ary.sortBy(function(item) {
if (item.v && item.v.time) { if (item.v && item.v.time) return -item.v.time;
return -item.v.time; return 0;
} else {
return 0;
}
}).each(function(item) { }).each(function(item) {
var output = f("" + item.k, item.v); var output = f("" + item.k, item.v);
if (output) { if (output) {
return console.log(output); console.log(output);
} }
}); });
if (typeof console !== "undefined" && console !== null) {
if (typeof console.groupEnd === "function") { if (console.group) {
console.groupEnd(); console.groupEnd();
}
} }
return window.probes.clear(); window.probes.clear();
} }
} }
}); });

View file

@ -8,13 +8,13 @@
* someFunction = window.probes.measure(someFunction, { * someFunction = window.probes.measure(someFunction, {
* name: "somename" // or function(args) { return "name"; }, * name: "somename" // or function(args) { return "name"; },
* before: function(data, owner, args) { * before: function(data, owner, args) {
* // if owner is true, we are not in a recursive function call. * // if owner is true, we are not in a recursive function call.
* // * //
* // data contains the bucker of data already measuer * // data contains the bucker of data already measuer
* // data.count >= 0 * // data.count >= 0
* // data.time is the total time measured till now * // data.time is the total time measured till now
* // * //
* // arguments contains the original arguments sent to the function * // arguments contains the original arguments sent to the function
* }, * },
* after: function(data, owner, args) { * after: function(data, owner, args) {
* // same format as before * // same format as before
@ -22,9 +22,9 @@
* }); * });
* *
* *
* // minimal * // minimal
* someFunction = window.probes.measure(someFunction, "someFunction"); * someFunction = window.probes.measure(someFunction, "someFunction");
* *
* */ * */
(function(){ (function(){
var measure, clear; var measure, clear;
@ -92,8 +92,7 @@
start = now(); start = now();
callStart = start; callStart = start;
} }
else if(after) else if(after) {
{
callStart = now(); callStart = now();
} }

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff