Source Code Cross Referenced for StackProfiler.java in  » Mail-Clients » columba-1.4 » org » columba » core » 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 » Mail Clients » columba 1.4 » org.columba.core.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.columba.core.util;
002:
003:        import java.util.Hashtable;
004:        import java.util.Iterator;
005:        import java.util.Vector;
006:
007:        import org.columba.core.logging.Logging;
008:
009:        public class StackProfiler {
010:
011:            private static final java.util.logging.Logger LOG = java.util.logging.Logger
012:                    .getLogger("org.columba.core.util"); //$NON-NLS-1$
013:
014:            /**
015:             * keeps a list of profile point ids
016:             */
017:            private Vector vector = new Vector();
018:
019:            /**
020:             * key is the id, value is the profile data
021:             */
022:            private Hashtable hashtable = new Hashtable();
023:
024:            /**
025:             * current path in simple tree-like hierarchy
026:             */
027:            private String currentPath = "";
028:
029:            /**
030:             * Set new profiling starting point. This is where the time measurment
031:             * actually starts.
032:             *
033:             * @param id
034:             *            unique id of profiling point
035:             */
036:            public void push(String id) {
037:                // abort if not in debugging mode
038:                if (Logging.DEBUG == false)
039:                    return;
040:
041:                // current time
042:                long currentTime = System.currentTimeMillis();
043:
044:                // store profiling point data
045:                hashtable.put(id, new ProfileData(id, currentPath, new Long(
046:                        currentTime).longValue()));
047:
048:                // this profiling point is parent of the next one
049:                currentPath = currentPath + "/" + id;
050:
051:                // store id
052:                vector.add(id);
053:            }
054:
055:            /**
056:             * Close profiling point. This is where the time measurement actually ends.
057:             *
058:             * @param id
059:             *            unique id of profiling point
060:             */
061:            public void pop(String id) {
062:                System.out.println("id=" + id);
063:                // abort if not in debugging mode
064:                if (Logging.DEBUG == false)
065:                    return;
066:
067:                if (id == null)
068:                    throw new IllegalArgumentException("id == null");
069:
070:                if (hashtable.containsKey(id) == false)
071:                    throw new IllegalArgumentException("id=" + id
072:                            + " not found");
073:
074:                long currentTime = System.currentTimeMillis();
075:
076:                ProfileData bean = (ProfileData) hashtable.get(id);
077:                bean.endTime = currentTime;
078:
079:                String firstItem = (String) vector.get(0);
080:                if (firstItem.equals(id)) {
081:                    // print all collected profile data
082:
083:                    LOG.info("profiler info:"); //$NON-NLS-1$
084:                    Iterator it = vector.listIterator();
085:
086:                    while (it.hasNext()) {
087:                        String nextId = (String) it.next();
088:                        printDuration(nextId);
089:                    }
090:                } else {
091:                    // current path is the parent of the current element
092:                    int index = currentPath.lastIndexOf("/");
093:                    currentPath = currentPath.substring(0, index);
094:                }
095:            }
096:
097:            /**
098:             * Print debug data.
099:             *
100:             * @param id
101:             *            unique profiling point id
102:             */
103:            private void printDuration(String id) {
104:                if (id == null)
105:                    throw new IllegalArgumentException("id == null");
106:                if (hashtable.containsKey(id) == false)
107:                    throw new IllegalArgumentException("id not found");
108:
109:                ProfileData bean = (ProfileData) hashtable.get(id);
110:                String splits[] = bean.path.split("/");
111:
112:                for (int i = 0; i < splits.length; i++)
113:                    System.out.print("  ");
114:
115:                long duration = bean.endTime - bean.startTime;
116:                LOG.info("[" + duration + "ms] - " + id); //$NON-NLS-2$
117:            }
118:
119:            /**
120:             * Structure containing profiling data.
121:             */
122:            private class ProfileData {
123:                protected String id;
124:
125:                protected String path;
126:
127:                protected long startTime;
128:
129:                protected long endTime;
130:
131:                protected ProfileData(String id, String path, long startTime) {
132:                    this.id = id;
133:                    this.path = path;
134:                    this.startTime = startTime;
135:                }
136:
137:            }
138:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.