tmf: Add dispose methods to the state and stats backends
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / statesystem / ITmfStateSystem.java
1 /*******************************************************************************
2 * Copyright (c) 2012 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Alexandre Montplaisir - Initial API
11 ******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.core.statesystem;
14
15 import java.util.List;
16
17 import org.eclipse.core.runtime.IProgressMonitor;
18 import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;
19 import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;
20 import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;
21 import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval;
22 import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue;
23
24 /**
25 * This is the read-only interface to the generic state system. It contains all
26 * the read-only quark-getting methods, as well as the history-querying ones.
27 *
28 * @author Alexandre Montplaisir
29 * @version 2.0
30 * @since 2.0
31 */
32 public interface ITmfStateSystem {
33
34 /**
35 * Return the start time of this history. It usually matches the start time
36 * of the original trace.
37 *
38 * @return The history's registered start time
39 */
40 public long getStartTime();
41
42 /**
43 * Return the current end time of the history.
44 *
45 * @return The current end time of this state history
46 */
47 public long getCurrentEndTime();
48
49 /**
50 * While it's possible to query a state history that is being built,
51 * sometimes we might want to wait until the construction is finished before
52 * we start doing queries.
53 *
54 * This method blocks the calling thread until the history back-end is done
55 * building. If it's already built (ie, opening a pre-existing file) this
56 * should return immediately. It's an alternative to listening to the
57 * {@link org.eclipse.linuxtools.tmf.core.signal.TmfStateSystemBuildCompleted}
58 * signal.
59 *
60 * @return If the build was successful. If false is returned, this either
61 * means there was a problem during the build, or it got cancelled
62 * before it could finished. In that case, no queries should be run
63 * afterwards.
64 */
65 public boolean waitUntilBuilt();
66
67 /**
68 * Notify the state system that the trace is being closed, so it should
69 * clean up, close its files, etc.
70 */
71 public void dispose();
72
73 /**
74 * Return the current total amount of attributes in the system. This is also
75 * equal to the quark that will be assigned to the next attribute that's
76 * created.
77 *
78 * @return The current number of attributes in the system
79 */
80 public int getNbAttributes();
81
82 /**
83 * Check if a given quark is the last attribute that was added to the
84 * system.
85 *
86 * This is a common case, and it's a bit clearer than
87 * " x == getNbAttributes - 1"
88 *
89 * @param quark
90 * The quark to check for
91 * @return True if this is the last quark that was added to the system,
92 * false if not
93 * @since 2.0
94 */
95 public boolean isLastAttribute(int quark);
96
97 /**
98 * @name Read-only quark-getting methods
99 */
100
101 /**
102 * Basic quark-retrieving method. Pass an attribute in parameter as an array
103 * of strings, the matching quark will be returned.
104 *
105 * This version will NOT create any new attributes. If an invalid attribute
106 * is requested, an exception will be thrown.
107 *
108 * @param attribute
109 * Attribute given as its full path in the Attribute Tree
110 * @return The quark of the requested attribute, if it existed.
111 * @throws AttributeNotFoundException
112 * This exception is thrown if the requested attribute simply
113 * did not exist in the system.
114 */
115 public int getQuarkAbsolute(String... attribute)
116 throws AttributeNotFoundException;
117
118 /**
119 * "Relative path" quark-getting method. Instead of specifying a full path,
120 * if you know the path is relative to another attribute for which you
121 * already have the quark, use this for better performance.
122 *
123 * This is useful for cases where a lot of modifications or queries will
124 * originate from the same branch of the attribute tree : the common part of
125 * the path won't have to be re-hashed for every access.
126 *
127 * This version will NOT create any new attributes. If an invalid attribute
128 * is requested, an exception will be thrown.
129 *
130 * @param startingNodeQuark
131 * The quark of the attribute from which 'subPath' originates.
132 * @param subPath
133 * "Rest" of the path to get to the final attribute
134 * @return The matching quark, if it existed
135 * @throws AttributeNotFoundException
136 * If the quark is invalid
137 */
138 public int getQuarkRelative(int startingNodeQuark, String... subPath)
139 throws AttributeNotFoundException;
140
141 /**
142 * Return the sub-attributes of the target attribute, as a List of quarks.
143 *
144 * @param quark
145 * The attribute of which you want to sub-attributes. You can use
146 * "-1" here to specify the root node.
147 * @param recursive
148 * True if you want all recursive sub-attributes, false if you
149 * only want the first level.
150 * @return A List of integers, matching the quarks of the sub-attributes.
151 * @throws AttributeNotFoundException
152 * If the quark was not existing or invalid.
153 */
154 public List<Integer> getSubAttributes(int quark, boolean recursive)
155 throws AttributeNotFoundException;
156
157 /**
158 * Batch quark-retrieving method. This method allows you to specify a path
159 * pattern which includes a wildcard "*" somewhere. It will check all the
160 * existing attributes in the attribute tree and return those who match the
161 * pattern.
162 *
163 * For example, passing ("Threads", "*", "Exec_mode") will return the list
164 * of quarks for attributes "Threads/1000/Exec_mode",
165 * "Threads/1500/Exec_mode", and so on, depending on what exists at this
166 * time in the attribute tree.
167 *
168 * If no wildcard is specified, the behavior is the same as
169 * getQuarkAbsolute() (except it will return a List with one entry). This
170 * method will never create new attributes.
171 *
172 * Only one wildcard "*" is supported at this time.
173 *
174 * @param pattern
175 * The array of strings representing the pattern to look for. It
176 * should ideally contain one entry that is only a "*".
177 * @return A List of attribute quarks, representing attributes that matched
178 * the pattern. If no attribute matched, the list will be empty (but
179 * not null).
180 */
181 public List<Integer> getQuarks(String... pattern);
182
183 /**
184 * Return the name assigned to this quark. This returns only the "basename",
185 * not the complete path to this attribute.
186 *
187 * @param attributeQuark
188 * The quark for which we want the name
189 * @return The name of the quark
190 */
191 public String getAttributeName(int attributeQuark);
192
193 /**
194 * This returns the slash-separated path of an attribute by providing its
195 * quark
196 *
197 * @param attributeQuark
198 * The quark of the attribute we want
199 * @return One single string separated with '/', like a filesystem path
200 */
201 public String getFullAttributePath(int attributeQuark);
202
203 /**
204 * @name Query methods
205 */
206
207 /**
208 * Returns the current state value we have (in the Transient State) for the
209 * given attribute.
210 *
211 * This is useful even for a StateHistorySystem, as we are guaranteed it
212 * will only do a memory access and not go look on disk (and we don't even
213 * have to provide a timestamp!)
214 *
215 * @param attributeQuark
216 * For which attribute we want the current state
217 * @return The State value that's "current" for this attribute
218 * @throws AttributeNotFoundException
219 * If the requested attribute is invalid
220 */
221 public ITmfStateValue queryOngoingState(int attributeQuark)
222 throws AttributeNotFoundException;
223
224 /**
225 * Load the complete state information at time 't' into the returned List.
226 * You can then get the intervals for single attributes by using
227 * List.get(n), where 'n' is the quark of the attribute.
228 *
229 * On average if you need around 10 or more queries for the same timestamps,
230 * use this method. If you need less than 10 (for example, running many
231 * queries for the same attributes but at different timestamps), you might
232 * be better using the querySingleState() methods instead.
233 *
234 * @param t
235 * We will recreate the state information to what it was at time
236 * t.
237 * @return The List of intervals, where the offset = the quark
238 * @throws TimeRangeException
239 * If the 't' parameter is outside of the range of the state
240 * history.
241 */
242 public List<ITmfStateInterval> queryFullState(long t)
243 throws TimeRangeException;
244
245 /**
246 * Singular query method. This one does not update the whole stateInfo
247 * vector, like queryFullState() does. It only searches for one specific
248 * entry in the state history.
249 *
250 * It should be used when you only want very few entries, instead of the
251 * whole state (or many entries, but all at different timestamps). If you do
252 * request many entries all at the same time, you should use the
253 * conventional queryFullState() + List.get() method.
254 *
255 * @param t
256 * The timestamp at which we want the state
257 * @param attributeQuark
258 * Which attribute we want to get the state of
259 * @return The StateInterval representing the state
260 * @throws TimeRangeException
261 * If 't' is invalid
262 * @throws AttributeNotFoundException
263 * If the requested quark does not exist in the model
264 */
265 public ITmfStateInterval querySingleState(long t, int attributeQuark)
266 throws AttributeNotFoundException, TimeRangeException;
267
268 /**
269 * Convenience method to query attribute stacks (created with
270 * pushAttribute()/popAttribute()). This will return the interval that is
271 * currently at the top of the stack, or 'null' if that stack is currently
272 * empty. It works similarly to querySingleState().
273 *
274 * To retrieve the other values in a stack, you can query the sub-attributes
275 * manually.
276 *
277 * @param t
278 * The timestamp of the query
279 * @param stackAttributeQuark
280 * The top-level stack-attribute (that was the target of
281 * pushAttribute() at creation time)
282 * @return The interval that was at the top of the stack, or 'null' if the
283 * stack was empty.
284 * @throws StateValueTypeException
285 * If the target attribute is not a valid stack attribute (if it
286 * has a string value for example)
287 * @throws AttributeNotFoundException
288 * If the attribute was simply not found
289 * @throws TimeRangeException
290 * If the given timestamp is invalid
291 * @since 2.0
292 */
293 public ITmfStateInterval querySingleStackTop(long t, int stackAttributeQuark)
294 throws StateValueTypeException, AttributeNotFoundException,
295 TimeRangeException;
296
297 /**
298 * Return a list of state intervals, containing the "history" of a given
299 * attribute between timestamps t1 and t2. The list will be ordered by
300 * ascending time.
301 *
302 * Note that contrary to queryFullState(), the returned list here is in the
303 * "direction" of time (and not in the direction of attributes, as is the
304 * case with queryFullState()).
305 *
306 * @param attributeQuark
307 * Which attribute this query is interested in
308 * @param t1
309 * Start time of the range query
310 * @param t2
311 * Target end time of the query. If t2 is greater than the end of
312 * the trace, we will return what we have up to the end of the
313 * history.
314 * @return The List of state intervals that happened between t1 and t2
315 * @throws TimeRangeException
316 * If t1 is invalid, or if t2 <= t1
317 * @throws AttributeNotFoundException
318 * If the requested quark does not exist in the model.
319 */
320 public List<ITmfStateInterval> queryHistoryRange(int attributeQuark,
321 long t1, long t2) throws TimeRangeException,
322 AttributeNotFoundException;
323
324 /**
325 * Return the state history of a given attribute, but with at most one
326 * update per "resolution". This can be useful for populating views (where
327 * it's useless to have more than one query per pixel, for example). A
328 * progress monitor can be used to cancel the query before completion.
329 *
330 * @param attributeQuark
331 * Which attribute this query is interested in
332 * @param t1
333 * Start time of the range query
334 * @param t2
335 * Target end time of the query. If t2 is greater than the end of
336 * the trace, we will return what we have up to the end of the
337 * history.
338 * @param resolution
339 * The "step" of this query
340 * @param monitor
341 * A progress monitor. If the monitor is canceled during a query,
342 * we will return what has been found up to that point. You can
343 * use "null" if you do not want to use one.
344 * @return The List of states that happened between t1 and t2
345 * @throws TimeRangeException
346 * If t1 is invalid, if t2 <= t1, or if the resolution isn't
347 * greater than zero.
348 * @throws AttributeNotFoundException
349 * If the attribute doesn't exist
350 * @since 2.0
351 */
352 public List<ITmfStateInterval> queryHistoryRange(int attributeQuark,
353 long t1, long t2, long resolution, IProgressMonitor monitor)
354 throws TimeRangeException, AttributeNotFoundException;
355 }
This page took 0.050096 seconds and 6 git commands to generate.