Added some more JUnit tests
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / control / service / LTTngControlService.java
index 597cbb7acc5981e202e18cd6bf2e7ee9ec348015..94290e27c7258a3c45f39b938796a7385a2bb1c4 100644 (file)
 package org.eclipse.linuxtools.lttng.ui.views.control.service;
 
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
-import java.util.regex.PatternSyntaxException;
 
 import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.core.runtime.IProgressMonitor;
@@ -25,14 +25,20 @@ import org.eclipse.linuxtools.lttng.ui.views.control.model.IBaseEventInfo;
 import org.eclipse.linuxtools.lttng.ui.views.control.model.IChannelInfo;
 import org.eclipse.linuxtools.lttng.ui.views.control.model.IDomainInfo;
 import org.eclipse.linuxtools.lttng.ui.views.control.model.IEventInfo;
+import org.eclipse.linuxtools.lttng.ui.views.control.model.IProbeEventInfo;
 import org.eclipse.linuxtools.lttng.ui.views.control.model.ISessionInfo;
 import org.eclipse.linuxtools.lttng.ui.views.control.model.IUstProviderInfo;
+import org.eclipse.linuxtools.lttng.ui.views.control.model.LogLevelType;
+import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceEventType;
+import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceLogLevel;
 import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.BaseEventInfo;
 import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.ChannelInfo;
 import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.DomainInfo;
 import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.EventInfo;
+import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.ProbeEventInfo;
 import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.SessionInfo;
 import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.UstProviderInfo;
+
 /**
  * <b><u>LTTngControlService</u></b>
  * <p>
@@ -49,100 +55,232 @@ public class LTTngControlService implements ILttngControlService {
      */
     private final static String CONTROL_COMMAND = "lttng"; //$NON-NLS-1$
     /**
-     * Command: lttng list. 
+     * Command: lttng list.
      */
     private final static String COMMAND_LIST = CONTROL_COMMAND + " list "; //$NON-NLS-1$
     /**
-     * Command to list kernel tracer information. 
+     * Command to list kernel tracer information.
      */
-    private final static String COMMAND_LIST_KERNEL = COMMAND_LIST + "-k";  //$NON-NLS-1$
+    private final static String COMMAND_LIST_KERNEL = COMMAND_LIST + "-k"; //$NON-NLS-1$
     /**
-     * Command to list user space trace information. 
+     * Command to list user space trace information.
      */
     private final static String COMMAND_LIST_UST = COMMAND_LIST + "-u";  //$NON-NLS-1$
+    /**
+     * Command to create a session. 
+     */
+    private final static String COMMAND_CREATE_SESSION = CONTROL_COMMAND + " create "; //$NON-NLS-1$
+    /**
+     * Command to destroy a session. 
+     */
+    private final static String COMMAND_DESTROY_SESSION = CONTROL_COMMAND + " destroy "; //$NON-NLS-1$
+    /**
+     * Command to destroy a session. 
+     */
+    private final static String COMMAND_START_SESSION = CONTROL_COMMAND + " start "; //$NON-NLS-1$
+    /**
+     * Command to destroy a session. 
+     */
+    private final static String COMMAND_STOP_SESSION = CONTROL_COMMAND + " stop "; //$NON-NLS-1$
+    /**
+     * Command to enable a channel. 
+     */
+    private final static String COMMAND_ENABLE_CHANNEL = CONTROL_COMMAND + " enable-channel "; //$NON-NLS-1$
+    /**
+     * Command to disable a channel. 
+     */
+    private final static String COMMAND_DISABLE_CHANNEL = CONTROL_COMMAND + " disable-channel "; //$NON-NLS-1$
+    /**
+     * Command to enable a event. 
+     */
+    private final static String COMMAND_ENABLE_EVENT = CONTROL_COMMAND + " enable-event "; //$NON-NLS-1$
+    /**
+     * Command to disable a event. 
+     */
+    private final static String COMMAND_DISABLE_EVENT = CONTROL_COMMAND + " disable-event "; //$NON-NLS-1$
 
+    // Command options constants 
+    /**
+     * Command line option for kernel tracer.
+     */
+    private final static String OPTION_KERNEL = " -k "; //$NON-NLS-1$
+    /**
+     * Command line option for UST tracer.
+     */
+    private final static String OPTION_UST = " -u "; //$NON-NLS-1$
+    /**
+     * Command line option for specifying a session.
+     */
+    private final static String OPTION_SESSION = " -s ";  //$NON-NLS-1$
+    /**
+     * Command line option for specifying a channel.
+     */
+    private final static String OPTION_CHANNEL = " -c ";  //$NON-NLS-1$
+    /**
+     * Command line option for specifying all events.
+     */
+    private final static String OPTION_ALL = " -a ";  //$NON-NLS-1$
+    /**
+     * Command line option for specifying tracepoint events.
+     */
+    private final static String OPTION_TRACEPOINT = " --tracepoint ";  //$NON-NLS-1$
+    /**
+     * Command line option for specifying syscall events.
+     */
+    private final static String OPTION_SYSCALL = " --syscall ";  //$NON-NLS-1$
+    /**
+     * Command line option for specifying a dynamic probe.
+     */
+    private final static String OPTION_PROBE = " --probe ";  //$NON-NLS-1$
+    /**
+     * Command line option for specifying a dynamic function entry/return probe.
+     */
+    private final static String OPTION_FUNCTION_PROBE = " --function ";  //$NON-NLS-1$
+    /**
+     * Command line option for specifying a log level range.
+     */
+    private final static String OPTION_LOGLEVEL = " --loglevel ";  //$NON-NLS-1$
+    /**
+     * Command line option for specifying a specific log level.
+     */
+    private final static String OPTION_LOGLEVEL_ONLY = " --loglevel-only ";  //$NON-NLS-1$
+    /**
+     * Optional command line option for configuring a channel's overwrite mode.
+     */
+    private final static String OPTION_OVERWRITE = " --overwrite ";  //$NON-NLS-1$ 
+    /**
+     * Optional command line option for configuring a channel's number of sub buffers.
+     */
+    private final static String OPTION_NUM_SUB_BUFFERS = " --num-subbuf ";  //$NON-NLS-1$
+    /**
+     * Optional command line option for configuring a channel's sub buffer size.
+     */
+    private final static String OPTION_SUB_BUFFER_SIZE = " --subbuf-size ";  //$NON-NLS-1$
+    /**
+     * Optional command line option for configuring a channel's switch timer interval.
+     */
+    private final static String OPTION_SWITCH_TIMER = " --switch-timer ";  //$NON-NLS-1$
+    /**
+     * Optional command line option for configuring a channel's read timer interval.
+     */
+    private final static String OPTION_READ_TIMER = " --read-timer ";  //$NON-NLS-1$
+    
     // Parsing constants
     /**
      * Pattern to match for error output
      */
-    private final static String ERROR_PATTERN = "\\s*Error\\:.*"; //$NON-NLS-1$
+    private final static Pattern ERROR_PATTERN = Pattern.compile("\\s*Error\\:.*"); //$NON-NLS-1$
     /**
      * Pattern to match for session information (lttng list)
      */
-    private final static String SESSION_PATTERN = "\\s+(\\d+)\\)\\s+(.*)\\s+\\((.*)\\)\\s+\\[(active|inactive)\\].*"; //$NON-NLS-1$
+    private final static Pattern SESSION_PATTERN = Pattern.compile("\\s+(\\d+)\\)\\s+(.*)\\s+\\((.*)\\)\\s+\\[(active|inactive)\\].*"); //$NON-NLS-1$
     /**
      * Pattern to match for session information (lttng list <session>)
      */
-    private final static String TRACE_SESSION_PATTERN = "\\s*Tracing\\s+session\\s+(.*)\\:\\s+\\[(active|inactive)\\].*"; //$NON-NLS-1$
+    private final static Pattern TRACE_SESSION_PATTERN = Pattern.compile("\\s*Tracing\\s+session\\s+(.*)\\:\\s+\\[(active|inactive)\\].*"); //$NON-NLS-1$
     /**
      * Pattern to match for session path information (lttng list <session>)
      */
-    private final static String TRACE_SESSION_PATH_PATTERN = "\\s*Trace\\s+path\\:\\s+(.*)"; //$NON-NLS-1$
+    private final static Pattern TRACE_SESSION_PATH_PATTERN = Pattern.compile("\\s*Trace\\s+path\\:\\s+(.*)"); //$NON-NLS-1$
     /**
      * Pattern to match for kernel domain information (lttng list <session>)
      */
-    private final static String DOMAIN_KERNEL_PATTERN = "=== Domain: Kernel ==="; //$NON-NLS-1$
+    private final static Pattern DOMAIN_KERNEL_PATTERN = Pattern.compile("=== Domain: Kernel ==="); //$NON-NLS-1$
     /**
      * Pattern to match for ust domain information (lttng list <session>)
      */
-    private final static String DOMAIN_UST_GLOBAL_PATTERN = "=== Domain: UST global ==="; //$NON-NLS-1$
+    private final static Pattern DOMAIN_UST_GLOBAL_PATTERN = Pattern.compile("=== Domain: UST global ==="); //$NON-NLS-1$
     /**
      * Pattern to match for channels section (lttng list <session>)
      */
-    private final static String CHANNELS_SECTION_PATTERN = "\\s*Channels\\:";  //$NON-NLS-1$
+    private final static Pattern CHANNELS_SECTION_PATTERN = Pattern.compile("\\s*Channels\\:"); //$NON-NLS-1$
     /**
      * Pattern to match for channel information (lttng list <session>)
      */
-    private final static String CHANNEL_PATTERN = "\\s*-\\s+(.*)\\:\\s+\\[(enabled|disabled)\\]"; //$NON-NLS-1$
+    private final static Pattern CHANNEL_PATTERN = Pattern.compile("\\s*-\\s+(.*)\\:\\s+\\[(enabled|disabled)\\]"); //$NON-NLS-1$
     /**
      * Pattern to match for events section information (lttng list <session>)
      */
-    private final static String EVENT_SECTION_PATTERN = "\\s*Events\\:"; //$NON-NLS-1$
+    private final static Pattern EVENT_SECTION_PATTERN = Pattern.compile("\\s*Events\\:"); //$NON-NLS-1$
     /**
      * Pattern to match for event information (no enabled events) (lttng list <session>)
      */
-//    private final static String EVENT_NONE_PATTERN = "\\s+None"; //$NON-NLS-1$
+    //    private final static String EVENT_NONE_PATTERN = "\\s+None"; //$NON-NLS-1$
     /**
      * Pattern to match for event information (lttng list <session>)
      */
-    private final static String EVENT_PATTERN = "\\s+(.*)\\s+\\(loglevel:\\s+(.*)\\)\\s+\\(type:\\s+(.*)\\)\\s+\\[(enabled|disabled)\\].*"; //$NON-NLS-1$
+    private final static Pattern EVENT_PATTERN = Pattern.compile("\\s+(.*)\\s+\\(loglevel:\\s+(.*)\\s+\\(\\d*\\)\\)\\s+\\(type:\\s+(.*)\\)\\s+\\[(enabled|disabled)\\].*"); //$NON-NLS-1$
     /**
-     * Pattern to match for channel (overwite mode) information (lttng list <session>)
+     * Pattern to match a wildcarded event information (lttng list <session>)
      */
-    private final static String OVERWRITE_MODE_ATTRIBUTE = "\\s+overwrite\\s+mode\\:.*";  //$NON-NLS-1$
+    private final static Pattern WILDCARD_EVENT_PATTERN = Pattern.compile("\\s+(.*)\\s+\\(type:\\s+(.*)\\)\\s+\\[(enabled|disabled)\\].*"); //$NON-NLS-1$
+    /**
+     * Pattern to match a probe address information (lttng list <session>)
+     */
+    private final static Pattern PROBE_ADDRESS_PATTERN = Pattern.compile("\\s+(addr)\\:\\s+(0x[0-9a-fA-F]{1,8})"); //$NON-NLS-1$
+    /**
+     * Pattern to match a probe OFFSET information (lttng list <session>)
+     */
+    private final static Pattern PROBE_OFFSET_PATTERN = Pattern.compile("\\s+(offset)\\:\\s+(0x[0-9a-fA-F]{1,8})"); //$NON-NLS-1$
+    /**
+     * Pattern to match a probe SYMBOL information (lttng list <session>)
+     */
+    private final static Pattern PROBE_SYMBOL_PATTERN = Pattern.compile("\\s+(symbol)\\:\\s+(.+)"); //$NON-NLS-1$
+    /**
+     * Pattern to match for channel (overwite mode) information (lttng list
+     * <session>)
+     */
+    private final static Pattern OVERWRITE_MODE_ATTRIBUTE = Pattern.compile("\\s+overwrite\\s+mode\\:.*"); //$NON-NLS-1$
     /**
      * Pattern to match indicating false for overwrite mode
      */
     private final static String OVERWRITE_MODE_ATTRIBUTE_FALSE = "0"; //$NON-NLS-1$
     /**
-     * Pattern to match for channel (sub-buffer size) information (lttng list <session>)
+     * Pattern to match for channel (sub-buffer size) information (lttng list
+     * <session>)
      */
-    private final static String SUBBUFFER_SIZE_ATTRIBUTE = "\\s+subbufers\\s+size\\:.*"; //$NON-NLS-1$
+    private final static Pattern SUBBUFFER_SIZE_ATTRIBUTE = Pattern.compile("\\s+subbufers\\s+size\\:.*"); //$NON-NLS-1$
     /**
-     * Pattern to match for channel (number of sub-buffers) information (lttng list <session>)
+     * Pattern to match for channel (number of sub-buffers) information (lttng
+     * list <session>)
      */
-    private final static String NUM_SUBBUFFERS_ATTRIBUTE = "\\s+number\\s+of\\s+subbufers\\:.*"; //$NON-NLS-1$
+    private final static Pattern NUM_SUBBUFFERS_ATTRIBUTE = Pattern.compile("\\s+number\\s+of\\s+subbufers\\:.*"); //$NON-NLS-1$
     /**
-     * Pattern to match for channel (switch timer) information (lttng list <session>)
+     * Pattern to match for channel (switch timer) information (lttng list
+     * <session>)
      */
-    private final static String SWITCH_TIMER_ATTRIBUTE = "\\s+switch\\s+timer\\s+interval\\:.*"; //$NON-NLS-1$
+    private final static Pattern SWITCH_TIMER_ATTRIBUTE = Pattern.compile("\\s+switch\\s+timer\\s+interval\\:.*"); //$NON-NLS-1$
     /**
-     * Pattern to match for channel (read timer) information (lttng list <session>)
+     * Pattern to match for channel (read timer) information (lttng list
+     * <session>)
      */
-    private final static String READ_TIMER_ATTRIBUTE = "\\s+read\\s+timer\\s+interval\\:.*"; //$NON-NLS-1$
+    private final static Pattern READ_TIMER_ATTRIBUTE = Pattern.compile("\\s+read\\s+timer\\s+interval\\:.*"); //$NON-NLS-1$
     /**
-     * Pattern to match for channel (output type) information (lttng list <session>)
+     * Pattern to match for channel (output type) information (lttng list
+     * <session>)
      */
-    private final static String OUTPUT_ATTRIBUTE = "\\s+output\\:.*"; //$NON-NLS-1$
+    private final static Pattern OUTPUT_ATTRIBUTE = Pattern.compile("\\s+output\\:.*"); //$NON-NLS-1$
     /**
      * Pattern to match for provider information (lttng list -k/-u)
      */
-    private final static String PROVIDER_EVENT_PATTERN = "\\s*(.*)\\s+\\(loglevel:\\s+(.*)\\)\\s+\\(type:\\s+(.*)\\)"; //$NON-NLS-1$
+    private final static Pattern PROVIDER_EVENT_PATTERN = Pattern.compile("\\s*(.*)\\s+\\(loglevel:\\s+(.*)\\s+\\(\\d*\\)\\)\\s+\\(type:\\s+(.*)\\)"); //$NON-NLS-1$
     /**
      * Pattern to match for UST provider information (lttng list -u)
-     */   
-    private final static String UST_PROVIDER_PATTERN = "\\s*PID\\:\\s+(\\d+)\\s+-\\s+Name\\:\\s+(.*)"; //$NON-NLS-1$
-
+     */
+    private final static Pattern UST_PROVIDER_PATTERN = Pattern.compile("\\s*PID\\:\\s+(\\d+)\\s+-\\s+Name\\:\\s+(.*)"); //$NON-NLS-1$
+    /**
+     * Pattern to match for session information (lttng create <session name>)
+     */
+    private final static Pattern CREATE_SESSION_NAME_PATTERN = Pattern.compile("\\s*Session\\s+(.*)\\s+created\\."); //$NON-NLS-1$
+    /**
+     * Pattern to match for session path information (lttng create <session name>)
+     */
+    private final static Pattern CREATE_SESSION_PATH_PATTERN = Pattern.compile("\\s*Traces\\s+will\\s+be\\s+written\\s+in\\s+(.*).*"); //$NON-NLS-1$
+    /**
+     * Pattern to match for session command output for "session name not found".
+     */
+    private final static Pattern SESSION_NOT_FOUND_ERROR_PATTERN = Pattern.compile("\\s*Error:\\s+Session\\s+name\\s+not\\s+found"); //$NON-NLS-1$
+    
     // ------------------------------------------------------------------------
     // Attributes
     // ------------------------------------------------------------------------
@@ -157,85 +295,71 @@ public class LTTngControlService implements ILttngControlService {
 
     /**
      * Constructor
-     * @param shell - the command shell implementation to use
+     * 
+     * @param shell
+     *            - the command shell implementation to use
      */
     public LTTngControlService(ICommandShell shell) {
         fCommandShell = shell;
     }
+
     // ------------------------------------------------------------------------
     // Operations
-    // ------------------------------------------------------------------------  
-
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#getSessionNames()
-     */
-    @Override
-    public String[] getSessionNames() throws ExecutionException {
-        return getSessionNames(new NullProgressMonitor());
-    }
+    // ------------------------------------------------------------------------
 
     /*
      * (non-Javadoc)
-     * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#getSessionNames(org.eclipse.core.runtime.IProgressMonitor)
+     * 
+     * @see
+     * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService
+     * #getSessionNames(org.eclipse.core.runtime.IProgressMonitor)
      */
     @Override
     public String[] getSessionNames(IProgressMonitor monitor) throws ExecutionException {
 
-      String command = COMMAND_LIST;
-      ICommandResult result = fCommandShell.executeCommand(command, monitor);
-
-      if (isError(result)) {
-          // TODO: no session available shouldn't be an error!
-          if (result.getOutput().length > 0 && result.getOutput()[0].matches(ERROR_PATTERN)) {
-              // no sessions available
-              return new String[0];
-          }
-          throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
-      }
-
-      // Output:
-      // Available tracing sessions:
-      //   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 
-      
-      ArrayList<String> retArray = new ArrayList<String>();
-      int index = 0;
-      while (index < result.getOutput().length) {
-          String line = result.getOutput()[index];
-          try {
-              Pattern pattern = Pattern.compile(SESSION_PATTERN);
-              Matcher matcher = pattern.matcher(line);
-              if (matcher.matches()) {
-                  retArray.add(matcher.group(2).trim());
-              }
-          } catch (PatternSyntaxException e) {
-          }
-          index++;
-      }
-      return retArray.toArray(new String[retArray.size()]);
-    }
+        String command = COMMAND_LIST;
+        ICommandResult result = fCommandShell.executeCommand(command, monitor);
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#getSession(java.lang.String)
-     */
-    @Override
-    public ISessionInfo getSession(String sessionName) throws ExecutionException {
-        return getSession(sessionName, new NullProgressMonitor());
+        if (isError(result)) {
+            throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
+        }
+
+        // Output:
+        // Available tracing sessions:
+        // 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
+
+        ArrayList<String> retArray = new ArrayList<String>();
+        int index = 0;
+        while (index < result.getOutput().length) {
+            String line = result.getOutput()[index];
+            Matcher matcher = SESSION_PATTERN.matcher(line);
+            if (matcher.matches()) {
+                retArray.add(matcher.group(2).trim());
+            }
+            index++;
+        }
+        return retArray.toArray(new String[retArray.size()]);
     }
 
     /*
      * (non-Javadoc)
-     * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#getSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
+     * 
+     * @see
+     * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService
+     * #getSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
      */
     @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$
         }
@@ -243,77 +367,76 @@ public class LTTngControlService implements ILttngControlService {
         int index = 0;
 
         // Output:
-        //   Tracing session mysession2: [inactive]
-        //   Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
+        // Tracing session mysession2: [inactive]
+        // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
         ISessionInfo sessionInfo = new SessionInfo(sessionName);
 
-        try {
-            while (index < result.getOutput().length) {
-                //   Tracing session mysession2: [inactive]
-                //   Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
-                //
-                //    === Domain: Kernel ===
-                //
-                String line = result.getOutput()[index];
-                if (line.matches(TRACE_SESSION_PATTERN)) {
-                    Pattern pattern = Pattern.compile(TRACE_SESSION_PATTERN);
-                    Matcher matcher = pattern.matcher(line);
-                    if (matcher.matches()) {
-                        sessionInfo.setSessionState(matcher.group(2));
-                    }
-                    index++;
-                } else if (line.matches(TRACE_SESSION_PATH_PATTERN)) {
-                    Pattern pattern = Pattern.compile(TRACE_SESSION_PATH_PATTERN);
-                    Matcher matcher = pattern.matcher(line);
-                    if (matcher.matches()) {
-                        sessionInfo.setSessionPath(matcher.group(1).trim());
-                    }
-                    index++;
-                }
-                else if (line.matches(DOMAIN_KERNEL_PATTERN)) {
-                    // Create Domain
-                    IDomainInfo domainInfo = new DomainInfo(Messages.TraceControl_KernelDomainDisplayName);
-                    sessionInfo.addDomain(domainInfo);
+        while (index < result.getOutput().length) {
+            // Tracing session mysession2: [inactive]
+            // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330
+            //
+            // === Domain: Kernel ===
+            //
+            String line = result.getOutput()[index];
+            Matcher matcher = TRACE_SESSION_PATTERN.matcher(line);
+            if (matcher.matches()) {
+                sessionInfo.setSessionState(matcher.group(2));
+                index++;
+                continue;
+            }
 
-                    // in domain kernel
-                    ArrayList<IChannelInfo> channels = new ArrayList<IChannelInfo>();
-                    index = parseDomain(result.getOutput(), index, channels);
+            matcher = TRACE_SESSION_PATH_PATTERN.matcher(line);
+            if (matcher.matches()) {
+                sessionInfo.setSessionPath(matcher.group(1).trim());
+                index++;
+                continue;
+            }
 
-                    // set channels
-                    domainInfo.setChannels(channels);
+            matcher = DOMAIN_KERNEL_PATTERN.matcher(line);
+            if (matcher.matches()) {
+                // Create Domain
+                IDomainInfo domainInfo = new DomainInfo(Messages.TraceControl_KernelDomainDisplayName);
+                sessionInfo.addDomain(domainInfo);
 
-                } else if (line.contains(DOMAIN_UST_GLOBAL_PATTERN)) {
-                    IDomainInfo domainInfo = new DomainInfo(Messages.TraceControl_UstGlobalDomainDisplayName);
-                    sessionInfo.addDomain(domainInfo);
+                // in domain kernel
+                ArrayList<IChannelInfo> channels = new ArrayList<IChannelInfo>();
+                index = parseDomain(result.getOutput(), index, channels);
 
-                    // in domain kernel
-                    ArrayList<IChannelInfo> channels = new ArrayList<IChannelInfo>();
-                    index = parseDomain(result.getOutput(), index, channels);
+                // set channels
+                domainInfo.setChannels(channels);
+                
+                // set kernel flag
+                domainInfo.setIsKernel(true);
+                continue;
+            }
 
-                    // set channels
-                    domainInfo.setChannels(channels);
-                } else {
-                    index++;
-                }
+            matcher = DOMAIN_UST_GLOBAL_PATTERN.matcher(line);
+            if (matcher.matches()) {
+                IDomainInfo domainInfo = new DomainInfo(Messages.TraceControl_UstGlobalDomainDisplayName);
+                sessionInfo.addDomain(domainInfo);
+
+                // in domain UST
+                ArrayList<IChannelInfo> channels = new ArrayList<IChannelInfo>();
+                index = parseDomain(result.getOutput(), index, channels);
+
+                // set channels
+                domainInfo.setChannels(channels);
+                
+                // set kernel flag
+                domainInfo.setIsKernel(false);
+                continue;
             }
-        } catch (PatternSyntaxException e) {
-            throw new ExecutionException("Invalid regular expression", e); //$NON-NLS-1$
-        }   
+            index++;
+        }
         return sessionInfo;
     }
-    
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#getKernelProvider()
-     */
-    @Override
-    public List<IBaseEventInfo> getKernelProvider() throws ExecutionException {
-        return getKernelProvider(new NullProgressMonitor());
-    }
-    
+
     /*
      * (non-Javadoc)
-     * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#getKernelProvider(org.eclipse.core.runtime.IProgressMonitor)
+     * 
+     * @see
+     * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService
+     * #getKernelProvider(org.eclipse.core.runtime.IProgressMonitor)
      */
     @Override
     public List<IBaseEventInfo> getKernelProvider(IProgressMonitor monitor) throws ExecutionException {
@@ -322,10 +445,10 @@ public class LTTngControlService implements ILttngControlService {
         if (isError(result)) {
             throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
         }
-        
-//        Kernel events:
-//        -------------
-//        sched_kthread_stop (type: tracepoint)
+
+        // Kernel events:
+        // -------------
+        // sched_kthread_stop (type: tracepoint)
         List<IBaseEventInfo> events = new ArrayList<IBaseEventInfo>();
         getProviderEventInfo(result.getOutput(), 0, events);
         return events;
@@ -333,16 +456,22 @@ public class LTTngControlService implements ILttngControlService {
 
     /*
      * (non-Javadoc)
-     * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#getUstProvider()
+     * 
+     * @see
+     * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService
+     * #getUstProvider()
      */
     @Override
     public List<IUstProviderInfo> getUstProvider() throws ExecutionException {
         return getUstProvider(new NullProgressMonitor());
     }
-    
+
     /*
      * (non-Javadoc)
-     * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#getUstProvider(org.eclipse.core.runtime.IProgressMonitor)
+     * 
+     * @see
+     * org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService
+     * #getUstProvider(org.eclipse.core.runtime.IProgressMonitor)
      */
     @Override
     public List<IUstProviderInfo> getUstProvider(IProgressMonitor monitor) throws ExecutionException {
@@ -352,65 +481,493 @@ public class LTTngControlService implements ILttngControlService {
         if (isError(result)) {
             throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
         }
-        
-//      UST events:
-//      -------------
-//
-//      PID: 3635 - 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)
-//        
-//      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)
+
+        // UST events:
+        // -------------
+        //
+        // PID: 3635 - 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)
+        //
+        // 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)
 
         List<IUstProviderInfo> allProviders = new ArrayList<IUstProviderInfo>();
         IUstProviderInfo provider = null;
-        
+
         int index = 0;
         while (index < result.getOutput().length) {
             String line = result.getOutput()[index];
-            if (line.matches(UST_PROVIDER_PATTERN)) {
-                Pattern pattern = Pattern.compile(UST_PROVIDER_PATTERN);
+            Matcher matcher = UST_PROVIDER_PATTERN.matcher(line);
+            if (matcher.matches()) {
 
-                Matcher matcher = pattern.matcher(line);
-
-                if (matcher.matches()) {
-
-                    provider = new UstProviderInfo(matcher.group(2).trim());
-                    provider.setPid(Integer.valueOf(matcher.group(1).trim()));
-                    List<IBaseEventInfo> events = new ArrayList<IBaseEventInfo>();        
-                    index = getProviderEventInfo(result.getOutput(), ++index, events);
-                    provider.setEvents(events);
-                    allProviders.add(provider);
-                }
+                provider = new UstProviderInfo(matcher.group(2).trim());
+                provider.setPid(Integer.valueOf(matcher.group(1).trim()));
+                List<IBaseEventInfo> events = new ArrayList<IBaseEventInfo>();
+                index = getProviderEventInfo(result.getOutput(), ++index, events);
+                provider.setEvents(events);
+                allProviders.add(provider);
 
             } else {
                 index++;
             }
-            
+
         }
         return allProviders;
     }
 
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.linuxtools.lttng.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 {
+
+        String newName = formatParameter(sessionName);
+        String newPath = formatParameter(sessionPath);
+
+        String command = COMMAND_CREATE_SESSION + newName;
+        if (newPath != null && !"".equals(newPath)) { //$NON-NLS-1$
+            command += " -o " + newPath; //$NON-NLS-1$
+        }
+
+        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$
+        }
+        //Session myssession2 created.
+        //Traces will be written in /home/user/lttng-traces/myssession2-20120209-095418
+        String[] output = result.getOutput();
+        
+        // Get and verify session name
+        Matcher matcher = CREATE_SESSION_NAME_PATTERN.matcher(output[0]);
+        String name = 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_UnexpectedCommnadOutputFormat + ":\n" + //$NON-NLS-1$ 
+                    formatOutput(result.getOutput())); 
+        }
+
+        if ((name == null) || (!name.equals(sessionName))) {
+            // Unexpected name returned
+            throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$ 
+                    Messages.TraceControl_UnexpectedNameError + ": " + name); //$NON-NLS-1$ 
+        }
+        
+        // Get and verify session path
+        matcher = 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_UnexpectedCommnadOutputFormat + ":\n" + //$NON-NLS-1$ 
+                    formatOutput(result.getOutput())); 
+        }
+
+        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 sessionInfo = new SessionInfo(name);
+        sessionInfo.setSessionPath(path);
+
+        return sessionInfo;
+    }
+    
+    @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);
+        String[] output = result.getOutput();
+        
+        if (isError(result)) {
+            // In case "session not found" treat it as success 
+            if ((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$
+            }
+        }
+        //Session <sessionName> destroyed
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#startSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
+     */
+    @Override
+    public void startSession(String sessionName, IProgressMonitor monitor) throws ExecutionException {
+
+        String newSessionName = formatParameter(sessionName);
+
+        String command = COMMAND_START_SESSION + newSessionName;
+
+        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$
+        }
+        //Session <sessionName> started
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.linuxtools.lttng.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);
+        String command = COMMAND_STOP_SESSION + newSessionName;
+
+        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$
+        }
+        //Session <sessionName> stopped
+        
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#enableChannel(java.lang.String, java.util.List, boolean, org.eclipse.linuxtools.lttng.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 {
+
+        // no channels to enable
+        if (channelNames.size() == 0) {
+            return;
+        }
+
+        String newSessionName = formatParameter(sessionName);
+        
+        StringBuffer command = new StringBuffer(COMMAND_ENABLE_CHANNEL);
+
+        for (Iterator<String> iterator = channelNames.iterator(); iterator.hasNext();) {
+            String channel = (String) iterator.next();
+            command.append(channel);
+            if (iterator.hasNext()) {
+                command.append(","); //$NON-NLS-1$
+            }
+        }
+
+        if (isKernel) {
+            command.append(OPTION_KERNEL);
+        } else {
+            command.append(OPTION_UST);
+        }
+
+        command.append(OPTION_SESSION);
+        command.append(newSessionName);
+
+        if (info != null) {
+//            --discard            Discard event when buffers are full (default)
+
+//            --overwrite          Flight recorder mode
+            if (info.isOverwriteMode()) {
+                command.append(OPTION_OVERWRITE);
+            }
+//            --subbuf-size SIZE   Subbuffer size in bytes
+//                                     (default: 4096, kernel default: 262144)
+            command.append(OPTION_SUB_BUFFER_SIZE);
+            command.append(String.valueOf(info.getSubBufferSize()));
+
+//            --num-subbuf NUM     Number of subbufers
+//                                     (default: 8, kernel default: 4)
+            command.append(OPTION_NUM_SUB_BUFFERS);
+            command.append(String.valueOf(info.getNumberOfSubBuffers()));
+            
+//            --switch-timer USEC  Switch timer interval in usec (default: 0)
+            command.append(OPTION_SWITCH_TIMER);
+            command.append(String.valueOf(info.getSwitchTimer()));
+
+//            --read-timer USEC    Read timer interval in usec (default: 200)
+            command.append(OPTION_READ_TIMER);
+            command.append(String.valueOf(info.getReadTimer()));
+        } 
+
+        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$
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.linuxtools.lttng.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 {
+        
+        // no channels to enable
+        if (channelNames.size() == 0) {
+            return;
+        }
+
+        String newSessionName = formatParameter(sessionName);
+        
+        StringBuffer command = new StringBuffer(COMMAND_DISABLE_CHANNEL);
+
+        for (Iterator<String> iterator = channelNames.iterator(); iterator.hasNext();) {
+            String channel = (String) iterator.next();
+            command.append(channel);
+            if (iterator.hasNext()) {
+                command.append(","); //$NON-NLS-1$
+            }
+        }
+
+        if (isKernel) {
+            command.append(OPTION_KERNEL);
+        } else {
+            command.append(OPTION_UST);
+        }
+
+        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$
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.linuxtools.lttng.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);
+
+        if (eventNames == null || eventNames.size() == 0) {
+            command.append(OPTION_ALL);
+        } else {
+
+            for (Iterator<String> iterator = eventNames.iterator(); iterator.hasNext();) {
+                String event = (String) iterator.next();
+                command.append(event);
+                if (iterator.hasNext()) {
+                    command.append(","); //$NON-NLS-1$
+                }
+            }
+        }
+
+        if (isKernel) {
+            command.append(OPTION_KERNEL);
+        } else {
+            command.append(OPTION_UST);
+        }
+
+        command.append(OPTION_SESSION);
+        command.append(newSessionName);
+
+        if (channelName != null) {
+            command.append(OPTION_CHANNEL);
+            command.append(channelName);
+        }
+        
+        command.append(OPTION_TRACEPOINT);
+        
+        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$
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.linuxtools.lttng.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 {
+        String newSessionName = formatParameter(sessionName);
+        
+        StringBuffer command = new StringBuffer(COMMAND_ENABLE_EVENT);
+
+        command.append(OPTION_ALL);
+        command.append(OPTION_KERNEL);
+
+        command.append(OPTION_SESSION);
+        command.append(newSessionName);
+
+        if (channelName != null) {
+            command.append(OPTION_CHANNEL);
+            command.append(channelName);
+        }
+        
+        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$
+        }        
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.linuxtools.lttng.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 {
+        String newSessionName = formatParameter(sessionName);
+        
+        StringBuffer command = new StringBuffer(COMMAND_ENABLE_EVENT);
+
+        command.append(eventName);
+        command.append(OPTION_KERNEL);
+
+        command.append(OPTION_SESSION);
+        command.append(newSessionName);
+
+        if (channelName != null) {
+            command.append(OPTION_CHANNEL);
+            command.append(channelName);
+        }
+        if (isFunction) {
+            command.append(OPTION_FUNCTION_PROBE);
+        } else {
+            command.append(OPTION_PROBE);
+        }
+        
+        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$
+        }        
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#enableLogLevel(java.lang.String, java.lang.String, java.lang.String, org.eclipse.linuxtools.lttng.ui.views.control.model.LogLevelType, org.eclipse.linuxtools.lttng.ui.views.control.model.TraceLogLevel, org.eclipse.core.runtime.IProgressMonitor)
+     */
+    @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);
+
+        command.append(eventName);
+        command.append(OPTION_UST);
+
+        command.append(OPTION_SESSION);
+        command.append(newSessionName);
+
+        if (channelName != null) {
+            command.append(OPTION_CHANNEL);
+            command.append(channelName);
+        }
+        
+        if (logLevelType == LogLevelType.LOGLEVEL) {
+            command.append(OPTION_LOGLEVEL);
+        } else if (logLevelType == LogLevelType.LOGLEVEL_ONLY) {
+            command.append(OPTION_LOGLEVEL_ONLY);
+            
+        } else {
+            return;
+        }
+        command.append(level.getInName());
+        
+        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$
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.linuxtools.lttng.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 {
+        String newSessionName = formatParameter(sessionName);
+
+        StringBuffer command = new StringBuffer(COMMAND_DISABLE_EVENT);
+        if (eventNames == null) {
+            command.append(OPTION_ALL);
+        } else {
+            // no events to enable
+            if (eventNames.size() == 0) {
+                return;
+            }
+
+            for (Iterator<String> iterator = eventNames.iterator(); iterator.hasNext();) {
+                String event = (String) iterator.next();
+                command.append(event);
+                if (iterator.hasNext()) {
+                    command.append(","); //$NON-NLS-1$
+                }
+            }
+        }
+
+        if (isKernel) {
+            command.append(OPTION_KERNEL);
+        } else {
+            command.append(OPTION_UST);
+        }
+
+        command.append(OPTION_SESSION);
+        command.append(newSessionName);
+
+        if (channelName != null) {
+            command.append(OPTION_CHANNEL);
+            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$
+        }
+    }
+    
     // ------------------------------------------------------------------------
     // Helper methods
     // ------------------------------------------------------------------------
     /**
      * Checks if command result is an error result.
-     * @param result - the command result to check
+     * 
+     * @param result
+     *            - the command result to check
      * @return true if error else false
      */
     private boolean isError(ICommandResult result) {
-        if ((result.getResult()) != 0 || (result.getOutput().length < 1 || result.getOutput()[0].matches(ERROR_PATTERN))) {
+        if ((result.getResult()) != 0 || (result.getOutput().length < 1 || ERROR_PATTERN.matcher(result.getOutput()[0]).matches())) {
             return true;
         }
         return false;
     }
-    
+
     /**
      * Formats the output string as single string.
-     * @param output - output array
+     * 
+     * @param output
+     *            - output array
      * @return - the formatted output
      */
     private String formatOutput(String[] output) {
@@ -424,81 +981,83 @@ public class LTTngControlService implements ILttngControlService {
         }
         return ret.toString();
     }
-    
+
     /**
      * Parses the domain information.
      * 
-     * @param output - a command output array
-     * @param currentIndex - current index in command output array
-     * @param channels - list for returning channel information
-     * @return the new current index in command output array 
-     * @throws PatternSyntaxException
+     * @param output
+     *            - a command output array
+     * @param currentIndex
+     *            - current index in command output array
+     * @param channels
+     *            - list for returning channel information
+     * @return the new current index in command output array
      */
-    private int parseDomain(String[] output, int currentIndex, List<IChannelInfo> channels) throws PatternSyntaxException {
+    private int parseDomain(String[] output, int currentIndex, List<IChannelInfo> channels) {
         int index = currentIndex;
 
-//      Channels:
-//      -------------
-//      - channnel1: [enabled]
-//
-//          Attributes:
-//            overwrite mode: 0
-//            subbufers size: 262144
-//            number of subbufers: 4
-//            switch timer interval: 0
-//            read timer interval: 200
-//            output: splice()
-       
+        // Channels:
+        // -------------
+        // - channnel1: [enabled]
+        //
+        // Attributes:
+        // overwrite mode: 0
+        // subbufers size: 262144
+        // number of subbufers: 4
+        // switch timer interval: 0
+        // read timer interval: 200
+        // output: splice()
+
         while (index < output.length) {
             String line = output[index];
-            if (line.matches(CHANNELS_SECTION_PATTERN)) {
+
+            Matcher outerMatcher = CHANNELS_SECTION_PATTERN.matcher(line);
+            if (outerMatcher.matches()) {
                 IChannelInfo channelInfo = null;
                 while (index < output.length) {
                     String subLine = output[index];
-                    if (subLine.matches(CHANNEL_PATTERN)) {
-                        
-                        Pattern pattern = Pattern.compile(CHANNEL_PATTERN);
-                        Matcher matcher = pattern.matcher(subLine);
+
+                    Matcher innerMatcher = CHANNEL_PATTERN.matcher(subLine);
+                    if (innerMatcher.matches()) {
                         channelInfo = new ChannelInfo(""); //$NON-NLS-1$
-                        if (matcher.matches()) {
-                            // get channel name
-                            channelInfo.setName(matcher.group(1));
-                            
-                            // get channel enablement
-                            channelInfo.setState(matcher.group(2));
-
-                            // add channel
-                            channels.add(channelInfo);
-                        }
-                    } else if (subLine.matches(OVERWRITE_MODE_ATTRIBUTE)) {
+                        // get channel name
+                        channelInfo.setName(innerMatcher.group(1));
+
+                        // get channel enablement
+                        channelInfo.setState(innerMatcher.group(2));
+
+                        // add channel
+                        channels.add(channelInfo);
+
+                    } else if (OVERWRITE_MODE_ATTRIBUTE.matcher(subLine).matches()) {
                         String value = getAttributeValue(subLine);
                         channelInfo.setOverwriteMode(!OVERWRITE_MODE_ATTRIBUTE_FALSE.equals(value));
-                    } else if (subLine.matches(SUBBUFFER_SIZE_ATTRIBUTE)) {
+                    } else if (SUBBUFFER_SIZE_ATTRIBUTE.matcher(subLine).matches()) {
                         channelInfo.setSubBufferSize(Long.valueOf(getAttributeValue(subLine)));
-                        
-                    } else if (subLine.matches(NUM_SUBBUFFERS_ATTRIBUTE)) {
+
+                    } else if (NUM_SUBBUFFERS_ATTRIBUTE.matcher(subLine).matches()) {
                         channelInfo.setNumberOfSubBuffers(Integer.valueOf(getAttributeValue(subLine)));
-                        
-                    } else if (subLine.matches(SWITCH_TIMER_ATTRIBUTE)) {
+
+                    } else if (SWITCH_TIMER_ATTRIBUTE.matcher(subLine).matches()) {
                         channelInfo.setSwitchTimer(Long.valueOf(getAttributeValue(subLine)));
-                        
-                    } else if (subLine.matches(READ_TIMER_ATTRIBUTE)) {
+
+                    } else if (READ_TIMER_ATTRIBUTE.matcher(subLine).matches()) {
                         channelInfo.setReadTimer(Long.valueOf(getAttributeValue(subLine)));
-                        
-                    } else if (subLine.matches(OUTPUT_ATTRIBUTE)) {
+
+                    } else if (OUTPUT_ATTRIBUTE.matcher(subLine).matches()) {
                         channelInfo.setOutputType(getAttributeValue(subLine));
-                        
-                    } else if (subLine.matches(EVENT_SECTION_PATTERN)) {
-                        List<IEventInfo> events = new ArrayList<IEventInfo>(); 
+
+                    } else if (EVENT_SECTION_PATTERN.matcher(subLine).matches()) {
+                        List<IEventInfo> events = new ArrayList<IEventInfo>();
                         index = parseEvents(output, index, events);
                         channelInfo.setEvents(events);
-                        // we want to stay at the current index to be able to exit the domain
+                        // we want to stay at the current index to be able to
+                        // exit the domain
                         continue;
-                    }
-                    else if (subLine.matches(DOMAIN_KERNEL_PATTERN)) {
+                    } else if (DOMAIN_KERNEL_PATTERN.matcher(subLine).matches()) {
                         return index;
 
-                    } else if (subLine.contains(DOMAIN_UST_GLOBAL_PATTERN)) {
+                    } else if (DOMAIN_UST_GLOBAL_PATTERN.matcher(subLine).matches()) {
                         return index;
                     }
                     index++;
@@ -512,43 +1071,102 @@ public class LTTngControlService implements ILttngControlService {
     /**
      * Parses the event information within a domain.
      * 
-     * @param output - a command output array
-     * @param currentIndex - current index in command output array
-     * @param events - list for returning event information
+     * @param output
+     *            - a command output array
+     * @param currentIndex
+     *            - current index in command output array
+     * @param events
+     *            - list for returning event information
      * @return the new current index in command output array
-     * @throws PatternSyntaxException
      */
-    private int parseEvents(String[] output, int currentIndex, List<IEventInfo> events) throws PatternSyntaxException {
+    private int parseEvents(String[] output, int currentIndex, List<IEventInfo> events) {
         int index = currentIndex;
 
         while (index < output.length) {
             String line = output[index];
-            if (line.matches(CHANNEL_PATTERN)) {
+            if (CHANNEL_PATTERN.matcher(line).matches()) {
                 // end of channel
                 return index;
-            } else if (line.matches(DOMAIN_KERNEL_PATTERN)) {
+            } else if (DOMAIN_KERNEL_PATTERN.matcher(line).matches()) {
                 // end of domain
                 return index;
-            } else if (line.contains(DOMAIN_UST_GLOBAL_PATTERN)) {
+            } else if (DOMAIN_UST_GLOBAL_PATTERN.matcher(line).matches()) {
                 // end of domain
                 return index;
-            } else if (line.matches(EVENT_PATTERN)) {
-                Pattern pattern = Pattern.compile(EVENT_PATTERN);
+            } 
 
-                Matcher matcher = pattern.matcher(line);
+            Matcher matcher = EVENT_PATTERN.matcher(line);
+            Matcher matcher2 = WILDCARD_EVENT_PATTERN.matcher(line);
 
-                if (matcher.matches()) {
-                    IEventInfo eventInfo = new EventInfo(matcher.group(1).trim());
-                    eventInfo.setLogLevel(matcher.group(2).trim());
-                    eventInfo.setEventType(matcher.group(3).trim());
-                    eventInfo.setState(matcher.group(4));
+            if (matcher.matches()) {
+                IEventInfo eventInfo = new EventInfo(matcher.group(1).trim());
+                eventInfo.setLogLevel(matcher.group(2).trim());
+                eventInfo.setEventType(matcher.group(3).trim());
+                eventInfo.setState(matcher.group(4));
+                events.add(eventInfo);
+                index++;
+            } else if (matcher2.matches()) {
+                IEventInfo eventInfo = new EventInfo(matcher2.group(1).trim());
+                eventInfo.setLogLevel(TraceLogLevel.LEVEL_UNKNOWN);
+                eventInfo.setEventType(matcher2.group(2).trim());
+                eventInfo.setState(matcher2.group(3));
+                
+                if (eventInfo.getEventType() == TraceEventType.PROBE) {
+                    IProbeEventInfo probeEvent = new ProbeEventInfo(eventInfo.getName());
+                    probeEvent.setLogLevel(eventInfo.getLogLevel());
+                    probeEvent.setEventType(eventInfo.getEventType());
+                    probeEvent.setState(eventInfo.getState());
+
+                    // Overwrite eventinfo
+                    eventInfo = probeEvent;
+
+                    // myevent2 (type: probe) [enabled]
+                    // addr: 0xc0101340
+                    // myevent0 (type: probe) [enabled]
+                    // offset: 0x0
+                    // symbol: init_post
+                    index++;
+                    while (index < output.length) {
+                        String probeLine = output[index];
+                        // parse probe
+                        Matcher addrMatcher = PROBE_ADDRESS_PATTERN.matcher(probeLine);
+                        Matcher offsetMatcher = PROBE_OFFSET_PATTERN.matcher(probeLine);
+                        Matcher symbolMatcher = PROBE_SYMBOL_PATTERN.matcher(probeLine);
+                        if (addrMatcher.matches()) {
+                            String addr = addrMatcher.group(2).trim();
+                            probeEvent.setAddress(addr);
+                        } else if (offsetMatcher.matches()) {
+                            String offset = offsetMatcher.group(2).trim();
+                            probeEvent.setOffset(offset);
+                        } else if (symbolMatcher.matches()) {
+                            String symbol = symbolMatcher.group(2).trim();
+                            probeEvent.setSymbol(symbol);
+                        } else if ((EVENT_PATTERN.matcher(probeLine).matches()) || (WILDCARD_EVENT_PATTERN.matcher(probeLine).matches())) {
+                            break;
+                        } else if (CHANNEL_PATTERN.matcher(probeLine).matches()) {
+                            break;
+                        } else if (DOMAIN_KERNEL_PATTERN.matcher(probeLine).matches()) {
+                            // end of domain
+                            break;
+                        } else if (DOMAIN_UST_GLOBAL_PATTERN.matcher(probeLine).matches()) {
+                            // end of domain
+                            break;
+                        }
+                        index++;
+                    }
                     events.add(eventInfo);
+                } else {
+                    events.add(eventInfo);
+                    index++;
+                    continue;
                 }
+            } else {
+                index++;
             }
 //            else if (line.matches(EVENT_NONE_PATTERN)) {
                 // do nothing
 //            } else 
-            index++;
+
         }
 
         return index;
@@ -557,9 +1175,9 @@ public class LTTngControlService implements ILttngControlService {
     /**
      * Parses a line with attributes: <attribute Name>: <attribute value>
      * 
-     * @param line - attribute line to parse
+     * @param line
+     *            - attribute line to parse
      * @return the attribute value as string
-     * @throws PatternSyntaxException
      */
     private String getAttributeValue(String line) {
         String[] temp = line.split("\\: "); //$NON-NLS-1$
@@ -567,30 +1185,29 @@ public class LTTngControlService implements ILttngControlService {
     }
 
     /**
-     * Parses the event information within a provider. 
+     * Parses the event information within a provider.
      * 
-     * @param output - a command output array
-     * @param currentIndex - current index in command output array
-     * @param events - list for returning event information
+     * @param output
+     *            - a command output array
+     * @param currentIndex
+     *            - current index in command output array
+     * @param events
+     *            - list for returning event information
      * @return the new current index in command output array
      */
     private int getProviderEventInfo(String[] output, int currentIndex, List<IBaseEventInfo> events) {
         int index = currentIndex;
         while (index < output.length) {
             String line = output[index];
-            if (line.matches(PROVIDER_EVENT_PATTERN)) {
-                // sched_kthread_stop (loglevel: TRACE_EMERG0) (type: tracepoint)
-                Pattern pattern = Pattern.compile(PROVIDER_EVENT_PATTERN);
-
-                Matcher matcher = pattern.matcher(line);
-
-                if (matcher.matches()) {
-                    IBaseEventInfo eventInfo = new BaseEventInfo(matcher.group(1).trim());
-                    eventInfo.setLogLevel(matcher.group(2).trim());
-                    eventInfo.setEventType(matcher.group(3).trim());
-                    events.add(eventInfo);
-                }
-            } else if (line.matches(UST_PROVIDER_PATTERN)) {
+            Matcher matcher = PROVIDER_EVENT_PATTERN.matcher(line);
+            if (matcher.matches()) {
+                // sched_kthread_stop (loglevel: TRACE_EMERG0) (type:
+                // tracepoint)
+                IBaseEventInfo eventInfo = new BaseEventInfo(matcher.group(1).trim());
+                eventInfo.setLogLevel(matcher.group(2).trim());
+                eventInfo.setEventType(matcher.group(3).trim());
+                events.add(eventInfo);
+            } else if (UST_PROVIDER_PATTERN.matcher(line).matches()) {
                 return index;
             }
             index++;
@@ -598,4 +1215,22 @@ public class LTTngControlService implements ILttngControlService {
         return index;
     }
 
+    /**
+     * 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
+     */
+    private String formatParameter(String parameter) {
+        if (parameter != null) {
+            String newString = String.valueOf(parameter);
+
+            if (parameter.contains(" ")) { //$NON-NLS-1$
+                newString = "\"" + newString + "\""; //$NON-NLS-1$ //$NON-NLS-2$
+            }
+            return newString;
+        }
+        return null;
+    }
+    
 }
This page took 0.039424 seconds and 5 git commands to generate.