Source Code Cross Referenced for MemoryStopwatchEngine.java in  » Profiler » stopwatch » com » commsen » stopwatch » engines » 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 » Profiler » stopwatch » com.commsen.stopwatch.engines 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


01:        /*
02:         * $Id: MemoryStopwatchEngine.java,v 1.2 2006/03/06 11:30:53 azzazzel Exp $
03:         *
04:         * Copyright 2006 Commsen International
05:         * 
06:         * Licensed under the Common Public License, Version 1.0 (the "License");
07:         * you may not use this file except in compliance with the License.
08:         * You may obtain a copy of the License at
09:         * 
10:         *      http://www.opensource.org/licenses/cpl1.0.txt
11:         * 
12:         * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
13:         * EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS 
14:         * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
15:         *
16:         */
17:        package com.commsen.stopwatch.engines;
18:
19:        import org.apache.log4j.Logger;
20:
21:        import com.commsen.stopwatch.storages.MemoryHSQLInMemoryStorage;
22:
23:        /**
24:         * This class extends default Stopwatch's engine to provide information about memory usage.
25:         * <b>Note: the memory usage measurements performed by this class are FAR FROM ACCURATE.</b>
26:         * 
27:         * <p>As of now I'm not aware of how one can measure the actual amount of memory given object uses.
28:         * This class simply remembers the amount of memory used by JVM at the time of starting the measurement
29:         * and compares it to the amount of memory used by JVM at the time of completing the measurement.
30:         * This of course may have nothing to do the truth if some other threads are running and consuming memory
31:         * or for example GC is started while measuring.</p>
32:         * 
33:         * <p>So the results may vary from "almost correct" in the case of single threaded application
34:         * to "pure fiction" in case of heavily loaded, multi threaded application</p>
35:         * 
36:         * <p>To use MemoryStopwatchEngine with Stopwatch one can :
37:         * <ul> 
38:         *   <li>run application with <code>-Dcom.commsen.stopwatch.engine=com.commsen.stopwatch.engines.MemoryStopwatchEngine</code> JVM parameter</li>
39:         *   <li>create "stopwatch.properties" file on classpath and set <code>engine=com.commsen.stopwatch.engines.MemoryStopwatchEngine</code></li>
40:         * </ul>
41:         * </p>  
42:         * 
43:         * @author Milen Dyankov
44:         */
45:        public class MemoryStopwatchEngine extends DefaultStopwatchEngine {
46:
47:            /**
48:             * Logger for this class
49:             */
50:            private static final Logger log = Logger
51:                    .getLogger(MemoryStopwatchEngine.class);
52:
53:            private static Runtime runtime = Runtime.getRuntime();
54:
55:            /**
56:             * 
57:             */
58:            public MemoryStopwatchEngine() {
59:                setStorage(new MemoryHSQLInMemoryStorage());
60:            }
61:
62:            /**
63:             * @see com.commsen.stopwatch.engines.DefaultStopwatchEngine#end(long)
64:             */
65:            public void end(long id) {
66:                // first of all get the time
67:                Long timestamp = new Long(System.currentTimeMillis());
68:                getStorageManager().completeRecord(id,
69:                        new Object[] { timestamp, usedMemory() });
70:            }
71:
72:            /**
73:             * @see com.commsen.stopwatch.engines.DefaultStopwatchEngine#begin(java.lang.String, java.lang.String)
74:             */
75:            public long begin(String group, String label) {
76:                // first of all get the time
77:                Long timestamp = new Long(System.currentTimeMillis());
78:                return getStorageManager().newRecord(
79:                        new Object[] { group, label, timestamp, usedMemory() });
80:            }
81:
82:            private Long usedMemory() {
83:                return new Long(runtime.totalMemory() - runtime.freeMemory());
84:            }
85:
86:            protected Logger getLogger() {
87:                return log;
88:            }
89:
90:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.