ctf: Don't include all test traces in jar
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / statesystem / ITmfStateSystem.java
CommitLineData
d26f90fd 1/*******************************************************************************
60ae41e1 2 * Copyright (c) 2012, 2014 Ericsson
d26f90fd
AM
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
18ab1d18 13package org.eclipse.linuxtools.tmf.core.statesystem;
d26f90fd
AM
14
15import java.util.List;
16
b5a8d0cc 17import org.eclipse.core.runtime.IProgressMonitor;
6d08acca 18import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;
96345c5a 19import org.eclipse.linuxtools.tmf.core.exceptions.StateSystemDisposedException;
4bff6e6e 20import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;
6d08acca 21import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;
d26f90fd 22import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval;
d26f90fd
AM
23import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue;
24
25/**
26 * This is the read-only interface to the generic state system. It contains all
27 * the read-only quark-getting methods, as well as the history-querying ones.
5df842b3 28 *
2cb26548 29 * @author Alexandre Montplaisir
f1f86dfb
AM
30 * @version 2.0
31 * @since 2.0
d26f90fd 32 */
f1f86dfb 33public interface ITmfStateSystem {
d26f90fd 34
84a9548a
AM
35 /**
36 * Get the ID of this state system.
37 *
38 * @return The state system's ID
39 * @since 3.0
40 */
41 String getSSID();
42
d26f90fd
AM
43 /**
44 * Return the start time of this history. It usually matches the start time
45 * of the original trace.
5df842b3 46 *
d26f90fd
AM
47 * @return The history's registered start time
48 */
57a2a5ca 49 long getStartTime();
d26f90fd
AM
50
51 /**
52 * Return the current end time of the history.
5df842b3
AM
53 *
54 * @return The current end time of this state history
d26f90fd 55 */
57a2a5ca 56 long getCurrentEndTime();
d26f90fd 57
2002c638
AM
58 /**
59 * Check if the construction of this state system was cancelled or not. If
60 * false is returned, it can mean that the building was finished
61 * successfully, or that it is still ongoing. You can check independently
62 * with {@link #waitUntilBuilt()} if it is finished or not.
63 *
64 * @return If the construction was cancelled or not. In true is returned, no
65 * queries should be run afterwards.
66 * @since 3.0
67 */
68 boolean isCancelled();
69
16576a7e
AM
70 /**
71 * While it's possible to query a state history that is being built,
72 * sometimes we might want to wait until the construction is finished before
73 * we start doing queries.
74 *
75 * This method blocks the calling thread until the history back-end is done
76 * building. If it's already built (ie, opening a pre-existing file) this
e45de797 77 * should return immediately.
1a4205d9 78 *
2002c638
AM
79 * You should always check with {@link #isCancelled()} if it is safe to
80 * query this state system before doing queries.
81 *
82 * @since 3.0
1a4205d9 83 */
2002c638 84 void waitUntilBuilt();
1a4205d9 85
9287b6a2
AM
86 /**
87 * Wait until the state system construction is finished. Similar to
88 * {@link #waitUntilBuilt()}, but we also specify a timeout. If the timeout
89 * elapses before the construction is finished, the method will return.
90 *
91 * The return value determines if the return was due to the construction
92 * finishing (true), or the timeout elapsing (false).
93 *
94 * This can be useful, for example, for a component doing queries
95 * periodically to the system while it is being built.
96 *
97 * @param timeout
98 * Timeout value in milliseconds
99 * @return True if the return was due to the construction finishing, false
100 * if it was because the timeout elapsed. Same logic as
101 * {@link java.util.concurrent.CountDownLatch#await(long, java.util.concurrent.TimeUnit)}
102 * @since 3.0
103 */
104 boolean waitUntilBuilt(long timeout);
105
1a4205d9
AM
106 /**
107 * Notify the state system that the trace is being closed, so it should
108 * clean up, close its files, etc.
16576a7e 109 */
57a2a5ca 110 void dispose();
16576a7e 111
4623f57f 112 /**
f5295294
AM
113 * Return the current total amount of attributes in the system. This is also
114 * equal to the quark that will be assigned to the next attribute that's
115 * created.
5df842b3
AM
116 *
117 * @return The current number of attributes in the system
4623f57f 118 */
57a2a5ca 119 int getNbAttributes();
4623f57f 120
d26f90fd
AM
121 /**
122 * @name Read-only quark-getting methods
123 */
124
125 /**
126 * Basic quark-retrieving method. Pass an attribute in parameter as an array
127 * of strings, the matching quark will be returned.
5df842b3 128 *
d26f90fd
AM
129 * This version will NOT create any new attributes. If an invalid attribute
130 * is requested, an exception will be thrown.
5df842b3 131 *
d26f90fd
AM
132 * @param attribute
133 * Attribute given as its full path in the Attribute Tree
134 * @return The quark of the requested attribute, if it existed.
135 * @throws AttributeNotFoundException
136 * This exception is thrown if the requested attribute simply
137 * did not exist in the system.
138 */
57a2a5ca 139 int getQuarkAbsolute(String... attribute)
d26f90fd
AM
140 throws AttributeNotFoundException;
141
142 /**
143 * "Relative path" quark-getting method. Instead of specifying a full path,
144 * if you know the path is relative to another attribute for which you
145 * already have the quark, use this for better performance.
5df842b3 146 *
d26f90fd
AM
147 * This is useful for cases where a lot of modifications or queries will
148 * originate from the same branch of the attribute tree : the common part of
149 * the path won't have to be re-hashed for every access.
5df842b3 150 *
d26f90fd
AM
151 * This version will NOT create any new attributes. If an invalid attribute
152 * is requested, an exception will be thrown.
5df842b3 153 *
d26f90fd
AM
154 * @param startingNodeQuark
155 * The quark of the attribute from which 'subPath' originates.
156 * @param subPath
157 * "Rest" of the path to get to the final attribute
158 * @return The matching quark, if it existed
159 * @throws AttributeNotFoundException
5df842b3 160 * If the quark is invalid
d26f90fd 161 */
57a2a5ca 162 int getQuarkRelative(int startingNodeQuark, String... subPath)
d26f90fd
AM
163 throws AttributeNotFoundException;
164
165 /**
166 * Return the sub-attributes of the target attribute, as a List of quarks.
5df842b3 167 *
d26f90fd
AM
168 * @param quark
169 * The attribute of which you want to sub-attributes. You can use
170 * "-1" here to specify the root node.
171 * @param recursive
172 * True if you want all recursive sub-attributes, false if you
173 * only want the first level.
174 * @return A List of integers, matching the quarks of the sub-attributes.
175 * @throws AttributeNotFoundException
176 * If the quark was not existing or invalid.
177 */
57a2a5ca 178 List<Integer> getSubAttributes(int quark, boolean recursive)
d26f90fd
AM
179 throws AttributeNotFoundException;
180
5206c858
AM
181 /**
182 * Return the sub-attributes of the target attribute, as a List of quarks,
183 * similarly to {@link #getSubAttributes(int, boolean)}, but with an added
184 * regex pattern to filter on the return attributes.
185 *
186 * @param quark
187 * The attribute of which you want to sub-attributes. You can use
188 * "-1" here to specify the root node.
189 * @param recursive
190 * True if you want all recursive sub-attributes, false if you
191 * only want the first level. Note that the returned value will
192 * be flattened.
193 * @param pattern
194 * The regular expression to match the attribute base name.
195 * @return A List of integers, matching the quarks of the sub-attributes
196 * that match the regex. An empty list is returned if there is no
197 * matching attribute.
198 * @throws AttributeNotFoundException
199 * If the 'quark' was not existing or invalid.
200 * @since 3.0
201 */
202 List<Integer> getSubAttributes(int quark, boolean recursive, String pattern)
203 throws AttributeNotFoundException;
204
d26f90fd
AM
205 /**
206 * Batch quark-retrieving method. This method allows you to specify a path
207 * pattern which includes a wildcard "*" somewhere. It will check all the
208 * existing attributes in the attribute tree and return those who match the
209 * pattern.
5df842b3 210 *
d26f90fd
AM
211 * For example, passing ("Threads", "*", "Exec_mode") will return the list
212 * of quarks for attributes "Threads/1000/Exec_mode",
213 * "Threads/1500/Exec_mode", and so on, depending on what exists at this
214 * time in the attribute tree.
5df842b3 215 *
d26f90fd
AM
216 * If no wildcard is specified, the behavior is the same as
217 * getQuarkAbsolute() (except it will return a List with one entry). This
218 * method will never create new attributes.
5df842b3 219 *
d26f90fd 220 * Only one wildcard "*" is supported at this time.
5df842b3 221 *
d26f90fd
AM
222 * @param pattern
223 * The array of strings representing the pattern to look for. It
224 * should ideally contain one entry that is only a "*".
225 * @return A List of attribute quarks, representing attributes that matched
226 * the pattern. If no attribute matched, the list will be empty (but
227 * not null).
228 */
57a2a5ca 229 List<Integer> getQuarks(String... pattern);
d26f90fd
AM
230
231 /**
232 * Return the name assigned to this quark. This returns only the "basename",
233 * not the complete path to this attribute.
5df842b3 234 *
d26f90fd
AM
235 * @param attributeQuark
236 * The quark for which we want the name
237 * @return The name of the quark
238 */
57a2a5ca 239 String getAttributeName(int attributeQuark);
d26f90fd
AM
240
241 /**
242 * This returns the slash-separated path of an attribute by providing its
243 * quark
5df842b3 244 *
d26f90fd
AM
245 * @param attributeQuark
246 * The quark of the attribute we want
247 * @return One single string separated with '/', like a filesystem path
248 */
57a2a5ca 249 String getFullAttributePath(int attributeQuark);
d26f90fd 250
0fdd2c45
FG
251 /**
252 * Returns the parent quark of the attribute.
253 *
254 * @param attributeQuark
255 * The quark of the attribute
256 * @return Quark of the parent attribute or <code>-1</code> if root quark or
257 * no parent.
258 * @since 3.0
259 */
260 int getParentAttributeQuark(int attributeQuark);
261
d26f90fd
AM
262 /**
263 * @name Query methods
264 */
265
266 /**
267 * Returns the current state value we have (in the Transient State) for the
268 * given attribute.
5df842b3 269 *
d26f90fd
AM
270 * This is useful even for a StateHistorySystem, as we are guaranteed it
271 * will only do a memory access and not go look on disk (and we don't even
272 * have to provide a timestamp!)
5df842b3 273 *
d26f90fd
AM
274 * @param attributeQuark
275 * For which attribute we want the current state
276 * @return The State value that's "current" for this attribute
277 * @throws AttributeNotFoundException
278 * If the requested attribute is invalid
279 */
57a2a5ca 280 ITmfStateValue queryOngoingState(int attributeQuark)
d26f90fd
AM
281 throws AttributeNotFoundException;
282
602c0697
AM
283 /**
284 * Get the start time of the current ongoing state, for the specified
285 * attribute.
286 *
287 * @param attribute
288 * Quark of the attribute
289 * @return The current start time of the ongoing state
290 * @throws AttributeNotFoundException
291 * If the attribute is invalid
292 */
57a2a5ca 293 long getOngoingStartTime(int attribute)
602c0697
AM
294 throws AttributeNotFoundException;
295
d26f90fd
AM
296 /**
297 * Load the complete state information at time 't' into the returned List.
298 * You can then get the intervals for single attributes by using
299 * List.get(n), where 'n' is the quark of the attribute.
5df842b3 300 *
d26f90fd
AM
301 * On average if you need around 10 or more queries for the same timestamps,
302 * use this method. If you need less than 10 (for example, running many
303 * queries for the same attributes but at different timestamps), you might
304 * be better using the querySingleState() methods instead.
5df842b3 305 *
d26f90fd
AM
306 * @param t
307 * We will recreate the state information to what it was at time
308 * t.
5df842b3 309 * @return The List of intervals, where the offset = the quark
d26f90fd
AM
310 * @throws TimeRangeException
311 * If the 't' parameter is outside of the range of the state
312 * history.
96345c5a
AM
313 * @throws StateSystemDisposedException
314 * If the query is sent after the state system has been disposed
d26f90fd 315 */
57a2a5ca 316 List<ITmfStateInterval> queryFullState(long t)
6dd46830 317 throws StateSystemDisposedException;
d26f90fd
AM
318
319 /**
320 * Singular query method. This one does not update the whole stateInfo
2fc8ca37 321 * vector, like queryFullState() does. It only searches for one specific
d26f90fd 322 * entry in the state history.
5df842b3 323 *
d26f90fd
AM
324 * It should be used when you only want very few entries, instead of the
325 * whole state (or many entries, but all at different timestamps). If you do
326 * request many entries all at the same time, you should use the
2fc8ca37 327 * conventional queryFullState() + List.get() method.
5df842b3 328 *
d26f90fd
AM
329 * @param t
330 * The timestamp at which we want the state
331 * @param attributeQuark
332 * Which attribute we want to get the state of
333 * @return The StateInterval representing the state
334 * @throws TimeRangeException
335 * If 't' is invalid
336 * @throws AttributeNotFoundException
337 * If the requested quark does not exist in the model
96345c5a
AM
338 * @throws StateSystemDisposedException
339 * If the query is sent after the state system has been disposed
d26f90fd 340 */
57a2a5ca 341 ITmfStateInterval querySingleState(long t, int attributeQuark)
6dd46830 342 throws AttributeNotFoundException, StateSystemDisposedException;
d26f90fd 343
4bff6e6e
AM
344 /**
345 * Convenience method to query attribute stacks (created with
346 * pushAttribute()/popAttribute()). This will return the interval that is
347 * currently at the top of the stack, or 'null' if that stack is currently
348 * empty. It works similarly to querySingleState().
349 *
350 * To retrieve the other values in a stack, you can query the sub-attributes
351 * manually.
352 *
353 * @param t
354 * The timestamp of the query
355 * @param stackAttributeQuark
356 * The top-level stack-attribute (that was the target of
357 * pushAttribute() at creation time)
358 * @return The interval that was at the top of the stack, or 'null' if the
359 * stack was empty.
360 * @throws StateValueTypeException
361 * If the target attribute is not a valid stack attribute (if it
362 * has a string value for example)
363 * @throws AttributeNotFoundException
364 * If the attribute was simply not found
365 * @throws TimeRangeException
366 * If the given timestamp is invalid
96345c5a
AM
367 * @throws StateSystemDisposedException
368 * If the query is sent after the state system has been disposed
4bff6e6e
AM
369 * @since 2.0
370 */
57a2a5ca 371 ITmfStateInterval querySingleStackTop(long t, int stackAttributeQuark)
6dd46830 372 throws AttributeNotFoundException, StateSystemDisposedException;
4bff6e6e 373
d26f90fd
AM
374 /**
375 * Return a list of state intervals, containing the "history" of a given
376 * attribute between timestamps t1 and t2. The list will be ordered by
377 * ascending time.
5df842b3 378 *
2fc8ca37 379 * Note that contrary to queryFullState(), the returned list here is in the
d26f90fd 380 * "direction" of time (and not in the direction of attributes, as is the
2fc8ca37 381 * case with queryFullState()).
5df842b3 382 *
d26f90fd
AM
383 * @param attributeQuark
384 * Which attribute this query is interested in
385 * @param t1
386 * Start time of the range query
387 * @param t2
388 * Target end time of the query. If t2 is greater than the end of
389 * the trace, we will return what we have up to the end of the
390 * history.
391 * @return The List of state intervals that happened between t1 and t2
392 * @throws TimeRangeException
393 * If t1 is invalid, or if t2 <= t1
394 * @throws AttributeNotFoundException
395 * If the requested quark does not exist in the model.
96345c5a
AM
396 * @throws StateSystemDisposedException
397 * If the query is sent after the state system has been disposed
d26f90fd 398 */
6dd46830
AM
399 List<ITmfStateInterval> queryHistoryRange(int attributeQuark, long t1, long t2)
400 throws AttributeNotFoundException, StateSystemDisposedException;
d26f90fd
AM
401
402 /**
403 * Return the state history of a given attribute, but with at most one
404 * update per "resolution". This can be useful for populating views (where
b5a8d0cc
AM
405 * it's useless to have more than one query per pixel, for example). A
406 * progress monitor can be used to cancel the query before completion.
5df842b3 407 *
d26f90fd
AM
408 * @param attributeQuark
409 * Which attribute this query is interested in
410 * @param t1
411 * Start time of the range query
412 * @param t2
413 * Target end time of the query. If t2 is greater than the end of
414 * the trace, we will return what we have up to the end of the
415 * history.
416 * @param resolution
417 * The "step" of this query
b5a8d0cc
AM
418 * @param monitor
419 * A progress monitor. If the monitor is canceled during a query,
420 * we will return what has been found up to that point. You can
421 * use "null" if you do not want to use one.
d26f90fd
AM
422 * @return The List of states that happened between t1 and t2
423 * @throws TimeRangeException
08aaa754
AM
424 * If t1 is invalid, if t2 <= t1, or if the resolution isn't
425 * greater than zero.
d26f90fd
AM
426 * @throws AttributeNotFoundException
427 * If the attribute doesn't exist
96345c5a
AM
428 * @throws StateSystemDisposedException
429 * If the query is sent after the state system has been disposed
b5a8d0cc 430 * @since 2.0
d26f90fd 431 */
57a2a5ca 432 List<ITmfStateInterval> queryHistoryRange(int attributeQuark,
b5a8d0cc 433 long t1, long t2, long resolution, IProgressMonitor monitor)
6dd46830 434 throws AttributeNotFoundException, StateSystemDisposedException;
d26f90fd 435}
This page took 0.175061 seconds and 5 git commands to generate.