From 6593e16b8c5ef4774a6327fea867ac9fd0af1fc0 Mon Sep 17 00:00:00 2001 From: Camilo Bernal Date: Wed, 30 May 2012 09:50:57 -0400 Subject: Added ability to open perf data files in the Perf Viewer. In the plug-in.xml file, an editor extension point is included in order to add a launcher (PerfOpenData.java) for perf data files. In order to properly report on the the perf file a configuration is needed. This is done in the createDefaultConfiguration (PerfOpenData.java), which creates a new default configuration based on the project's name. In PerfCore.java, it is not necesssary to differentiate between default events and multiple events, so now events are collected without having to check this. Changes were made to the current tests (ModelTest.java) to reflect the new change, which specifies what the "Default Event" is, namely "cycles". --- .../eclipse/linuxtools/internal/perf/PerfCore.java | 21 +------ .../internal/perf/launch/PerfOpenData.java | 72 ++++++++++++++++++++++ 2 files changed, 73 insertions(+), 20 deletions(-) create mode 100644 perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/launch/PerfOpenData.java (limited to 'perf/org.eclipse.linuxtools.perf/src') diff --git a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/PerfCore.java b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/PerfCore.java index 1e691ce8d3..87007a530f 100644 --- a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/PerfCore.java +++ b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/PerfCore.java @@ -322,29 +322,13 @@ public class PerfCore { PMFile currentFile = null; PMSymbol currentSym = null; try { - //Set up the event parent depending on whats selected. - if (config.getAttribute(PerfPlugin.ATTR_DefaultEvent, PerfPlugin.ATTR_DefaultEvent_default)) { - currentEvent = new PMEvent("Default Event"); - invisibleRoot.addChild(currentEvent); - } else if (!config.getAttribute(PerfPlugin.ATTR_MultipleEvents, PerfPlugin.ATTR_MultipleEvents_default)) { - ArrayList selE = (ArrayList) config.getAttribute(PerfPlugin.ATTR_SelectedEvents, PerfPlugin.ATTR_SelectedEvents_default); - if (selE != null) { - currentEvent = new PMEvent(selE.get(0)); - } else { - // this should never happen. - currentEvent = new PMEvent("Error please fix profiling events chosen in launch config"); - } - } - while (( line = input.readLine()) != null){ if (monitor != null && monitor.isCanceled()) { RefreshView(); return; } //System.out.println("Reading line: " + line); if ((line.startsWith("#"))) { //if (PerfPlugin.DEBUG_ON) System.out.println("Reading line: " + line); // # is comment line, but if we're in multi-event mode then we need to scan for event name. - if (line.contains("Events:") - && config.getAttribute(PerfPlugin.ATTR_MultipleEvents, PerfPlugin.ATTR_MultipleEvents_default) - && !config.getAttribute(PerfPlugin.ATTR_DefaultEvent, PerfPlugin.ATTR_DefaultEvent_default)) { + if (line.contains("Events:")) { String[] tmp = line.trim().split(" "); currentEvent = new PMEvent(tmp[tmp.length - 1]); //if (PerfPlugin.DEBUG_ON) System.out.println("Event is " + tmp[tmp.length - 1]); @@ -387,9 +371,6 @@ public class PerfCore { } } catch (IOException e) { e.printStackTrace(); - } catch (CoreException e) { - // TODO Auto-generated catch block - e.printStackTrace(); } spitStream(error,"Perf Report STDERR", print); diff --git a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/launch/PerfOpenData.java b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/launch/PerfOpenData.java new file mode 100644 index 0000000000..f4a27944b3 --- /dev/null +++ b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/launch/PerfOpenData.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2012 Red Hat, Inc. + * 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: + * Camilo Bernal - Initial Implementation. + *******************************************************************************/ +package org.eclipse.linuxtools.internal.perf.launch; + +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationType; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.debug.ui.IDebugUIConstants; +import org.eclipse.linuxtools.internal.perf.PerfCore; +import org.eclipse.linuxtools.internal.perf.PerfPlugin; +import org.eclipse.linuxtools.profiling.launch.ProfileLaunchShortcut; +import org.eclipse.ui.IEditorLauncher; + +public class PerfOpenData extends ProfileLaunchShortcut implements + IEditorLauncher { + + @Override + public void open(IPath file) { + + // get project name of where the file resides. + String projectName = ResourcesPlugin.getWorkspace().getRoot() + .getFileForLocation(file).getProject().getName(); + ILaunchConfiguration config = createDefaultConfiguration(projectName); + PerfCore.Report(config, null, null, null, file.toOSString(), null); + } + + @Override + protected ILaunchConfigurationType getLaunchConfigType() { + return getLaunchManager().getLaunchConfigurationType( + PerfPlugin.LAUNCHCONF_ID); + } + + @Override + protected void setDefaultProfileAttributes( + ILaunchConfigurationWorkingCopy wc) throws CoreException { + wc.setAttribute(IDebugUIConstants.ATTR_LAUNCH_IN_BACKGROUND, false); + wc.setAttribute(IDebugUIConstants.ATTR_CAPTURE_IN_CONSOLE, true); + } + + /** + * Create an ILaunchConfiguration instance given the project's name. + * + * @param projectName + * @return ILaunchConfiguration based on String projectName + */ + protected ILaunchConfiguration createDefaultConfiguration(String projectName) { + ILaunchConfiguration config = null; + try { + ILaunchConfigurationType configType = getLaunchConfigType(); + ILaunchConfigurationWorkingCopy wc = configType.newInstance( + null, + getLaunchManager().generateLaunchConfigurationName( + projectName)); + config = (ILaunchConfiguration) wc; + + } catch (CoreException e) { + e.printStackTrace(); + } + return config; + } +} \ No newline at end of file -- cgit v1.2.3