2 * Copyright (C) 2015, EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 package org
.lttng
.tools
;
21 import static org
.lttng
.tools
.utils
.ShellUtils
.executeCommand
;
23 import java
.util
.Arrays
;
24 import java
.util
.List
;
25 import java
.util
.UUID
;
26 import java
.util
.stream
.Collectors
;
28 import org
.lttng
.tools
.utils
.ShellUtils
;
31 * Implementation of {@link ILttngSession} which uses the command-line "lttng"
32 * tool to manipulate the session. Creating an instance will run "lttng create",
33 * close()'ing it will run "lttng destroy".
35 * @author Alexandre Montplaisir
37 class LttngCommandLineSession
implements ILttngSession
{
39 private final String sessionName
;
40 private final Domain domain
;
42 private volatile boolean channelCreated
= false;
45 * Constructor to create a new LTTng tracing session.
48 * The name of the session to use. It can be null, in which case
49 * we will provide a unique random name.
51 * The tracing domain of this session
53 public LttngCommandLineSession(String sessionName
, Domain domain
) {
54 if (sessionName
!= null) {
55 this.sessionName
= sessionName
;
57 this.sessionName
= UUID
.randomUUID().toString();
61 /* Create the session in LTTng */
62 executeCommand(Arrays
.asList("lttng", "create", this.sessionName
));
67 /* Destroy the session */
68 executeCommand(Arrays
.asList("lttng", "destroy", sessionName
));
69 // FIXME also delete the trace we generated ?
73 public boolean enableAllEvents() {
74 channelCreated
= true;
75 return executeCommand(Arrays
.asList(
76 "lttng", "enable-event", domain
.flag(), "-a", "-s", sessionName
));
80 public boolean enableEvents(String
... enabledEvents
) {
81 if (enabledEvents
== null || enabledEvents
.length
== 0) {
82 throw new IllegalArgumentException();
84 channelCreated
= true;
85 return executeCommand(Arrays
.asList(
86 "lttng", "enable-event", domain
.flag(),
87 Arrays
.stream(enabledEvents
).collect(Collectors
.joining(",")),
92 public boolean disableEvents(String
... disabledEvents
) {
93 if (disabledEvents
== null || disabledEvents
.length
== 0) {
94 throw new IllegalArgumentException();
96 return executeCommand(Arrays
.asList(
97 "lttng", "disable-event", domain
.flag(),
98 Arrays
.stream(disabledEvents
).collect(Collectors
.joining(",")),
103 public boolean start() {
105 * We have to enable a channel for 'lttng start' to work. However, we
106 * cannot enable a channel directly, see
107 * https://bugs.lttng.org/issues/894 . Instead we will enable an event
108 * we know does not exist
110 if (!channelCreated
) {
111 enableEvents("non-event");
113 return executeCommand(Arrays
.asList("lttng", "start", sessionName
));
117 public boolean stop() {
118 return executeCommand(Arrays
.asList("lttng", "stop", sessionName
));
122 public List
<String
> view() {
123 return ShellUtils
.getOutputFromCommand(true, Arrays
.asList("lttng", "view", sessionName
));
This page took 0.045178 seconds and 5 git commands to generate.