incubator-kato-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From monte...@apache.org
Subject svn commit: r806117 - in /incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx: ./ appendices/ chapters/
Date Thu, 20 Aug 2009 10:57:38 GMT
Author: monteith
Date: Thu Aug 20 10:57:38 2009
New Revision: 806117

URL: http://svn.apache.org/viewvc?rev=806117&view=rev
Log:
Add examples to the appendices. Darken examples slightly.

Added:
    incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/appendices/causeexample.xml
  (with props)
    incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/appendices/imageinterfaceexample.xml
  (with props)
    incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/appendices/objectfieldsexample.xml
  (with props)
    incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/appendices/readimageexample.xml
  (with props)
    incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/appendices/runtimeexample.xml
  (with props)
    incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/appendices/whatexample.xml 
 (with props)
Modified:
    incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/appendices/registers.xml
    incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/chapters/examples.xml
    incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/fo.xsl
    incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/spec.xml

Added: incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/appendices/causeexample.xml
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/appendices/causeexample.xml?rev=806117&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/appendices/causeexample.xml
(added)
+++ incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/appendices/causeexample.xml
Thu Aug 20 10:57:38 2009
@@ -0,0 +1,115 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<appendix version="5.0" xml:id="appendix.causeexample"
+         xmlns="http://docbook.org/ns/docbook"
+         xmlns:xlink="http://www.w3.org/1999/xlink"
+         xmlns:xi="http://www.w3.org/2001/XInclude"
+         xmlns:svg="http://www.w3.org/2000/svg"
+         xmlns:mml="http://www.w3.org/1998/Math/MathML"
+         xmlns:html="http://www.w3.org/1999/xhtml"
+         xmlns:db="http://docbook.org/ns/docbook">
+<title>Snapshot Cause Example</title>
+<sect2>
+<para>
+This class implements the <classname>ImageAnalyzer</classname> interface in
+<xref linkend="appendix.imageinterfaceexample"/>.
+</para>
+<programlisting>
+<![CDATA[
+/*******************************************************************************
+ * 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.examples;
+
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.image.DataUnavailable;
+import javax.tools.diagnostics.image.Image;
+import javax.tools.diagnostics.image.ImageAddressSpace;
+import javax.tools.diagnostics.image.ImageProcess;
+import javax.tools.diagnostics.image.ImageStackFrame;
+import javax.tools.diagnostics.image.ImageThread;
+import javax.tools.diagnostics.runtime.ManagedRuntime;
+import javax.tools.diagnostics.runtime.java.JavaRuntime;
+import javax.tools.diagnostics.runtime.java.JavaStackFrame;
+import javax.tools.diagnostics.runtime.java.JavaThread;
+
+/**
+ * This analyzer determines what process and thread
+ * caused the dump, and what signal, if any.
+ *
+ */
+public class CauseAnalyzer implements ImageAnalyzer {
+
+	@Override
+	public void analyze(Image image) {
+		for (ImageAddressSpace as : image.getAddressSpaces()) {
+			ImageProcess process = as.getCurrentProcess();
+			
+			// Only invoked if there is a "current" process,
+			// This is a process that caused the dump to occur.
+			if (process != null) {
+				try {
+					int signum = process.getSignalNumber();
+					String signame = process.getSignalName();
+
+					// Identify the process by number and command line.
+					System.out.println("Process "+process.getID()+
+							" was started with `" + 
+							process.getCommandLine()+"'");
+					
+					// The signals that cause the dump to be generated
+					if (signame != null) {
+						System.out.println("Dump caused by signal " + signame+"("+signum+")");						
+					}
+
+					ImageThread thread = process.getCurrentThread();
+					// Identify the thread, by id, various properties and a stack trace.
+					if (thread != null) {
+						System.out.println("\nDump caused by thread "+
+								thread.getID()+
+								", "+thread.getProperties());
+						for(ImageStackFrame frame: thread.getStackFrames()) {
+							System.out.println("\t" + frame);
+						}
+						
+						// Find JavaThread and then do stacktrace.
+RUNTIME:				for(ManagedRuntime runtime : process.getRuntimes() ) {
+							if (runtime instanceof JavaRuntime) {
+								JavaRuntime jr = (JavaRuntime) runtime;
+								
+								for(JavaThread jthread : jr.getThreads()) {
+									if (thread.equals(jthread.getImageThread())) {										
+										System.out.println("\nDump caused by JavaThread "+
+												jthread.getName());
+										
+										for(JavaStackFrame frame : jthread.getStackFrames()) {
+											System.out.println("\t" + frame);
+										}
+										break RUNTIME;
+									}
+								}
+							}
+						}
+					}										
+				} catch (DataUnavailable e) {					
+					e.printStackTrace();
+				} catch (CorruptDataException e) {
+					e.printStackTrace();
+				}			
+			}
+		}
+	}
+}
+]]>	
+</programlisting>
+</sect2>
+</appendix>

Propchange: incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/appendices/causeexample.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/appendices/imageinterfaceexample.xml
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/appendices/imageinterfaceexample.xml?rev=806117&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/appendices/imageinterfaceexample.xml
(added)
+++ incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/appendices/imageinterfaceexample.xml
Thu Aug 20 10:57:38 2009
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<appendix version="5.0" xml:id="appendix.imageinterfaceexample"
+         xmlns="http://docbook.org/ns/docbook"
+         xmlns:xlink="http://www.w3.org/1999/xlink"
+         xmlns:xi="http://www.w3.org/2001/XInclude"
+         xmlns:svg="http://www.w3.org/2000/svg"
+         xmlns:mml="http://www.w3.org/1998/Math/MathML"
+         xmlns:html="http://www.w3.org/1999/xhtml"
+         xmlns:db="http://docbook.org/ns/docbook">
+<title>ImageAnalyzer interface</title>
+<sect2>
+<programlisting>
+<![CDATA[
+/*******************************************************************************
+ * 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.examples;
+
+import javax.tools.diagnostics.image.Image;
+
+public interface ImageAnalyzer {
+	public abstract void analyze(Image image);
+}
+
+]]>	
+</programlisting>
+</sect2>
+</appendix>

Propchange: incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/appendices/imageinterfaceexample.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/appendices/objectfieldsexample.xml
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/appendices/objectfieldsexample.xml?rev=806117&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/appendices/objectfieldsexample.xml
(added)
+++ incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/appendices/objectfieldsexample.xml
Thu Aug 20 10:57:38 2009
@@ -0,0 +1,316 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<appendix version="5.0" xml:id="appendix.objectfieldsexample"
+         xmlns="http://docbook.org/ns/docbook"
+         xmlns:xlink="http://www.w3.org/1999/xlink"
+         xmlns:xi="http://www.w3.org/2001/XInclude"
+         xmlns:svg="http://www.w3.org/2000/svg"
+         xmlns:mml="http://www.w3.org/1998/Math/MathML"
+         xmlns:html="http://www.w3.org/1999/xhtml"
+         xmlns:db="http://docbook.org/ns/docbook">
+<title>Retrieving Object Fields Example</title>
+<sect2>
+<para>
+This class extends the <classname>RuntimeAnalyzer</classname> class in
+<xref linkend="appendix.runtimeexample"/> to simplify obtaining a
+<classname>JavaRuntime</classname> instance. 
+</para>
+<programlisting>
+<![CDATA[
+/*******************************************************************************
+ * 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.examples;
+
+import java.lang.reflect.Array;
+
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.image.ImagePointer;
+import javax.tools.diagnostics.image.KatoException;
+import javax.tools.diagnostics.image.MemoryAccessException;
+import javax.tools.diagnostics.runtime.java.JavaClass;
+import javax.tools.diagnostics.runtime.java.JavaField;
+import javax.tools.diagnostics.runtime.java.JavaHeap;
+import javax.tools.diagnostics.runtime.java.JavaObject;
+import javax.tools.diagnostics.runtime.java.JavaRuntime;
+
+/**
+ * This examples walks over all objects on the heap and prints the values
+ * of all of the fields, and the contents of all elements of all the arrays.
+ */
+public class ObjectFields extends RuntimeAnalyzer{
+	
+	/**
+	 * Given a JavaRuntime, print out all of the objects on the heap.
+	 * @param jr JavaRuntime to get objects from
+	 */
+	public void analyzeRuntime(JavaRuntime jr) {
+		for (JavaHeap heap : jr.getHeaps()) {
+				walkHeap (heap);
+		} 		
+	}
+	
+	/**
+	 * Walks over all objects on the heap. 
+	 * @param heap JavaHeap to iterate over.
+	 */
+	public void walkHeap(JavaHeap heap) {
+		for (JavaObject jObject : heap.getObjects()) {
+
+			try {
+				if (jObject.isArray()) {
+					walkArray (jObject);
+				} else {
+					walkObject (jObject);
+				}
+
+				// Even determining whether or not the JavaObject is an array has difficulties.
+			} catch (CorruptDataException e) {
+				System.err.println("Corrupt data exception calling jObject.isArray() at "+
+						pointerToHexString(jObject.getID()));
+				e.printStackTrace();
+			}
+		} 
+	}
+	
+	/**
+	 * Prints out all of the values of the fields in an object, along with
+	 * identifying information of the type itself.
+	 * 
+	 * @param jObject A JavaObject
+	 */
+	public void walkObject(JavaObject jObject) {	
+		// Just identify the object by its ID - this would the address on the heap.
+		System.out.println("JavaObject @ " + pointerToHexString(jObject.getID()));
+		// Handle indentation.
+		String prefix = "\t";
+		
+		// Get the type of this object.		
+		JavaClass clazz;
+		try {
+			clazz = jObject.getJavaClass();
+		} catch (CorruptDataException e) {
+			System.err.println(prefix+"Error getting JavaClass");
+			e.printStackTrace();
+			return;
+		}
+		
+		while (clazz != null) {
+			// print out the name of the class and the the fields.
+			try {
+				System.out.println( prefix + clazz.getName() +":");
+				prefix += "  ";
+
+				/* Print out all fields for this class.
+				 */
+				for (JavaField nextField : clazz.getDeclaredFields()) {					
+					printField(prefix, nextField, jObject);						
+				}
+			} catch (KatoException e) {
+				System.err.println("Error printing out fields.");
+				e.printStackTrace();
+			}
+			
+			// Get the next superclass.
+			try {
+				clazz = clazz.getSuperclass();
+			} catch (CorruptDataException e) {				
+				e.printStackTrace();
+				break;
+			}
+			
+		} // while (class != null)
+	}
+	
+	/**
+	 * Print out the content of one field.
+	 * Only prints out instance fields. Will return if a
+	 * static field is passed.
+	 * 
+	 * @param prefix Pad out message
+	 * @param field The field to print
+	 * @param object The object to print out
+	 * @throws CorruptDataException if something goes wrong
+	 * @throws MemoryAccessException 
+	 */
+	private void printField(String prefix, JavaField field, JavaObject object) throws CorruptDataException,
MemoryAccessException {
+
+		if (java.lang.reflect.Modifier.isStatic(field.getModifiers())) {
+			return;
+		}
+		
+		Object fieldValue = field.get(object);
+		
+		String valueString = "";
+		
+		// Format the field's value. 
+		if(fieldValue == null) {
+			valueString = "<null reference>";
+			
+			// Most of the primitive fields can be handled as Number instances.
+		} else if (fieldValue instanceof Number) {
+			valueString = fieldValue.toString();
+		} else if (fieldValue instanceof Character) {
+			valueString = "`" + (Character)fieldValue + "'";
+		} else if (fieldValue instanceof Boolean) {
+			valueString = ((Boolean) fieldValue).booleanValue() ? "true" : "false";
+		} else if (fieldValue instanceof JavaObject) {
+			// Note how we have to get an instance of the object to know anything about it.
+			JavaObject reference = (JavaObject) fieldValue;
+			
+			// classname: @ 0xadddress
+			valueString = reference.getJavaClass().getName() + ": @ " + pointerToHexString(reference.getID());
+			
+			if ("java/lang/String".equals(reference.getJavaClass().getName())) {
+				valueString += valueString +" = \"" + field.getString(object) + "\"";
+			}
+			
+		}
+
+		System.out.println(prefix + field.getSignature() + " " + 
+				field.getName() + " = " + valueString);		
+	}
+
+	/**
+	 * Print out the contents of an array.
+	 * 
+	 * @param jObject JavaObject of an array.
+	 */
+	public void walkArray(JavaObject object) {
+		// Just identify the object by its ID - this would the address on the heap.
+		System.out.println("JavaObject @ " + pointerToHexString(object.getID()));
+		// Handle indentation.		
+		String className;
+		
+		JavaClass clazz;
+		try {
+			clazz = object.getJavaClass();
+		} catch (CorruptDataException e) {
+			System.err.println("Unable to determine array's JavaClass. aborting");
+			e.printStackTrace();
+			return;
+		}
+		
+		// The class name is needed to determine the element types
+		try {
+			className = clazz.getName();
+		} catch (CorruptDataException e) {
+			System.err.println("Error getting Array class name.");
+			e.printStackTrace();
+			return;
+		}
+
+		
+		int arraySize = 0;
+
+		// This gets the number of elements in the array. 
+		try {
+			arraySize = object.getArraySize();
+		} catch (CorruptDataException e) {
+			System.err.println("Unable to get object size.");
+			e.printStackTrace();
+			return;
+		}		
+		
+		String componentName;
+		try {
+			componentName = clazz.getComponentType().getName();
+		} catch (CorruptDataException e) {
+			System.err.println("Unable to determine component type name. Quitting.");
+			e.printStackTrace();
+			return;
+		}
+		
+		Object arrayCopy;
+		
+		if ("boolean".equals(componentName)) {
+			arrayCopy = new boolean[arraySize];
+		} else if ("byte".equals(componentName)) {
+			arrayCopy = new byte[arraySize];
+		} else if ("char".equals(componentName)) {
+			arrayCopy = new char[arraySize];
+		} else if ("short".equals(componentName)) {
+			arrayCopy = new short[arraySize];
+		} else if ("int".equals(componentName)) {
+			arrayCopy = new int[arraySize];
+		} else if ("long".equals(componentName)) {
+			arrayCopy = new long[arraySize];
+		} else if ("float".equals(componentName)) {
+			arrayCopy = new float[arraySize];
+		} else if ("double".equals(componentName)) {
+			arrayCopy = new double[arraySize];
+		} else {
+			// Anything element that is not a primitive must be a reference type.
+			arrayCopy = new JavaObject[arraySize];
+		}
+							
+		/* Copy the contents of the JavaObject array into the array we prepared earlier.
+		 * This is the only way to get the values of an array in a dump.
+		 */
+		try {
+			object.arraycopy(0, arrayCopy, 0, arraySize);
+		} catch (CorruptDataException e) {
+			e.printStackTrace();
+			return;
+		} catch (MemoryAccessException e) {
+			e.printStackTrace();
+			return;
+		} catch (IllegalArgumentException e){
+			e.printStackTrace();
+			return;
+		} catch (IndexOutOfBoundsException e) {
+			e.printStackTrace();
+			return;
+		}
+		
+		/* Go through every element in the copy of the array and print out its contents.
+		 * This example uses java.lang.Array.get() to make this easy to handle generically.
+		 * 
+		 * Object references - JavaObjects - are only printed out at the type name @ an address.
+		 * We don't print out subarrays - they will be encountered later in the heap anyhow.
+		 */
+		System.out.println("\t" + className + "[" + arraySize +"] = {");
+		for (int cnt=0; cnt < arraySize; cnt++) {
+			Object obj = Array.get(arrayCopy, cnt);
+			
+			if (obj == null) {
+				System.out.println("\t\tnull,");
+			} else if (obj instanceof JavaObject) {
+				JavaObject refObj = (JavaObject) obj;
+				try {
+					System.out.println("\t\t" + refObj.getJavaClass().getName()+ " @ "+
+							pointerToHexString(refObj.getID())+",");
+				} catch (CorruptDataException e) {
+					System.err.println("\t\t CorruptDataException while printing out array element");
+					e.printStackTrace();
+				}
+			} else {
+				System.out.println("\t\t"+obj+",");
+			}
+		}
+		System.out.println("\t};");
+	}
+	
+	/**
+	 * Takes ImagePointer and returns it as a hex string. Perhaps this should be defined
+	 * behaviour for ImagePointer.toString().
+	 * @param pointer ImagePointer
+	 * @return Address of pointer as a hex string prefixed with "0x"
+	 */
+	public static String pointerToHexString(ImagePointer pointer) {
+		return "0x"+Long.toHexString(pointer.getAddress());
+	}
+}
+]]>	
+</programlisting>
+</sect2>
+</appendix>

Propchange: incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/appendices/objectfieldsexample.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/appendices/readimageexample.xml
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/appendices/readimageexample.xml?rev=806117&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/appendices/readimageexample.xml
(added)
+++ incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/appendices/readimageexample.xml
Thu Aug 20 10:57:38 2009
@@ -0,0 +1,99 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<appendix version="5.0" xml:id="appendix.readimageexample"
+         xmlns="http://docbook.org/ns/docbook"
+         xmlns:xlink="http://www.w3.org/1999/xlink"
+         xmlns:xi="http://www.w3.org/2001/XInclude"
+         xmlns:svg="http://www.w3.org/2000/svg"
+         xmlns:mml="http://www.w3.org/1998/Math/MathML"
+         xmlns:html="http://www.w3.org/1999/xhtml"
+         xmlns:db="http://docbook.org/ns/docbook">
+<title>Opening Images example</title>
+<sect2>
+<para>
+This class takes the name of at least one dump, and the
+name of a class that implements <classname>ImageAnalyzer</classname> listed in
+<xref linkend="appendix.imageinterfaceexample"/>.
+</para>
+<programlisting>
+<![CDATA[
+/*******************************************************************************
+ * 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.examples;
+
+import java.io.File;
+import java.io.IOException;
+
+import javax.tools.diagnostics.FactoryRegistry;
+import javax.tools.diagnostics.image.Image;
+
+/**
+ * This example shows how an Image is opened, given a snapshot's file name.
+ *   
+ */
+public abstract class ReadImage {
+
+	/**
+	 * Main method. Takes names of snapshot dumps and opens them with the
+	 * ImageFactory.
+	 * 
+	 * @param args
+	 */
+	public static void main(String[] args) {
+		if (args.length < 2) {
+			System.err.println("Usage: ReadImage <snapshot> [snapshot...] <Image analyzer>");
+		}
+		
+		String analyzerName = "org.apache.kato.examples."+args[args.length-1];		
+		Class analyzerClass = null;
+		try {
+			analyzerClass = Class.forName(analyzerName);
+		} catch (ClassNotFoundException e) {
+			System.err.println("Unable to find test class `"+analyzerName+"'");
+			e.printStackTrace();
+			System.exit(1);
+		}
+		
+		for(int i = 0; i < args.length-1; i++) {
+			String filename = args[i];
+			System.out.println("\nAnalysing `"+filename+"'");
+			System.out.println("==========================");
+			
+			Image image;
+			try {
+				image = FactoryRegistry.getDefaultRegistry().getImage(new File(filename));
+			} catch (IOException e) {
+				System.out.println("Unable to open snapshot.");
+				e.printStackTrace();
+				continue;
+			}
+			try {
+				ImageAnalyzer analyzerInstance =  (ImageAnalyzer) analyzerClass.newInstance();
+				analyzerInstance.analyze(image);
+			} catch (InstantiationException e) {
+				e.printStackTrace();
+			} catch (IllegalAccessException e) {
+				e.printStackTrace();
+			} catch (ClassCastException e) {
+				System.out.println("Analzyer class should be instances of ImageAnalyzer.");
+				e.printStackTrace();				
+				System.exit(2);
+			}
+			
+		}
+	}
+}
+]]>	
+</programlisting>
+</sect2>
+</appendix>

Propchange: incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/appendices/readimageexample.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/appendices/registers.xml
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/appendices/registers.xml?rev=806117&r1=806116&r2=806117&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/appendices/registers.xml (original)
+++ incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/appendices/registers.xml Thu
Aug 20 10:57:38 2009
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<appendix version="5.0" xml:id="appendix"
+<appendix version="5.0" xml:id="appendix.register"
          xmlns="http://docbook.org/ns/docbook"
          xmlns:xlink="http://www.w3.org/1999/xlink"
          xmlns:xi="http://www.w3.org/2001/XInclude"

Added: incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/appendices/runtimeexample.xml
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/appendices/runtimeexample.xml?rev=806117&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/appendices/runtimeexample.xml
(added)
+++ incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/appendices/runtimeexample.xml
Thu Aug 20 10:57:38 2009
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<appendix version="5.0" xml:id="appendix.runtimeexample"
+         xmlns="http://docbook.org/ns/docbook"
+         xmlns:xlink="http://www.w3.org/1999/xlink"
+         xmlns:xi="http://www.w3.org/2001/XInclude"
+         xmlns:svg="http://www.w3.org/2000/svg"
+         xmlns:mml="http://www.w3.org/1998/Math/MathML"
+         xmlns:html="http://www.w3.org/1999/xhtml"
+         xmlns:db="http://docbook.org/ns/docbook">
+<title>Retrieval of all JavaRuntimes</title>
+<sect2>
+<para>
+This class allows subclasses to be given an <classname>Image</classname> and
+have their <methodname>analyzerRuntime(JavaRuntime)</methodname> methods invoked.
+This class implements the <classname>ImageAnalyzer</classname> interface in
+<xref linkend="appendix.imageinterfaceexample"/>.
+</para>
+<programlisting width="79">
+<![CDATA[
+/*******************************************************************************
+ * 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.examples;
+
+import javax.tools.diagnostics.image.Image;
+import javax.tools.diagnostics.image.ImageAddressSpace;
+import javax.tools.diagnostics.image.ImageProcess;
+import javax.tools.diagnostics.runtime.ManagedRuntime;
+import javax.tools.diagnostics.runtime.java.JavaRuntime;
+
+public abstract class RuntimeAnalyzer implements ImageAnalyzer {
+
+	/**
+	 * Calls the {@link #analyzeRuntime(JavaRuntime jr)} method against all {@link JavaRuntime}
+	 * instances found in the image.
+	 * 
+	 * @param image Image to analyse
+	 */
+	@Override
+	public void analyze(Image image) {
+		for(ImageAddressSpace as : image.getAddressSpaces()) {
+			for(ImageProcess process : as.getProcesses()) {
+				for(ManagedRuntime runtime : process.getRuntimes()) {
+					if (runtime instanceof JavaRuntime) {
+						analyzeRuntime((JavaRuntime) runtime);
+					}
+				}
+			}
+		}
+	}
+
+	/**
+	 * Override this method to analyze just the JavaRuntime.
+	 * 
+	 * @param jr
+	 */
+	public abstract void analyzeRuntime(JavaRuntime jr);
+}
+
+]]>	
+</programlisting>
+</sect2>
+</appendix>

Propchange: incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/appendices/runtimeexample.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/appendices/whatexample.xml
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/appendices/whatexample.xml?rev=806117&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/appendices/whatexample.xml (added)
+++ incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/appendices/whatexample.xml Thu
Aug 20 10:57:38 2009
@@ -0,0 +1,153 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<appendix version="5.0" xml:id="appendix.whatexample"
+         xmlns="http://docbook.org/ns/docbook"
+         xmlns:xlink="http://www.w3.org/1999/xlink"
+         xmlns:xi="http://www.w3.org/2001/XInclude"
+         xmlns:svg="http://www.w3.org/2000/svg"
+         xmlns:mml="http://www.w3.org/1998/Math/MathML"
+         xmlns:html="http://www.w3.org/1999/xhtml"
+         xmlns:db="http://docbook.org/ns/docbook">
+<title>Identifying Java VM Example</title>
+<sect2>
+<para>
+This class implements the <classname>ImageAnalyzer</classname> interface in
+<xref linkend="appendix.imageinterfaceexample"/>.
+</para>
+<programlisting>
+<![CDATA[
+/*******************************************************************************
+ * 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.examples;
+
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.image.DataUnavailable;
+import javax.tools.diagnostics.image.Image;
+import javax.tools.diagnostics.image.ImageAddressSpace;
+import javax.tools.diagnostics.image.ImageModule;
+import javax.tools.diagnostics.image.ImagePointer;
+import javax.tools.diagnostics.image.ImageProcess;
+import javax.tools.diagnostics.runtime.ManagedRuntime;
+import javax.tools.diagnostics.runtime.java.JavaRuntime;
+import javax.tools.diagnostics.runtime.java.JavaVMOption;
+/**
+ * This Analyzer generates a reports information useful for
+ * identifying the JVM that was running when the snapshot was taken.
+ * Elements from the Java and Image APIs are used.
+ */
+public class WhatAnalyzer implements ImageAnalyzer {
+
+	@Override
+	public void analyze(Image image) {
+		// Report the hostname.
+		String hostname;
+		try {
+			hostname = image.getHostName();
+		} catch (DataUnavailable e) {
+			hostname = "<Could not retrieve hostname";
+		} catch (CorruptDataException e) {
+			hostname = "<Error retrieving hostname>";
+			e.printStackTrace();
+		}
+		
+		System.out.println("Snapshot was generated on " + hostname);
+		
+		for (ImageAddressSpace as : image.getAddressSpaces()) {
+			for(ImageProcess process : as.getProcesses()) {
+				String processID;
+				try {
+					processID = process.getID();
+				} catch (DataUnavailable e) {					
+					processID = "<Unknown>";
+				} catch (CorruptDataException e) {
+					processID = "<Error>";
+					e.printStackTrace();
+				}
+				System.out.println("Process ID="+processID);
+
+				String commandLine;
+				try {
+					commandLine = process.getCommandLine();
+				} catch (DataUnavailable e) {
+					commandLine = "<Unknown>";
+				} catch (CorruptDataException e) {
+					commandLine = "<Error>";
+					e.printStackTrace();
+				}
+				System.out.println("Command line: "+commandLine);
+				
+				String executable;
+				try {
+					executable = process.getExecutable().getName();
+				} catch (CorruptDataException e) {
+					executable = "<Unknown>";
+				} catch (DataUnavailable e) {
+					executable = "<Error>";
+					e.printStackTrace();
+				}
+				System.out.println("Process Executable "+ executable);
+				
+				System.out.println("Loaded Libraries:");
+				try {
+					for(ImageModule module : process.getLibraries()) {
+						System.out.println("\t" + module.getName());
+					}
+				} catch (DataUnavailable e) {
+					System.out.println("No libraries found.");
+				} catch (CorruptDataException e) {
+					System.out.println("Error retrieving libraries:");
+					e.printStackTrace();
+				}
+				
+				for (ManagedRuntime runtime : process.getRuntimes()) {
+					if (runtime instanceof JavaRuntime) {
+						analyzeRuntime ((JavaRuntime) runtime);
+					}
+				}
+			}
+		}
+	}
+
+	public void analyzeRuntime(JavaRuntime jr) {
+		
+		try {
+			System.out.println("Java VM version:`"+jr.getVersion()+"'");
+		} catch (CorruptDataException e1) {
+			System.out.println("Error retrieving Java VM version");
+			e1.printStackTrace();
+		}
+		
+		System.out.println("VM options:");
+		try {
+			for (JavaVMOption option : jr.getJavaVMInitArgs().getOptions()) {
+				String optionString = "\t\t\""+option.getOptionString()+"\"";
+				
+				ImagePointer extra = option.getExtraInfo();
+				if (extra != null) {
+					optionString += ", extraInfo=0x"+Long.toHexString(extra.getAddress());
+				}
+				
+				System.out.println(optionString);
+			}
+		} catch (DataUnavailable e) {
+			System.out.println("Unable to report VM options");
+		} catch (CorruptDataException e) {
+			System.out.println("Error retrieving VM options");
+			e.printStackTrace();
+		}
+	}
+}
+]]>	
+</programlisting>
+</sect2>
+</appendix>

Propchange: incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/appendices/whatexample.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/chapters/examples.xml
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/chapters/examples.xml?rev=806117&r1=806116&r2=806117&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/chapters/examples.xml (original)
+++ incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/chapters/examples.xml Thu Aug
20 10:57:38 2009
@@ -19,6 +19,7 @@
 	<sect2 xml:id="api.examples.open">
 	<title>Opening Images</title>
 	<para><classname>Image</classname> instances are obtained using the <classname>javax.tools.diagnostics.FactoryRegistry</classname>
class.
+	See <xref linkend="appendix.readimageexample"/> for a complete example.
 	</para>
 	<para>
 	Programs using the API can obtain an Image like so:
@@ -66,7 +67,7 @@
 	</para>
 	
 	<para>
-	Here is an example of how to determine the cause of a snapshot. 
+	The complete listing is in <xref linkend="appendix.causeexample"/>.
 	</para>
 	<para>
 	First of all, there are the declarations. This implements a method in an interface that
expects
@@ -249,6 +250,9 @@
 	</itemizedlist>
 	</para>
 	<para>
+	The complete listing is in <xref linkend="appendix.whatexample"/>.
+	</para>
+	<para>
 	First, we have the class declaration, and imports. Note the use of both API's.
 <example xml:id="api.examples.what.declaration">
 <title>Declaration of WhatAnalyzer class</title>
@@ -472,7 +476,8 @@
 	<title>Retrieving Object Fields</title>
 	<para>
 	This example demonstrates how object instance fields and array elements are accessed
-	using the API. 
+	using the API.	
+	The complete listing is in <xref linkend="appendix.objectfieldsexample"/>.	 
 	</para>
 	<para>
 	The follow is the declaration for this example class. It extends a class that will

Modified: incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/fo.xsl
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/fo.xsl?rev=806117&r1=806116&r2=806117&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/fo.xsl (original)
+++ incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/fo.xsl Thu Aug 20 10:57:38 2009
@@ -51,11 +51,11 @@
 <xsl:attribute-set name="figure.properties">
 		<xsl:attribute name="color">#000000</xsl:attribute>
 		<xsl:attribute name="font-weight">bold</xsl:attribute>
-		<xsl:attribute name="background-color">#F0F0F0</xsl:attribute>
+		<xsl:attribute name="background-color">#E0E0E0</xsl:attribute>
 	</xsl:attribute-set>
 <xsl:attribute-set name="example.properties">
 		<xsl:attribute name="color">#000000</xsl:attribute>
-		<xsl:attribute name="background-color">	#F0F0F0</xsl:attribute>
+		<xsl:attribute name="background-color">	#E0E0E0</xsl:attribute>
 		<xsl:attribute name="font-size">8</xsl:attribute>
 		
 	</xsl:attribute-set>

Modified: incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/spec.xml
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/spec.xml?rev=806117&r1=806116&r2=806117&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/spec.xml (original)
+++ incubator/kato/trunk/org.apache.kato/kato.docs/src/docbkx/spec.xml Thu Aug 20 10:57:38
2009
@@ -41,6 +41,10 @@
    	
    	<!-- Appendices -->
    	<xi:include href="appendices/registers.xml" />
-   
-
-</book>
\ No newline at end of file
+	<xi:include href="appendices/readimageexample.xml" />
+	<xi:include href="appendices/causeexample.xml" />
+	<xi:include href="appendices/whatexample.xml" />
+	<xi:include href="appendices/objectfieldsexample.xml" />
+	<xi:include href="appendices/imageinterfaceexample.xml" />
+	<xi:include href="appendices/runtimeexample.xml" />
+</book>



Mime
View raw message