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