Source Code Cross Referenced for PerfBehavior.java in  » 6.0-JDK-Modules » java-3d » org » jdesktop » j3dfly » utils » internalplugins » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » java 3d » org.jdesktop.j3dfly.utils.internalplugins 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  $Header: /cvs/j3dfly/J3dFly/src/org/jdesktop/j3dfly/utils/internalplugins/PerfBehavior.java,v 1.1 2005/04/20 21:05:05 paulby Exp $
003:         *
004:         *                         Sun Public License Notice
005:         *
006:         *  The contents of this file are subject to the Sun Public License Version
007:         *  1.0 (the "License"). You may not use this file except in compliance with
008:         *  the License. A copy of the License is available at http://www.sun.com/
009:         *  
010:         *  The Original Code is Java 3D(tm) Fly Through.
011:         *  The Initial Developer of the Original Code is Paul Byrne.
012:         *  Portions created by Paul Byrne are Copyright (C) 2002.
013:         *  All Rights Reserved.
014:         *  
015:         *  Contributor(s): Paul Byrne.
016:         *  
017:         **/
018:        package org.jdesktop.j3dfly.utils.internalplugins;
019:
020:        import javax.media.j3d.*;
021:        import javax.vecmath.*;
022:        import java.text.*;
023:
024:        public class PerfBehavior extends Behavior {
025:            WakeupOnElapsedFrames FPSwakeup = new WakeupOnElapsedFrames(0);
026:            private static final long testduration = 1000; // in milliseconds
027:            private static final long sampleduration = 10000; // in milliseconds
028:            private boolean doCalibration = true;
029:            private boolean startup = true;
030:            private boolean warmup = true;
031:            private int warmupTime = 20000; // Set the warmup time to 20 sec.
032:            private int numframes = 0;
033:            private int maxframes = 1;
034:            private long startuptime = 0;
035:            private long currtime = 0;
036:            private long lasttime = 0;
037:            private long deltatime;
038:            private boolean finiteLoop = true;
039:            static boolean avgFPS = true;
040:            private int sumFrames = 0;
041:            private long sumTimes = 0;
042:            private int loop = 0;
043:            private int loopCount = 5;
044:            private boolean doStat = false;
045:            private double fps;
046:            private double avgFps;
047:            private int prtMemFpCount = 0;
048:
049:            public NumberFormat nf = null;
050:
051:            public PerfBehavior(BoundingSphere bounds, boolean ds) {
052:                setSchedulingBounds(bounds);
053:                setEnable(true);
054:                doStat = ds;
055:                nf = NumberFormat.getNumberInstance();
056:            }
057:
058:            public PerfBehavior(BoundingSphere bounds, boolean ds, int memFpCnt) {
059:                setSchedulingBounds(bounds);
060:                setEnable(true);
061:                doStat = ds;
062:                nf = NumberFormat.getNumberInstance();
063:                prtMemFpCount = memFpCnt;
064:            }
065:
066:            // Called to init the behavior
067:            public void initialize() {
068:                // Set the trigger for the interpolator
069:                wakeupOn(FPSwakeup);
070:            }
071:
072:            private void memoryFootPrint() {
073:                long totalMem, freeMem, usedMem;
074:
075:                for (int i = 0; i < prtMemFpCount; i++) {
076:                    totalMem = Runtime.getRuntime().totalMemory();
077:                    freeMem = Runtime.getRuntime().freeMemory();
078:                    usedMem = totalMem - freeMem;
079:                    System.out
080:                            .print("mem used - before: " + usedMem + "bytes ");
081:                    //System.out.print("mem used - before: " + usedMem + " ");
082:                    System.runFinalization();
083:                    System.gc();
084:                    System.runFinalization();
085:                    totalMem = Runtime.getRuntime().totalMemory();
086:                    freeMem = Runtime.getRuntime().freeMemory();
087:                    usedMem = totalMem - freeMem;
088:                    System.out.println("after: " + usedMem + "bytes ");
089:                    //System.out.println("after: " + usedMem + " ");
090:                    try {
091:                        Thread.sleep(500);
092:                    } catch (InterruptedException e) {
093:                    }
094:                }
095:            }
096:
097:            // Called every time the behavior is activated
098:            public void processStimulus(java.util.Enumeration critera) {
099:                // Apply Calibration Algorithm :
100:                // To determine maxframes to run before sampling the time
101:                // to determine frames per second.
102:                // sampleduration = 10000, To run test pass for 10 seconds.
103:
104:                if (doCalibration) { // do the calibration
105:                    if (startup) {
106:                        memoryFootPrint();
107:                        startuptime = System.currentTimeMillis();
108:                        startup = false;
109:                    } else if (warmup) { // Let's wait for the system to stable down.
110:                        currtime = System.currentTimeMillis();
111:                        deltatime = currtime - startuptime;
112:                        if (deltatime > warmupTime) {
113:                            // System.out.println("I'm ready!!! deltatime " + deltatime);
114:                            warmup = false;
115:                            lasttime = System.currentTimeMillis();
116:                        }
117:                    } else {
118:                        numframes += 1;
119:                        // System.out.print(maxframes+" "+numframes+" "+lasttime+" ");
120:                        if (numframes >= maxframes) {
121:                            currtime = System.currentTimeMillis();
122:                            deltatime = currtime - lasttime;
123:                            // System.out.println("deltatime = " + deltatime +
124:                            //		          ", numframes = " + numframes);
125:                            if (deltatime > testduration) {
126:                                maxframes = (int) Math
127:                                        .ceil((double) numframes
128:                                                * ((double) sampleduration / (double) deltatime));
129:                                //System.out.println("maxframes = " + maxframes);
130:
131:                                // reset the value for the measurement
132:                                doCalibration = false;
133:                                numframes = 0;
134:                                lasttime = System.currentTimeMillis();
135:                            } else {
136:                                maxframes *= 2;
137:                            }
138:                        }
139:                    }
140:                } else { // do the measurement
141:                    numframes += 1;
142:                    // System.out.println("PerfBeh : numframes is " + numframes);
143:
144:                    if (numframes >= maxframes) {
145:                        currtime = System.currentTimeMillis();
146:                        deltatime = currtime - lasttime;
147:                        double fps = (double) numframes
148:                                / ((double) deltatime / 1000.0);
149:
150:                        System.out.println("PerfBeh : numframes : " + numframes
151:                                + " time : " + ((double) deltatime / 1000.0)
152:                                + " sec." + " fps : " + nf.format(fps));
153:                        if (finiteLoop) {
154:                            sumFrames += numframes;
155:                            sumTimes += deltatime;
156:                            avgFps = (double) sumFrames * 1000.0
157:                                    / (double) sumTimes;
158:                            loop++;
159:                            if (loop >= loopCount) {
160:                                System.out.println("PerfBeh : Avg fps "
161:                                        + avgFps);
162:                                if (doStat) {
163:                                    doCalibration = true;
164:                                    loop = 0;
165:                                    numframes = 0;
166:                                    maxframes = 1;
167:                                    currtime = 0;
168:                                    startup = true;
169:                                    warmup = true;
170:                                    lasttime = 0;
171:                                    doStat(avgFps, true);
172:                                } else {
173:                                    System.out
174:                                            .println("************** The End **************\n");
175:                                    System.exit(0);
176:                                }
177:                            }
178:                        }
179:
180:                        if (doStat) {
181:                            doStat(fps, false);
182:                        }
183:
184:                        numframes = 0;
185:                        lasttime = System.currentTimeMillis();
186:                        ;
187:                    }
188:                }
189:
190:                // Set the trigger for the interpolator
191:                wakeupOn(FPSwakeup);
192:
193:            }
194:
195:            public void setFiniteLoop(boolean fl) {
196:                finiteLoop = fl;
197:            }
198:
199:            public void setLoopCount(int lc) {
200:                loopCount = lc;
201:            }
202:
203:            public void doStat(double fps, boolean exit) {
204:
205:            }
206:
207:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.