added new feature for Thread dump:

"THREADS WITH STATES: LOCK FOR OTHERS"
will show only such threads that lock other threads. This is the 'opposite part' of the blocked threads.
Because that this uses a thread dump that is produced with a kill -3 on the PID of the process and such thread dumps are written by the Java core outside of System.out and Sytem.err it is necessary to read the dump from a log in the file system. Such a log is only written if YaCy is started with startYACY.sh on a linux system. That means:
this feature is only available on linux and Mac OS X if YaCy is started with ./startYACY.sh -l


git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7595 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 14 years ago
parent b62b79675b
commit 0a11727374

@ -34,7 +34,6 @@ 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;
@ -83,10 +82,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) {}
}
*/
try {
new ThreadDump().appendBlockTraces(buffer, plain);
} catch (IOException e) {
e.printStackTrace();
}
// generate a single thread dump
final Map<Thread,StackTraceElement[]> stackTraces = ThreadDump.getAllStackTraces();

@ -26,11 +26,13 @@
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;
import java.io.RandomAccessFile;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -92,45 +94,38 @@ public class ThreadDump extends HashMap<ThreadDump.Thread, List<String>> impleme
public static Map<java.lang.Thread, StackTraceElement[]> getAllStackTraces() {
return java.lang.Thread.getAllStackTraces();
}
/*
public ThreadDump() {
public ThreadDump() throws IOException {
super();
VirtualMachineManager manager = Bootstrap.virtualMachineManager();
AttachingConnector ac = manager.attachingConnectors().get(0);
Map<String, Connector.Argument> env = ac.defaultArguments();
env.get("port").setValue("8066");
env.get("hostname").setValue("localhost");
VirtualMachine vm = null;
try {
vm = ac.attach(env);
} catch (IOException e1) {
e1.printStackTrace();
} catch (IllegalConnectorArgumentsException e1) {
e1.printStackTrace();
}
Process proc = vm.process();
InputStream is = proc.getInputStream();
// try to get the thread dump from yacy.log which is available when YaCy is started with
// startYACY.sh -l
File logFile = new File("yacy.log");
if (!logFile.exists()) return;
long sizeBefore = logFile.length();
// get the current process PID
int pid = OS.getPID();
// call kill -3 on the pid
if (pid >= 0) try {OS.execSynchronous("kill -3 " + pid);} catch (IOException e) {}
//byte[] b = os.toByteArray();
//System.err.println("dump size: " + b.length + ", log out lines = " + o.size());
// read the log from the dump
long sizeAfter = logFile.length();
if (sizeAfter <= sizeBefore) return;
RandomAccessFile raf = new RandomAccessFile(logFile, "r");
raf.seek(sizeBefore);
byte[] b = new byte[(int) (sizeAfter - sizeBefore)];
raf.readFully(b);
raf.close();
System.out.println("dump size: " + b.length);
// import the thread dump;
try {
importText(is);
} catch (IOException e) {
e.printStackTrace();
}
importText(new ByteArrayInputStream(b));
}
*/
public ThreadDump(final File f) throws IOException {
this(new FileInputStream(f));
}
@ -245,6 +240,29 @@ public class ThreadDump extends HashMap<ThreadDump.Thread, List<String>> impleme
}
bufferappend(buffer, plain, "");
}
public void appendBlockTraces(
final StringBuilder buffer,
final boolean plain) {
bufferappend(buffer, plain, "THREADS WITH STATES: LOCK FOR OTHERS");
bufferappend(buffer, plain, "");
Map<Thread, Integer> locks = this.countLocks();
for (int i = 0; i < this.size() + 10; 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, "");
}
}
}
bufferappend(buffer, plain, "");
}
public static void appendStackTraceStats(
final File rootPath,

Loading…
Cancel
Save