aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoel Spilker <r.spilker@gmail.com>2011-07-18 23:21:43 +0200
committerRoel Spilker <r.spilker@gmail.com>2011-07-18 23:21:43 +0200
commit23754573c1221c70596b6287a68b05580f7c39e9 (patch)
treef1d56ede76197ae68c81d3900457b564a55f7ec9
parent57f7576170dd832b269d0001eb1393f1fe3f9713 (diff)
downloadlombok-23754573c1221c70596b6287a68b05580f7c39e9.tar.gz
lombok-23754573c1221c70596b6287a68b05580f7c39e9.tar.bz2
lombok-23754573c1221c70596b6287a68b05580f7c39e9.zip
Dump the debug snapshots for issue 164 to a file.
-rw-r--r--src/core/lombok/core/debug/DebugSnapshot.java30
-rw-r--r--src/core/lombok/core/debug/DebugSnapshotStore.java23
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<DebugSnapshot> {
- private final long when, nano;
+ private static AtomicLong counter = new AtomicLong();
+
+ private final long when, id = counter.getAndIncrement();
private final List<StackTraceElement> trace;
- private final Thread thread;
+ private final String threadName;
private final String message;
private final Object[] params;
private final WeakReference<CompilationUnitDeclaration> owner;
@@ -17,22 +20,17 @@ public class DebugSnapshot implements Comparable<DebugSnapshot> {
public DebugSnapshot(CompilationUnitDeclaration owner, int stackHiding, String message, Object... params) {
this.when = System.currentTimeMillis();
StackTraceElement[] stackTrace = new Throwable().getStackTrace();
- this.trace = new ArrayList<StackTraceElement>();
+ this.trace = new ArrayList<StackTraceElement>(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<CompilationUnitDeclaration>(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<DebugSnapshot> {
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<DebugSnapshot> {
}
@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);
}
}
}