Skip to content

Instantly share code, notes, and snippets.

@kentaromiura
Created October 10, 2011 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kentaromiura/1275736 to your computer and use it in GitHub Desktop.
Save kentaromiura/1275736 to your computer and use it in GitHub Desktop.
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