diff options
6 files changed, 184 insertions, 4 deletions
diff --git a/perf/org.eclipse.linuxtools.perf/plugin.xml b/perf/org.eclipse.linuxtools.perf/plugin.xml index ddc05962bc..e4303fc284 100644 --- a/perf/org.eclipse.linuxtools.perf/plugin.xml +++ b/perf/org.eclipse.linuxtools.perf/plugin.xml @@ -134,7 +134,7 @@ point="org.eclipse.ui.editors"> <editor default="true" - filenames="perf.data, perf.data.old" + filenames="*.data, *.data.old" id="org.eclipse.linuxtools.perf.editor" launcher="org.eclipse.linuxtools.internal.perf.launch.PerfOpenData" name="Perf Viewer"> @@ -153,5 +153,25 @@ tabgroup="org.eclipse.linuxtools.internal.perf.launch.PerfLaunchConfigurationTabGroup" type="timing"> </provider> + </extension> + <extension + point="org.eclipse.ui.menus"> + <menuContribution + allPopups="false" + locationURI="menu:org.eclipse.linuxtools.perf.ui.ProfileView"> + <command + commandId="org.eclipse.linuxtools.perf.SaveData" + id="org.eclipse.linuxtools.perf.SaveCommand" + label="Save Current Session" + style="push"> + </command> + </menuContribution> + </extension> + <extension + point="org.eclipse.ui.handlers"> + <handler + class="org.eclipse.linuxtools.internal.perf.ui.PerfSaveSessionHandler" + commandId="org.eclipse.linuxtools.perf.SaveData"> + </handler> </extension> </plugin> 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 4047f2bf3f..0b850805f3 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 @@ -28,6 +28,7 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.Path; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.linuxtools.internal.perf.model.PMCommand; import org.eclipse.linuxtools.internal.perf.model.PMDso; @@ -381,11 +382,15 @@ public class PerfCore { try { if (workingDir==null) { p = RuntimeProcessFactory.getFactory().exec(getReportString(config, perfDataLoc), project); + PerfPlugin.getDefault().setPerfProfileData(new Path(perfDataLoc)); + PerfPlugin.getDefault().setWorkingDir(project.getLocation()); } else { - p = RuntimeProcessFactory.getFactory().exec(getReportString(config, workingDir.toOSString() + PerfPlugin.PERF_DEFAULT_DATA), project); + String defaultPerfDataLoc = workingDir.toOSString() + PerfPlugin.PERF_DEFAULT_DATA; + p = RuntimeProcessFactory.getFactory().exec(getReportString(config, defaultPerfDataLoc), project); + PerfPlugin.getDefault().setPerfProfileData(new Path(defaultPerfDataLoc)); + PerfPlugin.getDefault().setWorkingDir(workingDir); } - // p.waitFor(); input = new BufferedReader(new InputStreamReader(p.getInputStream())); error = new BufferedReader(new InputStreamReader(p.getErrorStream())); //spitting error stream moved to end of while loop, due to commenting of p.waitFor() diff --git a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/PerfPlugin.java b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/PerfPlugin.java index a5e020269d..9b843d179d 100644 --- a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/PerfPlugin.java +++ b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/PerfPlugin.java @@ -16,6 +16,7 @@ package org.eclipse.linuxtools.internal.perf; import java.util.List; +import org.eclipse.core.runtime.IPath; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.linuxtools.internal.perf.model.TreeParent; import org.eclipse.linuxtools.internal.perf.ui.PerfProfileView; @@ -103,9 +104,15 @@ public class PerfPlugin extends AbstractUIPlugin { // Source Disassembly Data private SourceDisassemblyData sourceDisassemblyData; - //Profile view + // Profile view private PerfProfileView _ProfileView = null; + // Current profile data + private IPath curProfileData; + + // Current working directory + private IPath curWorkingDir; + public TreeParent getModelRoot() { return _modelRoot; } @@ -114,6 +121,14 @@ public class PerfPlugin extends AbstractUIPlugin { return sourceDisassemblyData; } + public IPath getPerfProfileData() { + return curProfileData; + } + + public IPath getWorkingDir(){ + return curWorkingDir; + } + /** * Return cleared model root. * @return TreeParent cleared model root. @@ -135,6 +150,14 @@ public class PerfPlugin extends AbstractUIPlugin { this.sourceDisassemblyData = sourceDisassemblyData; } + public void setPerfProfileData(IPath perfProfileData) { + this.curProfileData = perfProfileData; + } + + public void setWorkingDir(IPath workingDir){ + curWorkingDir = workingDir; + } + public PerfProfileView getProfileView() { if (_ProfileView == null) { try { diff --git a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/Messages.java b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/Messages.java new file mode 100644 index 0000000000..b2f2a9d1b6 --- /dev/null +++ b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/Messages.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2013 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: + * Red Hat initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.internal.perf.ui; + +import org.eclipse.osgi.util.NLS; + +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.eclipse.linuxtools.internal.perf.ui.messages"; //$NON-NLS-1$ + public static String PerfSaveSession_title; + public static String PerfSaveSession_msg; + public static String PerfSaveSession_invalid_filename_title; + public static String PerfSaveSession_invalid_filename_msg; + public static String PerfSaveSession_no_data_found_title; + public static String PerfSaveSession_no_data_found_msg; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/PerfSaveSessionHandler.java b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/PerfSaveSessionHandler.java new file mode 100644 index 0000000000..3b238bd371 --- /dev/null +++ b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/PerfSaveSessionHandler.java @@ -0,0 +1,96 @@ +/******************************************************************************* + * Copyright (c) 2013 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 <cabernal@redhat.com> - Initial Implementation. + *******************************************************************************/ +package org.eclipse.linuxtools.internal.perf.ui; + +import java.io.File; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.IHandler; +import org.eclipse.core.commands.IHandlerListener; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jface.dialogs.IInputValidator; +import org.eclipse.jface.dialogs.InputDialog; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.window.Window; +import org.eclipse.linuxtools.internal.perf.PerfPlugin; +import org.eclipse.swt.widgets.Display; + +public class PerfSaveSessionHandler implements IHandler { + + @Override + public Object execute(ExecutionEvent event) { + InputDialog dialog = new InputDialog(Display.getCurrent() + .getActiveShell(), Messages.PerfSaveSession_title, + Messages.PerfSaveSession_msg, "", new IInputValidator() { + + @Override + public String isValid(String newText) { + if ("".equals(newText)) { + return Messages.PerfSaveSession_invalid_filename_msg; + } + return null; + } + }); + + if (dialog.open() == Window.OK) { + String fileName = dialog.getValue(); + + // get paths + IPath curWorkingDirectory = PerfPlugin.getDefault().getWorkingDir(); + IPath newDataLoc = curWorkingDirectory.append(fileName).addFileExtension("data"); //$NON-NLS-1$ + IPath defaultDataLoc = PerfPlugin.getDefault().getPerfProfileData(); + + // get files + File newDataFile = newDataLoc.toFile(); + File defaultDataFile = defaultDataLoc.toFile(); + + // rename default perf data file + if (defaultDataFile.renameTo(newDataFile)) { + PerfPlugin.getDefault().setPerfProfileData(newDataLoc); + PerfPlugin.getDefault().getProfileView().setContentDescription(newDataLoc.toOSString()); + } else{ + MessageDialog.openError(Display.getCurrent().getActiveShell(), + Messages.PerfSaveSession_no_data_found_title, + Messages.PerfSaveSession_no_data_found_msg); + } + } + + return null; + } + + @Override + public boolean isEnabled() { + IPath defaultDataLoc = PerfPlugin.getDefault().getPerfProfileData(); + IPath curWorkingDirectory = PerfPlugin.getDefault().getWorkingDir(); + if (defaultDataLoc == null || curWorkingDirectory == null + || defaultDataLoc.isEmpty() || curWorkingDirectory.isEmpty()) { + return false; + } + return true; + } + + @Override + public boolean isHandled() { + return isEnabled(); + } + + @Override + public void removeHandlerListener(IHandlerListener handlerListener) { + } + @Override + public void addHandlerListener(IHandlerListener handlerListener) { + + } + + @Override + public void dispose() { + + } +} diff --git a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/messages.properties b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/messages.properties new file mode 100644 index 0000000000..8df3e05238 --- /dev/null +++ b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/messages.properties @@ -0,0 +1,6 @@ +PerfSaveSession_title=Save Current Session +PerfSaveSession_msg=Enter the new name of the current session +PerfSaveSession_invalid_filename_title=Invalid file name +PerfSaveSession_invalid_filename_msg=Please provide a valid file name +PerfSaveSession_no_data_found_title=No profile data found +PerfSaveSession_no_data_found_msg=No profile data found for the current session |