fix for bug in formatting in ThreadDump

and added hint for linux/Mac users that they may use the LOCKED feature using the start option -l

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7601 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 14 years ago
parent 2861d0888a
commit c2a968c23f

@ -34,6 +34,7 @@ import java.util.ArrayList;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.kelondro.logging.ThreadDump;
import net.yacy.kelondro.util.OS;
import de.anomic.search.Switchboard;
import de.anomic.server.serverObjects;
@ -82,17 +83,17 @@ public class Threaddump_p {
ThreadDump.appendStackTraceStats(appPath, buffer, traces, plain, null);
} else {
// write a thread dump to standard error output
/*
if (OS.canExecUnix) {
int pid = OS.getPID();
if (pid >= 0) try {OS.execSynchronous("kill -3 " + pid);} catch (IOException e) {}
}
*/
File logFile = new File("yacy.log");
if (ThreadDump.canProduceLockedBy(logFile)) {
try {
new ThreadDump().appendBlockTraces(buffer, plain);
new ThreadDump(logFile).appendBlockTraces(buffer, plain);
} catch (IOException e) {
e.printStackTrace();
}
} else if (OS.canExecUnix) {
ThreadDump.bufferappend(buffer, plain, "this thread dump function can find threads that lock others, to enable this function start YaCy with 'startYACY.sh -l'");
ThreadDump.bufferappend(buffer, plain, "");
}
// generate a single thread dump
final Map<Thread,StackTraceElement[]> stackTraces = ThreadDump.getAllStackTraces();

@ -28,7 +28,6 @@ package net.yacy.kelondro.logging;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@ -95,15 +94,26 @@ public class ThreadDump extends HashMap<ThreadDump.Thread, List<String>> impleme
return java.lang.Thread.getAllStackTraces();
}
public ThreadDump() throws IOException {
public static boolean canProduceLockedBy(File logFile) {
// check os version
if (!OS.canExecUnix) return false;
// check if log file exists
if (!logFile.exists()) return false;
// check last modification date of log file
if (System.currentTimeMillis() - logFile.lastModified() > 60000) return false;
return true;
}
public ThreadDump(File logFile) throws IOException {
super();
// try to get the thread dump from yacy.log which is available when YaCy is started with
// startYACY.sh -l
if (!OS.canExecUnix) return;
File logFile = new File("yacy.log");
if (!logFile.exists()) return;
if (!canProduceLockedBy(logFile)) return;
long sizeBefore = logFile.length();
// get the current process PID
@ -126,10 +136,6 @@ public class ThreadDump extends HashMap<ThreadDump.Thread, List<String>> impleme
importText(new ByteArrayInputStream(b));
}
public ThreadDump(final File f) throws IOException {
this(new FileInputStream(f));
}
public ThreadDump(final InputStream is) throws IOException {
super();
importText(is);
@ -248,14 +254,14 @@ public class ThreadDump extends HashMap<ThreadDump.Thread, List<String>> impleme
bufferappend(buffer, plain, "");
Map<Thread, Integer> locks = this.countLocks();
for (int i = 0; i < this.size() + 10; i++) {
for (int i = this.size() + 10; i > 0; i--) {
for (Map.Entry<Thread, Integer> entry: locks.entrySet()) {
if (entry.getValue().intValue() == i) {
bufferappend(buffer, plain, "holds lock for " + i + " threads:");
final List<String> list = this.get(entry.getKey());
if (list == null) continue;
bufferappend(buffer, plain, "Thread: " + entry.getKey());
for (String s: list) bufferappend(buffer, plain, " " + s);
bufferappend(buffer, plain, "Thread= " + entry.getKey());
for (String s: list) bufferappend(buffer, plain, " " + (plain ? s : s.replaceAll("<", "&lt;").replaceAll(">", "&gt;")));
bufferappend(buffer, plain, "");
}
}

Loading…
Cancel
Save