New DDMS extension: traceviewLauncher.
This allows another plug-in (traceview) to provide
a way to open traceview file. If this doesn't work
it revert to the default behavior of DDMS which is to
open the external traceview program.
also reverted the extension of traceview file
from .atv to .trace because earlier versions of
Android would automatically create those files
using this extension.
Change-Id: I2605ad47e501770ae100da2ace781b1d5d8cebc5
if (canStream) {
HandleProfiling.sendMPSS(this, 8*1024*1024, 0 /*flags*/);
} else {
- String file = "/sdcard/" + mClientData.getClientDescription().replaceAll("\\:.*", "") +
- ".trace";
+ String file = "/sdcard/" +
+ mClientData.getClientDescription().replaceAll("\\:.*", "") +
+ DdmConstants.DOT_TRACE;
HandleProfiling.sendMPRS(this, file, 8*1024*1024, 0 /*flags*/);
}
}
*/
public final static int CURRENT_PLATFORM = currentPlatform();
+ /**
+ * Extension for Traceview files.
+ */
+ public final static String DOT_TRACE = ".trace";
+
/** hprof-conv executable (with extension for the current OS) */
public final static String FN_HPROF_CONVERTER = (CURRENT_PLATFORM == PLATFORM_WINDOWS) ?
"hprof-conv.exe" : "hprof-conv"; //$NON-NLS-1$ //$NON-NLS-2$
* android.os.Debug.startMethodTracing() on the device.
*
* @param fileName is the name of the file to which profiling data
- * will be written (on the device); it will have ".trace"
+ * will be written (on the device); it will have {@link DdmConstants#DOT_TRACE}
* appended if necessary
* @param bufferSize is the desired buffer size in bytes (8MB is good)
* @param flags see startMethodTracing() docs; use 0 for default behavior
package com.android.ddmuilib.explorer;
import com.android.ddmlib.AdbCommandRejectedException;
+import com.android.ddmlib.DdmConstants;
import com.android.ddmlib.FileListingService;
import com.android.ddmlib.IDevice;
import com.android.ddmlib.IShellOutputReceiver;
String path;
try {
// create a temp file for keyFile
- File f = File.createTempFile(baseName, ".trace");
+ File f = File.createTempFile(baseName, DdmConstants.DOT_TRACE);
f.delete();
f.mkdir();
* @return the File into which the data was written or null if it failed.
* @throws IOException
*/
- protected File saveTempFile(byte[] data) throws IOException {
- File f = File.createTempFile("ddms", null);
+ protected File saveTempFile(byte[] data, String extension) throws IOException {
+ File f = File.createTempFile("ddms", extension);
saveFile(data, f);
return f;
}
package com.android.ddmuilib.handler;
import com.android.ddmlib.Client;
+import com.android.ddmlib.DdmConstants;
import com.android.ddmlib.IDevice;
import com.android.ddmlib.Log;
import com.android.ddmlib.SyncException;
public void onSuccess(byte[] data, final Client client) {
try {
- File tempFile = saveTempFile(data);
- openInTraceview(tempFile.getAbsolutePath());
+ File tempFile = saveTempFile(data, DdmConstants.DOT_TRACE);
+ open(tempFile.getAbsolutePath());
} catch (IOException e) {
String errorMsg = e.getMessage();
displayErrorInUiThread(
private void pullAndOpen(final SyncService sync, final String remoteFilePath)
throws InvocationTargetException, InterruptedException, IOException {
// get a temp file
- File temp = File.createTempFile("android", ".trace"); //$NON-NLS-1$ //$NON-NLS-2$
+ File temp = File.createTempFile("android", DdmConstants.DOT_TRACE); //$NON-NLS-1$
final String tempPath = temp.getAbsolutePath();
// pull the file
String.format("Pulling %1$s from the device", remoteFilePath), mParentShell);
// open the temp file in traceview
- openInTraceview(tempPath);
+ open(tempPath);
} catch (SyncException e) {
if (e.wasCanceled() == false) {
displayErrorFromUiThread("Unable to download trace file:\n\n%1$s", e.getMessage());
}
}
- private void openInTraceview(String tempPath) {
+ protected void open(String tempPath) {
// now that we have the file, we need to launch traceview
String[] command = new String[2];
command[0] = DdmUiPreferences.getTraceview();
<extension-point id="toolsLocator" name="Tools Locator" schema="schema/toolsLocator.exsd"/>
<extension-point id="debuggerConnector" name="Debugger Connector" schema="schema/debuggerConnector.exsd"/>
<extension-point id="sourceRevealer" name="Source Revealer" schema="schema/sourceRevealer.exsd"/>
+ <extension-point id="traceviewLauncher" name="TraceView Launcher" schema="schema/traceviewLauncher.exsd"/>
<extension
point="org.eclipse.ui.views">
--- /dev/null
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="com.android.ide.eclipse.ddms" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="com.android.ide.eclipse.ddms" id="traceviewLauncher" name="Traceview Launcher"/>
+ </appInfo>
+ <documentation>
+ Extension Point to launch Traceview.
+ </documentation>
+ </annotation>
+
+ <element name="launcher">
+ <complexType>
+ <attribute name="class" type="string" use="required">
+ <annotation>
+ <documentation>
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="java" basedOn=":com.android.ide.eclipse.ddms.ITraceviewLauncher"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="extension">
+ <annotation>
+ <appInfo>
+ <meta.element />
+ </appInfo>
+ </annotation>
+ <complexType>
+ <sequence>
+ <element ref="launcher"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+ </documentation>
+ <appInfo>
+ <meta.attribute translatable="true"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ 10.0.0
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ <extension point="com.android.ide.eclipse.ddms.traceviewLauncher">
+ <launcher class="com.android.ide.eclipse.adt.Launcher"/>
+</extension>
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiinfo"/>
+ </appInfo>
+ <documentation>
+ The class must implement com.android.ide.ddms.ITraceviewLauncher.
+ </documentation>
+ </annotation>
+
+
+ <annotation>
+ <appInfo>
+ <meta.section type="copyright"/>
+ </appInfo>
+ <documentation>
+ Copyright (C) 2011 The Android Open Source Project
+ </documentation>
+ </annotation>
+
+</schema>
*/
private IDebuggerConnector[] mDebuggerConnectors;
private ISourceRevealer[] mSourceRevealers;
+ private ITraceviewLauncher[] mTraceviewLaunchers;
/** Console for DDMS log message */
// get the other configElements and instantiante them in a Job.
new Job("DDMS post-create init") {
+
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
elements = findConfigElements("com.android.ide.eclipse.ddms.sourceRevealer"); //$NON-NLS-1$
mSourceRevealers = instantiateSourceRevealers(elements);
+ // get the available Traceview Launchers.
+ elements = findConfigElements("com.android.ide.eclipse.ddms.traceviewLauncher"); //$NON-NLS-1$
+ mTraceviewLaunchers = instantiateTraceviewLauncher(elements);
+
return Status.OK_STATUS;
} catch (CoreException e) {
return e.getStatus();
// only use the first one, ignore the others.
IConfigurationElement configElement = configElements[0];
- // instantiate the clas
+ // instantiate the class
Object obj = configElement.createExecutableExtension("class"); //$NON-NLS-1$
if (obj instanceof IToolsLocator) {
list.add((IToolsLocator) obj);
// only use the first one, ignore the others.
IConfigurationElement configElement = configElements[0];
- // instantiate the clas
+ // instantiate the class
Object obj = configElement.createExecutableExtension("class"); //$NON-NLS-1$
if (obj instanceof IDebuggerConnector) {
list.add((IDebuggerConnector) obj);
// only use the first one, ignore the others.
IConfigurationElement configElement = configElements[0];
- // instantiate the clas
+ // instantiate the class
Object obj = configElement.createExecutableExtension("class"); //$NON-NLS-1$
if (obj instanceof ISourceRevealer) {
list.add((ISourceRevealer) obj);
return list.toArray(new ISourceRevealer[list.size()]);
}
+ /**
+ * Finds if any other plug-in is extending the exposed Extension Point called traceviewLauncher.
+ *
+ * @return an array of all locators found, or an empty array if none were found.
+ */
+ private ITraceviewLauncher[] instantiateTraceviewLauncher(
+ IConfigurationElement[] configElements)
+ throws CoreException {
+ ArrayList<ITraceviewLauncher> list = new ArrayList<ITraceviewLauncher>();
+
+ if (configElements.length > 0) {
+ // only use the first one, ignore the others.
+ IConfigurationElement configElement = configElements[0];
+
+ // instantiate the class
+ Object obj = configElement.createExecutableExtension("class"); //$NON-NLS-1$
+ if (obj instanceof ITraceviewLauncher) {
+ list.add((ITraceviewLauncher) obj);
+ }
+ }
+
+ return list.toArray(new ITraceviewLauncher[list.size()]);
+ }
+
public static Display getDisplay() {
IWorkbench bench = sPlugin.getWorkbench();
if (bench != null) {
}
}
}
+
+ public boolean launchTraceview(String osPath) {
+ if (mTraceviewLaunchers != null) {
+ for (ITraceviewLauncher launcher : mTraceviewLaunchers) {
+ try {
+ if (launcher.openFile(osPath)) {
+ return true;
+ }
+ } catch (Throwable t) {
+ // ignore, we'll just not use this implementation.
+ }
+ }
+ }
+
+ return false;
+ }
}
--- /dev/null
+/*
+ * Copyright (C) 2011 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.ide.eclipse.ddms;
+
+/**
+ * Classes which implement this interface provides a way to open a traceview file.
+ */
+public interface ITraceviewLauncher {
+
+ boolean openFile(String osPath);
+}
if (ACTION_OPEN.equals(value)) {
try {
- File tempFile = saveTempFile(data);
+ // no need to give an extension since we're going to convert the
+ // file anyway after.
+ File tempFile = saveTempFile(data, null /*extension*/);
open(tempFile.getAbsolutePath());
} catch (Exception e) {
String errorMsg = e.getMessage();
}
}
- IDE.openEditorOnFileStore(
- getSite().getWorkbenchWindow().getActivePage(),
- fileStore);
+ IDE.openEditorOnFileStore(page, fileStore);
}
}
}
-
public DeviceView() {
// the view is declared with allowMultiple="false" so we
// can safely do this.
ClientData.setHprofDumpHandler(new HProfHandler(mParentShell));
AndroidDebugBridge.addClientChangeListener(this);
- ClientData.setMethodProfilingHandler(new MethodProfilingHandler(mParentShell));
+ ClientData.setMethodProfilingHandler(new MethodProfilingHandler(mParentShell) {
+ @Override
+ protected void open(String tempPath) {
+ if (DdmsPlugin.getDefault().launchTraceview(tempPath) == false) {
+ super.open(tempPath);
+ }
+ }
+ });
}
@Override
Bundle-Activator: com.android.ide.eclipse.traceview.TraceviewPlugin
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
- org.eclipse.ui.ide
+ org.eclipse.ui.ide,
+ com.android.ide.eclipse.ddms;bundle-version="10.0.0",
+ org.eclipse.core.filesystem,
+ org.eclipse.core.resources
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .,
libs/traceview.jar
<editor
class="com.android.ide.eclipse.traceview.editors.TraceviewEditor"
default="true"
- extensions="atv"
+ extensions="trace"
icon="icons/android.png"
id="com.android.ide.eclipse.traceview.editors.TraceviewEditor"
name="Traceview">
</editor>
</extension>
+ <extension
+ point="com.android.ide.eclipse.ddms.traceviewLauncher">
+ <launcher
+ class="com.android.ide.eclipse.traceview.TraceviewLauncher">
+ </launcher>
+ </extension>
</plugin>
--- /dev/null
+/*
+ * Copyright (C) 2011 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.ide.eclipse.traceview;
+
+import com.android.ide.eclipse.ddms.ITraceviewLauncher;
+
+import org.eclipse.core.filesystem.EFS;
+import org.eclipse.core.filesystem.IFileStore;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.WorkbenchException;
+import org.eclipse.ui.ide.IDE;
+
+public class TraceviewLauncher implements ITraceviewLauncher {
+
+ public boolean openFile(String osPath) {
+ final IFileStore fileStore = EFS.getLocalFileSystem().getStore(new Path(osPath));
+ if (!fileStore.fetchInfo().isDirectory() && fileStore.fetchInfo().exists()) {
+ // before we open the file in an editor window, we make sure the current
+ // workbench page has an editor area (typically the ddms perspective doesn't).
+ final IWorkbench workbench = PlatformUI.getWorkbench();
+ Display display = workbench.getDisplay();
+ final boolean[] result = new boolean[] { false };
+ display.syncExec(new Runnable() {
+ public void run() {
+ IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
+ IWorkbenchPage page = window.getActivePage();
+ if (page.isEditorAreaVisible() == false) {
+ IAdaptable input;
+ if (page != null)
+ input= page.getInput();
+ else
+ input= ResourcesPlugin.getWorkspace().getRoot();
+ try {
+ workbench.showPerspective("org.eclipse.debug.ui.DebugPerspective",
+ window, input);
+ } catch (WorkbenchException e) {
+ }
+ }
+
+ try {
+ result[0] = IDE.openEditorOnFileStore(page, fileStore) != null;
+ } catch (PartInitException e) {
+ // return false below
+ }
+ }
+ });
+
+ return result[0];
+ }
+
+ return false;
+ }
+}
<category name="platform"/>
</feature>
<feature url="features/com.android.ide.eclipse.traceview_10.0.0.qualifier.jar" id="com.android.ide.eclipse.traceview" version="10.0.0.qualifier">
+ <category name="developer"/>
<category name="platform"/>
</feature>
<category-def name="developer" label="Application Developer Tools">