Commit | Line | Data |
---|---|---|
45d1768c AM |
1 | /* |
2 | * Copyright (C) 2015, EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com> | |
3 | * | |
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. | |
8 | * | |
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. | |
13 | * | |
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. | |
17 | */ | |
18 | ||
19 | package org.lttng.tools; | |
20 | ||
21 | import java.util.List; | |
22 | ||
23 | /** | |
24 | * Java representation of a LTTng tracing session. | |
25 | * | |
26 | * @author Alexandre Montplaisir | |
27 | */ | |
28 | public interface ILttngSession extends AutoCloseable { | |
29 | ||
30 | /** | |
31 | * Tracing domains as they are defined by lttng-tools | |
32 | */ | |
33 | enum Domain { | |
34 | /** The JUL (java.util.logging) domain */ | |
9db2c69a MJ |
35 | JUL("--jul", ">=", Integer.MIN_VALUE), /** The log4j (org.apache.log4j) domain */ |
36 | LOG4J("--log4j", ">=", Integer.MIN_VALUE), | |
37 | LOG4J2("--log4j2", "<=", Integer.MAX_VALUE); | |
45d1768c AM |
38 | |
39 | private final String flag; | |
9db2c69a MJ |
40 | private final String rangeOperator; |
41 | private final int levelAllValue; | |
45d1768c | 42 | |
9db2c69a | 43 | private Domain(String flag, String rangeOperator, int levelAllValue) { |
45d1768c | 44 | this.flag = flag; |
9db2c69a MJ |
45 | this.rangeOperator = rangeOperator; |
46 | this.levelAllValue = levelAllValue; | |
45d1768c AM |
47 | } |
48 | ||
49 | /** | |
50 | * @return The corresponding command-line flag to pass to options like | |
51 | * "lttng enable-event" | |
52 | */ | |
53 | public String flag() { | |
54 | return flag; | |
55 | } | |
9db2c69a MJ |
56 | |
57 | public String rangeOperator() { | |
58 | return rangeOperator; | |
59 | } | |
60 | ||
61 | public int levelAllValue() { | |
62 | return levelAllValue; | |
63 | } | |
45d1768c AM |
64 | } |
65 | ||
66 | // ------------------------------------------------------------------------ | |
67 | // Factory methods | |
68 | // ------------------------------------------------------------------------ | |
69 | ||
70 | /** | |
ff620bef | 71 | * Create a new LTTng tracing session using the default backend. |
45d1768c AM |
72 | * |
73 | * @param sessionName | |
74 | * The name of the session to use. It can be null, in which case | |
75 | * we will provide a unique random name. | |
76 | * @param domain | |
77 | * The tracing domain of this session | |
78 | * @return The new session object | |
79 | */ | |
ff620bef AM |
80 | static ILttngSession createSession(String sessionName, Domain domain) { |
81 | return createCommandLineSession(sessionName, domain); | |
82 | } | |
83 | ||
84 | /** | |
85 | * Create a new LTTng tracing session, which will use the command-line | |
86 | * "lttng" utility. | |
87 | * | |
88 | * @param sessionName | |
89 | * The name of the session to use. It can be null, in which case | |
90 | * we will provide a unique random name. | |
91 | * @param domain | |
92 | * The tracing domain of this session | |
93 | * @return The new session object | |
94 | */ | |
95 | static ILttngSession createCommandLineSession(String sessionName, Domain domain) { | |
45d1768c AM |
96 | return new LttngCommandLineSession(sessionName, domain); |
97 | } | |
98 | ||
99 | // ------------------------------------------------------------------------ | |
100 | // AutoCloseable | |
101 | // ------------------------------------------------------------------------ | |
102 | ||
103 | /** | |
104 | * Should be used to destroy the LTTng session. | |
105 | */ | |
106 | @Override | |
107 | void close(); | |
108 | ||
109 | // ------------------------------------------------------------------------ | |
110 | // Session management | |
111 | // ------------------------------------------------------------------------ | |
112 | ||
113 | /** | |
f37120c3 | 114 | * Enable an individual event, specifying a loglevel and filter string. |
45d1768c | 115 | * |
f37120c3 AM |
116 | * @param eventName |
117 | * The name of the event to enable | |
118 | * @param loglevel | |
119 | * The loglevel, will be passed as-is to lttng. May be null to | |
120 | * not specify it. | |
121 | * @param loglevelOnly | |
122 | * True to use this log level only (--loglevel-only), or false to | |
123 | * include all more severe levels (--loglevel). Ignored if | |
124 | * "loglevel" is null. | |
125 | * @param filter | |
126 | * The filter string, may be null to not specify one. | |
127 | * @return If the command executed successfully (return code = 0) | |
45d1768c | 128 | */ |
f37120c3 | 129 | boolean enableEvent(String eventName, String loglevel, boolean loglevelOnly, String filter); |
45d1768c AM |
130 | |
131 | /** | |
f37120c3 | 132 | * Enable individual event(s) with no loglevel/filter specified. |
45d1768c AM |
133 | * |
134 | * @param enabledEvents | |
135 | * The list of events to enable. Should not be null or empty | |
136 | * @return If the command executed successfully (return code = 0). | |
137 | */ | |
138 | boolean enableEvents(String... enabledEvents); | |
139 | ||
140 | /** | |
f37120c3 AM |
141 | * Enable all events in the session (as with "enable-event -a"). |
142 | * | |
143 | * @return If the command executed successfully (return code = 0). | |
144 | */ | |
145 | boolean enableAllEvents(); | |
146 | ||
147 | /** | |
148 | * Send a disable-event command. Used to disable event(s) that were previously | |
45d1768c AM |
149 | * enabled. |
150 | * | |
151 | * @param disabledEvents | |
152 | * The list of disabled events. Should not be null or empty | |
153 | * @return If the command executed successfully (return code = 0). | |
154 | */ | |
155 | boolean disableEvents(String... disabledEvents); | |
156 | ||
f37120c3 AM |
157 | /** |
158 | * Disable all events currently enabled in the session | |
159 | * ("lttng disable-event -a"). | |
160 | * | |
161 | * @return If the command executed successfully (return code = 0) | |
162 | */ | |
163 | boolean disableAllEvents(); | |
164 | ||
b34f80ae AM |
165 | /** |
166 | * Get a list of events currently available (exposed by applications) in the | |
167 | * session's domain. | |
168 | * | |
169 | * @return The list of available events | |
170 | */ | |
8f21b7d2 | 171 | List<String> listEvents(); |
b34f80ae | 172 | |
73fb6785 AM |
173 | /** |
174 | * Enable an application context with the provided retriever/context names. | |
175 | * | |
176 | * There is currently no direct command to remove an existing context, the | |
177 | * session has to be destroyed and re-created to do so. | |
178 | * | |
179 | * @param retrieverName | |
180 | * The name of the retriever (or "namespace" of the context) | |
181 | * @param contextName | |
182 | * The name of the context | |
183 | * @return If the command executed successfully (return code = 0) | |
184 | */ | |
185 | boolean enableAppContext(String retrieverName, String contextName); | |
186 | ||
45d1768c AM |
187 | /** |
188 | * Start tracing | |
189 | * | |
190 | * @return If the command executed successfully (return code = 0). | |
191 | */ | |
192 | boolean start(); | |
193 | ||
194 | /** | |
195 | * Stop the tracing session | |
196 | * | |
197 | * @return If the command executed successfully (return code = 0). | |
198 | */ | |
199 | boolean stop(); | |
200 | ||
201 | /** | |
202 | * Issue a "lttng view" command on the session, and returns its output. This | |
203 | * effectively returns the current content of the trace in text form. | |
204 | * | |
205 | * @return The output of Babeltrace on the session's current trace | |
206 | */ | |
207 | List<String> view(); | |
208 | } |