Permalink
Browse files

Created launcher for running executables with profiling.

  • Loading branch information...
1 parent cfd9109 commit 1cd716fe3aad2eb6528979979ebc84a9e4ed59bd @serras serras committed Jul 22, 2011
@@ -14,7 +14,9 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.ui.console,
org.eclipse.jface.text;bundle-version="3.2.0",
org.eclipse.jdt.junit.core;bundle-version="3.2.0",
- org.eclipse.jdt.junit;bundle-version="3.2.0"
+ org.eclipse.jdt.junit;bundle-version="3.2.0",
+ org.eclipse.ui.ide,
+ org.eclipse.core.filesystem
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-Localization: plugin
@@ -10,5 +10,6 @@ bundleName = Haskell Plug-in Debug Core
haskellApplicationLaunchType_name = Haskell application
haskellInteractiveLaunchType_name = Haskell interactive session
testSuiteLaunchType_name = Test-framework test
+haskellProfilingLaunchType_name = Haskell application with profiling
source_locator=Haskell Source Lookup Director
@@ -27,6 +27,14 @@
sourceLocatorId="net.sf.eclipsefp.haskell.debug.core.sourceLookupDirector"
sourcePathComputerId="net.sf.eclipsefp.haskell.debug.core.sourcePathComputer">
</launchConfigurationType>
+ <launchConfigurationType
+ delegate="net.sf.eclipsefp.haskell.debug.core.internal.launch.ExecutableProfilingHaskellLaunchDelegate"
+ id="net.sf.eclipsefp.haskell.debug.core.internal.launch.ExecutableProfilingHaskellLaunchDelegate"
+ modes="run"
+ name="%haskellProfilingLaunchType_name"
+ sourceLocatorId="net.sf.eclipsefp.haskell.debug.core.sourceLookupDirector"
+ sourcePathComputerId="net.sf.eclipsefp.haskell.debug.core.sourcePathComputer">
+ </launchConfigurationType>
</extension>
<extension
@@ -1,47 +1,37 @@
package net.sf.eclipsefp.haskell.debug.core.internal.launch;
import java.util.Map;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.model.IProcess;
/**
* launch delegate for Haskell executables executables
+ *
* @author JP Moresmau
*
*/
public class ExecutableHaskellLaunchDelegate extends
- AbstractHaskellLaunchDelegate {
+ ExecutableOrTestSuiteHaskellLaunchDelegate {
+
+ @Override
+ protected String getExtraArguments() {
+ return ""; //$NON-NLS-1$
+ }
@Override
protected void preProcessCreation( final ILaunchConfiguration configuration,
- final String mode, final ILaunch launch, final Map<String, String> processAttribs ) {
+ final String mode, final ILaunch launch,
+ final Map<String, String> processAttribs ) {
// NOOP
}
@Override
protected void postProcessCreation( final ILaunchConfiguration configuration,
- final String mode, final ILaunch launch, final IProcess process ) {
+ final String mode, final ILaunch launch, final IProcess process ) {
// NOOP
}
- @Override
- protected IProject[] getBuildOrder( final ILaunchConfiguration configuration,
- final String mode ) throws CoreException {
- // indicate the project is to be looked at for unsaved files
- String prj=configuration.getAttribute( ILaunchAttributes.PROJECT_NAME, (String)null );
- if (prj!=null){
- IProject p=ResourcesPlugin.getWorkspace().getRoot().getProject( prj );
- if (p!=null){
- return new IProject[]{p};
- }
- }
- return super.getBuildOrder( configuration, mode );
- }
-
}
@@ -0,0 +1,42 @@
+package net.sf.eclipsefp.haskell.debug.core.internal.launch;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.ILaunchConfiguration;
+
+/**
+ * launch delegate for Haskell executables executables
+ * @author JP Moresmau
+ *
+ */
+public abstract class ExecutableOrTestSuiteHaskellLaunchDelegate extends
+ AbstractHaskellLaunchDelegate {
+
+ protected abstract String getExtraArguments();
+
+ @Override
+ String[] determineArguments( final ILaunchConfiguration config )
+ throws CoreException {
+ String extra = config.getAttribute( ILaunchAttributes.EXTRA_ARGUMENTS,
+ ILaunchAttributes.EMPTY );
+ String args = config.getAttribute( ILaunchAttributes.ARGUMENTS,
+ ILaunchAttributes.EMPTY );
+ return CommandLineUtil.parse( extra + " " + args + " " + getExtraArguments() ); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ @Override
+ protected IProject[] getBuildOrder( final ILaunchConfiguration configuration,
+ final String mode ) throws CoreException {
+ // indicate the project is to be looked at for unsaved files
+ String prj=configuration.getAttribute( ILaunchAttributes.PROJECT_NAME, (String)null );
+ if (prj!=null){
+ IProject p=ResourcesPlugin.getWorkspace().getRoot().getProject( prj );
+ if (p!=null){
+ return new IProject[]{p};
+ }
+ }
+ return super.getBuildOrder( configuration, mode );
+ }
+
+}
@@ -0,0 +1,99 @@
+package net.sf.eclipsefp.haskell.debug.core.internal.launch;
+
+import java.io.File;
+import java.util.Map;
+import net.sf.eclipsefp.haskell.debug.core.internal.util.CoreTexts;
+import org.eclipse.core.filesystem.EFS;
+import org.eclipse.core.filesystem.IFileStore;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.model.IProcess;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.ide.IDE;
+
+/**
+ * launch delegate for Haskell executables executables
+ *
+ * @author JP Moresmau
+ *
+ */
+public class ExecutableProfilingHaskellLaunchDelegate extends
+ ExecutableOrTestSuiteHaskellLaunchDelegate {
+
+ @Override
+ protected String getExtraArguments() {
+ return "+RTS -hT"; //$NON-NLS-1$
+ }
+
+ @Override
+ protected void preProcessCreation( final ILaunchConfiguration configuration,
+ final String mode, final ILaunch launch,
+ final Map<String, String> processAttribs ) {
+ // NOOP
+
+ }
+
+ @Override
+ protected void postProcessCreation( final ILaunchConfiguration configuration,
+ final String mode, final ILaunch launch, final IProcess process ) {
+
+ Job endJob = new Job( CoreTexts.testSuite_waiting ) {
+
+ @Override
+ protected IStatus run( final IProgressMonitor monitor ) {
+ monitor.beginTask( CoreTexts.testSuite_waiting, 1 );
+ while( !process.isTerminated() ) {
+ if( monitor.isCanceled() ) {
+ try {
+ process.terminate();
+ } catch( DebugException e ) {
+ // Do nothing
+ }
+ return Status.CANCEL_STATUS;
+ }
+ }
+ monitor.worked( 1 );
+
+ try {
+ IPath exeLocation = getExecutableLocation( configuration );
+ IPath hpLocation = exeLocation.removeFileExtension()
+ .addFileExtension( "hp" ); //$NON-NLS-1$
+ final File fileToOpen = hpLocation.toFile();
+
+ Display.getDefault().syncExec( new Runnable() {
+
+ public void run() {
+ try {
+ if( fileToOpen.exists() && fileToOpen.isFile() ) {
+ IFileStore fileStore = EFS.getLocalFileSystem().getStore(
+ fileToOpen.toURI() );
+ IWorkbenchPage page = PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow().getActivePage();
+ IDE.openEditorOnFileStore( page, fileStore );
+ } else {
+ // Do something if the file does not exist
+ }
+ } catch( Exception e ) {
+ // Do nothing
+ }
+ }
+ } );
+ } catch( Exception e ) {
+ return Status.CANCEL_STATUS;
+ }
+
+ return Status.OK_STATUS;
+ }
+ };
+ endJob.schedule();
+ }
+
+}
@@ -5,8 +5,6 @@
import java.util.Random;
import net.sf.eclipsefp.haskell.debug.core.internal.HaskellDebugCore;
import net.sf.eclipsefp.haskell.debug.core.internal.util.CoreTexts;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
@@ -23,54 +21,51 @@
/**
* launch delegate for Haskell executables executables
+ *
* @author JP Moresmau
*
*/
public class TestSuiteHaskellLaunchDelegate extends
- AbstractHaskellLaunchDelegate {
+ ExecutableOrTestSuiteHaskellLaunchDelegate {
String filename = null;
private String getFilename() {
- if (filename == null) {
- Random r = new Random(System.currentTimeMillis());
+ if( filename == null ) {
+ Random r = new Random( System.currentTimeMillis() );
int n = r.nextInt();
- filename = HaskellDebugCore.getDefault().getStateLocation().append( n + ".xml" ).toOSString(); //$NON-NLS-1$
+ filename = HaskellDebugCore.getDefault().getStateLocation()
+ .append( n + ".xml" ).toOSString(); //$NON-NLS-1$
}
return filename;
}
@Override
- String[] determineArguments( final ILaunchConfiguration config )
- throws CoreException {
- String extra = config.getAttribute( ILaunchAttributes.EXTRA_ARGUMENTS,
- ILaunchAttributes.EMPTY );
- String args = config.getAttribute( ILaunchAttributes.ARGUMENTS,
- ILaunchAttributes.EMPTY );
- String xmlArg = "--jxml=\"" + getFilename() + "\""; //$NON-NLS-1$ //$NON-NLS-2$
- return CommandLineUtil.parse( extra + " " + args + " " + xmlArg ); //$NON-NLS-1$ //$NON-NLS-2$
+ protected String getExtraArguments() {
+ return "--jxml=\"" + getFilename() + "\""; //$NON-NLS-1$ //$NON-NLS-2$
}
@Override
protected void preProcessCreation( final ILaunchConfiguration configuration,
- final String mode, final ILaunch launch, final Map<String, String> processAttribs ) {
+ final String mode, final ILaunch launch,
+ final Map<String, String> processAttribs ) {
// NOOP
}
@Override
protected void postProcessCreation( final ILaunchConfiguration configuration,
- final String mode, final ILaunch launch, final IProcess process ) {
- // NOOP
- Job endJob = new Job(CoreTexts.testSuite_waiting) {
+ final String mode, final ILaunch launch, final IProcess process ) {
+ Job endJob = new Job( CoreTexts.testSuite_waiting ) {
+
@Override
protected IStatus run( final IProgressMonitor monitor ) {
monitor.beginTask( CoreTexts.testSuite_waiting, 1 );
- while (!process.isTerminated()) {
- if (monitor.isCanceled()) {
+ while( !process.isTerminated() ) {
+ if( monitor.isCanceled() ) {
try {
process.terminate();
- } catch (DebugException e) {
+ } catch( DebugException e ) {
// Do nothing
}
return Status.CANCEL_STATUS;
@@ -81,37 +76,25 @@ protected IStatus run( final IProgressMonitor monitor ) {
// Get file and parse output
final String fname = getFilename();
Display.getDefault().syncExec( new Runnable() {
+
public void run() {
try {
- IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ IWorkbenchPage page = PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow().getActivePage();
page.showView( "org.eclipse.jdt.junit.ResultView" ); //$NON-NLS-1$
JUnitCore.importTestRunSession( new File( fname ) );
- } catch (CoreException e) {
+ } catch( CoreException e ) {
// Do nothing
}
}
} );
// Always delete the file at the end
- new File(getFilename()).delete();
+ new File( getFilename() ).delete();
return Status.OK_STATUS;
}
};
endJob.schedule();
}
- @Override
- protected IProject[] getBuildOrder( final ILaunchConfiguration configuration,
- final String mode ) throws CoreException {
- // indicate the project is to be looked at for unsaved files
- String prj=configuration.getAttribute( ILaunchAttributes.PROJECT_NAME, (String)null );
- if (prj!=null){
- IProject p=ResourcesPlugin.getWorkspace().getRoot().getProject( prj );
- if (p!=null){
- return new IProject[]{p};
- }
- }
- return super.getBuildOrder( configuration, mode );
- }
-
}
@@ -16,6 +16,9 @@ testSuiteLaunchContextLabel_label = Run Test-framework Test
ghciShortcut_label = GHCi session
ghciContextLabel_label = Run GHCi session
+appLaunchProfilingShortcut_label = Haskell Application with Profiling
+appLaunchProfilingContextLabel_label = Run Haskell Application with Profiling
+
runGHCiShortcut_name = Run GHCi session
runGHCiShortcut_desc = Starts an interactive GHC session, loading this file and \
adding the project source folders to GHCi's search path.
@@ -26,4 +29,7 @@ runHaskellShortcut_desc = Executes the built executable from this project.
runTestSuiteShortcut_name = Run Test-framework Test
runTestSuiteShortcut_desc = Executes the built test-suite from this project.
+runHaskellProfilingShortcut_name = Run Haskell program with profiling
+runHaskellProfilingShortcut_desc = Executes the built executable from this project with profiling support.
+
toggle_breakpoint=Toggle Breakpoint
Oops, something went wrong.

0 comments on commit 1cd716f

Please sign in to comment.