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