Introducing RacetrackStats v.0.0.1
Introduction
RacetrackStats is an in-Flash performance profiler that gives real-time feedback about how the code it is contained within is performing. It can be found at GitHub:
http://github.com/alecmce/RacetrackStats
RacetrackStats is inspired by and seeks to move forward from Mr Doob‘s Stats package (http://code.google.com/p/mrdoob/wiki/stats)
In Action
Below is the first alpha of RacetrackStats in action.
source: http://github.com/alecmce/RacetrackStats/blob/master/test/demo/RacetrackStatsDemo.as
The SWF comprises three small animations (from left to right):
- A mixture of computation and rendering: A simple BitmapData-driven particle system attempting to model smoke using 100000 pixels and a heavy glow filter and blur filter;
- Heavy computation: A prime-factorisation algorithm, which computes 24 * 100 prime factor decompositions per frame. As it continues to run, the numbers get larger which leads to heavier calculation cycles;
- Extremely heavy rendering: A cycadelic circle pattern that has hundreds of semi-transparent circular sprites moving around and overlapping with each other.
The ‘Elastic Racetrack’
RacetrackStats attempts to go beyond Mr Doob’s Stats by measuring how the elastic racetrack is being stretched. The Elastic Racetrack was a phrase coined to describe how the original AVM1 Flash Player segmented each second into frames and attempted to balance the requirements of code, refreshing the screen and doing work like garbage collection. The AVM2 player’s model is sufficiently similar, that the name remains appropriate.
Code Execution
It does this by hooking into the Event.ENTER_FRAME and Event.RENDER events to record when portions of the code start and end. By recording when the ENTER_FRAME starts and when the RENDER starts, the intervening time is taken to be code execution.
Pre-Render Code Execution
Commonly this part of the code cycle is almost unused. If you exploit stage.invalidate and Event.RENDER in order for your classes to execute code after the main code execution has completed, then it will be captured here, between the top-priority Event.RENDER and the bottom-priority Event.RENDER calls.
Rendering
A problem is, the time between the RENDER ending and the ENTER_FRAME starting is used to draw the screen but if time is left over in which the Flash Player has nothing to do, it will idle during this time also. To counteract this, RacetrackStats attempts to throttle the FlashPlayer so that the application is always running as fast as it can, minimising, or even eliminating that idle time. I call this the “render” portion – the “Event.RENDER” event is badly named – screen rendering happens after the RENDER event has finished.
Work To Do
As soon as you add weight like this to an application, the speed at which it runs changes. By measuring the speed, you change the speed. It is the classic scientific paradox. It is mitigated by shrinking down the weight of the stats package as far as possible. At the moment, functionality rather than size is the chief concern, though I have tried to minimize the package by avoiding embedding fonts, and so forth.
I would love to hear what you think about the package, whether positive or negative. I’d also really appreciate it if you use it in your applications. If you have any problems, questions, queries or comments, please leave a comment below, or open an issue on GitHub.
-
http://play.blog2t.net/ Og2t
-
http://alecmce.com Alec McEachran
-
http://twitter.com/miketwoface the.twoface
-
http://alecmce.com Alec McEachran
-
http://play.blog2t.net/ Og2t
-
http://twitter.com/miketwoface the.twoface
-
http://jpauclait.net/ jpauclair
-
http://alecmce.com Alec McEachran
-
http://jpauclair.net/ jpauclair
-
http://alecmce.com Alec McEachran
-
http://jpauclait.net/ jpauclair
-
http://alecmce.com alecmce
-
http://alecmce.com alecmce
-
http://alecmce.com alecmce
-
http://jpauclair.net/ jpauclair
-
http://alecmce.com alecmce
-
http://alecmce.com Alec McEachran
-
http://alecmce.com alecmce


