Skip to content

Commit

Permalink
added testing ability to FrameStats tool
Browse files Browse the repository at this point in the history
  • Loading branch information
Elad Elrom authored and Elad Elrom committed Jul 23, 2010
1 parent d9a929e commit 095455e
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 28 deletions.
Binary file modified bin-debug/BitmapCachingExample.swf
Binary file not shown.
Binary file modified bin-debug/CacheExternalAssetsExample.swf
Binary file not shown.
Binary file modified bin-debug/FrameRateControlExample.swf
Binary file not shown.
Binary file modified bin-debug/OptimazingTools.swf
Binary file not shown.
Binary file modified bin-debug/TrackListenersExample.swf
Binary file not shown.
33 changes: 5 additions & 28 deletions src/OptimazingTools.mxml
Expand Up @@ -8,20 +8,10 @@
<![CDATA[
import com.elad.optimize.framerate.FrameRateControl;
import com.elad.optimize.memory.FrameStats;
import com.gskinner.performance.*;
import flash.sampler.getSize;
import mx.controls.Text;
import mx.core.FlexGlobals;
import mx.core.UIComponent;
import spark.components.Button;
import spark.components.RichText;
import spark.components.supportClasses.Skin;
import tests.*;
private var frameRateControl:FrameRateControl;
private var frameStats:FrameStats;
Expand All @@ -36,9 +26,9 @@
componenent.addChild( frameStats );
frameStatsHolder.addElement( componenent );
this.addEventListener(Event.ENTER_FRAME, onEnterFrame );
uicom.addChild( sprite );
frameStats.testingExecutionTimeOfMethod( methodToTest, 10000 );
}
protected function button1_clickHandler():void
Expand All @@ -52,23 +42,10 @@
//PerformanceTestDemo();
}
private var counter:int = 0;
private function onEnterFrame(event:Event):void
private function methodToTest():void
{
if (++counter == 15)
{
frameStats.isDebugMode = true;
trace("********* add to stage START *********");
for (var i:int=0; i<1000; i++)
this.addElement( new RichText() );
}
if (counter == 16)
{
frameStats.isDebugMode = false;
this.removeEventListener(Event.ENTER_FRAME, onEnterFrame );
trace("********* add to stage END *********");
}
sprite.addChild( new Group() );
}
]]>
Expand Down
37 changes: 37 additions & 0 deletions src/com/elad/optimize/memory/FrameStats.as
Expand Up @@ -98,6 +98,13 @@ package com.elad.optimize.memory

// charts data provider
private var dataProvider:Vector.<Object>;

// testing
private var numOfFrames:int = 0;
private var methodToTest:Function;
private var numOfTimerToRun:int;
private var startEnterFrame:int;
private var stopEnterFrame:int;

public function FrameStats( main:*, isDebugMode:Boolean = false, isShowCounters:Boolean = false,
isForceInvalidateAndUpdateAfterEvent:Boolean = false )
Expand Down Expand Up @@ -382,5 +389,35 @@ package com.elad.optimize.memory
globalText.htmlText = globalStyle;
pieText.htmlText = pieStyle;
}

public function testingExecutionTimeOfMethod( methodToTest:Function, numOfTimerToRun:int,
startEnterFrame:int = 15, stopEnterFrame:int = 16 ):void
{
this.numOfFrames = numOfFrames;
this.methodToTest = methodToTest;
this.numOfTimerToRun = numOfTimerToRun;
this.startEnterFrame = startEnterFrame;
this.stopEnterFrame = stopEnterFrame;

main.addEventListener(Event.ENTER_FRAME, trackTest );
}

private function trackTest(event:Event):void
{
if ( ++numOfFrames == startEnterFrame )
{
isDebugMode = true;

for (var i:int=0; i < numOfTimerToRun; i++)
methodToTest();
}

if ( numOfFrames == stopEnterFrame )
{
isDebugMode = false;
this.removeEventListener(Event.ENTER_FRAME, trackTest );
methodToTest = null;
}
}
}
}

0 comments on commit 095455e

Please sign in to comment.