tmf: lttngControl: mi: handle error via errorOutput
authorJonathan Rajotte Julien <jonathan.rajotte-julien@ericsson.com>
Mon, 11 Aug 2014 13:22:14 +0000 (09:22 -0400)
committerBernd Hufmann <bernd.hufmann@ericsson.com>
Wed, 27 Aug 2014 15:34:22 +0000 (11:34 -0400)
Change-Id: Ic54b1dae3013b445ca5f47732a8a22f11f1b0389
Signed-off-by: Jonathan Rajotte Julien <jonathan.rajotte-julien@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/31393
Tested-by: Hudson CI
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
org.eclipse.linuxtools.lttng2.control.ui/src/org/eclipse/linuxtools/internal/lttng2/control/ui/views/messages/Messages.java
org.eclipse.linuxtools.lttng2.control.ui/src/org/eclipse/linuxtools/internal/lttng2/control/ui/views/messages/messages.properties
org.eclipse.linuxtools.lttng2.control.ui/src/org/eclipse/linuxtools/internal/lttng2/control/ui/views/service/LTTngControlService.java
org.eclipse.linuxtools.lttng2.control.ui/src/org/eclipse/linuxtools/internal/lttng2/control/ui/views/service/LTTngControlServiceMI.java

index 9bd58c264714aa4b29f4d36f3ec4f5f47dfafec9..fd5210fa2cd0967c42fdfb5acc4f1cce6e388933 100644 (file)
@@ -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;
index b5539f11d73f2a6e7a77755c7a901c51266eaf39..f826ea378918573f914d22d45cbc795151f204d2 100644 (file)
@@ -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
index d734b2076f15ec4e50b6f55c60c12154b0cc9608..1e8d8335736c52dedd162bfd85ca151eaf13eb49 100644 (file)
@@ -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 <session_name> 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<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;
@@ -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 <sessionName> destroyed
+        // Session <sessionName> destroyed
     }
 
     @Override
@@ -638,7 +648,7 @@ public class LTTngControlService implements ILttngControlService {
 
         executeCommand(command.toString(), monitor);
 
-        //Session <sessionName> started
+        // Session <sessionName> started
     }
 
     @Override
@@ -648,7 +658,7 @@ public class LTTngControlService implements ILttngControlService {
 
         executeCommand(command.toString(), monitor);
 
-        //Session <sessionName> stopped
+        // Session <sessionName> 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) {
index 3e72f1a8376480522d5d3a6da76fee36da09a8da..1583b1c36ce9456297a3e2255b898b9122a18150 100644 (file)
@@ -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<IBaseEventInfo> 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<IUstProviderInfo> 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
This page took 0.033146 seconds and 5 git commands to generate.