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