Cleaned up probe code a little.
This commit is contained in:
parent
37cf8b7d38
commit
4360d1bd61
|
@ -29,50 +29,44 @@ Discourse.Development = {
|
|||
},
|
||||
|
||||
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) {
|
||||
|
||||
f = function(name, data) {
|
||||
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));
|
||||
} else {
|
||||
console.log("");
|
||||
console.log(f(name, data));
|
||||
}
|
||||
|
||||
ary = [];
|
||||
_ref = window.probes;
|
||||
for (n in _ref) {
|
||||
v = _ref[n];
|
||||
if (n === name || v.time < 1) {
|
||||
continue;
|
||||
}
|
||||
ary.push({
|
||||
k: n,
|
||||
v: v
|
||||
});
|
||||
var ary = [];
|
||||
for (n in window.probes) {
|
||||
v = window.probes[n];
|
||||
if (n === name || v.time < 1) continue;
|
||||
ary.push({ k: n, v: v });
|
||||
}
|
||||
ary.sortBy(function(item) {
|
||||
if (item.v && item.v.time) {
|
||||
return -item.v.time;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
if (item.v && item.v.time) return -item.v.time;
|
||||
return 0;
|
||||
}).each(function(item) {
|
||||
var output = f("" + item.k, item.v);
|
||||
if (output) {
|
||||
return console.log(output);
|
||||
console.log(output);
|
||||
}
|
||||
});
|
||||
if (typeof console !== "undefined" && console !== null) {
|
||||
if (typeof console.groupEnd === "function") {
|
||||
console.groupEnd();
|
||||
}
|
||||
|
||||
if (console.group) {
|
||||
console.groupEnd();
|
||||
}
|
||||
return window.probes.clear();
|
||||
window.probes.clear();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -8,13 +8,13 @@
|
|||
* someFunction = window.probes.measure(someFunction, {
|
||||
* name: "somename" // or function(args) { return "name"; },
|
||||
* 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.count >= 0
|
||||
* // data.time is the total time measured till now
|
||||
* // data contains the bucker of data already measuer
|
||||
* // data.count >= 0
|
||||
* // 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) {
|
||||
* // same format as before
|
||||
|
@ -22,9 +22,9 @@
|
|||
* });
|
||||
*
|
||||
*
|
||||
* // minimal
|
||||
* // minimal
|
||||
* someFunction = window.probes.measure(someFunction, "someFunction");
|
||||
*
|
||||
*
|
||||
* */
|
||||
(function(){
|
||||
var measure, clear;
|
||||
|
@ -92,8 +92,7 @@
|
|||
start = now();
|
||||
callStart = start;
|
||||
}
|
||||
else if(after)
|
||||
{
|
||||
else if(after) {
|
||||
callStart = now();
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue