1 /*******************************************************************************
2 * Copyright (c) 2012, 2014 Ericsson
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
10 * Alexandre Montplaisir - Initial API
11 ******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.core
.statesystem
;
15 import java
.util
.List
;
17 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.AttributeNotFoundException
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.StateSystemDisposedException
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.StateValueTypeException
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TimeRangeException
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.interval
.ITmfStateInterval
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.statevalue
.ITmfStateValue
;
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.
29 * @author Alexandre Montplaisir
33 public interface ITmfStateSystem
{
36 * Get the ID of this state system.
38 * @return The state system's ID
44 * Return the start time of this history. It usually matches the start time
45 * of the original trace.
47 * @return The history's registered start time
52 * Return the current end time of the history.
54 * @return The current end time of this state history
56 long getCurrentEndTime();
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.
64 * @return If the construction was cancelled or not. In true is returned, no
65 * queries should be run afterwards.
68 boolean isCancelled();
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.
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
77 * should return immediately.
79 * You should always check with {@link #isCancelled()} if it is safe to
80 * query this state system before doing queries.
84 void waitUntilBuilt();
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.
91 * The return value determines if the return was due to the construction
92 * finishing (true), or the timeout elapsing (false).
94 * This can be useful, for example, for a component doing queries
95 * periodically to the system while it is being built.
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)}
104 boolean waitUntilBuilt(long timeout
);
107 * Notify the state system that the trace is being closed, so it should
108 * clean up, close its files, etc.
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
117 * @return The current number of attributes in the system
119 int getNbAttributes();
122 * @name Read-only quark-getting methods
126 * Basic quark-retrieving method. Pass an attribute in parameter as an array
127 * of strings, the matching quark will be returned.
129 * This version will NOT create any new attributes. If an invalid attribute
130 * is requested, an exception will be thrown.
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.
139 int getQuarkAbsolute(String
... attribute
)
140 throws AttributeNotFoundException
;
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.
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.
151 * This version will NOT create any new attributes. If an invalid attribute
152 * is requested, an exception will be thrown.
154 * @param startingNodeQuark
155 * The quark of the attribute from which 'subPath' originates.
157 * "Rest" of the path to get to the final attribute
158 * @return The matching quark, if it existed
159 * @throws AttributeNotFoundException
160 * If the quark is invalid
162 int getQuarkRelative(int startingNodeQuark
, String
... subPath
)
163 throws AttributeNotFoundException
;
166 * Return the sub-attributes of the target attribute, as a List of quarks.
169 * The attribute of which you want to sub-attributes. You can use
170 * "-1" here to specify the root node.
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.
178 List
<Integer
> getSubAttributes(int quark
, boolean recursive
)
179 throws AttributeNotFoundException
;
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.
187 * The attribute of which you want to sub-attributes. You can use
188 * "-1" here to specify the root node.
190 * True if you want all recursive sub-attributes, false if you
191 * only want the first level. Note that the returned value will
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.
202 List
<Integer
> getSubAttributes(int quark
, boolean recursive
, String pattern
)
203 throws AttributeNotFoundException
;
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
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.
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.
220 * Only one wildcard "*" is supported at this time.
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
229 List
<Integer
> getQuarks(String
... pattern
);
232 * Return the name assigned to this quark. This returns only the "basename",
233 * not the complete path to this attribute.
235 * @param attributeQuark
236 * The quark for which we want the name
237 * @return The name of the quark
239 String
getAttributeName(int attributeQuark
);
242 * This returns the slash-separated path of an attribute by providing its
245 * @param attributeQuark
246 * The quark of the attribute we want
247 * @return One single string separated with '/', like a filesystem path
249 String
getFullAttributePath(int attributeQuark
);
252 * Returns the parent quark of the attribute.
254 * @param attributeQuark
255 * The quark of the attribute
256 * @return Quark of the parent attribute or <code>-1</code> if root quark or
260 int getParentAttributeQuark(int attributeQuark
);
263 * @name Query methods
267 * Returns the current state value we have (in the Transient State) for the
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!)
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
280 ITmfStateValue
queryOngoingState(int attributeQuark
)
281 throws AttributeNotFoundException
;
284 * Get the start time of the current ongoing state, for the specified
288 * Quark of the attribute
289 * @return The current start time of the ongoing state
290 * @throws AttributeNotFoundException
291 * If the attribute is invalid
293 long getOngoingStartTime(int attribute
)
294 throws AttributeNotFoundException
;
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.
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.
307 * We will recreate the state information to what it was at time
309 * @return The List of intervals, where the offset = the quark
310 * @throws TimeRangeException
311 * If the 't' parameter is outside of the range of the state
313 * @throws StateSystemDisposedException
314 * If the query is sent after the state system has been disposed
316 List
<ITmfStateInterval
> queryFullState(long t
)
317 throws StateSystemDisposedException
;
320 * Singular query method. This one does not update the whole stateInfo
321 * vector, like queryFullState() does. It only searches for one specific
322 * entry in the state history.
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
327 * conventional queryFullState() + List.get() method.
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
336 * @throws AttributeNotFoundException
337 * If the requested quark does not exist in the model
338 * @throws StateSystemDisposedException
339 * If the query is sent after the state system has been disposed
341 ITmfStateInterval
querySingleState(long t
, int attributeQuark
)
342 throws AttributeNotFoundException
, StateSystemDisposedException
;
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().
350 * To retrieve the other values in a stack, you can query the sub-attributes
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
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
367 * @throws StateSystemDisposedException
368 * If the query is sent after the state system has been disposed
371 ITmfStateInterval
querySingleStackTop(long t
, int stackAttributeQuark
)
372 throws AttributeNotFoundException
, StateSystemDisposedException
;
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
379 * Note that contrary to queryFullState(), the returned list here is in the
380 * "direction" of time (and not in the direction of attributes, as is the
381 * case with queryFullState()).
383 * @param attributeQuark
384 * Which attribute this query is interested in
386 * Start time of the range query
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
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.
396 * @throws StateSystemDisposedException
397 * If the query is sent after the state system has been disposed
399 List
<ITmfStateInterval
> queryHistoryRange(int attributeQuark
, long t1
, long t2
)
400 throws AttributeNotFoundException
, StateSystemDisposedException
;
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
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.
408 * @param attributeQuark
409 * Which attribute this query is interested in
411 * Start time of the range query
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
417 * The "step" of this query
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.
422 * @return The List of states that happened between t1 and t2
423 * @throws TimeRangeException
424 * If t1 is invalid, if t2 <= t1, or if the resolution isn't
426 * @throws AttributeNotFoundException
427 * If the attribute doesn't exist
428 * @throws StateSystemDisposedException
429 * If the query is sent after the state system has been disposed
432 List
<ITmfStateInterval
> queryHistoryRange(int attributeQuark
,
433 long t1
, long t2
, long resolution
, IProgressMonitor monitor
)
434 throws AttributeNotFoundException
, StateSystemDisposedException
;