Created
October 10, 2011 16:27
-
-
Save kentaromiura/1275736 to your computer and use it in GitHub Desktop.
Class Profiler for Mootools 1.3.x
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
--- | |
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