Source Code Cross Referenced for MeasureWarmUp.java in  » IDE-Netbeans » performance » startup » 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 » IDE Netbeans » performance » startup 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        package startup;
043:
044:        import java.io.BufferedReader;
045:        import java.io.File;
046:        import java.io.FileReader;
047:        import java.io.IOException;
048:
049:        import java.util.Hashtable;
050:
051:        /**
052:         * Measure warm up time by org.netbeans.core.perftool.StartLog.
053:         * Number of starts with new userdir is defined by property
054:         * <br> <code> org.netbeans.performance.repeat.with.new.userdir </code>
055:         * <br> and number of starts with old userdir is defined by property
056:         * <br> <code> org.netbeans.performance.repeat </code>
057:         *
058:         * @author Marian.Mirilovic@sun.com
059:         */
060:        public class MeasureWarmUp
061:                extends
062:                org.netbeans.performance.test.utilities.MeasureStartupTimeTestCase {
063:
064:            protected static final String warmup = "Warmup task executed ";
065:            protected static final String warmup_started = "Warmup started";
066:            protected static final String warmup_finished = "Warmup finished, took ";
067:
068:            /** Define testcase
069:             * @param testName name of the testcase
070:             */
071:            public MeasureWarmUp(java.lang.String testName) {
072:                super (testName);
073:            }
074:
075:            /** Testing start of IDE with measurement of the startup time.
076:             * @throws IOException
077:             */
078:            public void testWarmUp() throws IOException {
079:                for (int i = 1; i <= repeat; i++) {
080:                    runIDEandMeasureWarmUp(getMeasureFile(i),
081:                            getUserdirFile(i), 5000);
082:                }
083:            }
084:
085:            /** Run IDE and read measured time from file
086:             *
087:             * @param measureFile file where the time of window system painting is stored
088:             * @throws java.io.IOException
089:             * @return startup time
090:             */
091:            private void runIDEandMeasureWarmUp(File measureFile, File userdir,
092:                    long timeout) throws IOException {
093:                runIDEWarmUp(getIdeHome(), userdir, measureFile, timeout);
094:                Hashtable measuredValues = parseMeasuredValues(measureFile);
095:
096:                if (measuredValues == null)
097:                    fail("It isn't possible measure Warm Up.");
098:
099:                java.util.Iterator iter = measuredValues.keySet().iterator();
100:                String name;
101:                long value;
102:                while (iter.hasNext()) {
103:                    name = (String) iter.next();
104:                    value = ((Long) measuredValues.get(name)).longValue();
105:                    System.out.println(name + "=" + value);
106:                    reportPerformance(name, value, "ms", 1);
107:                }
108:            }
109:
110:            /** Creates and executes the command line for running IDE.
111:             * @param ideHome IDE home directory
112:             * @param userdir User directory
113:             * @param measureFile file where measured time is stored
114:             * @throws IOException
115:             */
116:            private static void runIDEWarmUp(File ideHome, File userdir,
117:                    File measureFile, long timeout) throws IOException {
118:
119:                //check <userdir>/lock file
120:                if (new File(userdir, "lock").exists())
121:                    fail("Original Userdir is locked!");
122:
123:                //add guitracker on classpath
124:                String classpath = System
125:                        .getProperty("performance.testutilities.dist.jar");
126:
127:                //add property on command line
128:                String test_cmd_suffix = System
129:                        .getProperty("xtest.perf.commandline.suffix");
130:
131:                // create jdkhome switch
132:                String jdkhome = System.getProperty("java.home");
133:                if (jdkhome.endsWith("jre"))
134:                    jdkhome = jdkhome.substring(0, jdkhome.length() - 4);
135:
136:                File ideBinDir = new File(ideHome, "bin");
137:
138:                String executor;
139:
140:                if (getPlatform().equals(WINDOWS)) {
141:                    executor = "netbeans.exe";
142:                } else {
143:                    executor = "netbeans";
144:                }
145:
146:                // construct command line
147:                StringBuffer cmd = new StringBuffer((new File(ideBinDir,
148:                        executor)).getAbsolutePath());
149:
150:                // add other argumens
151:                // guiltracker lib
152:                cmd.append(" --cp:a " + classpath);
153:                // userdir
154:                cmd.append(" --userdir " + userdir.getAbsolutePath());
155:                // get jdkhome path
156:                cmd.append(" --jdkhome " + jdkhome);
157:                // netbeans full hack
158:                cmd.append(" -J-Dnetbeans.full.hack=true");
159:                // measure argument
160:                cmd.append(" -J-Dorg.netbeans.log.startup.logfile="
161:                        + measureFile.getAbsolutePath());
162:                // measure argument - we have to set this one to ommit repaint of memory toolbar (see openide/actions/GarbageCollectAction)
163:                cmd.append(" -J-Dorg.netbeans.log.startup=tests");
164:                // close the IDE after startup
165:                cmd.append(" -J-Dnetbeans.close=true");
166:                // close the IDE after warmup
167:                cmd.append(" -J-Dnetbeans.warm.close=true");
168:                // wait after startup, need to set longer time for complex startup because rescan rises
169:                cmd.append(" -J-Dorg.netbeans.performance.waitafterstartup="
170:                        + timeout);
171:                // disable rescaning after startup
172:                //        cmd += " -J-Dnetbeans.javacore.noscan=true";
173:                // test command line suffix
174:                if (test_cmd_suffix != null
175:                        && !test_cmd_suffix
176:                                .equalsIgnoreCase("${xtest.perf.commandline.suffix}"))
177:                    cmd.append(" " + test_cmd_suffix.replace('\'', ' ').trim());
178:
179:                System.out.println("Running: " + cmd);
180:
181:                Runtime runtime = Runtime.getRuntime();
182:
183:                // need to create out and err handlers
184:                Process ideProcess = runtime.exec(cmd.toString(), null,
185:                        ideBinDir);
186:
187:                // track out and errs from ide - the last parameter is PrintStream where the
188:                // streams are copied - currently set to null, so it does not hit performance much
189:                ThreadReader sout = new ThreadReader(ideProcess
190:                        .getInputStream(), null);
191:                ThreadReader serr = new ThreadReader(ideProcess
192:                        .getErrorStream(), null);
193:                try {
194:                    int exitStatus = ideProcess.waitFor();
195:                    System.out
196:                            .println("IDE exited with status = " + exitStatus);
197:                } catch (InterruptedException ie) {
198:                    ie.printStackTrace(System.err);
199:                    IOException ioe = new IOException(
200:                            "Caught InterruptedException :" + ie.getMessage());
201:                    ioe.initCause(ie);
202:                    throw ioe;
203:                }
204:            }
205:
206:            /** Parse logged startup time from the file.
207:             * @param measuredFile file where the startup time is stored
208:             * @return measured startup time
209:             */
210:            protected static Hashtable parseMeasuredValues(File measuredFile) {
211:                Hashtable measuredValues = new Hashtable();
212:
213:                BufferedReader br = null;
214:                try {
215:                    br = new BufferedReader(new FileReader(measuredFile));
216:                    String readLine, name = "";
217:                    long value, time = 0;
218:                    int begin;
219:
220:                    //read log file until "Warmup started"
221:                    while ((readLine = br.readLine()) != null
222:                            && readLine.indexOf(warmup_started) == -1)
223:                        ;
224:
225:                    //start to parse
226:                    while ((readLine = br.readLine()) != null) {
227:                        try {
228:                            if ((begin = readLine.indexOf(warmup)) != -1) { // @10741 - Warmup running org.netbeans.core.ui.DnDWarmUpTask dT=53
229:                                time = getTime(readLine);
230:                                name = readLine.substring(begin
231:                                        + warmup.length(), readLine.indexOf(
232:                                        " ", begin + warmup.length()));
233:                                measuredValues.put(name, Long.valueOf(time));
234:
235:                            } else if ((begin = readLine
236:                                    .indexOf(warmup_finished)) != -1) { // @12059 - Warmup finished, took 1459ms
237:                                name = "Warmup finished";
238:                                value = Long.parseLong(readLine.substring(
239:                                        readLine.indexOf("took ")
240:                                                + "took ".length(), readLine
241:                                                .indexOf("ms")));
242:                                measuredValues.put(name, new Long(value));
243:                            }
244:                        } catch (NumberFormatException nfe) {
245:                            nfe.printStackTrace(System.err);
246:                            return null;
247:                        }
248:                    }
249:                    return measuredValues;
250:                } catch (IOException ioe) {
251:                    ioe.printStackTrace(System.err);
252:                    return null;
253:                } finally {
254:                    if (br != null) {
255:                        try {
256:                            br.close();
257:                        } catch (IOException ioe) {
258:                            ioe.printStackTrace(System.err);
259:                            return null;
260:                        }
261:                    }
262:                }
263:            }
264:
265:            /**
266:             * Parse start time for the next warmup task
267:             */
268:            protected static long getTime(String line) {
269:                if (line.indexOf("@") != -1 && line.indexOf("-") != -1)
270:                    return Long.parseLong(line
271:                            .substring(line.indexOf(" dT=") + 4));
272:                return 0;
273:            }
274:
275:            /*
276:             @25078 - Warmup started
277:             @25078 - Warmup running org.netbeans.modules.java.JavaWarmUpTask dT=0
278:             @25187 - Warmup running org.netbeans.core.ui.warmup.ContextMenuWarmUpTask dT=109
279:             @25281 - Warmup running org.netbeans.core.ui.warmup.DnDWarmUpTask dT=94
280:             @25281 - Warmup running org.netbeans.core.ui.warmup.MenuWarmUpTask dT=0
281:             @28406 - Warmup running org.netbeans.modules.editor.EditorWarmUpTask dT=3125
282:             @30141 - Warmup running org.netbeans.modules.java.editor.JavaEditorWarmUpTask dT=1735
283:             @31172 - Warmup finished, took 6094ms
284:             */
285:
286:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.