Source Code Cross Referenced for UtilTimer.java in  » ERP-CRM-Financial » SourceTap-CRM » org » ofbiz » base » util » 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 » ERP CRM Financial » SourceTap CRM » org.ofbiz.base.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: UtilTimer.java,v 1.3 2003/08/20 23:46:03 ajzeneski Exp $
003:         *
004:         *  Copyright (c) 2001, 2002 The Open For Business Project - www.ofbiz.org
005:         *
006:         *  Permission is hereby granted, free of charge, to any person obtaining a
007:         *  copy of this software and associated documentation files (the "Software"),
008:         *  to deal in the Software without restriction, including without limitation
009:         *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
010:         *  and/or sell copies of the Software, and to permit persons to whom the
011:         *  Software is furnished to do so, subject to the following conditions:
012:         *
013:         *  The above copyright notice and this permission notice shall be included
014:         *  in all copies or substantial portions of the Software.
015:         *
016:         *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
017:         *  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
018:         *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
019:         *  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
020:         *  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
021:         *  OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
022:         *  THE USE OR OTHER DEALINGS IN THE SOFTWARE.
023:         */
024:        package org.ofbiz.base.util;
025:
026:        /**
027:         * Timer  handling utility
028:         * Utility class for simple reporting of the progress of a process. 
029:         * Steps are labelled, and the time between each label (or message) 
030:         * and the time since the start are reported in each call to timerString.
031:         *
032:         * @author     <a href="mailto:jonesde@ofbiz.org">David E. Jones</a>
033:         * @version    $Revision: 1.3 $
034:         * @since      2.0
035:         */
036:        public class UtilTimer {
037:
038:            public static final String module = UtilTimer.class.getName();
039:
040:            long realStartTime;
041:            long startTime;
042:            long lastMessageTime;
043:            String lastMessage = null;
044:            boolean log = false;
045:
046:            /** Default constructor. Starts the timer.
047:             */
048:            public UtilTimer() {
049:                lastMessageTime = realStartTime = startTime = System
050:                        .currentTimeMillis();
051:                lastMessage = "Begin";
052:            }
053:
054:            /** Creates a string with information including the passed message, the last passed message and the time since the last call, and the time since the beginning
055:             * @param message A message to put into the timer String
056:             * @return A String with the timing information, the timer String
057:             */
058:            public String timerString(String message) {
059:                return timerString(message, this .getClass().getName());
060:            }
061:
062:            /** Creates a string with information including the passed message, the last passed message and the time since the last call, and the time since the beginning
063:             * @param message A message to put into the timer String
064:             * @param module The debug/log module/thread to use, can be null for root module
065:             * @return A String with the timing information, the timer String
066:             */
067:            public String timerString(String message, String module) {
068:                // time this call to avoid it interfering with the main timer
069:                long tsStart = System.currentTimeMillis();
070:
071:                String retString = "[["
072:                        + message
073:                        + "- total:"
074:                        + secondsSinceStart()
075:                        + ",since last("
076:                        + ((lastMessage.length() > 20) ? (lastMessage
077:                                .substring(0, 17) + "...") : lastMessage)
078:                        + "):" + secondsSinceLast() + "]]";
079:
080:                lastMessage = message;
081:                if (log)
082:                    Debug.log(Debug.TIMING, null, retString, module,
083:                            "org.ofbiz.base.util.UtilTimer");
084:
085:                // have lastMessageTime come as late as possible to just time what happens between calls
086:                lastMessageTime = System.currentTimeMillis();
087:                // update startTime to disclude the time this call took
088:                startTime += (lastMessageTime - tsStart);
089:
090:                return retString;
091:            }
092:
093:            /** Returns the number of seconds since the timer started
094:             * @return The number of seconds since the timer started
095:             */
096:            public double secondsSinceStart() {
097:                return ((double) timeSinceStart()) / 1000.0;
098:            }
099:
100:            /** Returns the number of seconds since the last time timerString was called
101:             * @return The number of seconds since the last time timerString was called
102:             */
103:            public double secondsSinceLast() {
104:                return ((double) timeSinceLast()) / 1000.0;
105:            }
106:
107:            /** Returns the number of milliseconds since the timer started
108:             * @return The number of milliseconds since the timer started
109:             */
110:            public long timeSinceStart() {
111:                long currentTime = System.currentTimeMillis();
112:
113:                return currentTime - startTime;
114:            }
115:
116:            /** Returns the number of milliseconds since the last time timerString was called
117:             * @return The number of milliseconds since the last time timerString was called
118:             */
119:            public long timeSinceLast() {
120:                long currentTime = System.currentTimeMillis();
121:
122:                return currentTime - lastMessageTime;
123:            }
124:
125:            /** Sets the value of the log member, denoting whether log output is off or not
126:             * @param log The new value of log
127:             */
128:            public void setLog(boolean log) {
129:                this .log = log;
130:            }
131:
132:            /** Gets the value of the log member, denoting whether log output is off or not
133:             * @return The value of log
134:             */
135:            public boolean getLog() {
136:                return log;
137:            }
138:
139:            /** Creates a string with information including the passed message, the time since the last call,
140:             * and the time since the beginning.  This version allows an integer level to be specified to
141:             * improve readability of the output.
142:             * @param level Integer specifying how many levels to indent the timer string so the output can be more easily read through nested method calls.
143:             * @param message A message to put into the timer String
144:             * @return A String with the timing information, the timer String
145:             */
146:            public String timerString(int level, String message) {
147:                // String retString =  "[[" + message + ": seconds since start: " + secondsSinceStart() + ",since last(" + lastMessage + "):" + secondsSinceLast() + "]]";
148:
149:                StringBuffer retStringBuf = new StringBuffer();
150:
151:                for (int i = 0; i < level; i++) {
152:                    retStringBuf.append("| ");
153:                }
154:                retStringBuf.append("(");
155:
156:                String timeSinceStartStr = String.valueOf(timeSinceStart());
157:
158:                // int spacecount = 5 - timeSinceStartStr.length();
159:                // for (int i=0; i < spacecount; i++) { retStringBuf.append(' '); }
160:                retStringBuf.append(timeSinceStartStr + ",");
161:
162:                String timeSinceLastStr = String.valueOf(timeSinceLast());
163:
164:                // spacecount = 4 - timeSinceLastStr.length();
165:                // for (int i=0; i < spacecount; i++) { retStringBuf.append(' '); }
166:                retStringBuf.append(timeSinceLastStr);
167:
168:                retStringBuf.append(")");
169:                int spacecount = 12 + (2 * level) - retStringBuf.length();
170:
171:                for (int i = 0; i < spacecount; i++) {
172:                    retStringBuf.append(' ');
173:                }
174:                retStringBuf.append(message);
175:
176:                // lastMessageTime = (new Date()).getTime();
177:                lastMessageTime = System.currentTimeMillis();
178:                // lastMessage = message;
179:
180:                String retString = retStringBuf.toString();
181:
182:                // if(!quiet) Debug.logInfo(retString, module);
183:                if (Debug.infoOn())
184:                    Debug.logInfo(retString, module);
185:                return retString;
186:            }
187:
188:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.