summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorBernd Hufmann2013-03-06 13:17:35 (EST)
committer Bernd Hufmann2013-03-06 14:55:25 (EST)
commite522cab9b7b22cf871bc739b51450bbe20b39950 (patch)
tree64326fbce5590a39e2a209b28ccac385a2fdfff7
parent441fbd6714a5f013920c52b791e2b45342abb573 (diff)
downloadorg.eclipse.linuxtools-e522cab9b7b22cf871bc739b51450bbe20b39950.zip
org.eclipse.linuxtools-e522cab9b7b22cf871bc739b51450bbe20b39950.tar.gz
org.eclipse.linuxtools-e522cab9b7b22cf871bc739b51450bbe20b39950.tar.bz2
lttng ui: fix handling of command output for verbose commandsrefs/changes/64/10864/5
When executing commands with preference verbose the command output parsing of certain commands were not correct and caused ExecutionExceptions in Eclipse even if the command was successfully executed. This has been corrected with this commit. Also, this commit contains JUnit tests to verify the updates. Change-Id: I24196959a28093a292f599f93f6b78f6fd76c69e Signed-off-by: Bernd Hufmann <bhufmann@gmail.com> Reviewed-on: https://git.eclipse.org/r/10864 Tested-by: Hudson CI Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com> IP-Clean: Matthew Khouzam <matthew.khouzam@ericsson.com> Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.ui.tests/src/org/eclipse/linuxtools/lttng2/ui/tests/control/service/LTTngControlServiceTest.java127
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.ui.tests/testfiles/LTTngServiceTest.cfg108
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/service/LTTngControlService.java143
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/service/LTTngControlServiceConstants.java6
-rw-r--r--lttng/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/service/LTTngControlServiceFactory.java4
5 files changed, 317 insertions, 71 deletions
diff --git a/lttng/org.eclipse.linuxtools.lttng2.ui.tests/src/org/eclipse/linuxtools/lttng2/ui/tests/control/service/LTTngControlServiceTest.java b/lttng/org.eclipse.linuxtools.lttng2.ui.tests/src/org/eclipse/linuxtools/lttng2/ui/tests/control/service/LTTngControlServiceTest.java
index 2c99106..2d23d2c 100644
--- a/lttng/org.eclipse.linuxtools.lttng2.ui.tests/src/org/eclipse/linuxtools/lttng2/ui/tests/control/service/LTTngControlServiceTest.java
+++ b/lttng/org.eclipse.linuxtools.lttng2.ui.tests/src/org/eclipse/linuxtools/lttng2/ui/tests/control/service/LTTngControlServiceTest.java
@@ -13,7 +13,10 @@
package org.eclipse.linuxtools.lttng2.ui.tests.control.service;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.File;
import java.net.URL;
@@ -41,9 +44,13 @@ import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceSessionSta
import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.ChannelInfo;
import org.eclipse.linuxtools.internal.lttng2.stubs.service.CommandShellFactory;
import org.eclipse.linuxtools.internal.lttng2.stubs.shells.LTTngToolsFileShell;
+import org.eclipse.linuxtools.internal.lttng2.ui.Activator;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.logging.ControlCommandLogger;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.preferences.ControlPreferences;
import org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService;
import org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.LTTngControlService;
import org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.LTTngControlServiceFactory;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.osgi.framework.FrameworkUtil;
@@ -66,11 +73,13 @@ public class LTTngControlServiceTest {
private static final String SCEN_NO_SESSION_AVAILABLE = "NoSessionAvailable";
private static final String SCEN_GET_SESSION_NAMES1 = "GetSessionNames1";
private static final String SCEN_GET_SESSION_NAME_NOT_EXIST = "GetSessionNameNotExist";
+ private static final String SCEN_GET_SESSION_NAME_NOT_EXIST_VERBOSE = "GetSessionNameNotExistVerbose";
private static final String SCEN_GET_SESSION_GARBAGE_OUT = "GetSessionGarbageOut";
private static final String SCEN_GET_SESSION1 = "GetSession1";
private static final String SCEN_GET_KERNEL_PROVIDER1 = "GetKernelProvider1";
private static final String SCEN_LIST_WITH_NO_KERNEL1 = "ListWithNoKernel1";
private static final String SCEN_LIST_WITH_NO_KERNEL2 = "ListWithNoKernel2";
+ private static final String SCEN_LIST_WITH_NO_KERNEL_VERBOSE = "ListWithNoKernelVerbose";
private static final String SCEN_GET_UST_PROVIDER1 = "GetUstProvider1";
private static final String SCEN_GET_UST_PROVIDER2 = "GetUstProvider2";
private static final String SCEN_GET_UST_PROVIDER3 = "GetUstProvider3";
@@ -78,12 +87,14 @@ public class LTTngControlServiceTest {
private static final String SCEN_CREATE_SESSION_WITH_PROMPT = "CreateSessionWithPrompt";
private static final String SCEN_CREATE_SESSION_VARIANTS = "CreateSessionVariants";
private static final String SCEN_DESTROY_SESSION1 = "DestroySession1";
+ private static final String SCEN_DESTROY_SESSION_VERBOSE = "DestroySessionVerbose";
private static final String SCEN_CHANNEL_HANDLING = "ChannelHandling";
private static final String SCEN_EVENT_HANDLING = "EventHandling";
private static final String SCEN_CONTEXT_HANDLING = "ContextHandling";
private static final String SCEN_CONTEXT_ERROR_HANDLING = "ContextErrorHandling";
private static final String SCEN_CALIBRATE_HANDLING = "CalibrateHandling";
private static final String SCEN_CREATE_SESSION_2_1 = "CreateSessionLttng2.1";
+ private static final String SCEN_CREATE_SESSION_VERBOSE_2_1 = "CreateSessionLttngVerbose2.1";
// ------------------------------------------------------------------------
// Test data
@@ -115,6 +126,14 @@ public class LTTngControlServiceTest {
fShell = fShellFactory.getFileShell();
fShell.loadScenarioFile(fTestfile);
fService = new LTTngControlService(fShell);
+
+ ControlPreferences.getInstance().init(Activator.getDefault().getPreferenceStore());
+ }
+
+ @After
+ public void tearDown() {
+ disableVerbose();
+ ControlPreferences.getInstance().dispose();
}
// ------------------------------------------------------------------------
@@ -221,6 +240,21 @@ public class LTTngControlServiceTest {
}
@Test
+ public void testGetSessionNotExistVerbose() {
+ try {
+ enableVerbose();
+ fShell.setScenario(SCEN_GET_SESSION_NAME_NOT_EXIST_VERBOSE);
+ fService.getSessionNames(new NullProgressMonitor());
+ fail("No exeption thrown");
+
+ } catch (ExecutionException e) {
+ // success
+ } finally {
+ disableVerbose();
+ }
+ }
+
+ @Test
public void testGetSessionNameGarbage() {
try {
fShell.setScenario(SCEN_GET_SESSION_GARBAGE_OUT);
@@ -413,6 +447,24 @@ public class LTTngControlServiceTest {
}
@Test
+ public void testGetKernelProviderNoKernelVerbose() {
+ try {
+ enableVerbose();
+ fShell.setScenario(SCEN_LIST_WITH_NO_KERNEL_VERBOSE);
+ List<IBaseEventInfo> events = fService.getKernelProvider(new NullProgressMonitor());
+
+ // Verify event info
+ assertNotNull(events);
+ assertEquals(0, events.size());
+
+ } catch (ExecutionException e) {
+ fail(e.toString());
+ } finally {
+ disableVerbose();
+ }
+ }
+
+ @Test
public void testGetUstProvider() {
try {
fShell.setScenario(SCEN_GET_UST_PROVIDER1);
@@ -655,6 +707,19 @@ public class LTTngControlServiceTest {
}
@Test
+ public void testDestroySessionVerbose() {
+ try {
+ enableVerbose();
+ fShell.setScenario(SCEN_DESTROY_SESSION_VERBOSE);
+ fService.destroySession("mysession2", new NullProgressMonitor());
+ } catch (ExecutionException e) {
+ fail(e.toString());
+ } finally {
+ disableVerbose();
+ }
+ }
+
+ @Test
public void testCreateChannel() {
try {
@@ -741,17 +806,6 @@ public class LTTngControlServiceTest {
}
}
-// public void tesEnableChannelNoTracer() {
-// try {
-// ILttngControlService service = new LTTngControlService(fShellFactory.getShellForChannelNoTracer());
-// service.getSessionNames(new NullProgressMonitor());
-// fail("No exeption thrown");
-//
-// } catch (ExecutionException e) {
-// // success
-// }
-// }
-
@Test
public void testEnableEvents() {
try {
@@ -966,20 +1020,20 @@ public class LTTngControlServiceTest {
assertNotNull(info);
assertEquals("mysession", info.getName());
assertEquals("file:///tmp", info.getSessionPath());
- assertTrue(info.isStreamedTrace());
+ assertTrue(!info.isStreamedTrace());
fService.destroySession("mysession", new NullProgressMonitor());
info = fService.createSession("mysession", "file:///tmp", null, null, new NullProgressMonitor());
assertNotNull(info);
assertEquals("mysession", info.getName());
assertEquals("file:///tmp", info.getSessionPath());
- assertTrue(info.isStreamedTrace());
+ assertTrue(!info.isStreamedTrace());
fService.destroySession("mysession", new NullProgressMonitor());
info = fService.createSession("mysession", null, "tcp://172.0.0.1", "tcp://172.0.0.1:5343", new NullProgressMonitor());
assertNotNull(info);
assertEquals("mysession", info.getName());
- assertEquals("", info.getSessionPath()); // TODO: currently there is a bug in LTTng tracer and it returns string null
+ assertEquals("", info.getSessionPath()); // the complete network path is not available at this point
assertTrue(info.isStreamedTrace());
fService.destroySession("mysession", new NullProgressMonitor());
@@ -990,8 +1044,51 @@ public class LTTngControlServiceTest {
assertTrue(info.isStreamedTrace());
fService.destroySession("mysession", new NullProgressMonitor());
+ // verbose
+ enableVerbose();
+ info = fService.createSession("mysession", "net://172.0.0.1", null, null, new NullProgressMonitor());
+ assertNotNull(info);
+ assertEquals("mysession", info.getName());
+ assertEquals("net://172.0.0.1", info.getSessionPath());
+ assertTrue(info.isStreamedTrace());
+ disableVerbose();
+ fService.destroySession("mysession", new NullProgressMonitor());
+
+
+ } catch (ExecutionException e) {
+ fail(e.toString());
+ }
+ }
+
+ @Test
+ public void testCreateSessionVerbose2_1() {
+ try {
+ fShell.setScenario(SCEN_CREATE_SESSION_VERBOSE_2_1);
+
+ enableVerbose();
+ ISessionInfo info = fService.createSession("mysession", "net://172.0.0.1", null, null, new NullProgressMonitor());
+ assertNotNull(info);
+ assertEquals("mysession", info.getName());
+ assertEquals("net://172.0.0.1", info.getSessionPath());
+ assertTrue(info.isStreamedTrace());
+ fService.destroySession("mysession", new NullProgressMonitor());
} catch (ExecutionException e) {
fail(e.toString());
+ } finally {
+ disableVerbose();
}
}
+
+ private static void enableVerbose() {
+ // verbose
+ ControlCommandLogger.init(ControlPreferences.getInstance().getLogfilePath(), false);
+ ControlPreferences.getInstance().getPreferenceStore().setDefault(ControlPreferences.TRACE_CONTROL_LOG_COMMANDS_PREF, true);
+ ControlPreferences.getInstance().getPreferenceStore().setDefault(ControlPreferences.TRACE_CONTROL_VERBOSE_LEVEL_PREF, ControlPreferences.TRACE_CONTROL_VERBOSE_LEVEL_V_V_VERBOSE);
+ }
+
+ private static void disableVerbose() {
+ ControlPreferences.getInstance().getPreferenceStore().setDefault(ControlPreferences.TRACE_CONTROL_LOG_COMMANDS_PREF, false);
+ }
+
+
}
diff --git a/lttng/org.eclipse.linuxtools.lttng2.ui.tests/testfiles/LTTngServiceTest.cfg b/lttng/org.eclipse.linuxtools.lttng2.ui.tests/testfiles/LTTngServiceTest.cfg
index 9c6e495..e9341e5 100644
--- a/lttng/org.eclipse.linuxtools.lttng2.ui.tests/testfiles/LTTngServiceTest.cfg
+++ b/lttng/org.eclipse.linuxtools.lttng2.ui.tests/testfiles/LTTngServiceTest.cfg
@@ -156,6 +156,26 @@ Error: Session name not found
</SCENARIO>
####################################################################
+# Scenario: Test lttng -vvv list <name> where session doesn't exist
+####################################################################
+<SCENARIO>
+GetSessionNameNotExistVerbose
+<COMMAND_INPUT>
+lttng -vvv list test
+</COMMAND_INPUT>
+<COMMAND_RESULT>
+1
+</COMMAND_RESULT>
+<COMMAND_OUTPUT>
+DEBUG2: Session name: test [in cmd_list() at commands/list.c:618]
+DEBUG1: Session count 1 [in list_sessions() at commands/list.c:485]
+Error: Session 'test' not found
+Error: Command error
+DEBUG1: Clean exit [in clean_exit() at lttng.c:165]
+</COMMAND_OUTPUT>
+</SCENARIO>
+
+####################################################################
# Scenario: Test lttng list with garbage output
####################################################################
<SCENARIO>
@@ -320,6 +340,25 @@ Error: Unable to list kernel events
</SCENARIO>
####################################################################
+# Scenario: Test "lttng list -k" with no kernel, with session daemon and verbose
+####################################################################
+<SCENARIO>
+ListWithNoKernelVerbose
+<COMMAND_INPUT>
+lttng -vvv list -k
+</COMMAND_INPUT>
+<COMMAND_RESULT>
+1
+</COMMAND_RESULT>
+<COMMAND_OUTPUT>
+DEBUG2: Session name: (null) [in cmd_list() at commands/list.c:618]
+DEBUG1: Getting kernel tracing events [in list_kernel_events() at commands/list.c:309]
+Error: Unable to list kernel events
+DEBUG1: Clean exit [in clean_exit() at lttng.c:165]
+</COMMAND_OUTPUT>
+</SCENARIO>
+
+####################################################################
# Scenario: Test "lttng list -u" with sample output
####################################################################
<SCENARIO>
@@ -510,6 +549,26 @@ Session mysession2 destroyed.
</SCENARIO>
####################################################################
+# Scenario: Test "lttng -vvv destroy <session>"
+####################################################################
+
+<SCENARIO>
+DestroySessionVerbose
+<COMMAND_INPUT>
+lttng -vvv destroy mysession2
+</COMMAND_INPUT>
+<COMMAND_RESULT>
+0
+</COMMAND_RESULT>
+<COMMAND_OUTPUT>
+DEBUG2: Config file path found: /home/eedbhu [in get_session_name() at utils.c:98]
+DEBUG1: Session name found: mysession2 [in get_session_name() at utils.c:99]
+Session mysession2 destroyed at /home/eedbhu
+</COMMAND_OUTPUT>
+</SCENARIO>
+
+
+####################################################################
# Scenario: Test "lttng enable-channel ..." with different inputs
####################################################################
@@ -902,4 +961,53 @@ lttng destroy mysession
Session mysession destroyed.
</COMMAND_OUTPUT>
+<COMMAND_INPUT>
+lttng -vvv create mysession -U net://172.0.0.1
+</COMMAND_INPUT>
+<COMMAND_RESULT>
+0
+</COMMAND_RESULT>
+<COMMAND_OUTPUT>
+DEBUG3: URI string: net://172.0.0.1 [in uri_parse() at uri.c:253]
+DEBUG2: IP address resolved to 172.0.0.1 [in set_ip_address() at uri.c:132]
+DEBUG3: URI dtype: 1, proto: 1, host: 172.0.0.1, subdir: , ctrl: 0, data: 0 [in uri_parse() at uri.c:467]
+DEBUG1: LSM cmd type : 8 [in send_session_msg() at lttng-ctl.c:261]
+Session mysession created.
+Traces will be written in net://172.0.0.1
+DEBUG1: Init config session in /home/bernd [in config_init() at conf.c:294]
+</COMMAND_OUTPUT>
+
</SCENARIO>
+
+####################################################################
+# Scenario: Test "lttng -vvv create <session> with LTTng 2.1 options"
+####################################################################
+<SCENARIO>
+CreateSessionLttngVerbose2.1
+<COMMAND_INPUT>
+lttng -vvv create mysession -U net://172.0.0.1
+</COMMAND_INPUT>
+<COMMAND_RESULT>
+0
+</COMMAND_RESULT>
+<COMMAND_OUTPUT>
+DEBUG3: URI string: net://172.0.0.1 [in uri_parse() at uri.c:253]
+DEBUG2: IP address resolved to 172.0.0.1 [in set_ip_address() at uri.c:132]
+DEBUG3: URI dtype: 1, proto: 1, host: 172.0.0.1, subdir: , ctrl: 0, data: 0 [in uri_parse() at uri.c:467]
+DEBUG1: LSM cmd type : 8 [in send_session_msg() at lttng-ctl.c:261]
+Session mysession created.
+Traces will be written in net://172.0.0.1
+DEBUG1: Init config session in /home/bernd [in config_init() at conf.c:294]
+</COMMAND_OUTPUT>
+
+<COMMAND_INPUT>
+lttng -vvv destroy mysession
+</COMMAND_INPUT>
+<COMMAND_RESULT>
+0
+</COMMAND_RESULT>
+<COMMAND_OUTPUT>
+Session mysession destroyed.
+</COMMAND_OUTPUT>
+
+</SCENARIO> \ No newline at end of file
diff --git a/lttng/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/service/LTTngControlService.java b/lttng/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/service/LTTngControlService.java
index fd05617..294124e 100644
--- a/lttng/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/service/LTTngControlService.java
+++ b/lttng/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/service/LTTngControlService.java
@@ -265,10 +265,14 @@ public class LTTngControlService implements ILttngControlService {
// or:
// Error: Unable to list kernel events
//
-
- if ((result.getOutput().length > 0) && (LTTngControlServiceConstants.LIST_KERNEL_NO_KERNEL_PROVIDER_PATTERN.matcher(result.getOutput()[0]).matches()) ||
- ((result.getOutput().length > 1) && (LTTngControlServiceConstants.LIST_KERNEL_NO_KERNEL_PROVIDER_PATTERN.matcher(result.getOutput()[1]).matches()))) {
- return events;
+ int index = 0;
+ while (index < result.getOutput().length) {
+ String line = result.getOutput()[index];
+ Matcher matcher = LTTngControlServiceConstants.LIST_KERNEL_NO_KERNEL_PROVIDER_PATTERN.matcher(line);
+ if (matcher.matches()) {
+ return events;
+ }
+ index++;
}
}
@@ -380,19 +384,24 @@ public class LTTngControlService implements ILttngControlService {
//Traces will be written in /home/user/lttng-traces/myssession2-20120209-095418
String[] output = result.getOutput();
- // Get and verify session name
- Matcher matcher = LTTngControlServiceConstants.CREATE_SESSION_NAME_PATTERN.matcher(output[0]);
+ // Get and session name and path
String name = null;
+ String path = 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_UnexpectedCommandOutputFormat + ":\n" + //$NON-NLS-1$
- formatOutput(result));
+ int index = 0;
+ while (index < output.length) {
+ String line = output[index];
+ Matcher nameMatcher = LTTngControlServiceConstants.CREATE_SESSION_NAME_PATTERN.matcher(line);
+ Matcher pathMatcher = LTTngControlServiceConstants.CREATE_SESSION_PATH_PATTERN.matcher(line);
+ if (nameMatcher.matches()) {
+ name = String.valueOf(nameMatcher.group(1).trim());
+ } else if (pathMatcher.matches()) {
+ path = String.valueOf(pathMatcher.group(1).trim());
+ }
+ index++;
}
+ // Verify session name
if ((name == null) || (!"".equals(sessionName) && !name.equals(sessionName))) { //$NON-NLS-1$
// Unexpected name returned
throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
@@ -401,24 +410,13 @@ public class LTTngControlService implements ILttngControlService {
SessionInfo sessionInfo = new SessionInfo(name);
- // Get and verify session path
- matcher = LTTngControlServiceConstants.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_UnexpectedCommandOutputFormat + ":\n" + //$NON-NLS-1$
- formatOutput(result));
- }
-
+ // Verify session path
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.setSessionPath(path);
return sessionInfo;
@@ -448,45 +446,56 @@ 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
+ // Verify output
String[] output = result.getOutput();
- // Get and verify session name
- Matcher matcher = LTTngControlServiceConstants.CREATE_SESSION_NAME_PATTERN.matcher(output[0]);
+ // Get and session name and path
String name = null;
+ String path = null;
- if (matcher.matches()) {
- name = String.valueOf(matcher.group(1).trim());
- } else {
- // Output format not expected
+ int index = 0;
+ while (index < output.length) {
+ String line = output[index];
+ Matcher nameMatcher = LTTngControlServiceConstants.CREATE_SESSION_NAME_PATTERN.matcher(line);
+ Matcher pathMatcher = LTTngControlServiceConstants.CREATE_SESSION_PATH_PATTERN.matcher(line);
+
+ if (nameMatcher.matches()) {
+ name = String.valueOf(nameMatcher.group(1).trim());
+ } else if (pathMatcher.matches() && (networkUrl != null)) {
+ path = String.valueOf(pathMatcher.group(1).trim());
+ }
+ index++;
+ }
+
+ // Verify session name
+ if ((name == null) || (!"".equals(sessionName) && !name.equals(sessionName))) { //$NON-NLS-1$
+ // Unexpected name returned
throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
- Messages.TraceControl_UnexpectedCommandOutputFormat + ":\n" + //$NON-NLS-1$
- formatOutput(result));
+ Messages.TraceControl_UnexpectedNameError + ": " + name); //$NON-NLS-1$
}
- // Get and verify session path
- matcher = LTTngControlServiceConstants.CREATE_SESSION_PATH_PATTERN.matcher(output[1]);
- String path = null;
SessionInfo sessionInfo = new SessionInfo(name);
- if (networkUrl != 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_UnexpectedCommandOutputFormat + ":\n" + //$NON-NLS-1$
- formatOutput(result));
- }
+ sessionInfo.setStreamedTrace(true);
+
+ // Verify session path
+ if (networkUrl != null) {
if (path == null) {
// Unexpected path
throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
Messages.TraceControl_UnexpectedPathError + ": " + name); //$NON-NLS-1$
}
+
sessionInfo.setSessionPath(path);
+
+ // Check file protocol
+ Matcher matcher = LTTngControlServiceConstants.TRACE_FILE_PROTOCOL_PATTERN.matcher(path);
+ if (matcher.matches()) {
+ sessionInfo.setStreamedTrace(false);
+ }
}
- sessionInfo.setStreamedTrace(true);
+ // 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;
}
@@ -500,9 +509,24 @@ public class LTTngControlService implements ILttngControlService {
ICommandResult result = executeCommand(command.toString(), monitor, false);
String[] output = result.getOutput();
- if (isError(result) && ((output == null) || (!LTTngControlServiceConstants.SESSION_NOT_FOUND_ERROR_PATTERN.matcher(output[0]).matches()))) {
- throw new ExecutionException(Messages.TraceControl_CommandError + " " + command.toString() + "\n" + formatOutput(result)); //$NON-NLS-1$ //$NON-NLS-2$
- }
+ boolean isError = isError(result);
+ if (isError && (output != null)) {
+ int index = 0;
+ while (index < output.length) {
+ String line = output[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 (isError) {
+ throw new ExecutionException(Messages.TraceControl_CommandError + " " + command.toString() + "\n" + formatOutput(result)); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
//Session <sessionName> destroyed
}
@@ -934,9 +958,22 @@ public class LTTngControlService implements ILttngControlService {
* @return true if error else false
*/
protected boolean isError(ICommandResult result) {
- if ((result.getResult()) != 0 || (result.getOutput().length < 1 || LTTngControlServiceConstants.ERROR_PATTERN.matcher(result.getOutput()[0]).matches())) {
+ // Check return code and length of returned strings
+ if ((result.getResult()) != 0 || (result.getOutput().length < 1)) {
return true;
}
+
+ // Look for error pattern
+ int index = 0;
+ while (index < result.getOutput().length) {
+ String line = result.getOutput()[index];
+ Matcher matcher = LTTngControlServiceConstants.ERROR_PATTERN.matcher(line);
+ if (matcher.matches()) {
+ return true;
+ }
+ index++;
+ }
+
return false;
}
diff --git a/lttng/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/service/LTTngControlServiceConstants.java b/lttng/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/service/LTTngControlServiceConstants.java
index 79295b5..76528af 100644
--- a/lttng/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/service/LTTngControlServiceConstants.java
+++ b/lttng/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/service/LTTngControlServiceConstants.java
@@ -242,7 +242,11 @@ public class LTTngControlServiceConstants {
* Pattern to match session path for network tracing (lttng list <session>)
* Note: file for protocol is not considered as network trace since local consumer will be used.
*/
- public final static Pattern TRACE_NETWORK_PATH_PATTERN = Pattern.compile("\\s*Trace\\s+path\\:\\s+(net|net6|tcp|tcp6|)\\:\\/\\/(.*)(\\:(\\d*)\\/(.*)\\[data\\:\\s+(\\d*)\\]){0,1}"); //$NON-NLS-1$
+ public final static Pattern TRACE_NETWORK_PATH_PATTERN = Pattern.compile("\\s*Trace\\s+path\\:\\s+(net|net6|tcp|tcp6)\\:\\/\\/(.*)(\\:(\\d*)\\/(.*)\\[data\\:\\s+(\\d*)\\]){0,1}"); //$NON-NLS-1$
+ /**
+ * Sub-pattern to pattern TRACE_NETWORK_PATH_PATTERN to match file protocol
+ */
+ public final static Pattern TRACE_FILE_PROTOCOL_PATTERN = Pattern.compile("(file)\\:\\/\\/(.*)"); //$NON-NLS-1$
/**
* Pattern to match for kernel domain information (lttng list <session>)
*/
diff --git a/lttng/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/service/LTTngControlServiceFactory.java b/lttng/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/service/LTTngControlServiceFactory.java
index 77d1d85..7488b09 100644
--- a/lttng/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/service/LTTngControlServiceFactory.java
+++ b/lttng/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/service/LTTngControlServiceFactory.java
@@ -1,5 +1,5 @@
/**********************************************************************
- * Copyright (c) 2012 Ericsson
+ * Copyright (c) 2012. 2013 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
@@ -91,7 +91,7 @@ public class LTTngControlServiceFactory {
ControlCommandLogger.log(LTTngControlService.formatOutput(result));
}
- if ((result != null) && (result.getResult() == 0) && (result.getOutput().length >= 1) && (!LTTngControlServiceConstants.ERROR_PATTERN.matcher(result.getOutput()[0]).matches())) {
+ if ((result != null) && (result.getResult() == 0) && (result.getOutput().length >= 1)) {
int index = 0;
while (index < result.getOutput().length) {
String line = result.getOutput()[index];