incubator-kato-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From monte...@apache.org
Subject svn commit: r774422 - in /incubator/kato/trunk/HprofBinaryReaderPOC: .classpath src/org/apache/kato/hprof/HProfView.java src/org/apache/kato/hprof/datalayer/HProfFile.java
Date Wed, 13 May 2009 16:44:20 GMT
Author: monteith
Date: Wed May 13 16:44:16 2009
New Revision: 774422

URL: http://svn.apache.org/viewvc?rev=774422&view=rev
Log:
Add threads support to hprof.

Modified:
    incubator/kato/trunk/HprofBinaryReaderPOC/.classpath
    incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/HProfView.java
    incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/HProfFile.java

Modified: incubator/kato/trunk/HprofBinaryReaderPOC/.classpath
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/.classpath?rev=774422&r1=774421&r2=774422&view=diff
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/.classpath (original)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/.classpath Wed May 13 16:44:16 2009
@@ -1,9 +1,9 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
-	<classpathentry kind="src" path="src"/>
-	<classpathentry kind="src" path="testsrc"/>
-	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
-	<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
-	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
-	<classpathentry kind="output" path="bin"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="src" path="testsrc"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
+	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

Modified: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/HProfView.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/HProfView.java?rev=774422&r1=774421&r2=774422&view=diff
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/HProfView.java (original)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/HProfView.java Wed
May 13 16:44:16 2009
@@ -62,6 +62,9 @@
 	private HashMap<Integer,IJavaClass>  loadedClassesBySerial=new HashMap<Integer,IJavaClass>();
 	private HashMap<Long,IJavaClass>  loadedClassesByID=new HashMap<Long,IJavaClass>();
 	
+	// Thread ID Maps
+	private HashMap<Integer,IJavaThread> activeThreadsBySerial = new HashMap<Integer,
IJavaThread>();
+	
 	public HProfView(HProfFile file) {
 		this.file = file;
 	}
@@ -97,22 +100,37 @@
 					// Remove a loaded class if it is subsequently unloaded.
 					loadedClassesBySerial.remove(((IUnloadClassHProfRecord)record).getClassSerialNumber());
 				} else if (record instanceof IThreadActiveHProfRecord) {
-					// SRDM add by serial number
-					threadRecordNO.add(new ActiveJavaThread(r));
+					ActiveJavaThread ajt = new ActiveJavaThread(r);
+
+					threadRecordNO.add( ajt );
+					
+					// add by serial number
+					activeThreadsBySerial.put(ajt.getThreadSerialNumber(), ajt);
 				} else if (record instanceof IThreadEndingHProfRecord) {
-					// SRDM remove thread by serial number.
+					InactiveJavaThread ijt = new InactiveJavaThread(r);
 					
-					threadRecordNO.add(new InactiveJavaThread(r));
-
+					threadRecordNO.add(ijt);
+					// remove thread by serial number.
+					//SRDM activeThreadsBySerial.remove(ijt.getThreadSerialNumber());
 				} else if (record instanceof IJavaStackTraceHProfRecord) {
-					// SRDM Stack traces should be attached to threads
+					// Stack traces should be attached to threads
 					// keep the most recent. Attach to thread so that when thread removed,
 					// stacktrace is removed too.
 					IJavaStackTraceHProfRecord stackTrace = (IJavaStackTraceHProfRecord) record;
 					int sn = stackTrace.getSerialNumber();
+					
 					stackTraces.put(sn, r);
 					javastacks.add(r);
-
+					
+					// Attach this stack trace to its thread if the thread
+					// exists and this trace is newer.
+					int threadSerial = stackTrace.getThreadSerialNumber();				
+					IJavaThread ajt = activeThreadsBySerial.get(threadSerial);
+					
+					if(ajt != null) {
+						((ActiveJavaThread)ajt).setStackTrace(stackTrace);
+					}
+					
 				} else if (record instanceof IJavaStackFrameHProfRecord) {
 					IJavaStackFrameHProfRecord frame = (IJavaStackFrameHProfRecord) record;
 					long id = frame.getStackFrameID();
@@ -668,21 +686,37 @@
 		public int getThreadSerialNumber() {
 			return getActiveJavaThreadRecord(ref).getThreadSerialNumber();
 		}
-
+		
+		private IJavaStackTraceHProfRecord stackTrace;
+		public void setStackTrace(IJavaStackTraceHProfRecord stackTrace) {
+			if (this.stackTrace == null) {
+				this.stackTrace = stackTrace;
+				return;
+			}
+			
+			if (this.stackTrace.getSerialNumber() < stackTrace.getSerialNumber()) {
+				this.stackTrace = stackTrace;
+			}
+		}
+		
 		@Override
 		public IJavaStack getStack() {
 			// stack trace record no
-			int sn = getStackTraceSerialNumber();
-			int recordId = stackTraces.get(sn);
-			IJavaStackTraceHProfRecord record = (IJavaStackTraceHProfRecord) file
-					.getRecord(recordId);
-			int stackElements = record.getFrameCount();
-			final IJavaStackFrame[] data = new IJavaStackFrame[stackElements];
-			for (int i = 0; i < stackElements; i++) {
-				long stackFrameElementID = record.getStackFrameID(i);
-				int stackRecord=stackTraceFrames.get(stackFrameElementID);
-				data[i]=new JavaStackFrame(stackRecord);
+			IJavaStackTraceHProfRecord record = stackTrace;
+
+			final IJavaStackFrame[] data;
+			if (record != null) { // There might not be any frames with this thread.
+				int stackElements = record.getFrameCount();
+				data = new IJavaStackFrame[stackElements];
+				for (int i = 0; i < stackElements; i++) {
+					long stackFrameElementID = record.getStackFrameID(i);
+					int stackRecord=stackTraceFrames.get(stackFrameElementID);
+					data[i]=new JavaStackFrame(stackRecord);
+				}
+			} else {
+				data = new IJavaStackFrame[0]; 
 			}
+			
 			IJavaStack stack = new IJavaStack() {
 
 				@Override
@@ -699,7 +733,6 @@
 
 			return stack;
 		}
-
 	}
 
 	private IThreadEndingHProfRecord getEndingJavaThreadRecord(int ref) {
@@ -774,4 +807,14 @@
 		
 		return heapRecordLocation;
 	}
+	
+	/**
+	 * Returns the IJavaThreads that are active, i.e.
+	 * haven't got corresponding END THREAD records.
+	 * 
+	 * @return Collection of active JavaThreads
+	 */
+	public Collection<IJavaThread> getActiveThreads() {
+		return activeThreadsBySerial.values();
+	}
 }

Modified: incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/HProfFile.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/HProfFile.java?rev=774422&r1=774421&r2=774422&view=diff
==============================================================================
--- incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/HProfFile.java
(original)
+++ incubator/kato/trunk/HprofBinaryReaderPOC/src/org/apache/kato/hprof/datalayer/HProfFile.java
Wed May 13 16:44:16 2009
@@ -94,6 +94,19 @@
 			return readNumber(0, idSize);
 		}
 
+		/**
+		 * Check equality based on stack frame ID.
+		 */
+		public boolean equals(Object obj) {
+			if ((obj == null) || !(obj instanceof FrameHProfRecord)) {
+				return false;
+			}
+			
+			FrameHProfRecord record = (FrameHProfRecord) obj;
+			
+			return record.getStackFrameID() == getStackFrameID();
+		}
+
 	}
 
 	class HeapDumpHProfRecord extends HProfRecord implements



Mime
View raw message