From 6c7bac69f5e1096a93983817d6e093dd81fc7220 Mon Sep 17 00:00:00 2001 From: Jeff Hao Date: Mon, 26 Aug 2013 18:47:18 -0700 Subject: [PATCH] Merge MPSE and SPSE Chunk handlers for ddms. (cherry picked from commit fd224b97797dfb7e3ee1e2f56c3109d1594cf040) Change-Id: I1dab7801d47f092259916c4aea19b20d17951c2f --- core/java/android/ddm/DdmHandleProfiling.java | 47 +++++-------------- 1 file changed, 13 insertions(+), 34 deletions(-) diff --git a/core/java/android/ddm/DdmHandleProfiling.java b/core/java/android/ddm/DdmHandleProfiling.java index e1d359c0aa0c9..f4011eda89d82 100644 --- a/core/java/android/ddm/DdmHandleProfiling.java +++ b/core/java/android/ddm/DdmHandleProfiling.java @@ -37,6 +37,7 @@ public class DdmHandleProfiling extends ChunkHandler { public static final int CHUNK_SPSS = type("SPSS"); public static final int CHUNK_SPSE = type("SPSE"); + private static final boolean DEBUG = false; private static DdmHandleProfiling mInstance = new DdmHandleProfiling(); @@ -72,7 +73,7 @@ public class DdmHandleProfiling extends ChunkHandler { * Handle a chunk of data. */ public Chunk handleChunk(Chunk request) { - if (false) + if (DEBUG) Log.v("ddm-heap", "Handling " + name(request.type) + " chunk"); int type = request.type; @@ -83,13 +84,13 @@ public class DdmHandleProfiling extends ChunkHandler { } else if (type == CHUNK_MPSS) { return handleMPSS(request); } else if (type == CHUNK_MPSE) { - return handleMPSE(request); + return handleMPSEOrSPSE(request, "Method"); } else if (type == CHUNK_MPRQ) { return handleMPRQ(request); } else if (type == CHUNK_SPSS) { return handleSPSS(request); } else if (type == CHUNK_SPSE) { - return handleSPSE(request); + return handleMPSEOrSPSE(request, "Sample"); } else { throw new RuntimeException("Unknown packet " + ChunkHandler.name(type)); @@ -106,7 +107,7 @@ public class DdmHandleProfiling extends ChunkHandler { int flags = in.getInt(); int len = in.getInt(); String fileName = getString(in, len); - if (false) + if (DEBUG) Log.v("ddm-heap", "Method profiling start: filename='" + fileName + "', size=" + bufferSize + ", flags=" + flags); @@ -146,7 +147,7 @@ public class DdmHandleProfiling extends ChunkHandler { int bufferSize = in.getInt(); int flags = in.getInt(); - if (false) { + if (DEBUG) { Log.v("ddm-heap", "Method prof stream start: size=" + bufferSize + ", flags=" + flags); } @@ -160,20 +161,18 @@ public class DdmHandleProfiling extends ChunkHandler { } /* - * Handle a "Method Profiling w/Streaming End" request. + * Handle a "Method Profiling w/Streaming End" request or a + * "Sample Profiling w/Streaming End" request. */ - private Chunk handleMPSE(Chunk request) { - byte result; - - if (false) { - Log.v("ddm-heap", "Method prof stream end"); + private Chunk handleMPSEOrSPSE(Chunk request, String type) { + if (DEBUG) { + Log.v("ddm-heap", type + " prof stream end"); } try { Debug.stopMethodTracing(); - result = 0; } catch (RuntimeException re) { - Log.w("ddm-heap", "Method prof stream end failed: " + Log.w("ddm-heap", type + " prof stream end failed: " + re.getMessage()); return createFailChunk(1, re.getMessage()); } @@ -202,7 +201,7 @@ public class DdmHandleProfiling extends ChunkHandler { int bufferSize = in.getInt(); int flags = in.getInt(); int interval = in.getInt(); - if (false) { + if (DEBUG) { Log.v("ddm-heap", "Sample prof stream start: size=" + bufferSize + ", flags=" + flags + ", interval=" + interval); } @@ -214,25 +213,5 @@ public class DdmHandleProfiling extends ChunkHandler { return createFailChunk(1, re.getMessage()); } } - - /* - * Handle a "Sample Profiling w/Streaming End" request. - */ - private Chunk handleSPSE(Chunk request) { - if (false) { - Log.v("ddm-heap", "Sample prof stream end"); - } - - try { - Debug.stopMethodTracing(); - } catch (RuntimeException re) { - Log.w("ddm-heap", "Sample prof stream end failed: " - + re.getMessage()); - return createFailChunk(1, re.getMessage()); - } - - /* VM sent the (perhaps very large) response directly */ - return null; - } }