Created
January 19, 2011 20:12
-
-
Save bamboo/786773 to your computer and use it in GitHub Desktop.
Wraps every method with Profiler.BeginSample/Profiler.EndSample calls.
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
import Boo.Lang.Compiler | |
import Boo.Lang.Compiler.Ast | |
class DeepProfilingAttribute(AbstractAstAttribute): | |
""" | |
Wraps every method with Profiler.BeginSample/Profiler.EndSample calls. | |
Save it to the Plugins folder of your Unity project and enable it on a per script basis using: | |
@script DeepProfiling() | |
Or for the whole project using: | |
@assembly DeepProfiling() | |
""" | |
override def Apply(node as Node): | |
node.Accept(SamplingWrapper()) | |
class SamplingWrapper(FastDepthFirstVisitor): | |
override def OnMethod(node as Method): | |
node.Body = [| | |
Profiler.BeginSample($(node.Name)) | |
try: | |
$(node.Body) | |
ensure: | |
Profiler.EndSample() | |
|] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi benblo, it's injecting code before and after each visited method, yes. It happens during compilation, http://is.gd/UgjW8Z for more information. It could be written in any .net language but with boo you get to use quasi-quotation ([| code |]) which makes it much easier to express and understand the code transformations. This technique currently only works with boo and javascript.