2013-07-29 12:50:53 -04: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-13 18:12:25 -04:00
|
|
|
if ((typeof console !== 'undefined') && console.groupCollapsed && !window.QUnit) {
|
2013-07-29 12:50:53 -04:00
|
|
|
|
2013-08-05 15:00:05 -04:00
|
|
|
(function () {
|
2013-07-29 12:50:53 -04:00
|
|
|
|
|
|
|
/**
|
2013-08-05 15:00:05 -04:00
|
|
|
Used for assembling a tree of render calls so they can be grouped and displayed
|
|
|
|
nicely afterwards.
|
2013-07-29 12:50:53 -04:00
|
|
|
|
2013-08-05 15:00:05 -04:00
|
|
|
@class ProfileNode
|
2013-07-29 12:50:53 -04:00
|
|
|
**/
|
2013-08-05 15:00:05 -04:00
|
|
|
var ProfileNode = function(start, payload) {
|
|
|
|
this.start = start;
|
|
|
|
this.payload = payload;
|
|
|
|
this.children = [];
|
|
|
|
};
|
2013-07-29 12:50:53 -04:00
|
|
|
|
|
|
|
/**
|
2013-08-05 16:15:16 -04:00
|
|
|
Adds a child node underneath this node.
|
2013-07-29 12:50:53 -04:00
|
|
|
|
|
|
|
@method addChild
|
|
|
|
@param {ProfileNode} node the node we want as a child
|
|
|
|
**/
|
2013-08-05 15:00:05 -04:00
|
|
|
ProfileNode.prototype.addChild = function(node) {
|
|
|
|
this.children.push(node);
|
|
|
|
};
|
2013-07-29 12:50:53 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Logs this node and any children to the developer console, grouping appropriately
|
|
|
|
for easy drilling down.
|
|
|
|
|
|
|
|
@method log
|
|
|
|
**/
|
2013-08-05 15:00:05 -04: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-05 16:15:16 -04: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-29 12:50:53 -04:00
|
|
|
}
|
|
|
|
|
2013-08-05 15:00:05 -04:00
|
|
|
// Set up our instrumentation of Ember below
|
|
|
|
Ember.subscribe("render", {
|
|
|
|
depth: null,
|
2013-07-29 12:50:53 -04:00
|
|
|
|
2013-08-05 15:00:05 -04:00
|
|
|
before: function(name, timestamp, payload) {
|
|
|
|
var node = new ProfileNode(timestamp, payload);
|
2013-08-05 16:15:16 -04:00
|
|
|
if (this.depth) { node.parent = this.depth; }
|
2013-08-05 15:00:05 -04:00
|
|
|
this.depth = node;
|
2013-07-29 12:50:53 -04:00
|
|
|
|
2013-08-05 15:00:05 -04:00
|
|
|
return node;
|
|
|
|
},
|
2013-07-29 12:50:53 -04:00
|
|
|
|
2013-08-05 15:00:05 -04:00
|
|
|
after: function(name, timestamp, payload, profileNode) {
|
2013-08-05 16:15:16 -04:00
|
|
|
|
2013-12-02 13:15:31 -05:00
|
|
|
if (payload.exception) {
|
|
|
|
throw payload.exception;
|
|
|
|
}
|
|
|
|
|
2013-08-05 16:15:16 -04:00
|
|
|
var parent = profileNode.parent;
|
|
|
|
profileNode.time = (timestamp - profileNode.start);
|
2013-08-05 15:00:05 -04:00
|
|
|
this.depth = profileNode.parent;
|
2013-08-05 16:15:16 -04:00
|
|
|
|
2013-08-05 16:20:36 -04:00
|
|
|
if (profileNode.time < 1) { return; }
|
2013-07-29 12:50:53 -04:00
|
|
|
|
2013-08-05 16:20:36 -04:00
|
|
|
if (this.depth) {
|
|
|
|
this.depth.addChild(profileNode);
|
|
|
|
} else {
|
2013-08-05 15:00:05 -04:00
|
|
|
profileNode.log("Render");
|
|
|
|
}
|
2013-07-29 12:50:53 -04:00
|
|
|
}
|
2013-08-05 15:00:05 -04:00
|
|
|
});
|
2013-07-29 12:50:53 -04:00
|
|
|
|
2013-08-05 15:00:05 -04:00
|
|
|
})();
|
2013-07-29 12:50:53 -04:00
|
|
|
|
2013-08-05 16:15:16 -04:00
|
|
|
}
|