From 23754573c1221c70596b6287a68b05580f7c39e9 Mon Sep 17 00:00:00 2001 From: Roel Spilker Date: Mon, 18 Jul 2011 23:21:43 +0200 Subject: Dump the debug snapshots for issue 164 to a file. --- src/core/lombok/core/debug/DebugSnapshot.java | 30 ++++++++-------------- src/core/lombok/core/debug/DebugSnapshotStore.java | 23 ++++++++++++++--- 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/src/core/lombok/core/debug/DebugSnapshot.java b/src/core/lombok/core/debug/DebugSnapshot.java index a04a4820..f12cbcc4 100644 --- a/src/core/lombok/core/debug/DebugSnapshot.java +++ b/src/core/lombok/core/debug/DebugSnapshot.java @@ -3,13 +3,16 @@ package lombok.core.debug; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.atomic.AtomicLong; import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; public class DebugSnapshot implements Comparable { - private final long when, nano; + private static AtomicLong counter = new AtomicLong(); + + private final long when, id = counter.getAndIncrement(); private final List trace; - private final Thread thread; + private final String threadName; private final String message; private final Object[] params; private final WeakReference owner; @@ -17,22 +20,17 @@ public class DebugSnapshot implements Comparable { public DebugSnapshot(CompilationUnitDeclaration owner, int stackHiding, String message, Object... params) { this.when = System.currentTimeMillis(); StackTraceElement[] stackTrace = new Throwable().getStackTrace(); - this.trace = new ArrayList(); + this.trace = new ArrayList(Math.max(0, stackTrace.length - stackHiding - 1)); for (int i = 1 + stackHiding; i < stackTrace.length; i++) trace.add(stackTrace[i]); - this.nano = System.nanoTime(); - this.thread = Thread.currentThread(); + this.threadName = Thread.currentThread().getName(); this.message = message; this.params = params == null ? new Object[0] : params; this.owner = new WeakReference(owner); } - private String threadName() { - return thread.getName(); - } - private String ownerName() { CompilationUnitDeclaration node = owner.get(); - if (node == null) return "GCed"; + if (node == null) return "--GCed--"; char[] tn = node.getMainTypeName(); char[] fs = node.getFileName(); if (tn == null || tn.length == 0) { @@ -44,7 +42,7 @@ public class DebugSnapshot implements Comparable { public String shortToString() { StringBuilder out = new StringBuilder(); - out.append(String.format("WHEN: %14d THREAD: %s AST: %s", when, threadName(), ownerName())); + out.append(String.format("WHEN: %14d THREAD: %s AST: %s", when, threadName, ownerName())); if (message != null) out.append(String.format(message, params)); return out.toString(); } @@ -59,14 +57,6 @@ public class DebugSnapshot implements Comparable { } @Override public int compareTo(DebugSnapshot o) { - if (o.thread == this.thread) { - return Long.valueOf(nano).compareTo(Long.valueOf(o.nano)); - } - - if (o.when != when) { - return Long.valueOf(when).compareTo(Long.valueOf(o.when)); - } - - return Integer.valueOf(System.identityHashCode(thread)).compareTo(System.identityHashCode(o.thread)); + return Long.valueOf(id).compareTo(o.id); } } diff --git a/src/core/lombok/core/debug/DebugSnapshotStore.java b/src/core/lombok/core/debug/DebugSnapshotStore.java index cb15d2eb..fda3ba14 100644 --- a/src/core/lombok/core/debug/DebugSnapshotStore.java +++ b/src/core/lombok/core/debug/DebugSnapshotStore.java @@ -1,5 +1,8 @@ package lombok.core.debug; +import java.io.File; +import java.io.FileOutputStream; +import java.io.OutputStream; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -39,14 +42,26 @@ public class DebugSnapshotStore { Collections.sort(list); int idx = 1; - System.out.println("---------------------------"); + StringBuilder out = new StringBuilder(); + out.append("---------------------------\n"); for (DebugSnapshot snapshot : list) { - System.out.printf("%3d: %s\n", idx++, snapshot.shortToString()); + out.append(String.format("%3d: %s\n", idx++, snapshot.shortToString())); } - System.out.println("******"); + out.append("******\n"); idx = 1; for (DebugSnapshot snapshot : list) { - System.out.printf("%3d: %s", idx++, snapshot.toString()); + out.append(String.format("%3d: %s", idx++, snapshot.toString())); + } + + try { + OutputStream stream = new FileOutputStream(new File(System.getProperty("user.home", "."), String.format("lombok164-%d.err", System.currentTimeMillis()))); + try { + stream.write(out.toString().getBytes("UTF-8")); + } finally { + stream.close(); + } + } catch (Exception e) { + System.err.println(out); } } } -- cgit