X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;ds=sidebyside;f=src%2Ftest%2Fjava%2Forg%2Flttng%2Fust%2Fagent%2Futils%2FLttngSession.java;h=9d0b4ab52234aa94a19a31b3efce6e0212f0d924;hb=7dfd1adfc507b63e62004efd3a9a74ae7d1f0d3e;hp=cc3b4d74317bbfe9842c3c724930c38b5eb5682c;hpb=2b408e85806bd695f6036371701dcb8691ab3c32;p=lttng-ust-java-tests.git diff --git a/src/test/java/org/lttng/ust/agent/utils/LttngSession.java b/src/test/java/org/lttng/ust/agent/utils/LttngSession.java index cc3b4d7..9d0b4ab 100644 --- a/src/test/java/org/lttng/ust/agent/utils/LttngSession.java +++ b/src/test/java/org/lttng/ust/agent/utils/LttngSession.java @@ -18,8 +18,9 @@ package org.lttng.ust.agent.utils; +import static org.lttng.ust.agent.utils.ShellUtils.executeCommand; + import java.io.IOException; -import java.lang.ProcessBuilder.Redirect; import java.nio.file.FileVisitResult; import java.nio.file.Files; import java.nio.file.Path; @@ -31,10 +32,21 @@ import java.util.List; import java.util.UUID; import java.util.stream.Collectors; +/** + * Java representation of a LTTng tracing session. It uses the command-line + * "lttng" tool to manipulate the session. Creating an instance will run + * "lttng create", close()'ing it will run "lttng destroy". + * + * @author Alexandre Montplaisir + */ public class LttngSession implements AutoCloseable { + /** + * Tracing domains as they are defined by lttng-tools + */ public enum Domain { - JUL("-j"), + /** The JUL (java.util.logging) domain */ + JUL("-j"), /** The log4j (org.apache.log4j) domain */ LOG4J("-l"); private final String flag; @@ -43,6 +55,10 @@ public class LttngSession implements AutoCloseable { this.flag = flag; } + /** + * @return The corresponding command-line flag to pass to options like + * "lttng enable-event" + */ public String flag() { return flag; } @@ -53,6 +69,15 @@ public class LttngSession implements AutoCloseable { private volatile boolean channelCreated = false; + /** + * Constructor to create a new LTTng tracing session. + * + * @param sessionName + * The name of the session to use. It can be null, in which case + * we will provide a unique random name. + * @param domain + * The tracing domain of this session + */ public LttngSession(String sessionName, Domain domain) { if (sessionName != null) { this.sessionName = sessionName; @@ -123,6 +148,11 @@ public class LttngSession implements AutoCloseable { "-s", sessionName)); } + /** + * Start tracing + * + * @return If the command executed successfully (return code = 0). + */ public boolean start() { /* * We have to enable a channel for 'lttng start' to work. However, we @@ -152,7 +182,7 @@ public class LttngSession implements AutoCloseable { * @return The output of Babeltrace on the session's current trace */ public List view() { - return MiscTestUtils.getOutputFromCommand(Arrays.asList("lttng", "view", sessionName)); + return ShellUtils.getOutputFromCommand(true, Arrays.asList("lttng", "view", sessionName)); } /** @@ -202,26 +232,4 @@ public class LttngSession implements AutoCloseable { return true; } - /** - * Just to test the environment / stdout are working correctly - */ - public static void main(String[] args) { - List command = Arrays.asList("ls", "-l"); - executeCommand(command); - } - - private static boolean executeCommand(List command) { - try { - ProcessBuilder builder = new ProcessBuilder(command); - builder.redirectErrorStream(true); - builder.redirectOutput(Redirect.INHERIT); - - Process p = builder.start(); - int ret = p.waitFor(); - return (ret == 0); - - } catch (IOException | InterruptedException e) { - return false; - } - } }