From 2556d11918040b0f96bd8996b205bbffb874a7a6 Mon Sep 17 00:00:00 2001 From: Siva Velusamy Date: Thu, 6 Dec 2012 10:43:22 -0800 Subject: Automatically enable graphics profiling if necessary Rather than rely on the user enabling the setting in developer options, we enable it automatically. Change-Id: I25360d88e8b0262dc6c5b9f503cd0e7e2958ba28 --- .../src/com/android/ddmuilib/SysinfoPanel.java | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/ddms/libs/ddmuilib/src/com/android/ddmuilib/SysinfoPanel.java b/ddms/libs/ddmuilib/src/com/android/ddmuilib/SysinfoPanel.java index c063818..8ba2171 100644 --- a/ddms/libs/ddmuilib/src/com/android/ddmuilib/SysinfoPanel.java +++ b/ddms/libs/ddmuilib/src/com/android/ddmuilib/SysinfoPanel.java @@ -19,14 +19,17 @@ package com.android.ddmuilib; import com.android.ddmlib.AdbCommandRejectedException; import com.android.ddmlib.Client; import com.android.ddmlib.ClientData; +import com.android.ddmlib.IDevice; import com.android.ddmlib.IShellOutputReceiver; import com.android.ddmlib.Log; +import com.android.ddmlib.NullOutputReceiver; import com.android.ddmlib.ShellCommandUnresponsiveException; import com.android.ddmlib.TimeoutException; import com.android.ddmuilib.SysinfoPanel.BugReportParser.GfxProfileData; import com.google.common.base.Splitter; import com.google.common.collect.Lists; +import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.StackLayout; import org.eclipse.swt.events.SelectionAdapter; @@ -103,6 +106,9 @@ public class SysinfoPanel extends TablePanel implements IShellOutputReceiver { "Frame Render Time", }; + /** Shell property that controls whether graphics profiling is enabled or not. */ + private static final String PROP_GFX_PROFILING = "debug.hwui.profile"; //$NON-NLS-1$ + /** * Generates the dataset to display. * @@ -164,6 +170,23 @@ public class SysinfoPanel extends TablePanel implements IShellOutputReceiver { private void loadFromDevice() { clearDataSet(); + if (mMode == MODE_GFXINFO) { + boolean en = isGfxProfilingEnabled(); + if (!en) { + if (enableGfxProfiling()) { + MessageDialog.openInformation(Display.getCurrent().getActiveShell(), + "DDMS", + "Graphics profiling was enabled on the device.\n" + + "It may be necessary to relaunch your application to see profile information."); + } else { + MessageDialog.openError(Display.getCurrent().getActiveShell(), + "DDMS", + "Unexpected error enabling graphics profiling on device.\n"); + return; + } + } + } + final String command = getDumpsysCommand(mMode); if (command == null) { return; @@ -193,6 +216,37 @@ public class SysinfoPanel extends TablePanel implements IShellOutputReceiver { t.start(); } + private boolean isGfxProfilingEnabled() { + IDevice device = getCurrentDevice(); + if (device == null) { + return false; + } + + String prop; + try { + prop = device.getPropertySync(PROP_GFX_PROFILING); + return Boolean.valueOf(prop); + } catch (Exception e) { + return false; + } + } + + private boolean enableGfxProfiling() { + IDevice device = getCurrentDevice(); + if (device == null) { + return false; + } + + try { + device.executeShellCommand("setprop " + PROP_GFX_PROFILING + " true", + new NullOutputReceiver()); + } catch (Exception e) { + return false; + } + + return true; + } + private String getDumpsysCommand(int mode) { if (mode == MODE_GFXINFO) { Client c = getCurrentClient(); -- cgit v1.1