|
From: <ls...@us...> - 2011-08-07 08:53:47
|
Revision: 5844
http://jnode.svn.sourceforge.net/jnode/?rev=5844&view=rev
Author: lsantha
Date: 2011-08-07 08:53:41 +0000 (Sun, 07 Aug 2011)
Log Message:
-----------
Added default mode to 'thread' command to show a flat thread list sorted by id.
Modified Paths:
--------------
trunk/cli/descriptors/org.jnode.command.system.xml
trunk/cli/src/commands/org/jnode/command/system/ThreadCommand.java
Modified: trunk/cli/descriptors/org.jnode.command.system.xml
===================================================================
--- trunk/cli/descriptors/org.jnode.command.system.xml 2011-08-04 12:57:47 UTC (rev 5843)
+++ trunk/cli/descriptors/org.jnode.command.system.xml 2011-08-07 08:53:41 UTC (rev 5844)
@@ -288,6 +288,9 @@
<optional description="Display all extant JNode Threads">
<option argLabel="groupDump" shortName="g" longName="groupDump"/>
</optional>
+ <optional description="Display all threads in thread groups">
+ <option argLabel="verbose" shortName="v"/>
+ </optional>
<argument argLabel="threadName" description="Display the named Thread"/>
</syntax>
<syntax alias="vminfo">
Modified: trunk/cli/src/commands/org/jnode/command/system/ThreadCommand.java
===================================================================
--- trunk/cli/src/commands/org/jnode/command/system/ThreadCommand.java 2011-08-04 12:57:47 UTC (rev 5843)
+++ trunk/cli/src/commands/org/jnode/command/system/ThreadCommand.java 2011-08-07 08:53:41 UTC (rev 5844)
@@ -24,6 +24,8 @@
import java.security.AccessController;
import java.security.PrivilegedAction;
+import java.util.Comparator;
+import java.util.TreeSet;
import org.jnode.shell.AbstractCommand;
import org.jnode.shell.syntax.Argument;
import org.jnode.shell.syntax.FlagArgument;
@@ -36,11 +38,13 @@
* @author Ewout Prangsma (ep...@us...)
* @author Martin Husted Hartvig (ha...@jn...)
* @author cr...@jn...
+ * @author Levente S\u00e1ntha
*/
public class ThreadCommand extends AbstractCommand {
private static final String help_name = "the name of a specific thread to be printed";
- private static final String help_group = "if set, output a ThreadGroup dump";
+ private static final String help_group = "output a ThreadGroup dump";
+ private static final String help_verbose = "show all threads in thread groups";
private static final String help_super = "View info about all threads, or a specific thread";
private static final String SEPARATOR = ", ";
@@ -50,12 +54,14 @@
private final ThreadNameArgument argName;
private final FlagArgument argDump;
+ private final FlagArgument argVerbose;
public ThreadCommand() {
super(help_super);
argName = new ThreadNameArgument("threadName", Argument.OPTIONAL, help_name);
argDump = new FlagArgument("groupDump", Argument.OPTIONAL, help_group);
- registerArguments(argName, argDump);
+ argVerbose = new FlagArgument("verbose", Argument.OPTIONAL, help_verbose);
+ registerArguments(argName, argVerbose, argDump);
}
public static void main(String[] args) throws Exception {
@@ -82,11 +88,57 @@
// standard API.
grp.list();
} else {
- // Show the threads in the ThreadGroup tree.
- showThreads(grp, getOutput().getPrintWriter(), threadName);
+ if(!argVerbose.isSet() && !argName.isSet()) {
+ showDefaultInfo(grp);
+ } else {
+ // Show the threads in the ThreadGroup tree.
+ showThreads(grp, getOutput().getPrintWriter(), threadName);
+ }
}
}
+ private void showDefaultInfo(ThreadGroup grp) {
+ TreeSet<Thread> threadSet = new TreeSet<Thread>(new Comparator<Thread>() {
+ @Override
+ public int compare(Thread t1, Thread t2) {
+ return Long.valueOf(t1.getId()).compareTo(t2.getId());
+ }
+ });
+ findThreads(grp, threadSet);
+
+ PrintWriter out = getOutput().getPrintWriter();
+ for(final Thread thread : threadSet) {
+ VmThread vmThread = AccessController.doPrivileged(new PrivilegedAction<VmThread>() {
+ public VmThread run() {
+ return ThreadHelper.getVmThread(thread);
+ }
+ });
+ out.println(" " + thread.getId() + SEPARATOR + thread.getName() + SEPARATOR + thread.getPriority() +
+ SEPARATOR + vmThread.getThreadStateName());
+ }
+ }
+
+ private void findThreads(ThreadGroup grp, TreeSet<Thread> threadSet) {
+ final int max = grp.activeCount() * 2;
+ final Thread[] ts = new Thread[max];
+ grp.enumerate(ts);
+ for (int i = 0; i < max; i++) {
+ final Thread t = ts[i];
+ if (t != null) {
+ threadSet.add(t);
+ }
+ }
+ final int gmax = grp.activeGroupCount() * 2;
+ final ThreadGroup[] tgs = new ThreadGroup[gmax];
+ grp.enumerate(tgs);
+ for (int i = 0; i < gmax; i++) {
+ final ThreadGroup tg = tgs[i];
+ if (tg != null) {
+ findThreads(tg, threadSet);
+ }
+ }
+ }
+
/**
* Traverse the ThreadGroups threads and its child ThreadGroups printing
* information for each thread found. If 'threadName' is non-null, only
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|