public static void record(int level, Object... payload) { if (!isDebug()) return; if (getGlobalFlightRecorder() == null) return; getGlobalFlightRecorder().record(level, payload); }
public static void dumpAfter(final long millis) { dumpAfter(millis, FLIGHT_RECORDER_DUMP_FILE); }
private static void dumpRecorder() { if (isDebug()) { final String fileName = getDumpFile(); if (fileName != null && !fileName.trim().equals("")) { if (fileDumped.compareAndSet(false, true)) dumpRecorder(fileName); } else System.err.println("NO ERROR LOG FILE SPECIFIED."); } }
protected void onParked(boolean yield) { if (Debug.isDebug()) record("doExec", "parked " + (yield ? "(yield)" : "(park)") + " %s", this); }
@Override public void failed(Throwable e, Description desc) { System.out.println("FAILED TEST " + desc.getMethodName() + ": " + e.getMessage()); e.printStackTrace(System.err); if (Debug.isDebug() && !(e instanceof OutOfMemoryError)) { Debug.record(0, "EXCEPTION IN THREAD " + Thread.currentThread().getName() + ": " + e + " - " + Arrays.toString(e.getStackTrace())); Debug.dumpRecorder("quasar." + desc.getClassName() + "." + desc.getMethodName() + ".dump"); } }
@SuppressWarnings("CallToThreadDumpStack") public static void exit(int code, Throwable t, String filename) { final Strand currentStrand = Strand.currentStrand(); if (flightRecorder != null) { flightRecorder.record(1, "DEBUG EXIT REQUEST ON STRAND " + currentStrand + ": " + Arrays.toString(currentStrand.getStackTrace())); if (t != null) flightRecorder.record(1, "CAUSED BY " + t + ": " + Arrays.toString(currentStrand.getStackTrace())); flightRecorder.stop(); } if (requestShutdown.compareAndSet(false, true)) { System.err.println("DEBUG EXIT REQUEST ON STRAND " + currentStrand + (currentStrand.isFiber() ? " (THREAD " + Thread.currentThread() + ")" : "") + ": SHUTTING DOWN THE JVM."); Thread.dumpStack(); if (t != null) { System.err.println("CAUSED BY " + t); t.printStackTrace(); } dumpRecorder(filename); if (!isUnitTest()) // Calling System.exit() in gradle unit tests breaks gradle System.exit(code); } }
public static void dumpStack(PrintStream s, Throwable t, StackTraceFilter filter) { synchronized (s) { s.println(t); StackTraceElement[] trace = t.getStackTrace(); for (int i = 0; i < trace.length; i++) { if (filter.filter(trace[i])) s.println("\tat " + trace[i]); } Throwable ourCause = t.getCause(); if (ourCause != null) printStackTraceAsCause(s, trace, ourCause, filter); } }
public static void dumpStack(PrintStream s, Throwable t) { dumpStack(s, t, UNITTEST_FILTER); }
@Override public void run() { dumpRecorder(); } });
/** * Clears the registry (use only in tests!). */ public static void clear() { if (!Debug.isUnitTest()) throw new IllegalStateException("Must only be called in unit tests"); if (registry instanceof LocalActorRegistry) ((LocalActorRegistry) registry).clear(); else throw new UnsupportedOperationException(); } }
public FlightRecorderMessage(String clazz, String method, String format, Object[] args) { this.clazz = clazz; this.method = method; this.format = format; this.args = args; if (args != null) { for (int i = 0; i < args.length; i++) args[i] = recordingDouble(args[i]); } this.stackTrace = (Debug.isRecordStackTraces() ? Thread.currentThread().getStackTrace() : null); }
public static void dumpRecorder(String filename) { dumpLock.lock(); try { if (!dumped) { if (filename == null) { filename = getDumpFile(); if (filename == null || filename.trim().equals("")) filename = null; } if (filename == null) { System.err.println("NO ERROR LOG FILE SPECIFIED."); return; } if (flightRecorder != null) flightRecorder.dump(filename); dumped = true; dumpDone.signalAll(); } else { while (!dumped) dumpDone.await(); } } catch (InterruptedException e) { e.printStackTrace(); } finally { dumpLock.unlock(); } }
protected void onExec() { if (Debug.isDebug()) record("doExec", "executing %s", this); }
public static void dumpStack(PrintStream s, Throwable t, StackTraceFilter filter) { synchronized (s) { s.println(t); StackTraceElement[] trace = t.getStackTrace(); for (int i = 0; i < trace.length; i++) { if (filter.filter(trace[i])) s.println("\tat " + trace[i]); } Throwable ourCause = t.getCause(); if (ourCause != null) printStackTraceAsCause(s, trace, ourCause, filter); } }
public static void dumpStack(PrintStream s, Throwable t) { dumpStack(s, t, UNITTEST_FILTER); }
public static void dumpRecorder() { dumpRecorder(null); }
@SuppressWarnings("WeakerAccess") public boolean shouldInstrument(String className) { if (className != null) { className = className.replace('.', '/'); if (className.startsWith("co/paralleluniverse/fibers/instrument/") && !Debug.isUnitTest()) return false; if (className.equals(Classes.FIBER_CLASS_NAME) || className.startsWith(Classes.FIBER_CLASS_NAME + '$')) return false; if (className.equals(Classes.STACK_NAME)) return false; if (className.startsWith("org/objectweb/asm/") || className.startsWith("co/paralleluniverse/asm/")) return false; if (className.startsWith("org/gradle/")) return false; if (className.startsWith("org/netbeans/lib/")) return false; if (className.startsWith("java/lang/") || (!allowJdkInstrumentation && MethodDatabase.isJDK(className))) return false; if (isExcluded(className)) return false; } return true; }
public FlightRecorderMessage(String clazz, String method, String format, Object[] args) { this.clazz = clazz; this.method = method; this.format = format; this.args = args; if (args != null) { for (int i = 0; i < args.length; i++) args[i] = recordingDouble(args[i]); } this.stackTrace = (Debug.isRecordStackTraces() ? Thread.currentThread().getStackTrace() : null); }
protected void onExec() { if (Debug.isDebug()) record("doExec", "executing %s", this); }