incubator-kato-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From monte...@apache.org
Subject svn commit: r778912 - in /incubator/kato/trunk/org.apache.kato.tools.katoview/src/org/apache/kato/katoview/commands: TomcatCommand.java helpers/KatoSearch.java tomcat/TomcatJSPCommand.java tomcat/TomcatThreadPoolsCommand.java
Date Tue, 26 May 2009 22:20:32 GMT
Author: monteith
Date: Tue May 26 22:20:31 2009
New Revision: 778912

URL: http://svn.apache.org/viewvc?rev=778912&view=rev
Log:
Add new command - shows information on JSPs.

Added:
    incubator/kato/trunk/org.apache.kato.tools.katoview/src/org/apache/kato/katoview/commands/tomcat/TomcatJSPCommand.java
  (with props)
Modified:
    incubator/kato/trunk/org.apache.kato.tools.katoview/src/org/apache/kato/katoview/commands/TomcatCommand.java
    incubator/kato/trunk/org.apache.kato.tools.katoview/src/org/apache/kato/katoview/commands/helpers/KatoSearch.java
    incubator/kato/trunk/org.apache.kato.tools.katoview/src/org/apache/kato/katoview/commands/tomcat/TomcatThreadPoolsCommand.java

Modified: incubator/kato/trunk/org.apache.kato.tools.katoview/src/org/apache/kato/katoview/commands/TomcatCommand.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato.tools.katoview/src/org/apache/kato/katoview/commands/TomcatCommand.java?rev=778912&r1=778911&r2=778912&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato.tools.katoview/src/org/apache/kato/katoview/commands/TomcatCommand.java
(original)
+++ incubator/kato/trunk/org.apache.kato.tools.katoview/src/org/apache/kato/katoview/commands/TomcatCommand.java
Tue May 26 22:20:31 2009
@@ -16,6 +16,7 @@
 import java.util.Vector;
 
 import org.apache.kato.katoview.Output;
+import org.apache.kato.katoview.commands.tomcat.TomcatJSPCommand;
 import org.apache.kato.katoview.commands.tomcat.TomcatThreadPoolsCommand;
 import org.apache.kato.katoview.commands.tomcat.TomcatVersionCommand;
 
@@ -34,6 +35,8 @@
 		child_commands = new Vector();
 		child_commands.add(new TomcatVersionCommand(o));
 		child_commands.add(new TomcatThreadPoolsCommand(o));
+		child_commands.add(new TomcatJSPCommand(o));
+
 	}
 	
 }

Modified: incubator/kato/trunk/org.apache.kato.tools.katoview/src/org/apache/kato/katoview/commands/helpers/KatoSearch.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato.tools.katoview/src/org/apache/kato/katoview/commands/helpers/KatoSearch.java?rev=778912&r1=778911&r2=778912&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato.tools.katoview/src/org/apache/kato/katoview/commands/helpers/KatoSearch.java
(original)
+++ incubator/kato/trunk/org.apache.kato.tools.katoview/src/org/apache/kato/katoview/commands/helpers/KatoSearch.java
Tue May 26 22:20:31 2009
@@ -19,6 +19,7 @@
 
 import org.apache.kato.image.CorruptData;
 import org.apache.kato.image.CorruptDataException;
+import org.apache.kato.image.DataUnavailable;
 import org.apache.kato.image.Image;
 import org.apache.kato.image.ImageAddressSpace;
 import org.apache.kato.image.ImageProcess;
@@ -27,8 +28,12 @@
 import org.apache.kato.java.JavaClassLoader;
 import org.apache.kato.java.JavaField;
 import org.apache.kato.java.JavaHeap;
+import org.apache.kato.java.JavaLocation;
+import org.apache.kato.java.JavaMethod;
 import org.apache.kato.java.JavaObject;
 import org.apache.kato.java.JavaRuntime;
+import org.apache.kato.java.JavaStackFrame;
+import org.apache.kato.java.JavaThread;
 
 /**
  * Provides utility classes for retrieving things from dumps
@@ -241,6 +246,56 @@
 	}
 	
 	/**
+	 * Find all instances of a JavaClass with a passed name, and all of it's
+	 * subclasses.
+	 * 
+	 * @param runtime JavaRuntime 
+	 * @param className name o
+	 * @return List of JavaClasses
+	 */
+	public static List<JavaClass> findClasses(JavaRuntime runtime, String className) {
+		LinkedList<JavaClass> list = new LinkedList<JavaClass>();
+		
+		SubclassFinder finder = new SubclassFinder(className, list);
+		
+		visitClasses(runtime, finder);
+		
+		return list;
+	}
+	
+	/**
+	 * Supports findClasses method. 
+	 *
+	 */
+	private static class SubclassFinder implements JavaClassVisitor {
+		private String clazzName;
+		private List<JavaClass> list;
+		
+		public SubclassFinder(String name, List<JavaClass> list) {
+			if (name == null) {
+				throw new IllegalArgumentException("Cannot accept null class name");
+			}
+			this.clazzName = name;
+			this.list = list;
+		}
+		
+		public boolean visit(JavaClass clazz) throws KatoException {
+			JavaClass subClass = clazz;
+			while((clazz != null) 
+					&& !(clazzName.equals(clazz.getName()))) {
+				clazz = clazz.getSuperclass();
+			}
+			
+			if (clazz != null) {
+				list.add(subClass);
+			}
+			
+			return true;
+		}
+		
+	}
+	
+	/**
 	 * Executes the passed JavaObjectVisitor over all objects on all the heaps in
 	 * the given JavaRuntime.
 	 * CorruptData objects are not passed.
@@ -283,4 +338,56 @@
 			 }
 		}
 	}
+	
+	/**
+	 * Given a JavaClass, find all threads that are executing a method in that class.
+	 * 
+	 * @param runtime JavaRuntime to search
+	 * @param clazz JavaClass to look for
+	 * @return List of JavaThreads
+	 */
+	public static List<JavaThread> findClassInThreads(JavaRuntime runtime, JavaClass clazz)
{
+		List<JavaThread> list = new LinkedList<JavaThread>();
+		
+		for (Object nextThread : runtime.getThreads()) {
+			if (nextThread instanceof CorruptData) {
+				continue;
+			}
+			
+			JavaThread thread = (JavaThread) nextThread;
+			
+			// Iterate over all frames. If method is in passed class, add it to the list.
+	FRAMES:	for (Object nextFrame : thread.getStackFrames()) {
+				if (nextFrame instanceof CorruptData) {
+					continue;
+				}
+				
+				JavaStackFrame frame = (JavaStackFrame) nextFrame;
+				
+				JavaLocation location;
+				try {
+					location = frame.getLocation();
+				} catch (CorruptDataException e) {
+					continue FRAMES;
+				}
+				
+				if (location != null) {
+					try {
+						JavaMethod method = location.getMethod();
+						if (clazz.equals(method.getDeclaringClass())) {
+							list.add(thread);
+							break FRAMES;
+						}
+					} catch (CorruptDataException e) {
+						continue FRAMES;
+					} catch (DataUnavailable e) {
+						
+					}					
+				}				
+			}
+		}
+		
+		return list;
+	}
+	
 }

Added: incubator/kato/trunk/org.apache.kato.tools.katoview/src/org/apache/kato/katoview/commands/tomcat/TomcatJSPCommand.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato.tools.katoview/src/org/apache/kato/katoview/commands/tomcat/TomcatJSPCommand.java?rev=778912&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato.tools.katoview/src/org/apache/kato/katoview/commands/tomcat/TomcatJSPCommand.java
(added)
+++ incubator/kato/trunk/org.apache.kato.tools.katoview/src/org/apache/kato/katoview/commands/tomcat/TomcatJSPCommand.java
Tue May 26 22:20:31 2009
@@ -0,0 +1,112 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.katoview.commands.tomcat;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Stack;
+
+import org.apache.kato.image.CorruptData;
+import org.apache.kato.image.Image;
+import org.apache.kato.image.KatoException;
+import org.apache.kato.java.JavaClass;
+import org.apache.kato.java.JavaLocation;
+import org.apache.kato.java.JavaRuntime;
+import org.apache.kato.java.JavaStackFrame;
+import org.apache.kato.java.JavaThread;
+import org.apache.kato.katoview.Output;
+import org.apache.kato.katoview.commands.Command;
+import org.apache.kato.katoview.commands.helpers.JavaRuntimeVisitor;
+import org.apache.kato.katoview.commands.helpers.KatoSearch;
+
+/**
+ * Retrieves the version of Tomcat in the dump, or displays an error.
+ *
+ */
+public class TomcatJSPCommand extends Command {
+	private static final String SHORT_DESCRIPTION = "Shows JSPS";
+	private static final String COMMAND_NAME = "jsp";
+	private static final String LONG_DESCRIPTION = "Reports tomcat's thread pool state.";
+	
+	// Look for this class.
+	private static final String JSP_CLASS="org/apache/jasper/runtime/HttpJspBase"; 
+
+	
+	public TomcatJSPCommand(Output o) {
+		super(o, COMMAND_NAME, SHORT_DESCRIPTION, LONG_DESCRIPTION);
+		
+		child_commands = null;
+	}
+
+	public void doCommand(Stack args, Image loadedImage, HashMap properties) {
+		try {
+			KatoSearch.visitRuntimes(loadedImage, new PrintJSP());
+		} catch (KatoException e) {
+			e.printStackTrace();
+		}
+	}
+
+	/**
+	 * A visitor for finding the correct class and then return
+	 *
+	 */
+	private class PrintJSP implements JavaRuntimeVisitor {
+		boolean found = false;
+		JavaRuntime runtime;
+		
+		public void visit(JavaRuntime runtime) throws KatoException {
+			found = false;
+			this.runtime = runtime;
+			List<JavaClass> jsps = KatoSearch.findClasses(runtime, JSP_CLASS);
+			
+			for (JavaClass jsp : jsps) {
+				// Avoid the JSP superclass itself.
+				if (JSP_CLASS.equals(jsp.getName())) {
+					continue;
+				}
+					
+				found = true;
+				out.println("Found JSP:  "+ jsp.getName() );
+				out.println("JavaThread: ");
+				
+				List<JavaThread> threads = KatoSearch.findClassInThreads(runtime, jsp);
+				
+				for (JavaThread thread : threads) {					 
+					out.println("\tJava stack trace for thread `" + thread.getName() + "'");
+					out.println("\t=========================================================\n");
+					
+					for (Object nextFrame : thread.getStackFrames()) {
+						if (nextFrame instanceof CorruptData) {
+							continue;
+						}
+						
+						JavaLocation location = ((JavaStackFrame) nextFrame).getLocation();
+						
+						if (location != null) {
+							out.println("\t"+location);
+						}
+					}
+					out.println("");
+				}
+				out.println("");
+			}
+			
+			if (found == false) {
+				out.println("Couldn't find any JSPs");				
+			}
+		}
+
+		
+	}
+}
\ No newline at end of file

Propchange: incubator/kato/trunk/org.apache.kato.tools.katoview/src/org/apache/kato/katoview/commands/tomcat/TomcatJSPCommand.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/kato/trunk/org.apache.kato.tools.katoview/src/org/apache/kato/katoview/commands/tomcat/TomcatThreadPoolsCommand.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato.tools.katoview/src/org/apache/kato/katoview/commands/tomcat/TomcatThreadPoolsCommand.java?rev=778912&r1=778911&r2=778912&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato.tools.katoview/src/org/apache/kato/katoview/commands/tomcat/TomcatThreadPoolsCommand.java
(original)
+++ incubator/kato/trunk/org.apache.kato.tools.katoview/src/org/apache/kato/katoview/commands/tomcat/TomcatThreadPoolsCommand.java
Tue May 26 22:20:31 2009
@@ -41,8 +41,8 @@
 	// Look for this class.
 	private static final String THREAD_POOL_CLASS="org/apache/tomcat/util/threads/ThreadPool";

 	private static final String POOL_NAME = "name",
-								SERVER_BUILT = "serverBuilt",
-								SERVER_INFO = "serverInfo";
+								CURRENT_BUSY = "currentThreadsBusy",
+								CURRENT_COUNT = "currentThreadCount";
 	
 	public TomcatThreadPoolsCommand(Output o) {
 		super(o, COMMAND_NAME, SHORT_DESCRIPTION, LONG_DESCRIPTION);
@@ -80,13 +80,18 @@
 			if (clazz.getName().equals(THREAD_POOL_CLASS)) {
 				found = true;
 				JavaField nameField = KatoSearch.getField(clazz, POOL_NAME);
+				JavaField busyField = KatoSearch.getField(clazz, CURRENT_BUSY);
+				JavaField countField = KatoSearch.getField(clazz, CURRENT_COUNT);
+				
 				
 				List<JavaObject> instances = KatoSearch.findInstances(runtime, clazz);
 				if (instances.size() >0) {
 					out.println("Found thread pools");
 					for (JavaObject obj : instances) {
 						try {
-							out.println("Pool name:" + nameField.getString(obj));
+							out.println("Pool name:" + nameField.getString(obj)+", threads: "
+									+ countField.getInt(obj) +
+									", busy: " + busyField.getInt(obj));
 						
 						}catch (KatoException e) {
 							e.printStackTrace();



Mime
View raw message