From afe13e7af5312218f2b8130515e48a3667df5a98 Mon Sep 17 00:00:00 2001 From: Bernd Hufmann Date: Tue, 17 Apr 2012 09:07:34 -0400 Subject: [PATCH] Add preferences for LTTng 2.0 tracer control --- .../plugin.properties | 8 +- .../plugin.properties | 6 +- org.eclipse.linuxtools.lttng2.ui/plugin.xml | 18 +- .../internal/lttng2/ui/Activator.java | 3 + .../lttng2/ui/views/control/Messages.java | 14 +- .../handlers/BaseControlViewHandler.java | 2 +- .../control/logging/ControlCommandLogger.java | 122 +++++++ .../ui/views/control/messages.properties | 14 +- .../ControlPreferenceInitializer.java | 39 +++ .../preferences/ControlPreferencePage.java | 161 +++++++++ .../preferences/ControlPreferences.java | 127 +++++++ .../control/service/LTTngControlService.java | 309 ++++++++++-------- 12 files changed, 678 insertions(+), 145 deletions(-) create mode 100644 org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/logging/ControlCommandLogger.java create mode 100644 org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/preferences/ControlPreferenceInitializer.java create mode 100644 org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/preferences/ControlPreferencePage.java create mode 100644 org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/preferences/ControlPreferences.java diff --git a/org.eclipse.linuxtools.lttng.ui/plugin.properties b/org.eclipse.linuxtools.lttng.ui/plugin.properties index 33b4f83774..a60152ed96 100644 --- a/org.eclipse.linuxtools.lttng.ui/plugin.properties +++ b/org.eclipse.linuxtools.lttng.ui/plugin.properties @@ -52,11 +52,11 @@ commands.experiment.rename.description = Rename an LTTng Experiment commands.experiment.delete = Delete Experiment commands.experiment.delete.description = Delete an LTTng Experiment -# trace control (RSE) properties (LTTng 0.x) -lttng.rse.subsystem.type.name=LTTng (v0.x) -lttng.rse.subsystem.type.description=LTTng Trace Control (v0.x) +# trace control (RSE) properties (LTTng legacy) +lttng.rse.subsystem.type.name=LTTng (legacy) +lttng.rse.subsystem.type.description=LTTng Trace Control (legacy) lttng.rse.subsystem.config.name = LTTng Tracing -lttng.rse.subsystem.config.description = LTTng Tracing Subsystem Configuration (v0.x) +lttng.rse.subsystem.config.description = LTTng Tracing Subsystem Configuration (legacy) action.set.label = LTTng RSE action set action.set.description = LTTng RSE action set diff --git a/org.eclipse.linuxtools.lttng2.ui/plugin.properties b/org.eclipse.linuxtools.lttng2.ui/plugin.properties index dbbe92c719..e99ca54713 100644 --- a/org.eclipse.linuxtools.lttng2.ui/plugin.properties +++ b/org.eclipse.linuxtools.lttng2.ui/plugin.properties @@ -63,8 +63,8 @@ commands.experiment.delete = Delete Experiment commands.experiment.delete.description = Delete an LTTng Experiment # LTTng 2.0 trace control commands -trace.control.rse.system.type.name=LTTng (v2.0 or later) -trace.control.rse.system.type.description=LTTng Trace Control (v2.0 or later) +trace.control.rse.system.type.name=LTTng (v2.0) +trace.control.rse.system.type.description=LTTng Trace Control (v2.0) commands.control.category=LTTng Trace Control Commands commands.control.category.description=LTTng Trace Control Commands @@ -131,3 +131,5 @@ commands.control.import.description=Import Traces to LTTng Project commands.control.calibrate=Calibrate commands.control.calibrate.description=Quantify LTTng overhead + +preference.page.control.name=LTTng Tracer Control Preferences \ No newline at end of file diff --git a/org.eclipse.linuxtools.lttng2.ui/plugin.xml b/org.eclipse.linuxtools.lttng2.ui/plugin.xml index 31315fc7dd..6999c2ae85 100644 --- a/org.eclipse.linuxtools.lttng2.ui/plugin.xml +++ b/org.eclipse.linuxtools.lttng2.ui/plugin.xml @@ -1138,7 +1138,7 @@ - + + + + + + + + + + diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/Activator.java b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/Activator.java index 1b92b9844f..9b670be139 100644 --- a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/Activator.java +++ b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/Activator.java @@ -16,6 +16,7 @@ import java.net.URL; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.resource.ImageRegistry; +import org.eclipse.linuxtools.internal.lttng2.ui.views.control.preferences.ControlPreferences; import org.eclipse.swt.graphics.Image; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; @@ -73,6 +74,7 @@ public class Activator extends AbstractUIPlugin { public void start(BundleContext context) throws Exception { super.start(context); plugin = this; + ControlPreferences.getInstance().init(); } /* (non-Javadoc) @@ -80,6 +82,7 @@ public class Activator extends AbstractUIPlugin { */ @Override public void stop(BundleContext context) throws Exception { + ControlPreferences.getInstance().dispose(); plugin = null; super.stop(context); } diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/Messages.java b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/Messages.java index b885828846..a17b4d0e1e 100644 --- a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/Messages.java +++ b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/Messages.java @@ -33,7 +33,7 @@ final public class Messages extends NLS { public static String TraceControl_CommandShellError; public static String TraceControl_CommandError; - public static String TraceControl_UnexpectedCommnadOutputFormat; + public static String TraceControl_UnexpectedCommandOutputFormat; public static String TraceControl_UnexpectedNameError; public static String TraceControl_UnexpectedPathError; @@ -209,6 +209,18 @@ final public class Messages extends NLS { public static String TraceControl_ProbeOffsetPropertyName; public static String TraceControl_ProbeSymbolPropertyName; + // Preferences + public static String TraceControl_TracingGroupPreference; + public static String TraceControl_LoggingPreference; + public static String TraceControl_LogfilePath; + public static String TraceControl_AppendLogfilePreference; + + public static String TraceControl_VerboseLevelsPreference; + public static String TraceControl_VerboseLevelNonePreference; + public static String TraceControl_VerboseLevelVerbosePreference; + public static String TraceControl_VerboseLevelVeryVerbosePreference; + public static String TraceControl_VerboseLevelVeryVeryVerbosePreference; + static { // initialize resource bundle NLS.initializeMessages(BUNDLE_NAME, Messages.class); diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/BaseControlViewHandler.java b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/BaseControlViewHandler.java index d9e5fc0a8b..f08ce2781f 100644 --- a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/BaseControlViewHandler.java +++ b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/BaseControlViewHandler.java @@ -41,7 +41,7 @@ abstract public class BaseControlViewHandler extends AbstractHandler { /** * The synchronization lock. */ - protected ReentrantLock fLock = new ReentrantLock(); + final protected ReentrantLock fLock = new ReentrantLock(); // ------------------------------------------------------------------------ // Operations diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/logging/ControlCommandLogger.java b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/logging/ControlCommandLogger.java new file mode 100644 index 0000000000..acaaf85404 --- /dev/null +++ b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/logging/ControlCommandLogger.java @@ -0,0 +1,122 @@ +/********************************************************************** + * Copyright (c) 2012 Ericsson + * + * 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: + * Bernd Hufmann - Initial API and implementation + **********************************************************************/ +package org.eclipse.linuxtools.internal.lttng2.ui.views.control.logging; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; + +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.linuxtools.internal.lttng2.ui.Activator; + +/** + * ControlCommandLogger + *

+ * Class to log control commands. + *

+ */ +public class ControlCommandLogger { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + private static BufferedWriter fTraceLog = null; + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + /** + * Initializes the logger class and opens the log file with the given parameter. + * @param filename - file name of logger output + * @param append - true to open log file in append mode else false (overwrite) + */ + public static void init(String filename, boolean append) { + if (fTraceLog != null) { + close(); + } + fTraceLog = openLogFile(filename, append); + } + + /** + * Closes the log file if open. + */ + public static void close() { + if (fTraceLog == null) + return; + + try { + fTraceLog.close(); + fTraceLog = null; + } catch (IOException e) { + Activator.getDefault().getLog().log(new Status(IStatus.WARNING, Activator.PLUGIN_ID, IStatus.WARNING, + "Can't close log file of the trace control", e)); //$NON-NLS-1$ + } + } + + /** + * Logs a message to the log file. + * @param msg - message (e.g. command or command result) to log + */ + @SuppressWarnings("nls") + public static void log(String msg) { + long currentTime = System.currentTimeMillis(); + StringBuilder message = new StringBuilder("["); + message.append(currentTime / 1000); + message.append("."); + message.append(String.format("%1$03d", currentTime % 1000)); + message.append("] "); + message.append(msg); + if (fTraceLog != null) { + try { + fTraceLog.write(message.toString()); + fTraceLog.newLine(); + fTraceLog.flush(); + } catch (IOException e) { + Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, + "Can't log message in log file of the tracer control", e)); //$NON-NLS-1$ + } + } + } + + // ------------------------------------------------------------------------ + // Helper methods + // ------------------------------------------------------------------------ + /** + * Opens the trace log file with given name in the workspace root directory + * @param filename - file name of logger output + * @param append - true to open log file in append mode else false (overwrite) + * @return the buffer writer class or null if not successful + */ + private static BufferedWriter openLogFile(String filename, boolean append) { + IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + IPath newFile = root.getLocation().append(filename); + File file = newFile.toFile(); + BufferedWriter outfile = null; + try { + if (!file.exists()) { + file.createNewFile(); + file.setWritable(true, false); + } + outfile = new BufferedWriter(new FileWriter(file, append)); + } catch (IOException e) { + Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, + "Can't open log file for logging of tracer control commands", e)); //$NON-NLS-1$ + } + return outfile; + } + +} diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/messages.properties b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/messages.properties index e433e95227..72f94bfdcb 100644 --- a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/messages.properties +++ b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/messages.properties @@ -6,7 +6,7 @@ TraceControl_ExecutionTimeout=Command Execution timed-out TraceControl_ShellNotConnected=Command shell not connected TraceControl_CommandShellError=Could not create HostShellProcessAdapter TraceControl_CommandError=Command failed! Command: -TraceControl_UnexpectedCommnadOutputFormat=Unexpected command output +TraceControl_UnexpectedCommandOutputFormat=Unexpected command output TraceControl_UnexpectedNameError=Unexpected session name returned TraceControl_UnexpectedPathError=Unexpected session path returned @@ -181,3 +181,15 @@ TraceControl_ProcessIdPropertyName=Process ID TraceControl_ProbeAddressPropertyName=Address TraceControl_ProbeOffsetPropertyName=Offset TraceControl_ProbeSymbolPropertyName=Symbol + +# Preferences +TraceControl_TracingGroupPreference=&Tracing Group +#TraceControl_LoggingPreference=&Logging (File ${workspace_loc}/lttng_control.log) +TraceControl_LoggingPreference=&Logging +TraceControl_LogfilePath=Log file +TraceControl_AppendLogfilePreference=&Append +TraceControl_VerboseLevelsPreference=&Verbose Level +TraceControl_VerboseLevelNonePreference=None +TraceControl_VerboseLevelVerbosePreference=Verbose +TraceControl_VerboseLevelVeryVerbosePreference=Very Verbose +TraceControl_VerboseLevelVeryVeryVerbosePreference=Very Very Verbose diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/preferences/ControlPreferenceInitializer.java b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/preferences/ControlPreferenceInitializer.java new file mode 100644 index 0000000000..7777bd5c9b --- /dev/null +++ b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/preferences/ControlPreferenceInitializer.java @@ -0,0 +1,39 @@ +/********************************************************************** + * Copyright (c) 2012 Ericsson + * + * 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: + * Bernd Hufmann - Initial API and implementation + **********************************************************************/ +package org.eclipse.linuxtools.internal.lttng2.ui.views.control.preferences; + +import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.linuxtools.internal.lttng2.ui.Activator; + +/** + * ControlPreferenceInitializer + *

+ * A class to initialize the preferences. + *

+ */ +public class ControlPreferenceInitializer extends AbstractPreferenceInitializer { + /* + * (non-Javadoc) + * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences() + */ + @Override + public void initializeDefaultPreferences() { + final IPreferenceStore store = Activator.getDefault().getPreferenceStore(); + //Set default User ID if none already stored in preferences + store.setDefault(ControlPreferences.TRACE_CONTROL_TRACING_GROUP_PREF, ControlPreferences.TRACE_CONTROL_DEFAULT_TRACING_GROUP); + store.setDefault(ControlPreferences.TRACE_CONTROL_LOG_APPEND_PREF, false); + store.setDefault(ControlPreferences.TRACE_CONTROL_LOG_FILE_PATH_PREF, ControlPreferences.TRACE_CONTROL_DEFAULT_LOG_PATH); + store.setDefault(ControlPreferences.TRACE_CONTROL_LOG_COMMANDS_PREF, false); + store.setDefault(ControlPreferences.TRACE_CONTROL_VERBOSE_LEVEL_PREF, ControlPreferences.TRACE_CONTROL_VERBOSE_LEVEL_NONE); + } +} diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/preferences/ControlPreferencePage.java b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/preferences/ControlPreferencePage.java new file mode 100644 index 0000000000..34a63d1887 --- /dev/null +++ b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/preferences/ControlPreferencePage.java @@ -0,0 +1,161 @@ +/********************************************************************** + * Copyright (c) 2012 Ericsson + * + * 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: + * Bernd Hufmann - Initial API and implementation + **********************************************************************/ +package org.eclipse.linuxtools.internal.lttng2.ui.views.control.preferences; + +import org.eclipse.jface.preference.BooleanFieldEditor; +import org.eclipse.jface.preference.FieldEditor; +import org.eclipse.jface.preference.FieldEditorPreferencePage; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.preference.RadioGroupFieldEditor; +import org.eclipse.jface.preference.StringFieldEditor; +import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.linuxtools.internal.lttng2.ui.Activator; +import org.eclipse.linuxtools.internal.lttng2.ui.views.control.Messages; +import org.eclipse.linuxtools.internal.lttng2.ui.views.control.logging.ControlCommandLogger; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; + +/** + * ControlPreferencePage + *

+ * Preference page implementation for configuring LTTng tracer control preferences. + *

+ */ +public class ControlPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + RadioGroupFieldEditor fVerboseLevel; + BooleanFieldEditor fIsAppend; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + public ControlPreferencePage() { + super(FieldEditorPreferencePage.GRID); + + // Set the preference store for the preference page. + IPreferenceStore store = Activator.getDefault().getPreferenceStore(); + setPreferenceStore(store); + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + /* + * (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench) + */ + @Override + public void init(IWorkbench workbench) { + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors() + */ + @Override + protected void createFieldEditors() { + + StringFieldEditor tracingGroup = new StringFieldEditor(ControlPreferences.TRACE_CONTROL_TRACING_GROUP_PREF, Messages.TraceControl_TracingGroupPreference, getFieldEditorParent()); + addField(tracingGroup); + + BooleanFieldEditor logCommand = new BooleanFieldEditor(ControlPreferences.TRACE_CONTROL_LOG_COMMANDS_PREF, Messages.TraceControl_LoggingPreference, getFieldEditorParent()); + addField(logCommand); + + StringFieldEditor logfile = new StringFieldEditor(ControlPreferences.TRACE_CONTROL_LOG_FILE_PATH_PREF, Messages.TraceControl_LogfilePath, getFieldEditorParent()); + addField(logfile); + + fIsAppend = new BooleanFieldEditor(ControlPreferences.TRACE_CONTROL_LOG_APPEND_PREF, Messages.TraceControl_AppendLogfilePreference, getFieldEditorParent()); + addField(fIsAppend); + + fVerboseLevel = new RadioGroupFieldEditor ( + ControlPreferences.TRACE_CONTROL_VERBOSE_LEVEL_PREF, + Messages.TraceControl_VerboseLevelsPreference, + 4, + new String[][] { + { + Messages.TraceControl_VerboseLevelNonePreference, + ControlPreferences.TRACE_CONTROL_VERBOSE_LEVEL_NONE, + }, + { + Messages.TraceControl_VerboseLevelVerbosePreference, + ControlPreferences.TRACE_CONTROL_VERBOSE_LEVEL_VERBOSE + }, + { + Messages.TraceControl_VerboseLevelVeryVerbosePreference, + ControlPreferences.TRACE_CONTROL_VERBOSE_LEVEL_V_VERBOSE + }, + { + Messages.TraceControl_VerboseLevelVeryVeryVerbosePreference, + ControlPreferences.TRACE_CONTROL_VERBOSE_LEVEL_V_V_VERBOSE + } + }, + getFieldEditorParent(), + true); + + addField(fVerboseLevel); + + Boolean enabled = ControlPreferences.getInstance().isLoggingEnabled(); + fVerboseLevel.setEnabled(enabled, getFieldEditorParent()); + fIsAppend.setEnabled(enabled, getFieldEditorParent()); + logfile.setEnabled(false, getFieldEditorParent()); + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.preference.FieldEditorPreferencePage#propertyChange(org.eclipse.jface.util.PropertyChangeEvent) + */ + @Override + public void propertyChange(PropertyChangeEvent event) { + + if (event.getProperty().equals(FieldEditor.VALUE)) { + if (event.getSource() instanceof FieldEditor) { + FieldEditor editor = (FieldEditor) event.getSource(); + if (editor.getPreferenceName().equals(ControlPreferences.TRACE_CONTROL_LOG_COMMANDS_PREF)) { + Boolean enabled = (Boolean)event.getNewValue(); + fVerboseLevel.setEnabled(enabled, getFieldEditorParent()); + fIsAppend.setEnabled(enabled, getFieldEditorParent()); + } + } + } + super.propertyChange(event); + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.preference.FieldEditorPreferencePage#performDefaults() + */ + @Override + protected void performDefaults() { + super.performDefaults(); + fVerboseLevel.setEnabled(false, getFieldEditorParent()); + fIsAppend.setEnabled(false, getFieldEditorParent()); + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.preference.FieldEditorPreferencePage#performOk() + */ + @Override + public boolean performOk() { + boolean ret = super.performOk(); + // open or close log file + if (ControlPreferences.getInstance().isLoggingEnabled()) { + ControlCommandLogger.init(ControlPreferences.TRACE_CONTROL_LOG_FILENAME, ControlPreferences.getInstance().isAppend()); + } else { + ControlCommandLogger.close(); + } + return ret; + } +} diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/preferences/ControlPreferences.java b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/preferences/ControlPreferences.java new file mode 100644 index 0000000000..3eea084c4d --- /dev/null +++ b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/preferences/ControlPreferences.java @@ -0,0 +1,127 @@ +/********************************************************************** + * Copyright (c) 2012 Ericsson + * + * 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: + * Bernd Hufmann - Initial API and implementation + **********************************************************************/ +package org.eclipse.linuxtools.internal.lttng2.ui.views.control.preferences; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.linuxtools.internal.lttng2.ui.Activator; +import org.eclipse.linuxtools.internal.lttng2.ui.views.control.logging.ControlCommandLogger; + +/** + * ControlPreference + *

+ * Singleton class to access LTTng tracer control preferences. + *

+ */ +public class ControlPreferences { + + // ------------------------------------------------------------------------ + // Constants + // ------------------------------------------------------------------------ + public static final String TRACE_CONTROL_LOG_FILENAME = "lttng_control.log"; //$NON-NLS-1$ + + // Preference strings + public static final String TRACE_CONTROL_TRACING_GROUP_PREF = "trace.control.tracing.group"; //$NON-NLS-1$ + public static final String TRACE_CONTROL_LOG_COMMANDS_PREF = "trace.control.log.commands"; //$NON-NLS-1$ + public static final String TRACE_CONTROL_LOG_APPEND_PREF = "trace.control.log.append"; //$NON-NLS-1$ + public static final String TRACE_CONTROL_LOG_FILE_PATH_PREF = "trace.control.log.path"; //$NON-NLS-1$ + public static final String TRACE_CONTROL_VERBOSE_LEVEL_PREF = "trace.control.verbose.level"; //$NON-NLS-1$ + public static final String TRACE_CONTROL_VERBOSE_LEVEL_NONE = "trace.control.verbose.level.none"; //$NON-NLS-1$ + public static final String TRACE_CONTROL_VERBOSE_LEVEL_VERBOSE = "trace.control.verbose.level.v"; //$NON-NLS-1$ + public static final String TRACE_CONTROL_VERBOSE_LEVEL_V_VERBOSE = "trace.control.verbose.level.vv"; //$NON-NLS-1$ + public static final String TRACE_CONTROL_VERBOSE_LEVEL_V_V_VERBOSE = "trace.control.verbose.level.vvv"; //$NON-NLS-1$ + + public static final String TRACE_CONTROL_DEFAULT_TRACING_GROUP = "tracing"; //$NON-NLS-1$ + public static final String TRACE_CONTROL_DEFAULT_LOG_PATH = "${workspace_loc}/" + TRACE_CONTROL_LOG_FILENAME; //$NON-NLS-1$ + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + private static ControlPreferences fInstance = null; + + // ------------------------------------------------------------------------ + // Constructor + // ------------------------------------------------------------------------ + private ControlPreferences() { + } + + // ------------------------------------------------------------------------ + // Accessors + // ------------------------------------------------------------------------ + public synchronized static ControlPreferences getInstance() { + if (fInstance == null) { + fInstance = new ControlPreferences(); + } + return fInstance; + } + + /** + * @return the preference store + */ + public IPreferenceStore getPreferenceStore() { + return Activator.getDefault().getPreferenceStore(); + } + + /** + * @return true if tracing group is set to default + */ + public boolean isDefaultTracingGroup() { + IPreferenceStore store = getPreferenceStore(); + return store.getString(TRACE_CONTROL_TRACING_GROUP_PREF).equals(store.getDefaultString(TRACE_CONTROL_TRACING_GROUP_PREF)); + } + + /** + * @return value of tracing group preference + */ + public String getTracingGroup() { + return getPreferenceStore().getString(TRACE_CONTROL_TRACING_GROUP_PREF); + } + + /** + * @return whether is logging is enabled + */ + public boolean isLoggingEnabled() { + return getPreferenceStore().getBoolean(TRACE_CONTROL_LOG_COMMANDS_PREF); + } + + /** + * @return whether an existing log file will appended or not + */ + public boolean isAppend() { + return getPreferenceStore().getBoolean(ControlPreferences.TRACE_CONTROL_LOG_APPEND_PREF); + } + + /** + * @return verbose level preference + */ + public String getVerboseLevel() { + return getPreferenceStore().getString(TRACE_CONTROL_VERBOSE_LEVEL_PREF); + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + /** + * Initializes the control preferences (e.g. enable open log file) + */ + public void init() { + if (getPreferenceStore().getBoolean(ControlPreferences.TRACE_CONTROL_LOG_COMMANDS_PREF)) { + ControlCommandLogger.init(ControlPreferences.TRACE_CONTROL_LOG_FILENAME, isAppend()); + } + } + + /** + * Disposes any resource (e.g. close log file). + */ + public void dispose() { + ControlCommandLogger.close(); + } +} diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/service/LTTngControlService.java b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/service/LTTngControlService.java index 83c44a081c..a4db754b5f 100644 --- a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/service/LTTngControlService.java +++ b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/service/LTTngControlService.java @@ -21,6 +21,7 @@ import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.linuxtools.internal.lttng2.ui.views.control.Messages; +import org.eclipse.linuxtools.internal.lttng2.ui.views.control.logging.ControlCommandLogger; import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IBaseEventInfo; import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo; import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IDomainInfo; @@ -38,6 +39,7 @@ import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.EventI import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.ProbeEventInfo; import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.SessionInfo; import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.UstProviderInfo; +import org.eclipse.linuxtools.internal.lttng2.ui.views.control.preferences.ControlPreferences; /** * LTTngControlService @@ -57,7 +59,7 @@ public class LTTngControlService implements ILttngControlService { /** * Command: lttng list. */ - private final static String COMMAND_LIST = CONTROL_COMMAND + " list "; //$NON-NLS-1$ + private final static String COMMAND_LIST = " list "; //$NON-NLS-1$ /** * Command to list kernel tracer information. */ @@ -69,45 +71,61 @@ public class LTTngControlService implements ILttngControlService { /** * Command to create a session. */ - private final static String COMMAND_CREATE_SESSION = CONTROL_COMMAND + " create "; //$NON-NLS-1$ + private final static String COMMAND_CREATE_SESSION = " create "; //$NON-NLS-1$ /** * Command to destroy a session. */ - private final static String COMMAND_DESTROY_SESSION = CONTROL_COMMAND + " destroy "; //$NON-NLS-1$ + private final static String COMMAND_DESTROY_SESSION = " destroy "; //$NON-NLS-1$ /** * Command to destroy a session. */ - private final static String COMMAND_START_SESSION = CONTROL_COMMAND + " start "; //$NON-NLS-1$ + private final static String COMMAND_START_SESSION = " start "; //$NON-NLS-1$ /** * Command to destroy a session. */ - private final static String COMMAND_STOP_SESSION = CONTROL_COMMAND + " stop "; //$NON-NLS-1$ + private final static String COMMAND_STOP_SESSION = " stop "; //$NON-NLS-1$ /** * Command to enable a channel. */ - private final static String COMMAND_ENABLE_CHANNEL = CONTROL_COMMAND + " enable-channel "; //$NON-NLS-1$ + private final static String COMMAND_ENABLE_CHANNEL = " enable-channel "; //$NON-NLS-1$ /** * Command to disable a channel. */ - private final static String COMMAND_DISABLE_CHANNEL = CONTROL_COMMAND + " disable-channel "; //$NON-NLS-1$ + private final static String COMMAND_DISABLE_CHANNEL = " disable-channel "; //$NON-NLS-1$ /** * Command to enable a event. */ - private final static String COMMAND_ENABLE_EVENT = CONTROL_COMMAND + " enable-event "; //$NON-NLS-1$ + private final static String COMMAND_ENABLE_EVENT = " enable-event "; //$NON-NLS-1$ /** * Command to disable a event. */ - private final static String COMMAND_DISABLE_EVENT = CONTROL_COMMAND + " disable-event "; //$NON-NLS-1$ + private final static String COMMAND_DISABLE_EVENT = " disable-event "; //$NON-NLS-1$ /** * Command to add a context to channels and/or events */ - private final static String COMMAND_ADD_CONTEXT = CONTROL_COMMAND + " add-context "; //$NON-NLS-1$ + private final static String COMMAND_ADD_CONTEXT = " add-context "; //$NON-NLS-1$ /** * Command to execute calibrate command to quantify LTTng overhead */ - private final static String COMMAND_CALIBRATE = CONTROL_COMMAND + " calibrate "; //$NON-NLS-1$ + private final static String COMMAND_CALIBRATE = " calibrate "; //$NON-NLS-1$ - // Command options constants + // Command options constants + /** + * Command line option to add tracing group of user. + */ + private final static String OPTION_TRACING_GROUP = " -g "; //$NON-NLS-1$ + /** + * Command line option for verbose output. + */ + private final static String OPTION_VERBOSE = " -v "; //$NON-NLS-1$ + /** + * Command line option for verbose output. + */ + private final static String OPTION_VERY_VERBOSE = " -vv "; //$NON-NLS-1$ + /** + * Command line option for verbose output. + */ + private final static String OPTION_VERY_VERY_VERBOSE = " -vvv "; //$NON-NLS-1$ /** * Command line option for output path. */ @@ -349,13 +367,9 @@ public class LTTngControlService implements ILttngControlService { */ @Override public String[] getSessionNames(IProgressMonitor monitor) throws ExecutionException { + StringBuffer command = createCommand(COMMAND_LIST); - String command = COMMAND_LIST; - ICommandResult result = fCommandShell.executeCommand(command, monitor); - - if (isError(result)) { - throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$ - } + ICommandResult result = executeCommand(command.toString(), monitor); // Output: // Available tracing sessions: @@ -388,13 +402,8 @@ public class LTTngControlService implements ILttngControlService { */ @Override public ISessionInfo getSession(String sessionName, IProgressMonitor monitor) throws ExecutionException { - - String command = COMMAND_LIST + sessionName; - ICommandResult result = fCommandShell.executeCommand(command, monitor); - - if (isError(result)) { - throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$ - } + StringBuffer command = createCommand(COMMAND_LIST, sessionName); + ICommandResult result = executeCommand(command.toString(), monitor); int index = 0; @@ -472,11 +481,8 @@ public class LTTngControlService implements ILttngControlService { */ @Override public List getKernelProvider(IProgressMonitor monitor) throws ExecutionException { - String command = COMMAND_LIST_KERNEL; - ICommandResult result = fCommandShell.executeCommand(command, monitor); - if (isError(result)) { - throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$ - } + StringBuffer command = createCommand(COMMAND_LIST_KERNEL); + ICommandResult result = executeCommand(command.toString(), monitor); // Kernel events: // ------------- @@ -507,12 +513,9 @@ public class LTTngControlService implements ILttngControlService { */ @Override public List getUstProvider(IProgressMonitor monitor) throws ExecutionException { - String command = COMMAND_LIST_UST; - ICommandResult result = fCommandShell.executeCommand(command, monitor); + StringBuffer command = createCommand(COMMAND_LIST_UST); - if (isError(result)) { - throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$ - } + ICommandResult result = executeCommand(command.toString(), monitor); // UST events: // ------------- @@ -563,20 +566,15 @@ public class LTTngControlService implements ILttngControlService { String newName = formatParameter(sessionName); String newPath = formatParameter(sessionPath); - StringBuffer command = new StringBuffer(); - command.append(COMMAND_CREATE_SESSION); - command.append(newName); + StringBuffer command = createCommand(COMMAND_CREATE_SESSION, newName); if (newPath != null && !"".equals(newPath)) { //$NON-NLS-1$ command.append(OPTION_OUTPUT_PATH); command.append(newPath); } - ICommandResult result = fCommandShell.executeCommand(command.toString(), monitor); - - if (isError(result)) { - throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$ - } + ICommandResult result = executeCommand(command.toString(), monitor); + //Session myssession2 created. //Traces will be written in /home/user/lttng-traces/myssession2-20120209-095418 String[] output = result.getOutput(); @@ -590,8 +588,8 @@ public class LTTngControlService implements ILttngControlService { } else { // Output format not expected throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$ - Messages.TraceControl_UnexpectedCommnadOutputFormat + ":\n" + //$NON-NLS-1$ - formatOutput(result.getOutput())); + Messages.TraceControl_UnexpectedCommandOutputFormat + ":\n" + //$NON-NLS-1$ + formatOutput(result)); } if ((name == null) || (!name.equals(sessionName))) { @@ -609,8 +607,8 @@ public class LTTngControlService implements ILttngControlService { } else { // Output format not expected throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$ - Messages.TraceControl_UnexpectedCommnadOutputFormat + ":\n" + //$NON-NLS-1$ - formatOutput(result.getOutput())); + Messages.TraceControl_UnexpectedCommandOutputFormat + ":\n" + //$NON-NLS-1$ + formatOutput(result)); } if ((path == null) || ((sessionPath != null) && (!path.contains(sessionPath)))) { @@ -628,13 +626,14 @@ public class LTTngControlService implements ILttngControlService { @Override public void destroySession(String sessionName, IProgressMonitor monitor) throws ExecutionException { String newName = formatParameter(sessionName); - String command = COMMAND_DESTROY_SESSION + newName; - ICommandResult result = fCommandShell.executeCommand(command, monitor); + StringBuffer command = createCommand(COMMAND_DESTROY_SESSION, newName); + + ICommandResult result = executeCommand(command.toString(), monitor, false); String[] output = result.getOutput(); if (isError(result) && ((output == null) || (!SESSION_NOT_FOUND_ERROR_PATTERN.matcher(output[0]).matches()))) { - throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$ + throw new ExecutionException(Messages.TraceControl_CommandError + " " + command.toString() + "\n" + formatOutput(result)); //$NON-NLS-1$ //$NON-NLS-2$ } //Session destroyed } @@ -648,13 +647,10 @@ public class LTTngControlService implements ILttngControlService { String newSessionName = formatParameter(sessionName); - String command = COMMAND_START_SESSION + newSessionName; + StringBuffer command = createCommand(COMMAND_START_SESSION, newSessionName); - ICommandResult result = fCommandShell.executeCommand(command, monitor); + executeCommand(command.toString(), monitor); - if (isError(result)) { - throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$ - } //Session started } @@ -665,13 +661,10 @@ public class LTTngControlService implements ILttngControlService { @Override public void stopSession(String sessionName, IProgressMonitor monitor) throws ExecutionException { String newSessionName = formatParameter(sessionName); - String command = COMMAND_STOP_SESSION + newSessionName; + StringBuffer command = createCommand(COMMAND_STOP_SESSION, newSessionName); - ICommandResult result = fCommandShell.executeCommand(command, monitor); + executeCommand(command.toString(), monitor); - if (isError(result)) { - throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$ - } //Session stopped } @@ -688,9 +681,7 @@ public class LTTngControlService implements ILttngControlService { return; } - String newSessionName = formatParameter(sessionName); - - StringBuffer command = new StringBuffer(COMMAND_ENABLE_CHANNEL); + StringBuffer command = createCommand(COMMAND_ENABLE_CHANNEL); for (Iterator iterator = channelNames.iterator(); iterator.hasNext();) { String channel = (String) iterator.next(); @@ -706,6 +697,7 @@ public class LTTngControlService implements ILttngControlService { command.append(OPTION_UST); } + String newSessionName = formatParameter(sessionName); command.append(OPTION_SESSION); command.append(newSessionName); @@ -735,11 +727,8 @@ public class LTTngControlService implements ILttngControlService { command.append(String.valueOf(info.getReadTimer())); } - ICommandResult result = fCommandShell.executeCommand(command.toString(), monitor); + executeCommand(command.toString(), monitor); - if (isError(result)) { - throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$ - } } /* @@ -754,9 +743,7 @@ public class LTTngControlService implements ILttngControlService { return; } - String newSessionName = formatParameter(sessionName); - - StringBuffer command = new StringBuffer(COMMAND_DISABLE_CHANNEL); + StringBuffer command = createCommand(COMMAND_DISABLE_CHANNEL); for (Iterator iterator = channelNames.iterator(); iterator.hasNext();) { String channel = (String) iterator.next(); @@ -772,16 +759,13 @@ public class LTTngControlService implements ILttngControlService { command.append(OPTION_UST); } + String newSessionName = formatParameter(sessionName); command.append(OPTION_SESSION); command.append(newSessionName); - ICommandResult result = fCommandShell.executeCommand(command.toString(), monitor); - - if (isError(result)) { - throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$ - } + executeCommand(command.toString(), monitor); } - + /* * (non-Javadoc) * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#enableEvent(java.lang.String, java.lang.String, java.util.List, boolean, org.eclipse.core.runtime.IProgressMonitor) @@ -789,9 +773,7 @@ public class LTTngControlService implements ILttngControlService { @Override public void enableEvents(String sessionName, String channelName, List eventNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException { - String newSessionName = formatParameter(sessionName); - - StringBuffer command = new StringBuffer(COMMAND_ENABLE_EVENT); + StringBuffer command = createCommand(COMMAND_ENABLE_EVENT); if (eventNames == null || eventNames.isEmpty()) { command.append(OPTION_ALL); @@ -812,6 +794,8 @@ public class LTTngControlService implements ILttngControlService { command.append(OPTION_UST); } + String newSessionName = formatParameter(sessionName); + command.append(OPTION_SESSION); command.append(newSessionName); @@ -822,11 +806,8 @@ public class LTTngControlService implements ILttngControlService { command.append(OPTION_TRACEPOINT); - ICommandResult result = fCommandShell.executeCommand(command.toString(), monitor); + executeCommand(command.toString(), monitor); - if (isError(result)) { - throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$ - } } /* @@ -835,13 +816,14 @@ public class LTTngControlService implements ILttngControlService { */ @Override public void enableSyscalls(String sessionName, String channelName, IProgressMonitor monitor) throws ExecutionException { - String newSessionName = formatParameter(sessionName); - - StringBuffer command = new StringBuffer(COMMAND_ENABLE_EVENT); + + StringBuffer command = createCommand(COMMAND_ENABLE_EVENT); command.append(OPTION_ALL); command.append(OPTION_KERNEL); + String newSessionName = formatParameter(sessionName); + command.append(OPTION_SESSION); command.append(newSessionName); @@ -852,11 +834,7 @@ public class LTTngControlService implements ILttngControlService { command.append(OPTION_SYSCALL); - ICommandResult result = fCommandShell.executeCommand(command.toString(), monitor); - - if (isError(result)) { - throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$ - } + executeCommand(command.toString(), monitor); } /* @@ -865,13 +843,12 @@ public class LTTngControlService implements ILttngControlService { */ @Override public void enableProbe(String sessionName, String channelName, String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException { - String newSessionName = formatParameter(sessionName); - - StringBuffer command = new StringBuffer(COMMAND_ENABLE_EVENT); + StringBuffer command = createCommand(COMMAND_ENABLE_EVENT); command.append(eventName); command.append(OPTION_KERNEL); + String newSessionName = formatParameter(sessionName); command.append(OPTION_SESSION); command.append(newSessionName); @@ -887,11 +864,7 @@ public class LTTngControlService implements ILttngControlService { command.append(probe); - ICommandResult result = fCommandShell.executeCommand(command.toString(), monitor); - - if (isError(result)) { - throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$ - } + executeCommand(command.toString(), monitor); } /* @@ -900,13 +873,12 @@ public class LTTngControlService implements ILttngControlService { */ @Override public void enableLogLevel(String sessionName, String channelName, String eventName, LogLevelType logLevelType, TraceLogLevel level, IProgressMonitor monitor) throws ExecutionException { - String newSessionName = formatParameter(sessionName); - - StringBuffer command = new StringBuffer(COMMAND_ENABLE_EVENT); + StringBuffer command = createCommand(COMMAND_ENABLE_EVENT); command.append(eventName); command.append(OPTION_UST); + String newSessionName = formatParameter(sessionName); command.append(OPTION_SESSION); command.append(newSessionName); @@ -925,11 +897,8 @@ public class LTTngControlService implements ILttngControlService { } command.append(level.getInName()); - ICommandResult result = fCommandShell.executeCommand(command.toString(), monitor); + executeCommand(command.toString(), monitor); - if (isError(result)) { - throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$ - } } /* @@ -938,9 +907,8 @@ public class LTTngControlService implements ILttngControlService { */ @Override public void disableEvent(String sessionName, String channelName, List eventNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException { - String newSessionName = formatParameter(sessionName); + StringBuffer command = createCommand(COMMAND_DISABLE_EVENT); - StringBuffer command = new StringBuffer(COMMAND_DISABLE_EVENT); if (eventNames == null) { command.append(OPTION_ALL); } else { @@ -964,6 +932,7 @@ public class LTTngControlService implements ILttngControlService { command.append(OPTION_UST); } + String newSessionName = formatParameter(sessionName); command.append(OPTION_SESSION); command.append(newSessionName); @@ -972,11 +941,7 @@ public class LTTngControlService implements ILttngControlService { command.append(channelName); } - ICommandResult result = fCommandShell.executeCommand(command.toString(), monitor); - - if (isError(result)) { - throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$ - } + executeCommand(command.toString(), monitor); } /* @@ -986,13 +951,9 @@ public class LTTngControlService implements ILttngControlService { @Override public List getContextList(IProgressMonitor monitor) throws ExecutionException { - String command = COMMAND_ADD_CONTEXT + OPTION_HELP; + StringBuffer command = createCommand(COMMAND_ADD_CONTEXT, OPTION_HELP); - ICommandResult result = fCommandShell.executeCommand(command, monitor); - - if (isError(result)) { - throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$ - } + ICommandResult result = executeCommand(command.toString(), monitor); String[] output = result.getOutput(); @@ -1027,10 +988,9 @@ public class LTTngControlService implements ILttngControlService { */ @Override public void addContexts(String sessionName, String channelName, String eventName, boolean isKernel, List contextNames, IProgressMonitor monitor) throws ExecutionException { - - String newSessionName = formatParameter(sessionName); - StringBuffer command = new StringBuffer(COMMAND_ADD_CONTEXT); + StringBuffer command = createCommand(COMMAND_ADD_CONTEXT); + String newSessionName = formatParameter(sessionName); command.append(OPTION_SESSION); command.append(newSessionName); @@ -1056,11 +1016,8 @@ public class LTTngControlService implements ILttngControlService { command.append(context); } - ICommandResult result = fCommandShell.executeCommand(command.toString(), monitor); + executeCommand(command.toString(), monitor); - if (isError(result)) { - throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$ - } } /* @@ -1070,7 +1027,7 @@ public class LTTngControlService implements ILttngControlService { @Override public void calibrate(boolean isKernel, IProgressMonitor monitor) throws ExecutionException { // String newSessionName = formatParameter(sessionName); - StringBuffer command = new StringBuffer(COMMAND_CALIBRATE); + StringBuffer command = createCommand(COMMAND_CALIBRATE); // // command.append(OPTION_SESSION); // command.append(newSessionName); @@ -1083,11 +1040,7 @@ public class LTTngControlService implements ILttngControlService { command.append(OPTION_FUNCTION_PROBE); - ICommandResult result = fCommandShell.executeCommand(command.toString(), monitor); - - if (isError(result)) { - throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$ - } + executeCommand(command.toString(), monitor); } // ------------------------------------------------------------------------ @@ -1114,12 +1067,15 @@ public class LTTngControlService implements ILttngControlService { * - output array * @return - the formatted output */ - private String formatOutput(String[] output) { - if (output == null || output.length == 0) { + private String formatOutput(ICommandResult result) { + if ((result == null) || result.getOutput() == null || result.getOutput().length == 0) { return ""; //$NON-NLS-1$ } - + String[] output = result.getOutput(); StringBuffer ret = new StringBuffer(); + ret.append("Return Value: "); //$NON-NLS-1$ + ret.append(result.getResult()); + ret.append("\n"); //$NON-NLS-1$ for (int i = 0; i < output.length; i++) { ret.append(output[i] + "\n"); //$NON-NLS-1$ } @@ -1378,4 +1334,87 @@ public class LTTngControlService implements ILttngControlService { } return null; } + + /** + * @param strings array of string that makes up a command line + * @return string buffer with created command line + */ + private StringBuffer createCommand(String... strings) { + StringBuffer command = new StringBuffer(); + command.append(CONTROL_COMMAND); + command.append(getTracingGroupOption()); + command.append(getVerboseOption()); + for (String string : strings) { + command.append(string); + } + return command; + } + + /** + * @return the tracing group option if configured in the preferences + */ + private String getTracingGroupOption() { + if (!ControlPreferences.getInstance().isDefaultTracingGroup() && !ControlPreferences.getInstance().getTracingGroup().equals("")) { //$NON-NLS-1$ + return OPTION_TRACING_GROUP + ControlPreferences.getInstance().getTracingGroup(); + } + return ""; //$NON-NLS-1$ + } + + /** + * @return the verbose option as configured in the preferences + */ + private String getVerboseOption() { + if (ControlPreferences.getInstance().isLoggingEnabled()) { + String level = ControlPreferences.getInstance().getVerboseLevel(); + if (ControlPreferences.TRACE_CONTROL_VERBOSE_LEVEL_VERBOSE.equals(level)) { + return OPTION_VERBOSE; + } + if (ControlPreferences.TRACE_CONTROL_VERBOSE_LEVEL_V_VERBOSE.equals(level)) { + return OPTION_VERY_VERBOSE; + } + if (ControlPreferences.TRACE_CONTROL_VERBOSE_LEVEL_V_V_VERBOSE.equals(level)) { + return OPTION_VERY_VERY_VERBOSE; + } + } + return ""; //$NON-NLS-1$ + } + + /** + * Method that logs the command and command result if logging is enabled as well as forwards + * the command execution to the shell. + * @param command - the command to execute + * @param monitor - a progress monitor + * @return the command result + * @throws ExecutionException + */ + private ICommandResult executeCommand(String command, IProgressMonitor monitor) throws ExecutionException { + return executeCommand(command, monitor, true); + } + + /** + * Method that logs the command and command result if logging is enabled as well as forwards + * the command execution to the shell. + * @param command - the command to execute + * @param monitor - a progress monitor + * @param - checkForError - true to verify command result, else false + * @return the command result + * @throws ExecutionException in case of error result + */ + private ICommandResult executeCommand(String command, IProgressMonitor monitor, boolean checkForError) throws ExecutionException { + if (ControlPreferences.getInstance().isLoggingEnabled()) { + ControlCommandLogger.log(command); + } + + ICommandResult result = fCommandShell.executeCommand(command.toString(), monitor); + + if (ControlPreferences.getInstance().isLoggingEnabled()) { + ControlCommandLogger.log(formatOutput(result)); + } + + if (isError(result)) { + throw new ExecutionException(Messages.TraceControl_CommandError + " " + command.toString() + "\n" + formatOutput(result)); //$NON-NLS-1$ //$NON-NLS-2$ + } + + return result; + } } -- 2.34.1