Update ember-renderspeed. Much less overhead.

This commit is contained in:
Robin Ward 2013-08-05 15:00:05 -04:00
parent ee3a0f0bcb
commit dbbc5248aa

View File

@ -6,42 +6,21 @@
// //
// https://github.com/eviltrout/ember-renderspeed // https://github.com/eviltrout/ember-renderspeed
// //
(function () { if ((typeof console !== 'undefined') && console.groupCollapsed) {
/** (function () {
Used for assembling a tree of render calls so they can be grouped and displayed
nicely afterwards.
@class ProfileNode
**/
var ProfileNode = Ember.Object.extend({
init: function() {
this.set('children', []);
},
/** /**
A string description of this node. If we have a template name we display that Used for assembling a tree of render calls so they can be grouped and displayed
too. nicely afterwards.
@property description @class ProfileNode
**/ **/
description: function() { var ProfileNode = function(start, payload) {
var result = ""; this.start = start;
if (this.get('payload.template')) { this.payload = payload;
result += "'" + this.get('payload.template') + "' "; this.children = [];
} };
if (this.get('payload.object')) {
result += this.get('payload.object').toString() + " ";
}
result += (Math.round(this.get('time') * 100) / 100).toString() + "ms";
return result;
}.property('time', 'payload.template', 'payload.object'),
time: function() {
return this.get('end') - this.get('start');
}.property('start', 'end'),
/** /**
Adds a child node underneath this node. It also creates a reference between Adds a child node underneath this node. It also creates a reference between
@ -50,10 +29,10 @@
@method addChild @method addChild
@param {ProfileNode} node the node we want as a child @param {ProfileNode} node the node we want as a child
**/ **/
addChild: function(node) { ProfileNode.prototype.addChild = function(node) {
node.set('parent', this); node.parent = this;
this.get('children').pushObject(node); this.children.push(node);
}, };
/** /**
Logs this node and any children to the developer console, grouping appropriately Logs this node and any children to the developer console, grouping appropriately
@ -61,43 +40,51 @@
@method log @method log
**/ **/
log: function(type) { ProfileNode.prototype.log = function(type) {
if ((typeof console === 'undefined') || (!console.groupCollapsed)) { return; } var time = this.end - this.start;
if (time < 1) { return; }
// We don't care about really fast renders var description = "";
if (this.get('time') < 1) { return; } if (this.payload) {
if (this.payload.template) {
description += "'" + this.payload.template + "' ";
}
console.groupCollapsed(type + ": " + this.get('description')); if (this.payload.object) {
this.get('children').forEach(function (c) { description += this.payload.object.toString() + " ";
}
}
description += (Math.round(time * 100) / 100).toString() + "ms";
console.groupCollapsed(type + ": " + description);
this.children.forEach(function (c) {
c.log(type); c.log(type);
}); });
console.groupEnd(); console.groupEnd();
} }
});
// Set up our instrumentation of Ember below
Ember.subscribe("render", {
depth: null,
// Set up our instrumentation of Ember below before: function(name, timestamp, payload) {
Ember.subscribe("render", { var node = new ProfileNode(timestamp, payload);
depth: null, if (this.depth) { this.depth.addChild(node); }
this.depth = node;
before: function(name, timestamp, payload) { return node;
var node = ProfileNode.create({start: timestamp, payload: payload}); },
if (this.depth) { this.depth.addChild(node); } after: function(name, timestamp, payload, profileNode) {
this.depth = node; this.depth = profileNode.parent;
profileNode.end = timestamp;
return node; if (!this.depth) {
}, profileNode.log("Render");
}
after: function(name, timestamp, payload, profileNode) {
this.depth = profileNode.get('parent');
profileNode.set('end', timestamp);
if (!this.depth) {
profileNode.log("Render");
} }
} });
});
})(); })();
}