Add support for LTTng 2.0 command calibrate
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / service / LTTngControlService.java
index ef08cae9d85be0207c87d179fd96042757209276..83c44a081caab83302f858b5b82c4ee4fad1b89d 100644 (file)
@@ -98,6 +98,14 @@ public class LTTngControlService implements ILttngControlService {
      * Command to disable a event. 
      */
     private final static String COMMAND_DISABLE_EVENT = CONTROL_COMMAND + " disable-event "; //$NON-NLS-1$
+    /**
+     * Command to add a context to channels and/or events
+     */
+    private final static String COMMAND_ADD_CONTEXT = CONTROL_COMMAND + " add-context "; //$NON-NLS-1$
+    /**
+     * Command to execute calibrate command to quantify LTTng overhead
+     */
+    private final static String COMMAND_CALIBRATE = CONTROL_COMMAND + " calibrate "; //$NON-NLS-1$
 
     // Command options constants 
     /**
@@ -120,10 +128,18 @@ public class LTTngControlService implements ILttngControlService {
      * Command line option for specifying a channel.
      */
     private final static String OPTION_CHANNEL = " -c ";  //$NON-NLS-1$
+    /**
+     * Command line option for specifying a event.
+     */
+    private final static String OPTION_EVENT = " -e ";  //$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 a context.
+     */
+    private final static String OPTION_CONTEXT_TYPE = " -t ";  //$NON-NLS-1$
     /**
      * Command line option for specifying tracepoint events.
      */
@@ -168,6 +184,10 @@ public class LTTngControlService implements ILttngControlService {
      * Optional command line option for configuring a channel's read timer interval.
      */
     private final static String OPTION_READ_TIMER = " --read-timer ";  //$NON-NLS-1$
+    /**
+     * Command line option for printing the help of a specif command 
+     */
+    private final static String OPTION_HELP = " -h ";  //$NON-NLS-1$
     
     // Parsing constants
     /**
@@ -284,6 +304,15 @@ public class LTTngControlService implements ILttngControlService {
      * 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$
+    /**
+     * Pattern to match introduction line of context list.
+     */
+    private final static Pattern ADD_CONTEXT_HELP_CONTEXTS_INTRO = Pattern.compile("\\s*TYPE can\\s+be\\s+one\\s+of\\s+the\\s+strings\\s+below.*"); //$NON-NLS-1$
+    
+    /**
+     * Pattern to match introduction line of context list.
+     */
+    private final static Pattern ADD_CONTEXT_HELP_CONTEXTS_END_LINE = Pattern.compile("\\s*Example.*"); //$NON-NLS-1$
     
     // ------------------------------------------------------------------------
     // Attributes
@@ -949,6 +978,117 @@ public class LTTngControlService implements ILttngControlService {
             throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
         }
     }
+
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#getContexts(org.eclipse.core.runtime.IProgressMonitor)
+     */
+    @Override
+    public List<String> getContextList(IProgressMonitor monitor) throws ExecutionException {
+
+        String command = COMMAND_ADD_CONTEXT + OPTION_HELP;
+
+        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$
+        }
+
+        String[] output = result.getOutput(); 
+        
+        List<String> contexts = new ArrayList<String>(0);
+        
+        int index = 0;
+        boolean inList = false;
+        while (index < output.length) {
+            String line = result.getOutput()[index];
+            
+            Matcher startMatcher = ADD_CONTEXT_HELP_CONTEXTS_INTRO.matcher(line);
+            Matcher endMatcher = ADD_CONTEXT_HELP_CONTEXTS_END_LINE.matcher(line);
+
+            if (startMatcher.matches()) {
+                inList = true;
+            } else if (endMatcher.matches()) {
+                break;
+            } else if (inList == true) {
+                String[] tmp = line.split(","); //$NON-NLS-1$
+                for (int i = 0; i < tmp.length; i++) {
+                    contexts.add(tmp[i].trim());
+                }
+            }
+            index++;
+        }
+        return contexts;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#addContexts(java.lang.String, java.lang.String, java.lang.String, boolean, java.util.List, org.eclipse.core.runtime.IProgressMonitor)
+     */
+    @Override
+    public void addContexts(String sessionName, String channelName, String eventName, boolean isKernel, List<String> contextNames, IProgressMonitor monitor) throws ExecutionException {
+        
+        String newSessionName = formatParameter(sessionName);
+        StringBuffer command = new StringBuffer(COMMAND_ADD_CONTEXT);
+
+        command.append(OPTION_SESSION);
+        command.append(newSessionName);
+        
+        if (channelName != null) {
+            command.append(OPTION_CHANNEL);
+            command.append(channelName);
+        }
+
+        if (eventName != null) {
+            command.append(OPTION_EVENT);
+            command.append(eventName);
+        }
+
+        if (isKernel) {
+            command.append(OPTION_KERNEL);
+        } else {
+            command.append(OPTION_UST);
+        }
+        
+        for (Iterator<String> iterator = contextNames.iterator(); iterator.hasNext();) {
+            String context = (String) iterator.next();
+            command.append(OPTION_CONTEXT_TYPE);
+            command.append(context);
+        }
+
+        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.internal.lttng2.ui.views.control.service.ILttngControlService#calibrate(boolean, org.eclipse.core.runtime.IProgressMonitor)
+     */
+    @Override
+    public void calibrate(boolean isKernel, IProgressMonitor monitor) throws ExecutionException {
+//        String newSessionName = formatParameter(sessionName);
+        StringBuffer command = new StringBuffer(COMMAND_CALIBRATE);
+//
+//        command.append(OPTION_SESSION);
+//        command.append(newSessionName);
+
+        if (isKernel) {
+            command.append(OPTION_KERNEL);
+        } else {
+            command.append(OPTION_UST);
+        }
+
+        command.append(OPTION_FUNCTION_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$
+        }        
+    }
     
     // ------------------------------------------------------------------------
     // Helper methods
@@ -1238,5 +1378,4 @@ public class LTTngControlService implements ILttngControlService {
         }
         return null;
     }
-    
 }
This page took 0.025393 seconds and 5 git commands to generate.