2013-07-30 00:50:53 +08:00
|
|
|
//
|
|
|
|
// ember-renderspeed
|
|
|
|
//
|
|
|
|
// Include this script if you want to instrument your rendering speed in your Ember
|
|
|
|
// applications.
|
|
|
|
//
|
|
|
|
// https://github.com/eviltrout/ember-renderspeed
|
|
|
|
//
|
2013-08-14 06:12:25 +08:00
|
|
|
if ((typeof console !== 'undefined') && console.groupCollapsed && !window.QUnit) {
|
2013-07-30 00:50:53 +08:00
|
|
|
|
2013-08-06 03:00:05 +08:00
|
|
|
(function () {
|
2013-07-30 00:50:53 +08:00
|
|
|
|
|
|
|
/**
|
2013-08-06 03:00:05 +08:00
|
|
|
Used for assembling a tree of render calls so they can be grouped and displayed
|
|
|
|
nicely afterwards.
|
2013-07-30 00:50:53 +08:00
|
|
|
|
2013-08-06 03:00:05 +08:00
|
|
|
@class ProfileNode
|
2013-07-30 00:50:53 +08:00
|
|
|
**/
|
2013-08-06 03:00:05 +08:00
|
|
|
var ProfileNode = function(start, payload) {
|
|
|
|
this.start = start;
|
|
|
|
this.payload = payload;
|
|
|
|
this.children = [];
|
|
|
|
};
|
2013-07-30 00:50:53 +08:00
|
|
|
|
|
|
|
/**
|
2013-08-06 04:15:16 +08:00
|
|
|
Adds a child node underneath this node.
|
2013-07-30 00:50:53 +08:00
|
|
|
|
|
|
|
@method addChild
|
|
|
|
@param {ProfileNode} node the node we want as a child
|
|
|
|
**/
|
2013-08-06 03:00:05 +08:00
|
|
|
ProfileNode.prototype.addChild = function(node) {
|
|
|
|
this.children.push(node);
|
|
|
|
};
|
2013-07-30 00:50:53 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
Logs this node and any children to the developer console, grouping appropriately
|
|
|
|
for easy drilling down.
|
|
|
|
|
|
|
|
@method log
|
|
|
|
**/
|
2013-08-06 03:00:05 +08:00
|
|
|
ProfileNode.prototype.log = function(type) {
|
|
|
|
var description = "";
|
|
|
|
if (this.payload) {
|
|
|
|
if (this.payload.template) {
|
|
|
|
description += "'" + this.payload.template + "' ";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.payload.object) {
|
|
|
|
description += this.payload.object.toString() + " ";
|
|
|
|
}
|
|
|
|
}
|
2013-08-06 04:15:16 +08:00
|
|
|
description += (Math.round(this.time * 100) / 100).toString() + "ms";
|
|
|
|
|
|
|
|
if (this.children.length === 0) {
|
|
|
|
console.log(type + ": " + description);
|
|
|
|
} else {
|
|
|
|
// render a collapsed group when there are children
|
|
|
|
console.groupCollapsed(type + ": " + description);
|
|
|
|
this.children.forEach(function (c) {
|
|
|
|
c.log(type);
|
|
|
|
});
|
|
|
|
console.groupEnd();
|
|
|
|
}
|
2013-07-30 00:50:53 +08:00
|
|
|
}
|
|
|
|
|
2013-08-06 03:00:05 +08:00
|
|
|
// Set up our instrumentation of Ember below
|
|
|
|
Ember.subscribe("render", {
|
|
|
|
depth: null,
|
2013-07-30 00:50:53 +08:00
|
|
|
|
2013-08-06 03:00:05 +08:00
|
|
|
before: function(name, timestamp, payload) {
|
|
|
|
var node = new ProfileNode(timestamp, payload);
|
2013-08-06 04:15:16 +08:00
|
|
|
if (this.depth) { node.parent = this.depth; }
|
2013-08-06 03:00:05 +08:00
|
|
|
this.depth = node;
|
2013-07-30 00:50:53 +08:00
|
|
|
|
2013-08-06 03:00:05 +08:00
|
|
|
return node;
|
|
|
|
},
|
2013-07-30 00:50:53 +08:00
|
|
|
|
2013-08-06 03:00:05 +08:00
|
|
|
after: function(name, timestamp, payload, profileNode) {
|
2013-08-06 04:15:16 +08:00
|
|
|
|
2013-12-03 02:15:31 +08:00
|
|
|
if (payload.exception) {
|
|
|
|
throw payload.exception;
|
|
|
|
}
|
|
|
|
|
2013-08-06 04:15:16 +08:00
|
|
|
var parent = profileNode.parent;
|
|
|
|
profileNode.time = (timestamp - profileNode.start);
|
2013-08-06 03:00:05 +08:00
|
|
|
this.depth = profileNode.parent;
|
2013-08-06 04:15:16 +08:00
|
|
|
|
2013-08-06 04:20:36 +08:00
|
|
|
if (profileNode.time < 1) { return; }
|
2013-07-30 00:50:53 +08:00
|
|
|
|
2013-08-06 04:20:36 +08:00
|
|
|
if (this.depth) {
|
|
|
|
this.depth.addChild(profileNode);
|
|
|
|
} else {
|
2013-08-06 03:00:05 +08:00
|
|
|
profileNode.log("Render");
|
|
|
|
}
|
2013-07-30 00:50:53 +08:00
|
|
|
}
|
2013-08-06 03:00:05 +08:00
|
|
|
});
|
2013-07-30 00:50:53 +08:00
|
|
|
|
2013-08-06 03:00:05 +08:00
|
|
|
})();
|
2013-07-30 00:50:53 +08:00
|
|
|
|
2013-08-06 04:15:16 +08:00
|
|
|
}
|