1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 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 * Return the start time of this history. It usually matches the start time
37 * of the original trace.
39 * @return The history's registered start time
44 * Return the current end time of the history.
46 * @return The current end time of this state history
48 long getCurrentEndTime();
51 * Check if the construction of this state system was cancelled or not. If
52 * false is returned, it can mean that the building was finished
53 * successfully, or that it is still ongoing. You can check independently
54 * with {@link #waitUntilBuilt()} if it is finished or not.
56 * @return If the construction was cancelled or not. In true is returned, no
57 * queries should be run afterwards.
60 boolean isCancelled();
63 * While it's possible to query a state history that is being built,
64 * sometimes we might want to wait until the construction is finished before
65 * we start doing queries.
67 * This method blocks the calling thread until the history back-end is done
68 * building. If it's already built (ie, opening a pre-existing file) this
69 * should return immediately.
71 * You should always check with {@link #isCancelled()} if it is safe to
72 * query this state system before doing queries.
76 void waitUntilBuilt();
79 * Wait until the state system construction is finished. Similar to
80 * {@link #waitUntilBuilt()}, but we also specify a timeout. If the timeout
81 * elapses before the construction is finished, the method will return.
83 * The return value determines if the return was due to the construction
84 * finishing (true), or the timeout elapsing (false).
86 * This can be useful, for example, for a component doing queries
87 * periodically to the system while it is being built.
90 * Timeout value in milliseconds
91 * @return True if the return was due to the construction finishing, false
92 * if it was because the timeout elapsed. Same logic as
93 * {@link java.util.concurrent.CountDownLatch#await(long, java.util.concurrent.TimeUnit)}
96 boolean waitUntilBuilt(long timeout
);
99 * Notify the state system that the trace is being closed, so it should
100 * clean up, close its files, etc.
105 * Return the current total amount of attributes in the system. This is also
106 * equal to the quark that will be assigned to the next attribute that's
109 * @return The current number of attributes in the system
111 int getNbAttributes();
114 * @name Read-only quark-getting methods
118 * Basic quark-retrieving method. Pass an attribute in parameter as an array
119 * of strings, the matching quark will be returned.
121 * This version will NOT create any new attributes. If an invalid attribute
122 * is requested, an exception will be thrown.
125 * Attribute given as its full path in the Attribute Tree
126 * @return The quark of the requested attribute, if it existed.
127 * @throws AttributeNotFoundException
128 * This exception is thrown if the requested attribute simply
129 * did not exist in the system.
131 int getQuarkAbsolute(String
... attribute
)
132 throws AttributeNotFoundException
;
135 * "Relative path" quark-getting method. Instead of specifying a full path,
136 * if you know the path is relative to another attribute for which you
137 * already have the quark, use this for better performance.
139 * This is useful for cases where a lot of modifications or queries will
140 * originate from the same branch of the attribute tree : the common part of
141 * the path won't have to be re-hashed for every access.
143 * This version will NOT create any new attributes. If an invalid attribute
144 * is requested, an exception will be thrown.
146 * @param startingNodeQuark
147 * The quark of the attribute from which 'subPath' originates.
149 * "Rest" of the path to get to the final attribute
150 * @return The matching quark, if it existed
151 * @throws AttributeNotFoundException
152 * If the quark is invalid
154 int getQuarkRelative(int startingNodeQuark
, String
... subPath
)
155 throws AttributeNotFoundException
;
158 * Return the sub-attributes of the target attribute, as a List of quarks.
161 * The attribute of which you want to sub-attributes. You can use
162 * "-1" here to specify the root node.
164 * True if you want all recursive sub-attributes, false if you
165 * only want the first level.
166 * @return A List of integers, matching the quarks of the sub-attributes.
167 * @throws AttributeNotFoundException
168 * If the quark was not existing or invalid.
170 List
<Integer
> getSubAttributes(int quark
, boolean recursive
)
171 throws AttributeNotFoundException
;
174 * Batch quark-retrieving method. This method allows you to specify a path
175 * pattern which includes a wildcard "*" somewhere. It will check all the
176 * existing attributes in the attribute tree and return those who match the
179 * For example, passing ("Threads", "*", "Exec_mode") will return the list
180 * of quarks for attributes "Threads/1000/Exec_mode",
181 * "Threads/1500/Exec_mode", and so on, depending on what exists at this
182 * time in the attribute tree.
184 * If no wildcard is specified, the behavior is the same as
185 * getQuarkAbsolute() (except it will return a List with one entry). This
186 * method will never create new attributes.
188 * Only one wildcard "*" is supported at this time.
191 * The array of strings representing the pattern to look for. It
192 * should ideally contain one entry that is only a "*".
193 * @return A List of attribute quarks, representing attributes that matched
194 * the pattern. If no attribute matched, the list will be empty (but
197 List
<Integer
> getQuarks(String
... pattern
);
200 * Return the name assigned to this quark. This returns only the "basename",
201 * not the complete path to this attribute.
203 * @param attributeQuark
204 * The quark for which we want the name
205 * @return The name of the quark
207 String
getAttributeName(int attributeQuark
);
210 * This returns the slash-separated path of an attribute by providing its
213 * @param attributeQuark
214 * The quark of the attribute we want
215 * @return One single string separated with '/', like a filesystem path
217 String
getFullAttributePath(int attributeQuark
);
220 * @name Query methods
224 * Returns the current state value we have (in the Transient State) for the
227 * This is useful even for a StateHistorySystem, as we are guaranteed it
228 * will only do a memory access and not go look on disk (and we don't even
229 * have to provide a timestamp!)
231 * @param attributeQuark
232 * For which attribute we want the current state
233 * @return The State value that's "current" for this attribute
234 * @throws AttributeNotFoundException
235 * If the requested attribute is invalid
237 ITmfStateValue
queryOngoingState(int attributeQuark
)
238 throws AttributeNotFoundException
;
241 * Get the start time of the current ongoing state, for the specified
245 * Quark of the attribute
246 * @return The current start time of the ongoing state
247 * @throws AttributeNotFoundException
248 * If the attribute is invalid
250 long getOngoingStartTime(int attribute
)
251 throws AttributeNotFoundException
;
254 * Load the complete state information at time 't' into the returned List.
255 * You can then get the intervals for single attributes by using
256 * List.get(n), where 'n' is the quark of the attribute.
258 * On average if you need around 10 or more queries for the same timestamps,
259 * use this method. If you need less than 10 (for example, running many
260 * queries for the same attributes but at different timestamps), you might
261 * be better using the querySingleState() methods instead.
264 * We will recreate the state information to what it was at time
266 * @return The List of intervals, where the offset = the quark
267 * @throws TimeRangeException
268 * If the 't' parameter is outside of the range of the state
270 * @throws StateSystemDisposedException
271 * If the query is sent after the state system has been disposed
273 List
<ITmfStateInterval
> queryFullState(long t
)
274 throws TimeRangeException
, StateSystemDisposedException
;
277 * Singular query method. This one does not update the whole stateInfo
278 * vector, like queryFullState() does. It only searches for one specific
279 * entry in the state history.
281 * It should be used when you only want very few entries, instead of the
282 * whole state (or many entries, but all at different timestamps). If you do
283 * request many entries all at the same time, you should use the
284 * conventional queryFullState() + List.get() method.
287 * The timestamp at which we want the state
288 * @param attributeQuark
289 * Which attribute we want to get the state of
290 * @return The StateInterval representing the state
291 * @throws TimeRangeException
293 * @throws AttributeNotFoundException
294 * If the requested quark does not exist in the model
295 * @throws StateSystemDisposedException
296 * If the query is sent after the state system has been disposed
298 ITmfStateInterval
querySingleState(long t
, int attributeQuark
)
299 throws AttributeNotFoundException
, TimeRangeException
,
300 StateSystemDisposedException
;
303 * Convenience method to query attribute stacks (created with
304 * pushAttribute()/popAttribute()). This will return the interval that is
305 * currently at the top of the stack, or 'null' if that stack is currently
306 * empty. It works similarly to querySingleState().
308 * To retrieve the other values in a stack, you can query the sub-attributes
312 * The timestamp of the query
313 * @param stackAttributeQuark
314 * The top-level stack-attribute (that was the target of
315 * pushAttribute() at creation time)
316 * @return The interval that was at the top of the stack, or 'null' if the
318 * @throws StateValueTypeException
319 * If the target attribute is not a valid stack attribute (if it
320 * has a string value for example)
321 * @throws AttributeNotFoundException
322 * If the attribute was simply not found
323 * @throws TimeRangeException
324 * If the given timestamp is invalid
325 * @throws StateSystemDisposedException
326 * If the query is sent after the state system has been disposed
329 ITmfStateInterval
querySingleStackTop(long t
, int stackAttributeQuark
)
330 throws StateValueTypeException
, AttributeNotFoundException
,
331 TimeRangeException
, StateSystemDisposedException
;
334 * Return a list of state intervals, containing the "history" of a given
335 * attribute between timestamps t1 and t2. The list will be ordered by
338 * Note that contrary to queryFullState(), the returned list here is in the
339 * "direction" of time (and not in the direction of attributes, as is the
340 * case with queryFullState()).
342 * @param attributeQuark
343 * Which attribute this query is interested in
345 * Start time of the range query
347 * Target end time of the query. If t2 is greater than the end of
348 * the trace, we will return what we have up to the end of the
350 * @return The List of state intervals that happened between t1 and t2
351 * @throws TimeRangeException
352 * If t1 is invalid, or if t2 <= t1
353 * @throws AttributeNotFoundException
354 * If the requested quark does not exist in the model.
355 * @throws StateSystemDisposedException
356 * If the query is sent after the state system has been disposed
358 List
<ITmfStateInterval
> queryHistoryRange(int attributeQuark
,
359 long t1
, long t2
) throws TimeRangeException
,
360 AttributeNotFoundException
, StateSystemDisposedException
;
363 * Return the state history of a given attribute, but with at most one
364 * update per "resolution". This can be useful for populating views (where
365 * it's useless to have more than one query per pixel, for example). A
366 * progress monitor can be used to cancel the query before completion.
368 * @param attributeQuark
369 * Which attribute this query is interested in
371 * Start time of the range query
373 * Target end time of the query. If t2 is greater than the end of
374 * the trace, we will return what we have up to the end of the
377 * The "step" of this query
379 * A progress monitor. If the monitor is canceled during a query,
380 * we will return what has been found up to that point. You can
381 * use "null" if you do not want to use one.
382 * @return The List of states that happened between t1 and t2
383 * @throws TimeRangeException
384 * If t1 is invalid, if t2 <= t1, or if the resolution isn't
386 * @throws AttributeNotFoundException
387 * If the attribute doesn't exist
388 * @throws StateSystemDisposedException
389 * If the query is sent after the state system has been disposed
392 List
<ITmfStateInterval
> queryHistoryRange(int attributeQuark
,
393 long t1
, long t2
, long resolution
, IProgressMonitor monitor
)
394 throws TimeRangeException
, AttributeNotFoundException
,
395 StateSystemDisposedException
;