--- /dev/null
+/**********************************************************************
+ * 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;
+
+/**
+ * <b><u>ControlCommandLogger</u></b>
+ * <p>
+ * Class to log control commands.
+ * </p>
+ */
+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;
+ }
+
+}
--- /dev/null
+/**********************************************************************
+ * 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;
+
+/**
+ * <b><u>ControlPreferencePage</u></b>
+ * <p>
+ * Preference page implementation for configuring LTTng tracer control preferences.
+ * </p>
+ */
+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;
+ }
+}
--- /dev/null
+/**********************************************************************
+ * 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;
+
+/**
+ * <b><u>ControlPreference</u></b>
+ * <p>
+ * Singleton class to access LTTng tracer control preferences.
+ * </p>
+ */
+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();
+ }
+}
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;
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;
/**
* <b><u>LTTngControlService</u></b>
/**
* 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.
*/
/**
* 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.
*/
*/
@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:
*/
@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;
*/
@Override
public List<IBaseEventInfo> 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:
// -------------
*/
@Override
public List<IUstProviderInfo> 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:
// -------------
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();
} 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))) {
} 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)))) {
@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 <sessionName> destroyed
}
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 <sessionName> started
}
@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 <sessionName> stopped
}
return;
}
- String newSessionName = formatParameter(sessionName);
-
- StringBuffer command = new StringBuffer(COMMAND_ENABLE_CHANNEL);
+ StringBuffer command = createCommand(COMMAND_ENABLE_CHANNEL);
for (Iterator<String> iterator = channelNames.iterator(); iterator.hasNext();) {
String channel = (String) iterator.next();
command.append(OPTION_UST);
}
+ String newSessionName = formatParameter(sessionName);
command.append(OPTION_SESSION);
command.append(newSessionName);
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$
- }
}
/*
return;
}
- String newSessionName = formatParameter(sessionName);
-
- StringBuffer command = new StringBuffer(COMMAND_DISABLE_CHANNEL);
+ StringBuffer command = createCommand(COMMAND_DISABLE_CHANNEL);
for (Iterator<String> iterator = channelNames.iterator(); iterator.hasNext();) {
String channel = (String) iterator.next();
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)
@Override
public void enableEvents(String sessionName, String channelName, List<String> 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);
command.append(OPTION_UST);
}
+ String newSessionName = formatParameter(sessionName);
+
command.append(OPTION_SESSION);
command.append(newSessionName);
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$
- }
}
/*
*/
@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);
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);
}
/*
*/
@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);
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);
}
/*
*/
@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);
}
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$
- }
}
/*
*/
@Override
public void disableEvent(String sessionName, String channelName, List<String> 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 {
command.append(OPTION_UST);
}
+ String newSessionName = formatParameter(sessionName);
command.append(OPTION_SESSION);
command.append(newSessionName);
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);
}
/*
@Override
public List<String> 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();
*/
@Override
public void addContexts(String sessionName, String channelName, String eventName, boolean isKernel, List<String> 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);
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$
- }
}
/*
@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);
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);
}
// ------------------------------------------------------------------------
* - 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$
}
}
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;
+ }
}