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