Skip to content

Commit

Permalink
fix for bug in formatting in ThreadDump
Browse files Browse the repository at this point in the history
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
  • Loading branch information
orbiter committed Mar 15, 2011
1 parent 2861d08 commit c2a968c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
21 changes: 11 additions & 10 deletions htroot/Threaddump_p.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

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;
Expand Down Expand Up @@ -82,16 +83,16 @@ public static serverObjects respond(final RequestHeader header, final serverObje
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();
File logFile = new File("yacy.log");
if (ThreadDump.canProduceLockedBy(logFile)) {
try {
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
Expand Down
32 changes: 19 additions & 13 deletions source/net/yacy/kelondro/logging/ThreadDump.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
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;
Expand Down Expand Up @@ -95,15 +94,26 @@ public static Map<java.lang.Thread, StackTraceElement[]> getAllStackTraces() {
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
Expand All @@ -126,10 +136,6 @@ public ThreadDump() throws IOException {
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);
Expand Down Expand Up @@ -248,14 +254,14 @@ public void appendBlockTraces(
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, "");
}
}
Expand Down

0 comments on commit c2a968c

Please sign in to comment.