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 * Notify the state system that the trace is being closed, so it should
80 * clean up, close its files, etc.
85 * Return the current total amount of attributes in the system. This is also
86 * equal to the quark that will be assigned to the next attribute that's
89 * @return The current number of attributes in the system
91 int getNbAttributes();
94 * @name Read-only quark-getting methods
98 * Basic quark-retrieving method. Pass an attribute in parameter as an array
99 * of strings, the matching quark will be returned.
101 * This version will NOT create any new attributes. If an invalid attribute
102 * is requested, an exception will be thrown.
105 * Attribute given as its full path in the Attribute Tree
106 * @return The quark of the requested attribute, if it existed.
107 * @throws AttributeNotFoundException
108 * This exception is thrown if the requested attribute simply
109 * did not exist in the system.
111 int getQuarkAbsolute(String
... attribute
)
112 throws AttributeNotFoundException
;
115 * "Relative path" quark-getting method. Instead of specifying a full path,
116 * if you know the path is relative to another attribute for which you
117 * already have the quark, use this for better performance.
119 * This is useful for cases where a lot of modifications or queries will
120 * originate from the same branch of the attribute tree : the common part of
121 * the path won't have to be re-hashed for every access.
123 * This version will NOT create any new attributes. If an invalid attribute
124 * is requested, an exception will be thrown.
126 * @param startingNodeQuark
127 * The quark of the attribute from which 'subPath' originates.
129 * "Rest" of the path to get to the final attribute
130 * @return The matching quark, if it existed
131 * @throws AttributeNotFoundException
132 * If the quark is invalid
134 int getQuarkRelative(int startingNodeQuark
, String
... subPath
)
135 throws AttributeNotFoundException
;
138 * Return the sub-attributes of the target attribute, as a List of quarks.
141 * The attribute of which you want to sub-attributes. You can use
142 * "-1" here to specify the root node.
144 * True if you want all recursive sub-attributes, false if you
145 * only want the first level.
146 * @return A List of integers, matching the quarks of the sub-attributes.
147 * @throws AttributeNotFoundException
148 * If the quark was not existing or invalid.
150 List
<Integer
> getSubAttributes(int quark
, boolean recursive
)
151 throws AttributeNotFoundException
;
154 * Batch quark-retrieving method. This method allows you to specify a path
155 * pattern which includes a wildcard "*" somewhere. It will check all the
156 * existing attributes in the attribute tree and return those who match the
159 * For example, passing ("Threads", "*", "Exec_mode") will return the list
160 * of quarks for attributes "Threads/1000/Exec_mode",
161 * "Threads/1500/Exec_mode", and so on, depending on what exists at this
162 * time in the attribute tree.
164 * If no wildcard is specified, the behavior is the same as
165 * getQuarkAbsolute() (except it will return a List with one entry). This
166 * method will never create new attributes.
168 * Only one wildcard "*" is supported at this time.
171 * The array of strings representing the pattern to look for. It
172 * should ideally contain one entry that is only a "*".
173 * @return A List of attribute quarks, representing attributes that matched
174 * the pattern. If no attribute matched, the list will be empty (but
177 List
<Integer
> getQuarks(String
... pattern
);
180 * Return the name assigned to this quark. This returns only the "basename",
181 * not the complete path to this attribute.
183 * @param attributeQuark
184 * The quark for which we want the name
185 * @return The name of the quark
187 String
getAttributeName(int attributeQuark
);
190 * This returns the slash-separated path of an attribute by providing its
193 * @param attributeQuark
194 * The quark of the attribute we want
195 * @return One single string separated with '/', like a filesystem path
197 String
getFullAttributePath(int attributeQuark
);
200 * @name Query methods
204 * Returns the current state value we have (in the Transient State) for the
207 * This is useful even for a StateHistorySystem, as we are guaranteed it
208 * will only do a memory access and not go look on disk (and we don't even
209 * have to provide a timestamp!)
211 * @param attributeQuark
212 * For which attribute we want the current state
213 * @return The State value that's "current" for this attribute
214 * @throws AttributeNotFoundException
215 * If the requested attribute is invalid
217 ITmfStateValue
queryOngoingState(int attributeQuark
)
218 throws AttributeNotFoundException
;
221 * Get the start time of the current ongoing state, for the specified
225 * Quark of the attribute
226 * @return The current start time of the ongoing state
227 * @throws AttributeNotFoundException
228 * If the attribute is invalid
230 long getOngoingStartTime(int attribute
)
231 throws AttributeNotFoundException
;
234 * Load the complete state information at time 't' into the returned List.
235 * You can then get the intervals for single attributes by using
236 * List.get(n), where 'n' is the quark of the attribute.
238 * On average if you need around 10 or more queries for the same timestamps,
239 * use this method. If you need less than 10 (for example, running many
240 * queries for the same attributes but at different timestamps), you might
241 * be better using the querySingleState() methods instead.
244 * We will recreate the state information to what it was at time
246 * @return The List of intervals, where the offset = the quark
247 * @throws TimeRangeException
248 * If the 't' parameter is outside of the range of the state
250 * @throws StateSystemDisposedException
251 * If the query is sent after the state system has been disposed
253 List
<ITmfStateInterval
> queryFullState(long t
)
254 throws TimeRangeException
, StateSystemDisposedException
;
257 * Singular query method. This one does not update the whole stateInfo
258 * vector, like queryFullState() does. It only searches for one specific
259 * entry in the state history.
261 * It should be used when you only want very few entries, instead of the
262 * whole state (or many entries, but all at different timestamps). If you do
263 * request many entries all at the same time, you should use the
264 * conventional queryFullState() + List.get() method.
267 * The timestamp at which we want the state
268 * @param attributeQuark
269 * Which attribute we want to get the state of
270 * @return The StateInterval representing the state
271 * @throws TimeRangeException
273 * @throws AttributeNotFoundException
274 * If the requested quark does not exist in the model
275 * @throws StateSystemDisposedException
276 * If the query is sent after the state system has been disposed
278 ITmfStateInterval
querySingleState(long t
, int attributeQuark
)
279 throws AttributeNotFoundException
, TimeRangeException
,
280 StateSystemDisposedException
;
283 * Convenience method to query attribute stacks (created with
284 * pushAttribute()/popAttribute()). This will return the interval that is
285 * currently at the top of the stack, or 'null' if that stack is currently
286 * empty. It works similarly to querySingleState().
288 * To retrieve the other values in a stack, you can query the sub-attributes
292 * The timestamp of the query
293 * @param stackAttributeQuark
294 * The top-level stack-attribute (that was the target of
295 * pushAttribute() at creation time)
296 * @return The interval that was at the top of the stack, or 'null' if the
298 * @throws StateValueTypeException
299 * If the target attribute is not a valid stack attribute (if it
300 * has a string value for example)
301 * @throws AttributeNotFoundException
302 * If the attribute was simply not found
303 * @throws TimeRangeException
304 * If the given timestamp is invalid
305 * @throws StateSystemDisposedException
306 * If the query is sent after the state system has been disposed
309 ITmfStateInterval
querySingleStackTop(long t
, int stackAttributeQuark
)
310 throws StateValueTypeException
, AttributeNotFoundException
,
311 TimeRangeException
, StateSystemDisposedException
;
314 * Return a list of state intervals, containing the "history" of a given
315 * attribute between timestamps t1 and t2. The list will be ordered by
318 * Note that contrary to queryFullState(), the returned list here is in the
319 * "direction" of time (and not in the direction of attributes, as is the
320 * case with queryFullState()).
322 * @param attributeQuark
323 * Which attribute this query is interested in
325 * Start time of the range query
327 * Target end time of the query. If t2 is greater than the end of
328 * the trace, we will return what we have up to the end of the
330 * @return The List of state intervals that happened between t1 and t2
331 * @throws TimeRangeException
332 * If t1 is invalid, or if t2 <= t1
333 * @throws AttributeNotFoundException
334 * If the requested quark does not exist in the model.
335 * @throws StateSystemDisposedException
336 * If the query is sent after the state system has been disposed
338 List
<ITmfStateInterval
> queryHistoryRange(int attributeQuark
,
339 long t1
, long t2
) throws TimeRangeException
,
340 AttributeNotFoundException
, StateSystemDisposedException
;
343 * Return the state history of a given attribute, but with at most one
344 * update per "resolution". This can be useful for populating views (where
345 * it's useless to have more than one query per pixel, for example). A
346 * progress monitor can be used to cancel the query before completion.
348 * @param attributeQuark
349 * Which attribute this query is interested in
351 * Start time of the range query
353 * Target end time of the query. If t2 is greater than the end of
354 * the trace, we will return what we have up to the end of the
357 * The "step" of this query
359 * A progress monitor. If the monitor is canceled during a query,
360 * we will return what has been found up to that point. You can
361 * use "null" if you do not want to use one.
362 * @return The List of states that happened between t1 and t2
363 * @throws TimeRangeException
364 * If t1 is invalid, if t2 <= t1, or if the resolution isn't
366 * @throws AttributeNotFoundException
367 * If the attribute doesn't exist
368 * @throws StateSystemDisposedException
369 * If the query is sent after the state system has been disposed
372 List
<ITmfStateInterval
> queryHistoryRange(int attributeQuark
,
373 long t1
, long t2
, long resolution
, IProgressMonitor monitor
)
374 throws TimeRangeException
, AttributeNotFoundException
,
375 StateSystemDisposedException
;