* Bernd Hufmann - Initial API and implementation
* Bernd Hufmann - Updated for support of LTTng Tools 2.1
* Simon Delisle - Updated for support of LTTng Tools 2.2
+ * Marc-Andre Laperle - Support for creating a live session
**********************************************************************/
package org.eclipse.linuxtools.internal.lttng2.control.ui.views.service;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IProgressMonitor;
// ------------------------------------------------------------------------
@Override
- public String getVersion() {
+ public String getVersionString() {
if (fVersion == null) {
return "Unknown"; //$NON-NLS-1$
}
return fVersion.toString();
}
+ @Override
+ public LttngVersion getVersion() {
+ return fVersion;
+ }
+
/**
* Sets the version of the LTTng 2.0 control service.
- * @param version - a version to set
+ *
+ * @param version
+ * - a version to set
*/
public void setVersion(String version) {
fVersion = new LttngVersion(version);
}
+ /**
+ * Sets the version of the LTTng 2.x control service.
+ *
+ * @param version
+ * - a version to set
+ */
+ public void setVersion(LttngVersion version) {
+ fVersion = version;
+ }
+
@Override
public boolean isVersionSupported(String version) {
LttngVersion tmp = new LttngVersion(version);
// Output:
// Available tracing sessions:
- // 1) mysession1 (/home/user/lttng-traces/mysession1-20120123-083928) [inactive]
- // 2) mysession (/home/user/lttng-traces/mysession-20120123-083318) [inactive]
+ // 1) mysession1 (/home/user/lttng-traces/mysession1-20120123-083928)
+ // [inactive]
+ // 2) mysession (/home/user/lttng-traces/mysession-20120123-083318)
+ // [inactive]
//
// Use lttng list <session_name> for more details
return retArray.toArray(new String[retArray.size()]);
}
+ /**
+ * Check if there is a pattern to be ignored into a sequence of string
+ *
+ * @param input
+ * an arrays of string
+ * @param pattern
+ * the pattern to search for
+ * @return if the pattern exist into the array of string
+ */
+ protected boolean ignoredPattern(String[] input, Pattern pattern) {
+ for (String line : input) {
+ Matcher matcher = pattern.matcher(line);
+ if (matcher.matches()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
@Override
public ISessionInfo getSession(String sessionName, IProgressMonitor monitor) throws ExecutionException {
StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_LIST, sessionName);
List<IBaseEventInfo> events = new ArrayList<>();
- if (result.getOutput() != null) {
+ if (result.getErrorOutput() != null) {
// Ignore the following 2 cases:
// Spawning a session daemon
// Error: Unable to list kernel events
// or:
// Error: Unable to list kernel 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++;
+ if (ignoredPattern(result.getErrorOutput(), LTTngControlServiceConstants.LIST_KERNEL_NO_KERNEL_PROVIDER_PATTERN)) {
+ return events;
}
}
ICommandResult result = executeCommand(command.toString(), monitor, false);
List<IUstProviderInfo> allProviders = new ArrayList<>();
- // Workaround for versions 2.0.x which causes a segmentation fault for this command
+ // 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) {
+ if (result.getErrorOutput() != 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 (ignoredPattern(result.getErrorOutput(), LTTngControlServiceConstants.LIST_UST_NO_UST_PROVIDER_PATTERN)) {
+ return allProviders;
}
}
// ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
// tracepoint)
// ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
- // field: doublefield (float)
- // field: floatfield (float)
- // field: stringfield (string)
+ // field: doublefield (float)
+ // field: floatfield (float)
+ // field: stringfield (string)
//
// PID: 6459 - Name:
// /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello
// ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type:
// tracepoint)
// ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint)
- // field: doublefield (float)
- // field: floatfield (float)
- // field: stringfield (string)
+ // field: doublefield (float)
+ // field: floatfield (float)
+ // field: stringfield (string)
IUstProviderInfo provider = null;
return createStreamedSession(sessionInfo, monitor);
}
- String newName = formatParameter(sessionInfo.getName());
- String newPath = formatParameter(sessionInfo.getSessionPath());
-
- StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_CREATE_SESSION, newName);
-
- if (newPath != null && !"".equals(newPath)) { //$NON-NLS-1$
- command.append(LTTngControlServiceConstants.OPTION_OUTPUT_PATH);
- command.append(newPath);
- }
-
- if (sessionInfo.isSnapshotSession()) {
- command.append(LTTngControlServiceConstants.OPTION_SNAPSHOT);
- }
+ StringBuffer command = prepareSessionCreationCommand(sessionInfo);
ICommandResult result = executeCommand(command.toString(), monitor);
- //Session myssession2 created.
- //Traces will be written in /home/user/lttng-traces/myssession2-20120209-095418
+ // Session myssession2 created.
+ // Traces will be written in
+ // /home/user/lttng-traces/myssession2-20120209-095418
String[] output = result.getOutput();
// Get and session name and path
}
- private ISessionInfo createStreamedSession(ISessionInfo sessionInfo, IProgressMonitor monitor) throws ExecutionException {
-
+ /**
+ * Basic generation of command for session creation
+ *
+ * @param sessionInfo
+ * the session to create
+ * @return the basic command for command creation
+ */
+ protected StringBuffer prepareSessionCreationCommand(ISessionInfo sessionInfo) {
String newName = formatParameter(sessionInfo.getName());
+ String newPath = formatParameter(sessionInfo.getSessionPath());
+
StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_CREATE_SESSION, newName);
+ if (newPath != null && !"".equals(newPath)) { //$NON-NLS-1$
+ command.append(LTTngControlServiceConstants.OPTION_OUTPUT_PATH);
+ command.append(newPath);
+ }
+
if (sessionInfo.isSnapshotSession()) {
command.append(LTTngControlServiceConstants.OPTION_SNAPSHOT);
}
+ return command;
+ }
- if (sessionInfo.getNetworkUrl() != null) {
- command.append(LTTngControlServiceConstants.OPTION_NETWORK_URL);
- command.append(sessionInfo.getNetworkUrl());
- } else {
- command.append(LTTngControlServiceConstants.OPTION_CONTROL_URL);
- command.append(sessionInfo.getControlUrl());
+ private ISessionInfo createStreamedSession(ISessionInfo sessionInfo, IProgressMonitor monitor) throws ExecutionException {
- command.append(LTTngControlServiceConstants.OPTION_DATA_URL);
- command.append(sessionInfo.getDataUrl());
- }
+ StringBuffer command = prepareStreamedSessionCreationCommand(sessionInfo);
ICommandResult result = executeCommand(command.toString(), monitor);
}
}
- // When using controlUrl and dataUrl the full session path is not known yet
- // and will be set later on when listing the session
+ // 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;
}
+ /**
+ * Basic generation of command for streamed session creation
+ *
+ * @param sessionInfo
+ * the session to create
+ * @return the basic command for command creation
+ */
+ protected StringBuffer prepareStreamedSessionCreationCommand(ISessionInfo sessionInfo) {
+ String newName = formatParameter(sessionInfo.getName());
+ StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_CREATE_SESSION, newName);
+
+ if (sessionInfo.isSnapshotSession()) {
+ command.append(LTTngControlServiceConstants.OPTION_SNAPSHOT);
+ } else if (sessionInfo.isLive()) {
+ command.append(LTTngControlServiceConstants.OPTION_LIVE);
+ if (sessionInfo.getLiveDelay() != LTTngControlServiceConstants.UNUSED_VALUE) {
+ command.append(sessionInfo.getLiveDelay());
+ }
+ }
+
+ if (sessionInfo.getNetworkUrl() != null) {
+ command.append(LTTngControlServiceConstants.OPTION_NETWORK_URL);
+ command.append(sessionInfo.getNetworkUrl());
+ } else {
+ command.append(LTTngControlServiceConstants.OPTION_CONTROL_URL);
+ command.append(sessionInfo.getControlUrl());
+
+ command.append(LTTngControlServiceConstants.OPTION_DATA_URL);
+ command.append(sessionInfo.getDataUrl());
+ }
+ return command;
+ }
+
@Override
public void destroySession(String sessionName, IProgressMonitor monitor) throws ExecutionException {
String newName = formatParameter(sessionName);
StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_DESTROY_SESSION, newName);
ICommandResult result = executeCommand(command.toString(), monitor, false);
- String[] output = result.getOutput();
+ String[] errorOutput = result.getErrorOutput();
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 && (errorOutput != null)) {
+ if (ignoredPattern(result.getErrorOutput(), LTTngControlServiceConstants.SESSION_NOT_FOUND_ERROR_PATTERN)) {
+ isError = false;
+
}
}
throw new ExecutionException(Messages.TraceControl_CommandError + " " + command.toString() + "\n" + formatOutput(result)); //$NON-NLS-1$ //$NON-NLS-2$
}
- //Session <sessionName> destroyed
+ // Session <sessionName> destroyed
}
@Override
executeCommand(command.toString(), monitor);
- //Session <sessionName> started
+ // Session <sessionName> started
}
@Override
executeCommand(command.toString(), monitor);
- //Session <sessionName> stopped
+ // Session <sessionName> stopped
}
command.append(newSessionName);
if (info != null) {
-// --discard Discard event when buffers are full (default)
+ // --discard Discard event when buffers are full (default)
-// --overwrite Flight recorder mode
+ // --overwrite Flight recorder mode
if (info.isOverwriteMode()) {
command.append(LTTngControlServiceConstants.OPTION_OVERWRITE);
}
-// --subbuf-size SIZE Subbuffer size in bytes
-// (default: 4096, kernel default: 262144)
+ // --subbuf-size SIZE Subbuffer size in bytes
+ // (default: 4096, kernel default: 262144)
if (info.getSubBufferSize() != LTTngControlServiceConstants.UNUSED_VALUE) {
command.append(LTTngControlServiceConstants.OPTION_SUB_BUFFER_SIZE);
command.append(String.valueOf(info.getSubBufferSize()));
}
-// --num-subbuf NUM Number of subbufers
+ // --num-subbuf NUM Number of subbufers
if (info.getNumberOfSubBuffers() != LTTngControlServiceConstants.UNUSED_VALUE) {
command.append(LTTngControlServiceConstants.OPTION_NUM_SUB_BUFFERS);
command.append(String.valueOf(info.getNumberOfSubBuffers()));
}
-// --switch-timer USEC Switch timer interval in usec
+ // --switch-timer USEC Switch timer interval in usec
if (info.getSwitchTimer() != LTTngControlServiceConstants.UNUSED_VALUE) {
command.append(LTTngControlServiceConstants.OPTION_SWITCH_TIMER);
command.append(String.valueOf(info.getSwitchTimer()));
}
-// --read-timer USEC Read timer interval in usec
+ // --read-timer USEC Read timer interval in usec
if (info.getReadTimer() != LTTngControlServiceConstants.UNUSED_VALUE) {
command.append(LTTngControlServiceConstants.OPTION_READ_TIMER);
command.append(String.valueOf(info.getReadTimer()));
}
if (isVersionSupported("2.2.0")) { //$NON-NLS-1$
-// --buffers-uid Every application sharing the same UID use the same buffers
-// --buffers-pid Buffers are allocated per PID
+ // --buffers-uid Every application sharing the same UID use the
+ // same buffers --buffers-pid Buffers are allocated per PID
if (!isKernel) {
if (info.getBufferType() == BufferType.BUFFER_PER_PID) {
command.append(LTTngControlServiceConstants.OPTION_PER_PID_BUFFERS);
}
}
-// -C SIZE Maximum size of trace files in bytes
+ // -C SIZE Maximum size of trace files in bytes
if (info.getMaxSizeTraceFiles() != LTTngControlServiceConstants.UNUSED_VALUE) {
command.append(LTTngControlServiceConstants.OPTION_MAX_SIZE_TRACE_FILES);
command.append(String.valueOf(info.getMaxSizeTraceFiles()));
}
-// -W NUM Maximum number of trace files
+ // -W NUM Maximum number of trace files
if (info.getMaxNumberTraceFiles() != LTTngControlServiceConstants.UNUSED_VALUE) {
command.append(LTTngControlServiceConstants.OPTION_MAX_TRACE_FILES);
command.append(String.valueOf(info.getMaxNumberTraceFiles()));
executeCommand(command.toString(), monitor);
}
+ @Override
+ public void runCommands(IProgressMonitor monitor, List<String> commands) throws ExecutionException {
+ for (String command : commands) {
+ if (monitor.isCanceled()) {
+ return;
+ }
+
+ if (command.isEmpty() || command.startsWith("#")) { //$NON-NLS-1$
+ continue;
+ }
+ executeCommand(command, monitor);
+ }
+ }
+
// ------------------------------------------------------------------------
// Helper methods
// ------------------------------------------------------------------------
*/
protected boolean isError(ICommandResult result) {
// Check return code and length of returned strings
- if ((result.getResult()) != 0 || (result.getOutput().length < 1)) {
+
+ if ((result.getResult()) != 0) {
return true;
}
// Look for error pattern
int index = 0;
- while (index < result.getOutput().length) {
- String line = result.getOutput()[index];
+ while (index < result.getErrorOutput().length) {
+ String line = result.getErrorOutput()[index];
Matcher matcher = LTTngControlServiceConstants.ERROR_PATTERN.matcher(line);
if (matcher.matches()) {
return true;
* @return - the formatted output
*/
public static String formatOutput(ICommandResult result) {
- if ((result == null) || result.getOutput() == null || result.getOutput().length == 0) {
+ if ((result == null) || ((result.getOutput() == null || result.getOutput().length == 0) && (result.getErrorOutput() == null || result.getErrorOutput().length == 0))) {
return ""; //$NON-NLS-1$
}
String[] output = result.getOutput();
+ String[] errorOutput = result.getErrorOutput();
StringBuffer ret = new StringBuffer();
+ ret.append("Error Ouptut:\n"); //$NON-NLS-1$
+ for (int i = 0; i < errorOutput.length; i++) {
+ ret.append(errorOutput[i]).append("\n"); //$NON-NLS-1$
+ }
ret.append("Return Value: "); //$NON-NLS-1$
ret.append(result.getResult());
ret.append("\n"); //$NON-NLS-1$
eventInfo.setState(matcher.group(5));
String filter = matcher.group(6);
if (filter != null) {
- filter = filter.substring(1, filter.length() - 1); // remove '[' and ']'
+ // remove '[' and ']'
+ filter = filter.substring(1, filter.length() - 1);
eventInfo.setFilterExpression(filter);
}
events.add(eventInfo);
eventInfo.setState(matcher2.group(3));
String filter = matcher2.group(4);
if (filter != null) {
- filter = filter.substring(1, filter.length() - 1); // remove '[' and ']'
+ // remove '[' and ']'
+ filter = filter.substring(1, filter.length() - 1);
eventInfo.setFilterExpression(filter);
}
if ((eventInfo.getEventType() == TraceEventType.PROBE) ||
- (eventInfo.getEventType() == TraceEventType.FUNCTION)){
+ (eventInfo.getEventType() == TraceEventType.FUNCTION)) {
IProbeEventInfo probeEvent = new ProbeEventInfo(eventInfo.getName());
probeEvent.setLogLevel(eventInfo.getLogLevel());
probeEvent.setEventType(eventInfo.getEventType());
String line = output[index];
Matcher matcher = LTTngControlServiceConstants.PROVIDER_EVENT_PATTERN.matcher(line);
if (matcher.matches()) {
- // sched_kthread_stop (loglevel: TRACE_EMERG0) (type: tracepoint)
+ // sched_kthread_stop (loglevel: TRACE_EMERG0) (type:
+ // tracepoint)
eventInfo = new BaseEventInfo(matcher.group(1).trim());
eventInfo.setLogLevel(matcher.group(2).trim());
eventInfo.setEventType(matcher.group(3).trim());
return index;
}
-
/**
* Parse a field's information.
*
}
/**
- * Formats a command parameter for the command execution i.e. adds quotes
- * at the beginning and end if necessary.
- * @param parameter - parameter to format
+ * Formats a command parameter for the command execution i.e. adds quotes at
+ * the beginning and end if necessary.
+ *
+ * @param parameter
+ * - parameter to format
* @return formated parameter
*/
protected String formatParameter(String parameter) {
}
/**
- * @param strings array of string that makes up a command line
+ * @param strings
+ * array of string that makes up a command line
* @return string buffer with created command line
*/
protected StringBuffer createCommand(String... strings) {