Add benchmarks for old LTTng-JUL API vs. new one
[lttng-ust-java-tests.git] / src / org / lttng / ust / agent / jul / benchmarks / utils / LttngSessionControl.java
1 package org.lttng.ust.agent.jul.benchmarks.utils;
2
3 import java.io.IOException;
4 import java.lang.ProcessBuilder.Redirect;
5
6 public final class LttngSessionControl {
7
8 private LttngSessionControl() {}
9
10 public static boolean setupJulSessionNoEvents() {
11 return executeCommands(new String[][] {
12 { "lttng", "create" },
13 /*
14 * We have to enable a channel for 'lttng start' to work.
15 * However, we cannot enable a channel directly, see
16 * https://bugs.lttng.org/issues/894 . Instead we will enable an
17 * event we know does not exist
18 */
19 { "lttng", "enable-event", "-j", "non-event" },
20 { "lttng", "start" }
21 });
22 }
23
24 public static boolean setupJulSessionAllEvents() {
25 return executeCommands(new String[][] {
26 { "lttng", "create" },
27 { "lttng", "enable-event", "-j", "-a" },
28 { "lttng", "start" }
29 });
30 }
31
32 public static boolean stopSession() {
33 return executeCommand(new String[] { "lttng", "stop" });
34 }
35
36 public static boolean destroySession() {
37 return executeCommand(new String[] { "lttng", "destroy" });
38 }
39
40 private static boolean executeCommands(String [][] commands) {
41 for (String[] command : commands) {
42 if (executeCommand(command) == false) {
43 return false;
44 }
45 }
46 return true;
47 }
48
49 public static void main(String[] args) {
50 executeCommand(new String[] {"ls", "-l"});
51 }
52
53 private static boolean executeCommand(String[] command) {
54 try {
55 ProcessBuilder builder = new ProcessBuilder(command);
56 builder.redirectErrorStream(true);
57 builder.redirectOutput(Redirect.INHERIT);
58
59 Process p = builder.start();
60 int ret = p.waitFor();
61 return (ret == 0);
62 } catch (IOException | InterruptedException e) {
63 return false;
64 }
65 }
66 }
This page took 0.031131 seconds and 4 git commands to generate.