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