import org.eclipse.linuxtools.internal.lttng2.ui.views.control.preferences.ControlPreferences;
import org.eclipse.linuxtools.internal.lttng2.ui.views.control.remote.ICommandResult;
import org.eclipse.linuxtools.internal.lttng2.ui.views.control.remote.ICommandShell;
-import org.osgi.framework.Version;
/**
* <p>
/**
* The command shell implementation
*/
- protected ICommandShell fCommandShell = null;
+ private final ICommandShell fCommandShell;
/**
* The version string.
*/
- protected Version fVersion = null;
+ private LttngVersion fVersion = null;
// ------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------
// Accessors
// ------------------------------------------------------------------------
- /*
- * (non-Javadoc)
- * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#getVersion()
- */
+
@Override
public String getVersion() {
if (fVersion == null) {
* @param version - a version to set
*/
public void setVersion(String version) {
- fVersion = new Version(version);
+ fVersion = new LttngVersion(version);
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#isVersionSupported(java.lang.String)
- */
@Override
public boolean isVersionSupported(String version) {
- Version tmp = new Version(version);
+ LttngVersion tmp = new LttngVersion(version);
return (fVersion != null && fVersion.compareTo(tmp) >= 0) ? true : false;
}
+ /**
+ * Returns the command shell implementation.
+ *
+ * @return the command shell implementation
+ */
+ protected ICommandShell getCommandShell() {
+ return fCommandShell;
+ }
+
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
- * #getSessionNames(org.eclipse.core.runtime.IProgressMonitor)
- */
@Override
public String[] getSessionNames(IProgressMonitor monitor) throws ExecutionException {
StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_LIST);
return retArray.toArray(new String[retArray.size()]);
}
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
- * #getSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
- */
@Override
public ISessionInfo getSession(String sessionName, IProgressMonitor monitor) throws ExecutionException {
StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_LIST, sessionName);
return sessionInfo;
}
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
- * #getKernelProvider(org.eclipse.core.runtime.IProgressMonitor)
- */
@Override
public List<IBaseEventInfo> getKernelProvider(IProgressMonitor monitor) throws ExecutionException {
StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_LIST_KERNEL);
// or:
// Error: Unable to list kernel events
//
-
- if ((result.getOutput().length > 0) && (LTTngControlServiceConstants.LIST_KERNEL_NO_KERNEL_PROVIDER_PATTERN.matcher(result.getOutput()[0]).matches()) ||
- ((result.getOutput().length > 1) && (LTTngControlServiceConstants.LIST_KERNEL_NO_KERNEL_PROVIDER_PATTERN.matcher(result.getOutput()[1]).matches()))) {
- return events;
+ int index = 0;
+ while (index < result.getOutput().length) {
+ String line = result.getOutput()[index];
+ Matcher matcher = LTTngControlServiceConstants.LIST_KERNEL_NO_KERNEL_PROVIDER_PATTERN.matcher(line);
+ if (matcher.matches()) {
+ return events;
+ }
+ index++;
}
}
return events;
}
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
- * #getUstProvider()
- */
@Override
public List<IUstProviderInfo> getUstProvider() throws ExecutionException {
return getUstProvider(new NullProgressMonitor());
}
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
- * #getUstProvider(org.eclipse.core.runtime.IProgressMonitor)
- */
@Override
public List<IUstProviderInfo> getUstProvider(IProgressMonitor monitor) throws ExecutionException {
StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_LIST_UST);
command.append(LTTngControlServiceConstants.OPTION_FIELDS);
}
- ICommandResult result = executeCommand(command.toString(), monitor);
+ ICommandResult result = executeCommand(command.toString(), monitor, false);
+ List<IUstProviderInfo> allProviders = new ArrayList<IUstProviderInfo>();
+
+ // Workaround for versions 2.0.x which causes a segmentation fault for this command
+ // if LTTng Tools is compiled without UST support.
+ if (!isVersionSupported("2.1.0") && (result.getResult() != 0)) { //$NON-NLS-1$
+ return allProviders;
+ }
+
+ if (result.getOutput() != null) {
+ // Ignore the following 2 cases:
+ // Spawning a session daemon
+ // Error: Unable to list UST events: Listing UST events failed
+ // or:
+ // Error: Unable to list UST events: Listing UST events failed
+ //
+ int index = 0;
+ while (index < result.getOutput().length) {
+ String line = result.getOutput()[index];
+ Matcher matcher = LTTngControlServiceConstants.LIST_UST_NO_UST_PROVIDER_PATTERN.matcher(line);
+ if (matcher.matches()) {
+ return allProviders;
+ }
+ index++;
+ }
+ }
+
+ if (isError(result)) {
+ throw new ExecutionException(Messages.TraceControl_CommandError + " " + command.toString() + "\n" + formatOutput(result)); //$NON-NLS-1$ //$NON-NLS-2$
+ }
// Note that field print-outs exists for version >= 2.1.0
//
// field: floatfield (float)
// field: stringfield (string)
- List<IUstProviderInfo> allProviders = new ArrayList<IUstProviderInfo>();
IUstProviderInfo provider = null;
int index = 0;
} else {
index++;
}
-
}
return allProviders;
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#createSession(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
- */
@Override
public ISessionInfo createSession(String sessionName, String sessionPath, IProgressMonitor monitor) throws ExecutionException {
//Traces will be written in /home/user/lttng-traces/myssession2-20120209-095418
String[] output = result.getOutput();
- // Get and verify session name
- Matcher matcher = LTTngControlServiceConstants.CREATE_SESSION_NAME_PATTERN.matcher(output[0]);
+ // Get and session name and path
String name = null;
+ String path = null;
- if (matcher.matches()) {
- name = String.valueOf(matcher.group(1).trim());
- } else {
- // Output format not expected
- throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
- Messages.TraceControl_UnexpectedCommandOutputFormat + ":\n" + //$NON-NLS-1$
- formatOutput(result));
+ int index = 0;
+ while (index < output.length) {
+ String line = output[index];
+ Matcher nameMatcher = LTTngControlServiceConstants.CREATE_SESSION_NAME_PATTERN.matcher(line);
+ Matcher pathMatcher = LTTngControlServiceConstants.CREATE_SESSION_PATH_PATTERN.matcher(line);
+ if (nameMatcher.matches()) {
+ name = String.valueOf(nameMatcher.group(1).trim());
+ } else if (pathMatcher.matches()) {
+ path = String.valueOf(pathMatcher.group(1).trim());
+ }
+ index++;
}
+ // Verify session name
if ((name == null) || (!"".equals(sessionName) && !name.equals(sessionName))) { //$NON-NLS-1$
// Unexpected name returned
throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
SessionInfo sessionInfo = new SessionInfo(name);
- // Get and verify session path
- matcher = LTTngControlServiceConstants.CREATE_SESSION_PATH_PATTERN.matcher(output[1]);
- String path = null;
-
- if (matcher.matches()) {
- path = String.valueOf(matcher.group(1).trim());
- } else {
- // Output format not expected
- throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
- Messages.TraceControl_UnexpectedCommandOutputFormat + ":\n" + //$NON-NLS-1$
- formatOutput(result));
- }
-
+ // Verify session path
if ((path == null) || ((sessionPath != null) && (!path.contains(sessionPath)))) {
// Unexpected path
throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
Messages.TraceControl_UnexpectedPathError + ": " + name); //$NON-NLS-1$
}
+
sessionInfo.setSessionPath(path);
return sessionInfo;
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#createSession(java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
- */
@Override
public ISessionInfo createSession(String sessionName, String networkUrl, String controlUrl, String dataUrl, IProgressMonitor monitor) throws ExecutionException {
ICommandResult result = executeCommand(command.toString(), monitor);
- //Session myssession2 created.
- //Traces will be written in /home/user/lttng-traces/myssession2-20120209-095418
+ // Verify output
String[] output = result.getOutput();
- // Get and verify session name
- Matcher matcher = LTTngControlServiceConstants.CREATE_SESSION_NAME_PATTERN.matcher(output[0]);
+ // Get and session name and path
String name = null;
+ String path = null;
- if (matcher.matches()) {
- name = String.valueOf(matcher.group(1).trim());
- } else {
- // Output format not expected
+ int index = 0;
+ while (index < output.length) {
+ String line = output[index];
+ Matcher nameMatcher = LTTngControlServiceConstants.CREATE_SESSION_NAME_PATTERN.matcher(line);
+ Matcher pathMatcher = LTTngControlServiceConstants.CREATE_SESSION_PATH_PATTERN.matcher(line);
+
+ if (nameMatcher.matches()) {
+ name = String.valueOf(nameMatcher.group(1).trim());
+ } else if (pathMatcher.matches() && (networkUrl != null)) {
+ path = String.valueOf(pathMatcher.group(1).trim());
+ }
+ index++;
+ }
+
+ // Verify session name
+ if ((name == null) || (!"".equals(sessionName) && !name.equals(sessionName))) { //$NON-NLS-1$
+ // Unexpected name returned
throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
- Messages.TraceControl_UnexpectedCommandOutputFormat + ":\n" + //$NON-NLS-1$
- formatOutput(result));
+ Messages.TraceControl_UnexpectedNameError + ": " + name); //$NON-NLS-1$
}
- // Get and verify session path
- matcher = LTTngControlServiceConstants.CREATE_SESSION_PATH_PATTERN.matcher(output[1]);
- String path = null;
SessionInfo sessionInfo = new SessionInfo(name);
- if (networkUrl != null) {
- if (matcher.matches()) {
- path = String.valueOf(matcher.group(1).trim());
- } else {
- // Output format not expected
- throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
- Messages.TraceControl_UnexpectedCommandOutputFormat + ":\n" + //$NON-NLS-1$
- formatOutput(result));
- }
+ sessionInfo.setStreamedTrace(true);
+
+ // Verify session path
+ if (networkUrl != null) {
if (path == null) {
// Unexpected path
throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
Messages.TraceControl_UnexpectedPathError + ": " + name); //$NON-NLS-1$
}
+
sessionInfo.setSessionPath(path);
+
+ // Check file protocol
+ Matcher matcher = LTTngControlServiceConstants.TRACE_FILE_PROTOCOL_PATTERN.matcher(path);
+ if (matcher.matches()) {
+ sessionInfo.setStreamedTrace(false);
+ }
}
- sessionInfo.setStreamedTrace(true);
+ // When using controlUrl and dataUrl the full session path is not known yet
+ // and will be set later on when listing the session
return sessionInfo;
}
ICommandResult result = executeCommand(command.toString(), monitor, false);
String[] output = result.getOutput();
- if (isError(result) && ((output == null) || (!LTTngControlServiceConstants.SESSION_NOT_FOUND_ERROR_PATTERN.matcher(output[0]).matches()))) {
- throw new ExecutionException(Messages.TraceControl_CommandError + " " + command.toString() + "\n" + formatOutput(result)); //$NON-NLS-1$ //$NON-NLS-2$
- }
+ boolean isError = isError(result);
+ if (isError && (output != null)) {
+ int index = 0;
+ while (index < output.length) {
+ String line = output[index];
+ Matcher matcher = LTTngControlServiceConstants.SESSION_NOT_FOUND_ERROR_PATTERN.matcher(line);
+ if (matcher.matches()) {
+ // Don't treat this as an error
+ isError = false;
+ }
+ index++;
+ }
+ }
+
+ if (isError) {
+ throw new ExecutionException(Messages.TraceControl_CommandError + " " + command.toString() + "\n" + formatOutput(result)); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
//Session <sessionName> destroyed
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#startSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
- */
@Override
public void startSession(String sessionName, IProgressMonitor monitor) throws ExecutionException {
//Session <sessionName> started
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#stopSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
- */
@Override
public void stopSession(String sessionName, IProgressMonitor monitor) throws ExecutionException {
String newSessionName = formatParameter(sessionName);
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#enableChannel(java.lang.String, java.util.List, boolean, org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo, org.eclipse.core.runtime.IProgressMonitor)
- */
@Override
public void enableChannels(String sessionName, List<String> channelNames, boolean isKernel, IChannelInfo info, IProgressMonitor monitor) throws ExecutionException {
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#disableChannel(java.lang.String, java.util.List, org.eclipse.core.runtime.IProgressMonitor)
- */
@Override
public void disableChannels(String sessionName, List<String> channelNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException {
executeCommand(command.toString(), monitor);
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#enableEvents(java.lang.String, java.lang.String, java.util.List, boolean, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
- */
@Override
public void enableEvents(String sessionName, String channelName, List<String> eventNames, boolean isKernel, String filterExpression, IProgressMonitor monitor) throws ExecutionException {
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#enableSyscalls(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
- */
@Override
public void enableSyscalls(String sessionName, String channelName, IProgressMonitor monitor) throws ExecutionException {
executeCommand(command.toString(), monitor);
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#enableProbe(java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
- */
@Override
public void enableProbe(String sessionName, String channelName, String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException {
StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_ENABLE_EVENT);
executeCommand(command.toString(), monitor);
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#enableLogLevel(java.lang.String, java.lang.String, java.lang.String, org.eclipse.linuxtools.internal.lttng2.core.control.model.LogLevelType, org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceLogLevel, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
- */
@Override
public void enableLogLevel(String sessionName, String channelName, String eventName, LogLevelType logLevelType, TraceLogLevel level, String filterExpression, IProgressMonitor monitor) throws ExecutionException {
StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_ENABLE_EVENT);
executeCommand(command.toString(), monitor);
}
-
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#disableEvent(java.lang.String, java.lang.String, java.util.List, boolean, org.eclipse.core.runtime.IProgressMonitor)
- */
@Override
public void disableEvent(String sessionName, String channelName, List<String> eventNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException {
StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_DISABLE_EVENT);
executeCommand(command.toString(), monitor);
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#getContexts(org.eclipse.core.runtime.IProgressMonitor)
- */
@Override
public List<String> getContextList(IProgressMonitor monitor) throws ExecutionException {
return contexts;
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#addContexts(java.lang.String, java.lang.String, java.lang.String, boolean, java.util.List, org.eclipse.core.runtime.IProgressMonitor)
- */
@Override
public void addContexts(String sessionName, String channelName, String eventName, boolean isKernel, List<String> contextNames, IProgressMonitor monitor) throws ExecutionException {
StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_ADD_CONTEXT);
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#calibrate(boolean, org.eclipse.core.runtime.IProgressMonitor)
- */
@Override
public void calibrate(boolean isKernel, IProgressMonitor monitor) throws ExecutionException {
-// String newSessionName = formatParameter(sessionName);
StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_CALIBRATE);
-//
-// command.append(OPTION_SESSION);
-// command.append(newSessionName);
if (isKernel) {
command.append(LTTngControlServiceConstants.OPTION_KERNEL);
// ------------------------------------------------------------------------
// Helper methods
// ------------------------------------------------------------------------
+
/**
* Checks if command result is an error result.
*
* @return true if error else false
*/
protected boolean isError(ICommandResult result) {
- if ((result.getResult()) != 0 || (result.getOutput().length < 1 || LTTngControlServiceConstants.ERROR_PATTERN.matcher(result.getOutput()[0]).matches())) {
+ // Check return code and length of returned strings
+ if ((result.getResult()) != 0 || (result.getOutput().length < 1)) {
return true;
}
+
+ // Look for error pattern
+ int index = 0;
+ while (index < result.getOutput().length) {
+ String line = result.getOutput()[index];
+ Matcher matcher = LTTngControlServiceConstants.ERROR_PATTERN.matcher(line);
+ if (matcher.matches()) {
+ return true;
+ }
+ index++;
+ }
+
return false;
}
} else {
index++;
}
-// else if (line.matches(EVENT_NONE_PATTERN)) {
- // do nothing
-// } else
-
}
return index;