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