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