-
Notifications
You must be signed in to change notification settings - Fork 0
/
movieMonitor.as
125 lines (125 loc) · 4.54 KB
/
movieMonitor.as
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package {
import flash.display.Sprite;
import flash.display.DisplayObjectContainer;
import flash.display.DisplayObject;
import flash.events.Event;
import flash.system.System;
import flash.text.StyleSheet;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.utils.getTimer;
public class movieMonitor extends Sprite {
private var xml:XML;
private var theText:TextField;
private var fps:int=0;
private var ms:uint;
private var lastTimeCheck:uint;
private var maxMemory:Number=0;
private var fpsVector:Vector.<Number>=new Vector.<Number>();
private var childrenCount:int;
public function movieMonitor():void {
xml =
<xml>
<sectionTitle>FPS MONITOR</sectionTitle>
<sectionLabel>FPS: </sectionLabel>
<framesPerSecond>-</framesPerSecond>
<sectionLabel>Minute average: </sectionLabel>
<averageFPS>-</averageFPS>
<sectionLabel>ms per frame: </sectionLabel>
<msFrame>-</msFrame>
<sectionTitle>MEMORY MONITOR</sectionTitle>
<sectionLabel>Direct: </sectionLabel>
<directMemory>-</directMemory>
<sectionLabel>Max direct: </sectionLabel>
<directMemoryMax>-</directMemoryMax>
<sectionLabel>Total: </sectionLabel>
<veryTotalMemory>-</veryTotalMemory>
<sectionLabel>Garbage: </sectionLabel>
<garbageMemory>-</garbageMemory>
<sectionTitle>STAGE MONITOR</sectionTitle>
<sectionLabel>Width: </sectionLabel>
<widthPx>-</widthPx>
<sectionLabel>Height: </sectionLabel>
<heightPx>-</heightPx>
<sectionLabel>Children: </sectionLabel>
<nChildren>-</nChildren>
<sectionTitle>MOUSE MONITOR</sectionTitle>
<sectionLabel>MouseX: </sectionLabel>
<MouseX>-</MouseX>
<sectionLabel>MouseY: </sectionLabel>
<MouseY>-</MouseY>
</xml>;
var style:StyleSheet = new StyleSheet();
style.setStyle("xml",{fontSize:"9px",fontFamily:"arial"});
style.setStyle("sectionTitle",{color:"#FFAA00"});
style.setStyle("sectionLabel",{color:"#CCCCCC",display:"inline"});
style.setStyle("framesPerSecond",{color:"#FFFFFF"});
style.setStyle("msFrame",{color:"#FFFFFF"});
style.setStyle("averageFPS",{color:"#FFFFFF"});
style.setStyle("directMemory",{color:"#FFFFFF"});
style.setStyle("veryTotalMemory",{color:"#FFFFFF"});
style.setStyle("garbageMemory",{color:"#FFFFFF"});
style.setStyle("directMemoryMax",{color:"#FFFFFF"});
style.setStyle("widthPx",{color:"#FFFFFF"});
style.setStyle("heightPx",{color:"#FFFFFF"});
style.setStyle("nChildren",{color:"#FFFFFF"});
style.setStyle("MouseX",{color:"#FFFFFF"});
style.setStyle("MouseY",{color:"#FFFFFF"});
theText = new TextField();
theText.alpha=0.8;
theText.autoSize=TextFieldAutoSize.LEFT;
theText.styleSheet=style;
theText.condenseWhite=true;
theText.selectable=false;
theText.mouseEnabled=false;
theText.background=true;
theText.backgroundColor=0x000000;
theText.x = -90;
addChild(theText);
addEventListener(Event.ENTER_FRAME, update);
}
private function update(e:Event):void {
var timer:int=getTimer();
if (timer-1000>lastTimeCheck) {
var vectorLength:int=fpsVector.push(fps);
if (vectorLength>60) {
fpsVector.shift();
}
var vectorAverage:Number=0;
for (var i:Number = 0; i < fpsVector.length; i++) {
vectorAverage+=fpsVector[i];
}
vectorAverage=vectorAverage/fpsVector.length;
xml.averageFPS=Math.round(vectorAverage);
var directMemory:Number=System.totalMemory;
maxMemory=Math.max(directMemory,maxMemory);
xml.directMemory=(directMemory/1048576).toFixed(3);
xml.directMemoryMax=(maxMemory/1048576).toFixed(3);
xml.veryTotalMemory = (System.privateMemory/1048576).toFixed(3);
xml.garbageMemory = (System.freeMemory/1048576).toFixed(3);
xml.framesPerSecond=fps+" / "+stage.frameRate;
xml.widthPx=stage.width+" / "+stage.stageWidth;
xml.heightPx=stage.height+" / "+stage.stageHeight;
xml.MouseX=stage.mouseX+" / "+stage.stageWidth;
xml.MouseY=stage.mouseY+" / "+stage.stageHeight;
childrenCount=0;
countDisplayList(stage);
xml.nChildren=childrenCount;
fps=0;
lastTimeCheck=timer;
}
fps++;
xml.msFrame=(timer-ms);
ms=timer;
theText.htmlText=xml;
}
function countDisplayList(container:DisplayObjectContainer):void {
childrenCount+=container.numChildren;
for (var i:uint=0; i < container.numChildren; i++) {
if (container.getChildAt(i) is DisplayObjectContainer) {
countDisplayList(DisplayObjectContainer(container.getChildAt(i)));
}
}
}
}
}