Create a gist now

Instantly share code, notes, and snippets.

Class Profiler for Mootools 1.3.x
/*
---
name: kenta.AOP.Profile.js
description: Profiling for MooTools 1.3
version: 1.0
license: MIT-style license.
copyright: Carlesso Cristian
requires: Events, Class.PatternMutators, kenta.AOP
provides: [Profile]
...
*/
var Profile = new (new Class({
Implements:[Events],
_profilation:{},
initialize:function(){
var me = this;
if(typeof(AOP)=='undefined'){
alert('Profile requires kenta.AOP');
return;
}
AOP.addEvent('pre',function(params){
var Profilation = me._profilation;
var callID = params.uniqueID + '_' + params.name;
var data = Profilation[callID]||(Profilation[callID] = []);
data.push($time());
});
AOP.addEvent('post', function(params){
var Profilation = me._profilation;
var stop_time = $time();
var callID=params.uniqueID + '_' + params.name;
var data = Profilation[callID];
var start_time = data.pop();
if(data.length == 0){
delete Profilation[callID];
}
params.executionTime = stop_time - start_time;
me.fireEvent('trace', params);
});
}
}))();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment