You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2012/04/05 19:24:09 UTC

svn commit: r1309958 - /openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/Debug.java

Author: dblevins
Date: Thu Apr  5 17:24:08 2012
New Revision: 1309958

URL: http://svn.apache.org/viewvc?rev=1309958&view=rev
Log:
Minor tweaking to the Debug trace code -- not used at runtime

Modified:
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/Debug.java

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/Debug.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/Debug.java?rev=1309958&r1=1309957&r2=1309958&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/Debug.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/Debug.java Thu Apr  5 17:24:08 2012
@@ -16,11 +16,17 @@
  */
 package org.apache.openejb.util;
 
+import org.apache.openejb.loader.IO;
+import org.hsqldb.lib.Collection;
+
 import javax.naming.Binding;
 import javax.naming.Context;
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
 import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.OutputStream;
 import java.io.PrintStream;
 import java.lang.reflect.Field;
 import java.util.ArrayList;
@@ -109,6 +115,52 @@ public class Debug {
 
         private final Map<String, Node> elements = new LinkedHashMap<String, Node>();
 
+        private final List<Event> events = new ArrayList<Event>();
+
+        private static class Event {
+            private final long time = System.currentTimeMillis();
+            private final List<StackTraceElement> elements;
+
+            private Event(List<StackTraceElement> elements) {
+                this.elements = Collections.unmodifiableList(elements);
+            }
+
+            @Override
+            public String toString() {
+                return "<li>" +
+                        "time=" + time +
+                        ", elements=" + elements +
+                        "</li>";
+            }
+        }
+
+        public static void record() {
+            try {
+                final File file = new File("/tmp/trace.html");
+                final OutputStream write = IO.write(file);
+
+                report(write);
+            } catch (FileNotFoundException e) {
+                e.printStackTrace();
+            }
+        }
+
+        public static void report(OutputStream write) {
+            final PrintStream stream = new PrintStream(write);
+            report(stream);
+            stream.close();
+        }
+
+        public static void report(PrintStream stream) {
+            trace.print(stream);
+
+            stream.print("<br/><ul>");
+            for (Trace.Event event : trace.events) {
+                stream.println(event);
+            }
+            stream.print("</ul>");
+        }
+
         public static void mark() {
             Throwable throwable = new Exception().fillInStackTrace();
             List<StackTraceElement> stackTraceElements = new ArrayList<StackTraceElement>(Arrays.asList(throwable.getStackTrace()));
@@ -213,7 +265,13 @@ public class Debug {
             }
         }
 
+        public static void reset() {
+            trace.events.clear();
+            trace.elements.clear();
+        }
+
         public void link(List<StackTraceElement> elements) {
+            events.add(new Event(elements));
             Iterator<StackTraceElement> iterator = elements.iterator();
             if (!iterator.hasNext()) return;