1
/*******************************************************************************
2
* Copyright (c) 2004, 2008, 2009, 2012 Red Hat, Inc. and others
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* Kent Sebastian <ksebasti@redhat.com> - initial API and implementation
10
* Keith Seitz <keiths@redhat.com> - setup code in launch the method, initially
11
* written in the now-defunct OprofileSession class
12
* QNX Software Systems and others - the section of code marked in the launch
13
* method, and the exec method
14
* Red Hat Inc. - modification of OProfileLaunchConfigurationDelegate to here
15
*******************************************************************************/
16
package org.eclipse.linuxtools.internal.gprof.launch;
20
import org.eclipse.cdt.debug.core.CDebugUtils;
21
import org.eclipse.core.filesystem.IFileStore;
22
import org.eclipse.core.resources.IProject;
23
import org.eclipse.core.runtime.CoreException;
24
import org.eclipse.core.runtime.IPath;
25
import org.eclipse.core.runtime.IProgressMonitor;
26
import org.eclipse.core.runtime.Path;
27
import org.eclipse.debug.core.DebugPlugin;
28
import org.eclipse.debug.core.ILaunch;
29
import org.eclipse.debug.core.ILaunchConfiguration;
30
import org.eclipse.debug.core.ILaunchManager;
31
import org.eclipse.debug.core.ILaunchesListener2;
32
import org.eclipse.jface.dialogs.MessageDialog;
33
import org.eclipse.linuxtools.gprof.launch.GprofLaunchPlugin;
34
import org.eclipse.linuxtools.internal.gprof.view.GmonView;
35
import org.eclipse.linuxtools.profiling.launch.IRemoteCommandLauncher;
36
import org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy;
37
import org.eclipse.linuxtools.profiling.launch.ProfileLaunchConfigurationDelegate;
38
import org.eclipse.linuxtools.profiling.launch.RemoteProxyManager;
39
import org.eclipse.swt.widgets.Display;
40
import org.eclipse.swt.widgets.Shell;
41
import org.eclipse.ui.PlatformUI;
43
public class GprofLaunchConfigurationDelegate extends ProfileLaunchConfigurationDelegate {
44
protected ILaunchConfiguration config;
47
public void launch(ILaunchConfiguration config, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
49
IPath exePath = getExePath(config);
52
* this code written by QNX Software Systems and others and was
53
* originally in the CDT under LocalCDILaunchDelegate::RunLocalApplication
55
//set up and launch the local c/c++ program
56
IRemoteCommandLauncher launcher = RemoteProxyManager.getInstance().getLauncher(getProject());
58
URI workingDirURI = getProject().getLocationURI();
59
IPath workingDirPath = new Path(workingDirURI.getPath());
60
String arguments[] = getProgramArgumentsArray( config );
62
//add a listener for termination of the launch
63
ILaunchManager lmgr = DebugPlugin.getDefault().getLaunchManager();
64
lmgr.addLaunchListener(new LaunchTerminationWatcher(launch, exePath));
66
Process process = launcher.execute(exePath, arguments, getEnvironment(config), workingDirPath, monitor);
68
DebugPlugin.newProcess( launch, process, renderProcessLabel( exePath.toOSString() ) );
72
//A class used to listen for the termination of the current launch, and
73
// run some functions when it is finished.
74
class LaunchTerminationWatcher implements ILaunchesListener2 {
75
private ILaunch launch;
76
private IPath exePath;
78
class LaunchTerminationWatcherRunnable implements Runnable {
80
private String exePath;
81
private String gmonPath;
83
public LaunchTerminationWatcherRunnable(String exePath, String gmonPath) {
84
this.exePath = exePath;
85
this.gmonPath = gmonPath;
90
GmonView.displayGprofView(exePath, gmonPath, getProject());
94
public LaunchTerminationWatcher(ILaunch il, IPath exePath) {
96
this.exePath = exePath;
98
public void launchesTerminated(ILaunch[] launches) {
100
for (ILaunch l : launches) {
102
* Dump samples from the daemon,
103
* shut down the daemon,
104
* activate the OProfile view (open it if it isn't already),
105
* refresh the view (which parses the data/ui model and displays it).
107
if (l.equals(launch)) {
108
//need to run this in the ui thread otherwise get SWT Exceptions
109
// based on concurrency issues
110
Display.getDefault().syncExec(new Runnable() {
113
String s = exePath.toOSString();
114
URI workingDirURI = getProject().getLocationURI();
115
RemoteProxyManager rpmgr = RemoteProxyManager.getInstance();
116
IRemoteFileProxy proxy = rpmgr.getFileProxy(getProject());
117
String workingDirPath = proxy.toPath(workingDirURI);
118
// Because we set the working directory on execution to the top-level
119
// project directory, the gmon.out file should be found there
120
String gmonExpected = workingDirPath + "/gmon.out"; //$NON-NLS-1$
121
IFileStore f = proxy.getResource(gmonExpected);
122
if (!f.fetchInfo().exists()) {
123
String title = GprofLaunchMessages.GprofCompilerOptions_msg;
124
String message = GprofLaunchMessages.GprofCompileAgain_msg;
125
Shell parent = PlatformUI.getWorkbench().getDisplay().getActiveShell();
126
MessageDialog.openWarning(parent, title, message);
128
// We found gmon.out. Make sure it was generated after the executable was formed.
129
IFileStore exe = proxy.getResource(exePath.toString());
130
if (exe.fetchInfo().getLastModified() > f.fetchInfo().getLastModified()) {
131
String title = GprofLaunchMessages.GprofGmonStale_msg;
132
String message = GprofLaunchMessages.GprofGmonStaleExplanation_msg;
133
Shell parent = PlatformUI.getWorkbench().getDisplay().getActiveShell();
134
MessageDialog.openWarning(parent, title, message);
137
Display.getDefault().asyncExec(new LaunchTerminationWatcherRunnable(s, gmonExpected));
139
} catch (NullPointerException e) {
141
} catch (CoreException e) {
150
public void launchesAdded(ILaunch[] launches) { /* dont care */}
151
public void launchesChanged(ILaunch[] launches) { /* dont care */ }
152
public void launchesRemoved(ILaunch[] launches) { /* dont care */ }
157
protected String getPluginID() {
158
return GprofLaunchPlugin.getUniqueIdentifier();
161
/* all these functions exist to be overridden by the test class in order to allow launch testing */
163
protected IProject getProject(){
165
IProject project = CDebugUtils.verifyCProject(config).getProject();
167
} catch (CoreException e) {
174
* Return the exe path of the binary to be profiled.
176
* @return the exe path of the binary stored in the configuration
177
* @throws CoreException
180
protected IPath getExePath(ILaunchConfiguration config) throws CoreException{
181
IPath exePath = CDebugUtils.verifyProgramPath( config );
187
public String generateCommand(ILaunchConfiguration config) {