Bug 355571 - Trace JDI request/response times
diff --git a/org.eclipse.jdt.debug/.options b/org.eclipse.jdt.debug/.options
new file mode 100644
index 0000000..0e3193e
--- /dev/null
+++ b/org.eclipse.jdt.debug/.options
@@ -0,0 +1,3 @@
+org.eclipse.jdt.debug/debug=false
+org.eclipse.jdt.debug/debug/jdiEvents=false
+org.eclipse.jdt.debug/debug/jdiRequestTimes=false
\ No newline at end of file
diff --git a/org.eclipse.jdt.debug/jdi/org/eclipse/jdi/internal/MirrorImpl.java b/org.eclipse.jdt.debug/jdi/org/eclipse/jdi/internal/MirrorImpl.java
index 4c15198..a3b0048 100644
--- a/org.eclipse.jdt.debug/jdi/org/eclipse/jdi/internal/MirrorImpl.java
+++ b/org.eclipse.jdt.debug/jdi/org/eclipse/jdi/internal/MirrorImpl.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * Copyright (c) 2000, 2011 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -16,6 +16,7 @@
 import java.io.DataOutputStream;
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.util.Date;
 import java.util.Map;
 
 import org.eclipse.jdi.Bootstrap;
@@ -23,7 +24,10 @@
 import org.eclipse.jdi.internal.jdwp.JdwpPacket;
 import org.eclipse.jdi.internal.jdwp.JdwpReplyPacket;
 import org.eclipse.jdi.internal.jdwp.JdwpString;
+import org.eclipse.jdt.internal.debug.core.JDIDebugOptions;
 
+import com.ibm.icu.text.DateFormat;
+import com.ibm.icu.text.SimpleDateFormat;
 import com.sun.jdi.ClassNotPreparedException;
 import com.sun.jdi.InternalException;
 import com.sun.jdi.InvalidStackFrameException;
@@ -51,7 +55,10 @@
 	protected VerboseWriter fVerboseWriter = null;
 	/** True if a Jdwp request has been sent to the VM and the response is not yet (fully) processed. */
 	private boolean fPendingJdwpRequest = false;
-
+	
+	// used for debug messages
+	private static final DateFormat LOCAL_SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); //$NON-NLS-1$
+	
 	/**
 	 * Constructor only to be used by Virtual Machine objects: stores description of Mirror object and Virtual Machine.
 	 */	
@@ -167,11 +174,25 @@
 	public JdwpReplyPacket requestVM(int command, byte[] outData) {
 		JdwpCommandPacket commandPacket = new JdwpCommandPacket(command);
 		commandPacket.setData(outData);
+		long sent = System.currentTimeMillis();
 		fVirtualMachineImpl.packetSendManager().sendPacket(commandPacket);
 		fPendingJdwpRequest = true;
 		writeVerboseCommandPacketHeader(commandPacket);
 
 		JdwpReplyPacket reply = fVirtualMachineImpl.packetReceiveManager().getReply(commandPacket);
+		long recieved = System.currentTimeMillis();
+		if (JDIDebugOptions.DEBUG_JDI_REQUEST_TIMES) {
+			StringBuffer buf = new StringBuffer();
+			buf.append(LOCAL_SDF.format(new Date(sent)));
+			buf.append(" JDI Request: "); //$NON-NLS-1$
+			buf.append(commandPacket.toString());
+			buf.append("\n\tResponse Time: "); //$NON-NLS-1$
+			buf.append(recieved - sent);
+			buf.append("ms"); //$NON-NLS-1$
+			buf.append(" length: "); //$NON-NLS-1$
+			buf.append(reply.getLength());
+			System.out.println(buf.toString());
+		}
 		if (fVerboseWriter != null) {
 			fVerboseWriter.println();
 			fVerboseWriter.println("Received reply"); //$NON-NLS-1$
diff --git a/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/JDIDebugOptions.java b/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/JDIDebugOptions.java
new file mode 100644
index 0000000..034a9bb
--- /dev/null
+++ b/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/JDIDebugOptions.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2011 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.internal.debug.core;
+
+import org.eclipse.core.runtime.Platform;
+
+import com.ibm.icu.text.DateFormat;
+import com.ibm.icu.text.SimpleDateFormat;
+
+/**
+ * Debug flags in options file.
+ * 
+ * @since 3.4.2
+ */
+public class JDIDebugOptions {
+	// debug option flags
+	public static boolean DEBUG = false;
+	public static boolean DEBUG_JDI_EVENTS = false;
+	public static boolean DEBUG_JDI_REQUEST_TIMES = false;
+	
+	// used to format debug messages
+	public static final DateFormat FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); //$NON-NLS-1$
+
+	public static void initDebugOptions() {
+		DEBUG = "true".equals(Platform.getDebugOption("org.eclipse.jdt.debug/debug"));  //$NON-NLS-1$//$NON-NLS-2$
+		DEBUG_JDI_EVENTS = DEBUG && "true".equals( //$NON-NLS-1$
+				 Platform.getDebugOption("org.eclipse.jdt.debug/debug/jdiEvents")); //$NON-NLS-1$
+		DEBUG_JDI_REQUEST_TIMES = DEBUG && "true".equals( //$NON-NLS-1$
+				 Platform.getDebugOption("org.eclipse.jdt.debug/debug/jdiRequestTimes")); //$NON-NLS-1$
+	}
+}
\ No newline at end of file
diff --git a/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/JDIDebugPlugin.java b/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/JDIDebugPlugin.java
index 64bff34..6418965 100644
--- a/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/JDIDebugPlugin.java
+++ b/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/JDIDebugPlugin.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * Copyright (c) 2000, 2011 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -235,6 +235,7 @@
 	
 	public void start(BundleContext context) throws Exception {
 		super.start(context);
+		JDIDebugOptions.initDebugOptions();
 		ResourcesPlugin.getWorkspace().addSaveParticipant(this, new ISaveParticipant() {
 			public void doneSaving(ISaveContext c) {}
 			public void prepareToSave(ISaveContext c)	throws CoreException {}