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