Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Ferrazzutti2014-07-16 21:16:20 +0000
committerAlexander Kurtakov2014-07-28 09:17:09 +0000
commitc444ba8b493f941c2da9bb3858bde6802b8a194b (patch)
treea231a015698f6b6b85f663792065273876f591e4 /systemtap
parent73412315189a0fc463062f338aa705a79fd00cea (diff)
downloadorg.eclipse.linuxtools-c444ba8b493f941c2da9bb3858bde6802b8a194b.tar.gz
org.eclipse.linuxtools-c444ba8b493f941c2da9bb3858bde6802b8a194b.tar.xz
org.eclipse.linuxtools-c444ba8b493f941c2da9bb3858bde6802b8a194b.zip
Systemtap: Improve script stopping.
Fix bugs EBZ #439565 and #439566. Also, reduce the time it takes for a script to be stopped. Change-Id: I79a6ebe0b2f30e9b9c4bfb7208ae3e9d85646b89 Signed-off-by: Andrew Ferrazzutti <aferrazz@redhat.com> Reviewed-on: https://git.eclipse.org/r/30046 Tested-by: Hudson CI Reviewed-by: Alexander Kurtakov <akurtako@redhat.com> Tested-by: Alexander Kurtakov <akurtako@redhat.com>
Diffstat (limited to 'systemtap')
-rw-r--r--systemtap/org.eclipse.linuxtools.systemtap.structures/META-INF/MANIFEST.MF2
-rw-r--r--systemtap/org.eclipse.linuxtools.systemtap.structures/pom.xml2
-rw-r--r--systemtap/org.eclipse.linuxtools.systemtap.structures/src/org/eclipse/linuxtools/systemtap/structures/runnable/Command.java61
-rw-r--r--systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/ScpExec.java41
-rw-r--r--systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/structures/ScriptConsole.java102
-rw-r--r--systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/handlers/RunScriptHandler.java5
6 files changed, 89 insertions, 124 deletions
diff --git a/systemtap/org.eclipse.linuxtools.systemtap.structures/META-INF/MANIFEST.MF b/systemtap/org.eclipse.linuxtools.systemtap.structures/META-INF/MANIFEST.MF
index 183fc8d8fd..bb20ebe8b0 100644
--- a/systemtap/org.eclipse.linuxtools.systemtap.structures/META-INF/MANIFEST.MF
+++ b/systemtap/org.eclipse.linuxtools.systemtap.structures/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %bundleName
Bundle-SymbolicName: org.eclipse.linuxtools.systemtap.structures;singleton:=true
-Bundle-Version: 3.0.0.qualifier
+Bundle-Version: 3.1.0.qualifier
Bundle-Vendor: %bundleProvider
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.linuxtools.systemtap.structures,org.eclips
diff --git a/systemtap/org.eclipse.linuxtools.systemtap.structures/pom.xml b/systemtap/org.eclipse.linuxtools.systemtap.structures/pom.xml
index 3f1f24d147..2c8ce804b5 100644
--- a/systemtap/org.eclipse.linuxtools.systemtap.structures/pom.xml
+++ b/systemtap/org.eclipse.linuxtools.systemtap.structures/pom.xml
@@ -18,7 +18,7 @@
</parent>
<artifactId>org.eclipse.linuxtools.systemtap.structures</artifactId>
- <version>3.0.0-SNAPSHOT</version>
+ <version>3.1.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<name>Linux Tools Structures Plug-in</name>
diff --git a/systemtap/org.eclipse.linuxtools.systemtap.structures/src/org/eclipse/linuxtools/systemtap/structures/runnable/Command.java b/systemtap/org.eclipse.linuxtools.systemtap.structures/src/org/eclipse/linuxtools/systemtap/structures/runnable/Command.java
index 993442f0ac..df2cdff73c 100644
--- a/systemtap/org.eclipse.linuxtools.systemtap.structures/src/org/eclipse/linuxtools/systemtap/structures/runnable/Command.java
+++ b/systemtap/org.eclipse.linuxtools.systemtap.structures/src/org/eclipse/linuxtools/systemtap/structures/runnable/Command.java
@@ -114,16 +114,20 @@ public class Command implements Runnable {
/**
* Starts the <code>Thread</code> that the new <code>Process</code> will run in.
* This must be called in order to get the process to start running.
+ * Note that this method only takes effect the first time it is called.
* @throws CoreException
*/
public void start() throws CoreException {
+ if (started || stopped) {
+ return;
+ }
IStatus status = init();
if (status.isOK()) {
Thread t = new Thread(this, cmd[0]);
t.start();
started = true;
} else {
- stop();
+ cleanUpAfterStop();
returnVal = Integer.MIN_VALUE;
throw new CoreException(status);
}
@@ -178,16 +182,23 @@ public class Command implements Runnable {
inputGobbler.start();
try {
process.waitFor();
- } catch (InterruptedException e) {}
- stop();
+ cleanUpAfterStop();
+ } catch (InterruptedException e) {
+ // This thread was interrupted while waiting for
+ // the process to exit. Destroy the process just
+ // to make sure it exits.
+ stop();
+ }
}
/**
- * Stops the process from running and stops the <code>StreamGobblers</code> from monitering
- * the dead process and unregisters the StreamListener. Also wakes up any threads waiting
- * on this command.
+ * Performs cleanup operations for when the process ends:
+ * Stops the <code>StreamGobblers</code> from monitering
+ * the dead process and unregisters the StreamListener.
+ * Also wakes up any threads waiting on this command.
+ * @since 3.1
*/
- public synchronized void stop() {
+ protected synchronized void cleanUpAfterStop() {
if (!stopped) {
if (errorGobbler != null) {
errorGobbler.stop();
@@ -195,16 +206,6 @@ public class Command implements Runnable {
if (inputGobbler != null) {
inputGobbler.stop();
}
- try {
- if (process != null) {
- process.waitFor();
- }
- } catch (InterruptedException e) {
- // This thread was interrupted while waiting for
- // the process to exit. Destroy the process just
- // to make sure it exits.
- process.destroy();
- }
removeInputStreamListener(logger);
stopped = true;
notifyAll(); // Wake up threads waiting for this command to stop.
@@ -212,6 +213,18 @@ public class Command implements Runnable {
}
/**
+ * Stops the process from running and performs post-stop cleanup if necessary.
+ */
+ public synchronized void stop() {
+ if (!stopped) {
+ if (process != null) {
+ process.destroy();
+ }
+ cleanUpAfterStop();
+ }
+ }
+
+ /**
* Method to check whether or not the process is running.
* @return The execution status.
*/
@@ -311,12 +324,15 @@ public class Command implements Runnable {
public synchronized void dispose() {
if (!disposed) {
stop();
- disposed = true;
-
- inputListeners.clear();
- errorListeners.clear();
+ if (inputListeners != null) {
+ inputListeners.clear();
+ }
inputListeners = null;
+
+ if (errorListeners != null) {
+ errorListeners.clear();
+ }
errorListeners = null;
if (inputGobbler != null) {
@@ -328,7 +344,10 @@ public class Command implements Runnable {
errorGobbler.dispose();
}
errorGobbler = null;
+
logger.dispose();
+ process = null;
+ disposed = true;
}
}
diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/ScpExec.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/ScpExec.java
index 0c5ed7636f..edd580b500 100644
--- a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/ScpExec.java
+++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/ScpExec.java
@@ -28,6 +28,7 @@ import com.jcraft.jsch.JSchException;
public class ScpExec extends Command {
public static final int INPUT_STREAM = 1;
+ private static final int WAIT_DELAY = 1000;
private Channel channel;
private RemoteScriptOptions remoteOptions;
@@ -51,7 +52,7 @@ public class ScpExec extends Command {
errorGobbler = new StreamGobbler(channel.getExtInputStream());
inputGobbler = new StreamGobbler(channel.getInputStream());
- this.transferListeners();
+ transferListeners();
return Status.OK_STATUS;
} catch (final JSchException|IOException e) {
final IStatus status = new Status(IStatus.ERROR, ConsoleLogPlugin.PLUGIN_ID, Messages.ScpExec_FileTransferFailed, e);
@@ -67,35 +68,35 @@ public class ScpExec extends Command {
errorGobbler.start();
inputGobbler.start();
- while (!stopped) {
- if (channel.isClosed() || (channel.getExitStatus() != -1)) {
- stop();
- break;
+ synchronized (this) {
+ while (!channel.isClosed()) {
+ wait(WAIT_DELAY);
}
+ cleanUpAfterStop();
}
-
} catch (JSchException e) {
- ExceptionErrorDialog.openError(Messages.ScpExec_errorConnectingToServer, e);
+ ExceptionErrorDialog.openError(Messages.ScpExec_Error,
+ Messages.ScpExec_errorConnectingToServer, e);
+ } catch (InterruptedException e) {
+ // This thread was interrupted while waiting for
+ // the process to exit. Destroy the process just
+ // to make sure it exits.
+ stop();
}
}
- /* Stops the process from running and stops the <code>StreamGobblers</code> from monitoring
- * the dead process.
- */
@Override
public synchronized void stop() {
if (!stopped) {
- if(null != errorGobbler) {
- errorGobbler.stop();
- }
- if(null != inputGobbler) {
- inputGobbler.stop();
- }
- if (channel != null) {
- channel.disconnect();
+ try {
+ if (channel != null) {
+ channel.getSession().disconnect();
+ }
+ cleanUpAfterStop();
+ } catch (JSchException e) {
+ ExceptionErrorDialog.openError(Messages.ScpExec_Error,
+ e.getMessage(), e);
}
- stopped = true;
- notifyAll();
}
}
}
diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/structures/ScriptConsole.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/structures/ScriptConsole.java
index c131506096..70a74911d5 100644
--- a/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/structures/ScriptConsole.java
+++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.consolelog/src/org/eclipse/linuxtools/systemtap/ui/consolelog/structures/ScriptConsole.java
@@ -13,7 +13,6 @@
package org.eclipse.linuxtools.systemtap.ui.consolelog.structures;
import java.io.File;
-import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
@@ -26,7 +25,6 @@ import org.eclipse.linuxtools.systemtap.structures.runnable.Command;
import org.eclipse.linuxtools.systemtap.ui.consolelog.ScpExec;
import org.eclipse.linuxtools.systemtap.ui.consolelog.internal.Localization;
import org.eclipse.linuxtools.systemtap.ui.consolelog.views.ErrorView;
-import org.eclipse.linuxtools.tools.launch.core.factory.RuntimeProcessFactory;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.PlatformUI;
@@ -72,8 +70,6 @@ public class ScriptConsole extends IOConsole {
*/
private Thread onCmdStartThread;
- private String moduleName;
-
private ErrorStreamDaemon errorDaemon;
private ConsoleStreamDaemon consoleDaemon;
@@ -132,22 +128,18 @@ public class ScriptConsole extends IOConsole {
if (consoleIterator instanceof ScriptConsole) {
activeConsole = (ScriptConsole) consoleIterator;
if (activeConsole.getName().endsWith(name)) {
- //Stop any script currently running, and terminate stream listeners.
- if (activeConsole.isRunning()) {
- activeConsole.stopAndDispose();
- if (activeConsole.errorDaemon != null) {
- activeConsole.cmd.removeErrorStreamListener(activeConsole.errorDaemon);
- }
- if (activeConsole.consoleDaemon != null) {
- activeConsole.cmd.removeInputStreamListener(activeConsole.consoleDaemon);
- }
- }
+ //Stop any script currently running.
if (activeConsole.onCmdStopThread != null && activeConsole.onCmdStopThread.isAlive()) {
activeConsole.onCmdStopThread.interrupt();
try {
activeConsole.onCmdStopThread.join();
} catch (InterruptedException e) {}
}
+ if (activeConsole.isRunning()) {
+ activeConsole.stopAndDispose();
+ } else {
+ activeConsole.disposeCommand();
+ }
//Remove output from last run
activeConsole.clearConsole();
activeConsole.setName(name);
@@ -208,42 +200,30 @@ public class ScriptConsole extends IOConsole {
super(name, imageDescriptor);
}
- private abstract class StopCommand implements Runnable {
- private static final long RETRY_STOP_TIME = 500;
-
+ private class StopCommand implements Runnable {
protected final Command stopcmd;
- protected final String stopString;
private boolean disposeOnStop = false;
- private StopCommand(Command stopcmd, String stopString) {
+ private StopCommand(Command stopcmd) {
this.stopcmd = stopcmd;
- this.stopString = stopString;
}
- protected abstract void stop() throws IOException, CoreException;
-
void makeDisposeOnStop() {
disposeOnStop = true;
}
@Override
public void run() {
- try {
- synchronized (stopcmd) {
- while (stopcmd.isRunning()) {
- stop();
- stopcmd.wait(RETRY_STOP_TIME);
- }
- if (disposeOnStop) {
- stopcmd.dispose();
- }
- }
- } catch (IOException | CoreException e) {
- ExceptionErrorDialog.openError(Localization.
- getString("ScriptConsole.ErrorKillingStap"), //$NON-NLS-1$
- e.getMessage(), e);
- } catch (InterruptedException e) {
- // Wait was interrupted. Exit.
+ if (consoleDaemon != null) {
+ stopcmd.removeInputStreamListener(consoleDaemon);
+ }
+ if (errorDaemon != null) {
+ stopcmd.removeErrorStreamListener(errorDaemon);
+ }
+ if (!disposeOnStop) {
+ stopcmd.stop();
+ } else {
+ stopcmd.dispose();
}
}
@@ -288,16 +268,6 @@ public class ScriptConsole extends IOConsole {
return;
}
cmd = new ScpExec(command, remoteOptions, envVars);
-
- stopCommand = new StopCommand(cmd, getStopString()) {
- ScpExec stop = new ScpExec(new String[]{stopString}, remoteOptions, null);
-
- @Override
- protected void stop() throws CoreException {
- stop.start();
- }
- };
-
this.run(cmd, errorParser);
}
@@ -316,19 +286,11 @@ public class ScriptConsole extends IOConsole {
return;
}
cmd = new Command(command, envVars, project);
- final IProject proj = project;
-
- stopCommand = new StopCommand(cmd, getStopString()) {
- @Override
- protected void stop() throws IOException {
- RuntimeProcessFactory.getFactory().exec(stopString, null, proj);
- }
- };
-
this.run(cmd, errorParser);
}
private void run(final Command cmd, IErrorParser errorParser) {
+ stopCommand = new StopCommand(cmd);
final Runnable onCmdStop = new Runnable() {
@Override
public void run() {
@@ -370,6 +332,7 @@ public class ScriptConsole extends IOConsole {
cmd.dispose();
return;
}
+ clearConsole();
notifyConsoleObservers();
}
};
@@ -453,6 +416,12 @@ public class ScriptConsole extends IOConsole {
return cmd.isDisposed();
}
+ private void disposeCommand() {
+ if (!isDisposed()) {
+ cmd.dispose();
+ }
+ }
+
/**
* Method to allow the user to save the Commands output to a file for use latter.
* Does not return a value indicating success of the operation; for that, use
@@ -519,25 +488,6 @@ public class ScriptConsole extends IOConsole {
}
}
- private String getModuleName() {
- if (moduleName == null) {
- moduleName = getName();
- int lastSlash = moduleName.lastIndexOf('/')+1;
- if (lastSlash < 0) {
- lastSlash = 0;
- }
- int lastDot = moduleName.indexOf(".stp"); //$NON-NLS-1$
- if (lastDot > 0) {
- moduleName = moduleName.substring(lastSlash, lastDot);
- }
- }
- return moduleName;
- }
-
- private String getStopString() {
- return "pkill -SIGINT -f stapio.*"+ getModuleName(); //$NON-NLS-1$
- }
-
/**
* Disposes of all internal references in the class. No method should be called after this.
*/
diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/handlers/RunScriptHandler.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/handlers/RunScriptHandler.java
index f7b094fcbc..fb14ccfcec 100644
--- a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/handlers/RunScriptHandler.java
+++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/handlers/RunScriptHandler.java
@@ -432,9 +432,4 @@ public class RunScriptHandler extends AbstractHandler {
return dotIndex != -1 ? fileName.substring(0, dotIndex) : fileName;
}
- /*@Override
- public boolean isEnabled() {
- return (PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor() instanceof STPEditor);
- }*/
-
}

Back to the top