* 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
+ /**
+ * Command line option for output path.
+ */
+ private final static String OPTION_OUTPUT_PATH = " -o "; //$NON-NLS-1$
/**
* Command line option for kernel tracer.
*/
* 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.
*/
* 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
/**
* 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
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$
}
String newName = formatParameter(sessionName);
String newPath = formatParameter(sessionPath);
- String command = COMMAND_CREATE_SESSION + newName;
+ StringBuffer command = new StringBuffer();
+ command.append(COMMAND_CREATE_SESSION);
+ command.append(newName);
+
if (newPath != null && !"".equals(newPath)) { //$NON-NLS-1$
- command += " -o " + newPath; //$NON-NLS-1$
+ command.append(OPTION_OUTPUT_PATH);
+ command.append(newPath);
}
- ICommandResult result = fCommandShell.executeCommand(command, monitor);
+ 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$
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())) {
+ if (isError(result) && ((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.internal.lttng2.ui.views.control.service.ILttngControlService#startSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
public void enableChannels(String sessionName, List<String> channelNames, boolean isKernel, IChannelInfo info, IProgressMonitor monitor) throws ExecutionException {
// no channels to enable
- if (channelNames.size() == 0) {
+ if (channelNames.isEmpty()) {
return;
}
String channel = (String) iterator.next();
command.append(channel);
if (iterator.hasNext()) {
- command.append(","); //$NON-NLS-1$
+ command.append(',');
}
}
public void disableChannels(String sessionName, List<String> channelNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException {
// no channels to enable
- if (channelNames.size() == 0) {
+ if (channelNames.isEmpty()) {
return;
}
String channel = (String) iterator.next();
command.append(channel);
if (iterator.hasNext()) {
- command.append(","); //$NON-NLS-1$
+ command.append(',');
}
}
StringBuffer command = new StringBuffer(COMMAND_ENABLE_EVENT);
- if (eventNames == null || eventNames.size() == 0) {
+ if (eventNames == null || eventNames.isEmpty()) {
command.append(OPTION_ALL);
} else {
String event = (String) iterator.next();
command.append(event);
if (iterator.hasNext()) {
- command.append(","); //$NON-NLS-1$
+ command.append(',');
}
}
}
command.append(OPTION_ALL);
} else {
// no events to enable
- if (eventNames.size() == 0) {
+ if (eventNames.isEmpty()) {
return;
}
String event = (String) iterator.next();
command.append(event);
if (iterator.hasNext()) {
- command.append(","); //$NON-NLS-1$
+ command.append(',');
}
}
}
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
*/
private String formatParameter(String parameter) {
if (parameter != null) {
- String newString = String.valueOf(parameter);
+ StringBuffer newString = new StringBuffer();
+ newString.append(parameter);
if (parameter.contains(" ")) { //$NON-NLS-1$
- newString = "\"" + newString + "\""; //$NON-NLS-1$ //$NON-NLS-2$
+ newString.insert(0, "\""); //$NON-NLS-1$
+ newString.append("\""); //$NON-NLS-1$
}
- return newString;
+ return newString.toString();
}
return null;
}
-
}