From: Jonathan Rajotte Julien Date: Mon, 11 Aug 2014 13:22:14 +0000 (-0400) Subject: tmf: lttngControl: mi: handle error via errorOutput X-Git-Url: http://git.efficios.com/?a=commitdiff_plain;h=517c0261069c203ed84dc7cab7a4629cebb078f2;p=deliverable%2Ftracecompass.git tmf: lttngControl: mi: handle error via errorOutput Change-Id: Ic54b1dae3013b445ca5f47732a8a22f11f1b0389 Signed-off-by: Jonathan Rajotte Julien Reviewed-on: https://git.eclipse.org/r/31393 Tested-by: Hudson CI Reviewed-by: Bernd Hufmann Tested-by: Bernd Hufmann Reviewed-by: Matthew Khouzam --- diff --git a/org.eclipse.linuxtools.lttng2.control.ui/src/org/eclipse/linuxtools/internal/lttng2/control/ui/views/messages/Messages.java b/org.eclipse.linuxtools.lttng2.control.ui/src/org/eclipse/linuxtools/internal/lttng2/control/ui/views/messages/Messages.java index 9bd58c2647..fd5210fa2c 100644 --- a/org.eclipse.linuxtools.lttng2.control.ui/src/org/eclipse/linuxtools/internal/lttng2/control/ui/views/messages/Messages.java +++ b/org.eclipse.linuxtools.lttng2.control.ui/src/org/eclipse/linuxtools/internal/lttng2/control/ui/views/messages/Messages.java @@ -46,6 +46,7 @@ public final class Messages extends NLS { public static String TraceControl_UnexpectedNameError; public static String TraceControl_UnexpectedPathError; public static String TraceControl_UnexpectedNumberOfElementError; + public static String TraceControl_UnexpectedValueError; public static String TraceControl_UnsupportedVersionError; public static String TraceControl_GettingVersionError; diff --git a/org.eclipse.linuxtools.lttng2.control.ui/src/org/eclipse/linuxtools/internal/lttng2/control/ui/views/messages/messages.properties b/org.eclipse.linuxtools.lttng2.control.ui/src/org/eclipse/linuxtools/internal/lttng2/control/ui/views/messages/messages.properties index b5539f11d7..f826ea3789 100644 --- a/org.eclipse.linuxtools.lttng2.control.ui/src/org/eclipse/linuxtools/internal/lttng2/control/ui/views/messages/messages.properties +++ b/org.eclipse.linuxtools.lttng2.control.ui/src/org/eclipse/linuxtools/internal/lttng2/control/ui/views/messages/messages.properties @@ -26,6 +26,7 @@ TraceControl_UnexpectedCommandOutputFormat=Unexpected command output TraceControl_UnexpectedNameError=Unexpected session name returned TraceControl_UnexpectedPathError=Unexpected session path returned TraceControl_UnexpectedNumberOfElementError=Unexpected number of elements {0} returned +TraceControl_UnexpectedValueError=Unexpected value. Returned {0} Expected: {1} TraceControl_UnsupportedVersionError=Unsupported LTTng Tracer Control version TraceControl_GettingVersionError=Could not get version of LTTng Tracer Control diff --git a/org.eclipse.linuxtools.lttng2.control.ui/src/org/eclipse/linuxtools/internal/lttng2/control/ui/views/service/LTTngControlService.java b/org.eclipse.linuxtools.lttng2.control.ui/src/org/eclipse/linuxtools/internal/lttng2/control/ui/views/service/LTTngControlService.java index d734b2076f..1e8d833573 100644 --- a/org.eclipse.linuxtools.lttng2.control.ui/src/org/eclipse/linuxtools/internal/lttng2/control/ui/views/service/LTTngControlService.java +++ b/org.eclipse.linuxtools.lttng2.control.ui/src/org/eclipse/linuxtools/internal/lttng2/control/ui/views/service/LTTngControlService.java @@ -18,6 +18,7 @@ import java.util.ArrayList; 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; @@ -105,7 +106,9 @@ public class LTTngControlService implements ILttngControlService { /** * 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); @@ -113,7 +116,9 @@ public class LTTngControlService implements ILttngControlService { /** * Sets the version of the LTTng 2.x control service. - * @param version - a version to set + * + * @param version + * - a version to set */ public void setVersion(LttngVersion version) { fVersion = version; @@ -146,8 +151,10 @@ public class LTTngControlService implements ILttngControlService { // 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 for more details @@ -164,6 +171,25 @@ public class LTTngControlService implements ILttngControlService { 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); @@ -316,14 +342,8 @@ public class LTTngControlService implements ILttngControlService { // or: // Error: Unable to list kernel events // - int index = 0; - while (index < result.getErrorOutput().length) { - String line = result.getErrorOutput()[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; } } @@ -354,7 +374,8 @@ public class LTTngControlService implements ILttngControlService { ICommandResult result = executeCommand(command.toString(), monitor, false); List 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; @@ -367,14 +388,8 @@ public class LTTngControlService implements ILttngControlService { // or: // Error: Unable to list UST events: Listing UST events failed // - int index = 0; - while (index < result.getErrorOutput().length) { - String line = result.getErrorOutput()[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; } } @@ -392,18 +407,18 @@ public class LTTngControlService implements ILttngControlService { // 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; @@ -435,8 +450,9 @@ public class LTTngControlService implements ILttngControlService { 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 @@ -563,8 +579,8 @@ public class LTTngControlService implements ILttngControlService { } } - // 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; } @@ -610,15 +626,9 @@ public class LTTngControlService implements ILttngControlService { boolean isError = isError(result); if (isError && (errorOutput != null)) { - int index = 0; - while (index < errorOutput.length) { - String line = errorOutput[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 (ignoredPattern(result.getErrorOutput(), LTTngControlServiceConstants.SESSION_NOT_FOUND_ERROR_PATTERN)) { + isError = false; + } } @@ -626,7 +636,7 @@ public class LTTngControlService implements ILttngControlService { throw new ExecutionException(Messages.TraceControl_CommandError + " " + command.toString() + "\n" + formatOutput(result)); //$NON-NLS-1$ //$NON-NLS-2$ } - //Session destroyed + // Session destroyed } @Override @@ -638,7 +648,7 @@ public class LTTngControlService implements ILttngControlService { executeCommand(command.toString(), monitor); - //Session started + // Session started } @Override @@ -648,7 +658,7 @@ public class LTTngControlService implements ILttngControlService { executeCommand(command.toString(), monitor); - //Session stopped + // Session stopped } @@ -681,40 +691,40 @@ public class LTTngControlService implements ILttngControlService { 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); @@ -724,13 +734,13 @@ public class LTTngControlService implements ILttngControlService { } } -// -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())); @@ -1104,7 +1114,7 @@ public class LTTngControlService implements ILttngControlService { } ret.append("Error stream:\n"); //$NON-NLS-1$ for (int i = 0; i < errorOutput.length; i++) { - ret.append(errorOutput[i]).append("\n"); //$NON-NLS-1$ + ret.append(errorOutput[i]).append("\n"); //$NON-NLS-1$ } return ret.toString(); } @@ -1278,7 +1288,8 @@ public class LTTngControlService implements ILttngControlService { 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); @@ -1290,12 +1301,13 @@ public class LTTngControlService implements ILttngControlService { 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()); @@ -1382,7 +1394,8 @@ public class LTTngControlService implements ILttngControlService { 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()); @@ -1406,7 +1419,6 @@ public class LTTngControlService implements ILttngControlService { return index; } - /** * Parse a field's information. * @@ -1440,9 +1452,11 @@ public class LTTngControlService implements ILttngControlService { } /** - * 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) { @@ -1460,7 +1474,8 @@ public class LTTngControlService implements ILttngControlService { } /** - * @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) { diff --git a/org.eclipse.linuxtools.lttng2.control.ui/src/org/eclipse/linuxtools/internal/lttng2/control/ui/views/service/LTTngControlServiceMI.java b/org.eclipse.linuxtools.lttng2.control.ui/src/org/eclipse/linuxtools/internal/lttng2/control/ui/views/service/LTTngControlServiceMI.java index 3e72f1a837..1583b1c36c 100644 --- a/org.eclipse.linuxtools.lttng2.control.ui/src/org/eclipse/linuxtools/internal/lttng2/control/ui/views/service/LTTngControlServiceMI.java +++ b/org.eclipse.linuxtools.lttng2.control.ui/src/org/eclipse/linuxtools/internal/lttng2/control/ui/views/service/LTTngControlServiceMI.java @@ -225,7 +225,7 @@ public class LTTngControlServiceMI extends LTTngControlService { NodeList sessionsNode = document.getElementsByTagName(MIStrings.SESSION); // There should be only one session if (sessionsNode.getLength() != 1) { - throw new ExecutionException(Messages.TraceControl_MiInvalidNumberOfElementError); + throw new ExecutionException(NLS.bind(Messages.TraceControl_MiInvalidNumberOfElementError, MIStrings.SESSION)); } // Populate session information @@ -457,8 +457,16 @@ public class LTTngControlServiceMI extends LTTngControlService { ICommandResult result = executeCommand(command.toString(), monitor, false); List events = new ArrayList<>(); - if (isError(result)) { - return events; + if (isError(result) && 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 + if (ignoredPattern(result.getErrorOutput(), LTTngControlServiceConstants.LIST_KERNEL_NO_KERNEL_PROVIDER_PATTERN)) { + return events; + } + throw new ExecutionException(Messages.TraceControl_CommandError + LTTngControlServiceConstants.COMMAND_LIST_KERNEL); } Document document = getDocumentFromStrings(result.getOutput()); @@ -477,8 +485,16 @@ public class LTTngControlServiceMI extends LTTngControlService { ICommandResult result = executeCommand(command.toString(), monitor, false); List allProviders = new ArrayList<>(); - if (isError(result)) { - return allProviders; + if (isError(result) && 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 + if (ignoredPattern(result.getErrorOutput(), LTTngControlServiceConstants.LIST_UST_NO_UST_PROVIDER_PATTERN)) { + return allProviders; + } + throw new ExecutionException(Messages.TraceControl_CommandError + LTTngControlServiceConstants.COMMAND_LIST_UST); } Document document = getDocumentFromStrings(result.getOutput()); @@ -623,20 +639,38 @@ public class LTTngControlServiceMI extends LTTngControlService { @Override public void destroySession(String sessionName, IProgressMonitor monitor) throws ExecutionException { - // TODO Auto-generated method stub + String newName = formatParameter(sessionName); - } + StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_DESTROY_SESSION, newName); - @Override - public void startSession(String sessionName, IProgressMonitor monitor) throws ExecutionException { - // TODO Auto-generated method stub + ICommandResult result = executeCommand(command.toString(), monitor, false); + String[] errorOutput = result.getErrorOutput(); - } + if (isError(result) && (errorOutput != null)) { + // Don't treat this as an error + if (ignoredPattern(errorOutput, LTTngControlServiceConstants.SESSION_NOT_FOUND_ERROR_PATTERN)) { + return; - @Override - public void stopSession(String sessionName, IProgressMonitor monitor) throws ExecutionException { - // TODO Auto-generated method stub + } + throw new ExecutionException(Messages.TraceControl_CommandError + " " + command.toString() + "\n" + formatOutput(result)); //$NON-NLS-1$ //$NON-NLS-2$ + } + + // Check for action effect + Document doc = getDocumentFromStrings(result.getOutput()); + NodeList sessions = doc.getElementsByTagName(MIStrings.SESSION); + if (sessions.getLength() != 1) { + throw new ExecutionException(NLS.bind(Messages.TraceControl_MiInvalidNumberOfElementError, MIStrings.SESSION)); + } + Node rawSessionName = getFirstOf(sessions.item(0).getChildNodes(), MIStrings.NAME); + if (rawSessionName == null) { + throw new ExecutionException(Messages.TraceControl_MiMissingRequiredError); + } + + // Validity check + if (!rawSessionName.getTextContent().equals(sessionName)) { + throw new ExecutionException(NLS.bind(Messages.TraceControl_UnexpectedValueError, rawSessionName.getTextContent(), sessionName)); + } } @Override