aboutsummaryrefslogtreecommitdiffstats
path: root/ddms
diff options
context:
space:
mode:
authorSiva Velusamy <vsiva@google.com>2012-12-19 10:22:58 -0800
committerSiva Velusamy <vsiva@google.com>2012-12-20 10:30:09 -0800
commit94e177b50dc1ad3739f563668e1f2e43a9f97f46 (patch)
tree866fe385606bf4313d7c8edfcd5141e2dc49a880 /ddms
parent346f0a1a97c621f4c0dc3c31ffbfd89c5dca36cc (diff)
downloadsdk-94e177b50dc1ad3739f563668e1f2e43a9f97f46.zip
sdk-94e177b50dc1ad3739f563668e1f2e43a9f97f46.tar.gz
sdk-94e177b50dc1ad3739f563668e1f2e43a9f97f46.tar.bz2
ddmlib: Add controls for OpenGL tracing via jdwp
Currently, applications have to be launched with gltrace enabled for OpenGL tracing to work. This patch provides the host side support for dynamically enabling/disabling tracing on running apps. At a high level, the functionality is similar to traceview: - ClientData#FEATURE_OPENGL_TRACING indicates whether the VM on the device supports this feature. - If the feature is supported, then JDWP is used to send the enable or disable messages. - Users can trigger OpenGL tracing via a toolbar item in the DDMS device view. Change-Id: Icf5e5eade74f94cf6a74ff793533f75f1853731f
Diffstat (limited to 'ddms')
-rw-r--r--ddms/libs/ddmlib/src/main/java/com/android/ddmlib/Client.java30
-rw-r--r--ddms/libs/ddmlib/src/main/java/com/android/ddmlib/ClientData.java6
-rw-r--r--ddms/libs/ddmlib/src/main/java/com/android/ddmlib/OpenGlTraceChunkHandler.java63
3 files changed, 99 insertions, 0 deletions
diff --git a/ddms/libs/ddmlib/src/main/java/com/android/ddmlib/Client.java b/ddms/libs/ddmlib/src/main/java/com/android/ddmlib/Client.java
index 5b03462..f927dd7 100644
--- a/ddms/libs/ddmlib/src/main/java/com/android/ddmlib/Client.java
+++ b/ddms/libs/ddmlib/src/main/java/com/android/ddmlib/Client.java
@@ -271,6 +271,36 @@ public class Client {
}
}
+ public boolean startOpenGlTracing() {
+ boolean canTraceOpenGl = mClientData.hasFeature(ClientData.FEATURE_OPENGL_TRACING);
+ if (!canTraceOpenGl) {
+ return false;
+ }
+
+ try {
+ OpenGlTraceChunkHandler.sendStartGlTracing(this);
+ return true;
+ } catch (IOException e) {
+ Log.w("ddms", "Start OpenGL Tracing failed");
+ return false;
+ }
+ }
+
+ public boolean stopOpenGlTracing() {
+ boolean canTraceOpenGl = mClientData.hasFeature(ClientData.FEATURE_OPENGL_TRACING);
+ if (!canTraceOpenGl) {
+ return false;
+ }
+
+ try {
+ OpenGlTraceChunkHandler.sendStopGlTracing(this);
+ return true;
+ } catch (IOException e) {
+ Log.w("ddms", "Stop OpenGL Tracing failed");
+ return false;
+ }
+ }
+
/**
* Sends a request to the VM to send the enable status of the method profiling.
* This is asynchronous.
diff --git a/ddms/libs/ddmlib/src/main/java/com/android/ddmlib/ClientData.java b/ddms/libs/ddmlib/src/main/java/com/android/ddmlib/ClientData.java
index ff83c37..f490c1a 100644
--- a/ddms/libs/ddmlib/src/main/java/com/android/ddmlib/ClientData.java
+++ b/ddms/libs/ddmlib/src/main/java/com/android/ddmlib/ClientData.java
@@ -130,6 +130,12 @@ public class ClientData {
public final static String FEATURE_PROFILING_STREAMING = "method-trace-profiling-streaming"; //$NON-NLS-1$
/**
+ * String for feature indicating support for tracing OpenGL calls.
+ * @see #hasFeature(String)
+ */
+ public final static String FEATURE_OPENGL_TRACING = "opengl-tracing"; //$NON-NLS-1$
+
+ /**
* String for feature allowing to dump hprof files
* @see #hasFeature(String)
*/
diff --git a/ddms/libs/ddmlib/src/main/java/com/android/ddmlib/OpenGlTraceChunkHandler.java b/ddms/libs/ddmlib/src/main/java/com/android/ddmlib/OpenGlTraceChunkHandler.java
new file mode 100644
index 0000000..12ba142
--- /dev/null
+++ b/ddms/libs/ddmlib/src/main/java/com/android/ddmlib/OpenGlTraceChunkHandler.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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 com.android.ddmlib;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+public class OpenGlTraceChunkHandler extends ChunkHandler {
+ /** GL TRace Control: data in the packet enables or disables tracing. */
+ public static final int CHUNK_GLTR = type("GLTR");
+
+ private OpenGlTraceChunkHandler() {
+ }
+
+ @Override
+ void clientReady(Client client) throws IOException {
+ }
+
+ @Override
+ void clientDisconnected(Client client) {
+ }
+
+ @Override
+ void handleChunk(Client client, int type, ByteBuffer data, boolean isReply, int msgId) {
+ handleUnknownChunk(client, type, data, isReply, msgId);
+ }
+
+ public static void sendStartGlTracing(Client client) throws IOException {
+ ByteBuffer buf = allocBuffer(4);
+ JdwpPacket packet = new JdwpPacket(buf);
+
+ ByteBuffer chunkBuf = getChunkDataBuf(buf);
+ chunkBuf.putInt(1);
+ finishChunkPacket(packet, CHUNK_GLTR, chunkBuf.position());
+
+ client.sendAndConsume(packet);
+ }
+
+ public static void sendStopGlTracing(Client client) throws IOException {
+ ByteBuffer buf = allocBuffer(4);
+ JdwpPacket packet = new JdwpPacket(buf);
+
+ ByteBuffer chunkBuf = getChunkDataBuf(buf);
+ chunkBuf.putInt(0);
+ finishChunkPacket(packet, CHUNK_GLTR, chunkBuf.position());
+
+ client.sendAndConsume(packet);
+ }
+}