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
.statesystem
.core
;
15 import java
.util
.List
;
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
;
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
32 public interface ITmfStateSystem
{
35 * Get the ID of this state system.
37 * @return The state system's ID
42 * Return the start time of this history. It usually matches the start time
43 * of the original trace.
45 * @return The history's registered start time
50 * Return the current end time of the history.
52 * @return The current end time of this state history
54 long getCurrentEndTime();
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.
62 * @return If the construction was cancelled or not. In true is returned, no
63 * queries should be run afterwards.
65 boolean isCancelled();
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.
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.
76 * You should always check with {@link #isCancelled()} if it is safe to
77 * query this state system before doing queries.
79 void waitUntilBuilt();
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.
86 * The return value determines if the return was due to the construction
87 * finishing (true), or the timeout elapsing (false).
89 * This can be useful, for example, for a component doing queries
90 * periodically to the system while it is being built.
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)}
98 boolean waitUntilBuilt(long timeout
);
101 * Notify the state system that the trace is being closed, so it should
102 * clean up, close its files, etc.
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
111 * @return The current number of attributes in the system
113 int getNbAttributes();
116 * @name Read-only quark-getting methods
120 * Basic quark-retrieving method. Pass an attribute in parameter as an array
121 * of strings, the matching quark will be returned.
123 * This version will NOT create any new attributes. If an invalid attribute
124 * is requested, an exception will be thrown.
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.
133 int getQuarkAbsolute(String
... attribute
)
134 throws AttributeNotFoundException
;
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.
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.
145 * This version will NOT create any new attributes. If an invalid attribute
146 * is requested, an exception will be thrown.
148 * @param startingNodeQuark
149 * The quark of the attribute from which 'subPath' originates.
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
156 int getQuarkRelative(int startingNodeQuark
, String
... subPath
)
157 throws AttributeNotFoundException
;
160 * Return the sub-attributes of the target attribute, as a List of quarks.
163 * The attribute of which you want to sub-attributes. You can use
164 * "-1" here to specify the root node.
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.
172 List
<Integer
> getSubAttributes(int quark
, boolean recursive
)
173 throws AttributeNotFoundException
;
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.
181 * The attribute of which you want to sub-attributes. You can use
182 * "-1" here to specify the root node.
184 * True if you want all recursive sub-attributes, false if you
185 * only want the first level. Note that the returned value will
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.
195 List
<Integer
> getSubAttributes(int quark
, boolean recursive
, String pattern
)
196 throws AttributeNotFoundException
;
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
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.
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.
213 * Only one wildcard "*" is supported at this time.
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
222 List
<Integer
> getQuarks(String
... pattern
);
225 * Return the name assigned to this quark. This returns only the "basename",
226 * not the complete path to this attribute.
228 * @param attributeQuark
229 * The quark for which we want the name
230 * @return The name of the quark
232 String
getAttributeName(int attributeQuark
);
235 * This returns the slash-separated path of an attribute by providing its
238 * @param attributeQuark
239 * The quark of the attribute we want
240 * @return One single string separated with '/', like a filesystem path
242 String
getFullAttributePath(int attributeQuark
);
245 * Returns the parent quark of the attribute.
247 * @param attributeQuark
248 * The quark of the attribute
249 * @return Quark of the parent attribute or <code>-1</code> if root quark or
252 int getParentAttributeQuark(int attributeQuark
);
255 * @name Query methods
259 * Returns the current state value we have (in the Transient State) for the
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!)
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
272 ITmfStateValue
queryOngoingState(int attributeQuark
)
273 throws AttributeNotFoundException
;
276 * Get the start time of the current ongoing state, for the specified
280 * Quark of the attribute
281 * @return The current start time of the ongoing state
282 * @throws AttributeNotFoundException
283 * If the attribute is invalid
285 long getOngoingStartTime(int attribute
)
286 throws AttributeNotFoundException
;
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.
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.
299 * We will recreate the state information to what it was at time
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
305 * @throws StateSystemDisposedException
306 * If the query is sent after the state system has been disposed
308 List
<ITmfStateInterval
> queryFullState(long t
)
309 throws StateSystemDisposedException
;
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.
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.
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
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
333 ITmfStateInterval
querySingleState(long t
, int attributeQuark
)
334 throws AttributeNotFoundException
, StateSystemDisposedException
;
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().
342 * To retrieve the other values in a stack, you can query the sub-attributes
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
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
362 ITmfStateInterval
querySingleStackTop(long t
, int stackAttributeQuark
)
363 throws AttributeNotFoundException
, StateSystemDisposedException
;
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
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()).
374 * @param attributeQuark
375 * Which attribute this query is interested in
377 * Start time of the range query
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
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
390 List
<ITmfStateInterval
> queryHistoryRange(int attributeQuark
, long t1
, long t2
)
391 throws AttributeNotFoundException
, StateSystemDisposedException
;
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.
399 * @param attributeQuark
400 * Which attribute this query is interested in
402 * Start time of the range query
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
408 * The "step" of this query
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
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
422 List
<ITmfStateInterval
> queryHistoryRange(int attributeQuark
,
423 long t1
, long t2
, long resolution
, IProgressMonitor monitor
)
424 throws AttributeNotFoundException
, StateSystemDisposedException
;