tmf: Add a method to query an ongoing state's start time
[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 */
41 public long getStartTime();
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
AM
47 */
48 public long getCurrentEndTime();
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 */
64 public boolean waitUntilBuilt();
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 */
1a4205d9 70 public 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
AM
78 */
79 public int getNbAttributes();
80
f5295294
AM
81 /**
82 * Check if a given quark is the last attribute that was added to the
83 * system.
84 *
85 * This is a common case, and it's a bit clearer than
86 * " x == getNbAttributes - 1"
87 *
88 * @param quark
89 * The quark to check for
90 * @return True if this is the last quark that was added to the system,
91 * false if not
92 * @since 2.0
93 */
94 public boolean isLastAttribute(int quark);
95
d26f90fd
AM
96 /**
97 * @name Read-only quark-getting methods
98 */
99
100 /**
101 * Basic quark-retrieving method. Pass an attribute in parameter as an array
102 * of strings, the matching quark will be returned.
5df842b3 103 *
d26f90fd
AM
104 * This version will NOT create any new attributes. If an invalid attribute
105 * is requested, an exception will be thrown.
5df842b3 106 *
d26f90fd
AM
107 * @param attribute
108 * Attribute given as its full path in the Attribute Tree
109 * @return The quark of the requested attribute, if it existed.
110 * @throws AttributeNotFoundException
111 * This exception is thrown if the requested attribute simply
112 * did not exist in the system.
113 */
114 public int getQuarkAbsolute(String... attribute)
115 throws AttributeNotFoundException;
116
117 /**
118 * "Relative path" quark-getting method. Instead of specifying a full path,
119 * if you know the path is relative to another attribute for which you
120 * already have the quark, use this for better performance.
5df842b3 121 *
d26f90fd
AM
122 * This is useful for cases where a lot of modifications or queries will
123 * originate from the same branch of the attribute tree : the common part of
124 * the path won't have to be re-hashed for every access.
5df842b3 125 *
d26f90fd
AM
126 * This version will NOT create any new attributes. If an invalid attribute
127 * is requested, an exception will be thrown.
5df842b3 128 *
d26f90fd
AM
129 * @param startingNodeQuark
130 * The quark of the attribute from which 'subPath' originates.
131 * @param subPath
132 * "Rest" of the path to get to the final attribute
133 * @return The matching quark, if it existed
134 * @throws AttributeNotFoundException
5df842b3 135 * If the quark is invalid
d26f90fd
AM
136 */
137 public int getQuarkRelative(int startingNodeQuark, String... subPath)
138 throws AttributeNotFoundException;
139
140 /**
141 * Return the sub-attributes of the target attribute, as a List of quarks.
5df842b3 142 *
d26f90fd
AM
143 * @param quark
144 * The attribute of which you want to sub-attributes. You can use
145 * "-1" here to specify the root node.
146 * @param recursive
147 * True if you want all recursive sub-attributes, false if you
148 * only want the first level.
149 * @return A List of integers, matching the quarks of the sub-attributes.
150 * @throws AttributeNotFoundException
151 * If the quark was not existing or invalid.
152 */
153 public List<Integer> getSubAttributes(int quark, boolean recursive)
154 throws AttributeNotFoundException;
155
156 /**
157 * Batch quark-retrieving method. This method allows you to specify a path
158 * pattern which includes a wildcard "*" somewhere. It will check all the
159 * existing attributes in the attribute tree and return those who match the
160 * pattern.
5df842b3 161 *
d26f90fd
AM
162 * For example, passing ("Threads", "*", "Exec_mode") will return the list
163 * of quarks for attributes "Threads/1000/Exec_mode",
164 * "Threads/1500/Exec_mode", and so on, depending on what exists at this
165 * time in the attribute tree.
5df842b3 166 *
d26f90fd
AM
167 * If no wildcard is specified, the behavior is the same as
168 * getQuarkAbsolute() (except it will return a List with one entry). This
169 * method will never create new attributes.
5df842b3 170 *
d26f90fd 171 * Only one wildcard "*" is supported at this time.
5df842b3 172 *
d26f90fd
AM
173 * @param pattern
174 * The array of strings representing the pattern to look for. It
175 * should ideally contain one entry that is only a "*".
176 * @return A List of attribute quarks, representing attributes that matched
177 * the pattern. If no attribute matched, the list will be empty (but
178 * not null).
179 */
180 public List<Integer> getQuarks(String... pattern);
181
182 /**
183 * Return the name assigned to this quark. This returns only the "basename",
184 * not the complete path to this attribute.
5df842b3 185 *
d26f90fd
AM
186 * @param attributeQuark
187 * The quark for which we want the name
188 * @return The name of the quark
189 */
190 public String getAttributeName(int attributeQuark);
191
192 /**
193 * This returns the slash-separated path of an attribute by providing its
194 * quark
5df842b3 195 *
d26f90fd
AM
196 * @param attributeQuark
197 * The quark of the attribute we want
198 * @return One single string separated with '/', like a filesystem path
199 */
200 public String getFullAttributePath(int attributeQuark);
201
202 /**
203 * @name Query methods
204 */
205
206 /**
207 * Returns the current state value we have (in the Transient State) for the
208 * given attribute.
5df842b3 209 *
d26f90fd
AM
210 * This is useful even for a StateHistorySystem, as we are guaranteed it
211 * will only do a memory access and not go look on disk (and we don't even
212 * have to provide a timestamp!)
5df842b3 213 *
d26f90fd
AM
214 * @param attributeQuark
215 * For which attribute we want the current state
216 * @return The State value that's "current" for this attribute
217 * @throws AttributeNotFoundException
218 * If the requested attribute is invalid
219 */
220 public ITmfStateValue queryOngoingState(int attributeQuark)
221 throws AttributeNotFoundException;
222
602c0697
AM
223 /**
224 * Get the start time of the current ongoing state, for the specified
225 * attribute.
226 *
227 * @param attribute
228 * Quark of the attribute
229 * @return The current start time of the ongoing state
230 * @throws AttributeNotFoundException
231 * If the attribute is invalid
232 */
233 public long getOngoingStartTime(int attribute)
234 throws AttributeNotFoundException;
235
d26f90fd
AM
236 /**
237 * Load the complete state information at time 't' into the returned List.
238 * You can then get the intervals for single attributes by using
239 * List.get(n), where 'n' is the quark of the attribute.
5df842b3 240 *
d26f90fd
AM
241 * On average if you need around 10 or more queries for the same timestamps,
242 * use this method. If you need less than 10 (for example, running many
243 * queries for the same attributes but at different timestamps), you might
244 * be better using the querySingleState() methods instead.
5df842b3 245 *
d26f90fd
AM
246 * @param t
247 * We will recreate the state information to what it was at time
248 * t.
5df842b3 249 * @return The List of intervals, where the offset = the quark
d26f90fd
AM
250 * @throws TimeRangeException
251 * If the 't' parameter is outside of the range of the state
252 * history.
96345c5a
AM
253 * @throws StateSystemDisposedException
254 * If the query is sent after the state system has been disposed
d26f90fd 255 */
2fc8ca37 256 public List<ITmfStateInterval> queryFullState(long t)
96345c5a 257 throws TimeRangeException, StateSystemDisposedException;
d26f90fd
AM
258
259 /**
260 * Singular query method. This one does not update the whole stateInfo
2fc8ca37 261 * vector, like queryFullState() does. It only searches for one specific
d26f90fd 262 * entry in the state history.
5df842b3 263 *
d26f90fd
AM
264 * It should be used when you only want very few entries, instead of the
265 * whole state (or many entries, but all at different timestamps). If you do
266 * request many entries all at the same time, you should use the
2fc8ca37 267 * conventional queryFullState() + List.get() method.
5df842b3 268 *
d26f90fd
AM
269 * @param t
270 * The timestamp at which we want the state
271 * @param attributeQuark
272 * Which attribute we want to get the state of
273 * @return The StateInterval representing the state
274 * @throws TimeRangeException
275 * If 't' is invalid
276 * @throws AttributeNotFoundException
277 * If the requested quark does not exist in the model
96345c5a
AM
278 * @throws StateSystemDisposedException
279 * If the query is sent after the state system has been disposed
d26f90fd
AM
280 */
281 public ITmfStateInterval querySingleState(long t, int attributeQuark)
96345c5a
AM
282 throws AttributeNotFoundException, TimeRangeException,
283 StateSystemDisposedException;
d26f90fd 284
4bff6e6e
AM
285 /**
286 * Convenience method to query attribute stacks (created with
287 * pushAttribute()/popAttribute()). This will return the interval that is
288 * currently at the top of the stack, or 'null' if that stack is currently
289 * empty. It works similarly to querySingleState().
290 *
291 * To retrieve the other values in a stack, you can query the sub-attributes
292 * manually.
293 *
294 * @param t
295 * The timestamp of the query
296 * @param stackAttributeQuark
297 * The top-level stack-attribute (that was the target of
298 * pushAttribute() at creation time)
299 * @return The interval that was at the top of the stack, or 'null' if the
300 * stack was empty.
301 * @throws StateValueTypeException
302 * If the target attribute is not a valid stack attribute (if it
303 * has a string value for example)
304 * @throws AttributeNotFoundException
305 * If the attribute was simply not found
306 * @throws TimeRangeException
307 * If the given timestamp is invalid
96345c5a
AM
308 * @throws StateSystemDisposedException
309 * If the query is sent after the state system has been disposed
4bff6e6e
AM
310 * @since 2.0
311 */
312 public ITmfStateInterval querySingleStackTop(long t, int stackAttributeQuark)
313 throws StateValueTypeException, AttributeNotFoundException,
96345c5a 314 TimeRangeException, StateSystemDisposedException;
4bff6e6e 315
d26f90fd
AM
316 /**
317 * Return a list of state intervals, containing the "history" of a given
318 * attribute between timestamps t1 and t2. The list will be ordered by
319 * ascending time.
5df842b3 320 *
2fc8ca37 321 * Note that contrary to queryFullState(), the returned list here is in the
d26f90fd 322 * "direction" of time (and not in the direction of attributes, as is the
2fc8ca37 323 * case with queryFullState()).
5df842b3 324 *
d26f90fd
AM
325 * @param attributeQuark
326 * Which attribute this query is interested in
327 * @param t1
328 * Start time of the range query
329 * @param t2
330 * Target end time of the query. If t2 is greater than the end of
331 * the trace, we will return what we have up to the end of the
332 * history.
333 * @return The List of state intervals that happened between t1 and t2
334 * @throws TimeRangeException
335 * If t1 is invalid, or if t2 <= t1
336 * @throws AttributeNotFoundException
337 * If the requested quark does not exist in the model.
96345c5a
AM
338 * @throws StateSystemDisposedException
339 * If the query is sent after the state system has been disposed
d26f90fd
AM
340 */
341 public List<ITmfStateInterval> queryHistoryRange(int attributeQuark,
342 long t1, long t2) throws TimeRangeException,
96345c5a 343 AttributeNotFoundException, StateSystemDisposedException;
d26f90fd
AM
344
345 /**
346 * Return the state history of a given attribute, but with at most one
347 * update per "resolution". This can be useful for populating views (where
b5a8d0cc
AM
348 * it's useless to have more than one query per pixel, for example). A
349 * progress monitor can be used to cancel the query before completion.
5df842b3 350 *
d26f90fd
AM
351 * @param attributeQuark
352 * Which attribute this query is interested in
353 * @param t1
354 * Start time of the range query
355 * @param t2
356 * Target end time of the query. If t2 is greater than the end of
357 * the trace, we will return what we have up to the end of the
358 * history.
359 * @param resolution
360 * The "step" of this query
b5a8d0cc
AM
361 * @param monitor
362 * A progress monitor. If the monitor is canceled during a query,
363 * we will return what has been found up to that point. You can
364 * use "null" if you do not want to use one.
d26f90fd
AM
365 * @return The List of states that happened between t1 and t2
366 * @throws TimeRangeException
08aaa754
AM
367 * If t1 is invalid, if t2 <= t1, or if the resolution isn't
368 * greater than zero.
d26f90fd
AM
369 * @throws AttributeNotFoundException
370 * If the attribute doesn't exist
96345c5a
AM
371 * @throws StateSystemDisposedException
372 * If the query is sent after the state system has been disposed
b5a8d0cc 373 * @since 2.0
d26f90fd
AM
374 */
375 public List<ITmfStateInterval> queryHistoryRange(int attributeQuark,
b5a8d0cc 376 long t1, long t2, long resolution, IProgressMonitor monitor)
96345c5a
AM
377 throws TimeRangeException, AttributeNotFoundException,
378 StateSystemDisposedException;
d26f90fd 379}
This page took 0.051175 seconds and 5 git commands to generate.