1 /*******************************************************************************
2 * Copyright (c) 2012, 2015 Ericsson and others.
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
10 * Alexandre Montplaisir - Initial API
11 ******************************************************************************/
13 package org
.eclipse
.tracecompass
.statesystem
.core
;
15 import java
.util
.List
;
17 import org
.eclipse
.jdt
.annotation
.NonNull
;
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
.TimeRangeException
;
21 import org
.eclipse
.tracecompass
.statesystem
.core
.interval
.ITmfStateInterval
;
22 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.ITmfStateValue
;
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.
29 * @author Alexandre Montplaisir
30 * @noimplement Only the internal StateSystem class should implement this
33 public interface ITmfStateSystem
{
36 * Get the ID of this state system.
38 * @return The state system's ID
43 * Return the start time of this history. It usually matches the start time
44 * of the original trace.
46 * @return The history's registered start time
51 * Return the current end time of the history.
53 * @return The current end time of this state history
55 long getCurrentEndTime();
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.
63 * @return If the construction was cancelled or not. In true is returned, no
64 * queries should be run afterwards.
66 boolean isCancelled();
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.
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
75 * should return immediately.
77 * You should always check with {@link #isCancelled()} if it is safe to
78 * query this state system before doing queries.
80 void waitUntilBuilt();
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.
87 * The return value determines if the return was due to the construction
88 * finishing (true), or the timeout elapsing (false).
90 * This can be useful, for example, for a component doing queries
91 * periodically to the system while it is being built.
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)}
99 boolean waitUntilBuilt(long timeout
);
102 * Notify the state system that the trace is being closed, so it should
103 * clean up, close its files, etc.
107 // ------------------------------------------------------------------------
108 // Read-only quark-getting methods
109 // ------------------------------------------------------------------------
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
116 * @return The current number of attributes in the system
118 int getNbAttributes();
121 * Basic quark-retrieving method. Pass an attribute in parameter as an array
122 * of strings, the matching quark will be returned.
124 * This version will NOT create any new attributes. If an invalid attribute
125 * is requested, an exception will be thrown.
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.
134 int getQuarkAbsolute(String
... attribute
)
135 throws AttributeNotFoundException
;
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.
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.
146 * This version will NOT create any new attributes. If an invalid attribute
147 * is requested, an exception will be thrown.
149 * @param startingNodeQuark
150 * The quark of the attribute from which 'subPath' originates.
152 * "Rest" of the path to get to the final attribute
153 * @return The matching quark, if it existed
154 * @throws IndexOutOfBoundsException
155 * If the starting node quark is out of range
156 * @throws AttributeNotFoundException
157 * If the sub-attribute does not exist
159 int getQuarkRelative(int startingNodeQuark
, String
... subPath
)
160 throws AttributeNotFoundException
;
163 * Return the sub-attributes of the target attribute, as a List of quarks.
166 * The attribute of which you want to sub-attributes. You can use
167 * "-1" here to specify the root node.
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.
175 @NonNull List
<Integer
> getSubAttributes(int quark
, boolean recursive
)
176 throws AttributeNotFoundException
;
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.
184 * The attribute of which you want to sub-attributes. You can use
185 * "-1" here to specify the root node.
187 * True if you want all recursive sub-attributes, false if you
188 * only want the first level. Note that the returned value will
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.
198 List
<Integer
> getSubAttributes(int quark
, boolean recursive
, String pattern
)
199 throws AttributeNotFoundException
;
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
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.
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.
216 * Only one wildcard "*" is supported at this time.
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
225 List
<Integer
> getQuarks(String
... pattern
);
228 * Return the name assigned to this quark. This returns only the "basename",
229 * not the complete path to this attribute.
231 * @param attributeQuark
232 * The quark for which we want the name
233 * @return The name of the quark
234 * @throws IndexOutOfBoundsException
235 * If the attribute quark is out of range
237 @NonNull String
getAttributeName(int attributeQuark
);
240 * This returns the slash-separated path of an attribute by providing its
243 * @param attributeQuark
244 * The quark of the attribute we want
245 * @return One single string separated with '/', like a filesystem path
246 * @throws IndexOutOfBoundsException
247 * If the attribute quark is out of range
249 @NonNull String
getFullAttributePath(int attributeQuark
);
252 * Return the full attribute path, as an array of strings representing each
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
262 String
@NonNull [] getFullAttributePathArray(int attributeQuark
);
265 * Returns the parent quark of the attribute.
267 * @param attributeQuark
268 * The quark of the attribute
269 * @return Quark of the parent attribute or <code>-1</code> if root quark or
271 * @throws IndexOutOfBoundsException
272 * If the attribute quark is out of range
274 int getParentAttributeQuark(int attributeQuark
);
276 // ------------------------------------------------------------------------
278 // ------------------------------------------------------------------------
281 * Returns the current state value we have (in the Transient State) for the
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!)
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
294 ITmfStateValue
queryOngoingState(int attributeQuark
)
295 throws AttributeNotFoundException
;
298 * Get the start time of the current ongoing state, for the specified
302 * Quark of the attribute
303 * @return The current start time of the ongoing state
304 * @throws AttributeNotFoundException
305 * If the attribute is invalid
307 long getOngoingStartTime(int attribute
)
308 throws AttributeNotFoundException
;
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.
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.
321 * We will recreate the state information to what it was at time
323 * @return The List of intervals, where the offset = the quark
324 * @throws TimeRangeException
325 * If the 't' parameter is outside of the range of the state
327 * @throws StateSystemDisposedException
328 * If the query is sent after the state system has been disposed
330 @NonNull List
<ITmfStateInterval
> queryFullState(long t
)
331 throws StateSystemDisposedException
;
334 * Singular query method. This one does not update the whole stateInfo
335 * vector, like queryFullState() does. It only searches for one specific
336 * entry in the state history.
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
341 * conventional queryFullState() + List.get() method.
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
350 * @throws AttributeNotFoundException
351 * If the requested quark does not exist in the model
352 * @throws StateSystemDisposedException
353 * If the query is sent after the state system has been disposed
355 @NonNull ITmfStateInterval
querySingleState(long t
, int attributeQuark
)
356 throws AttributeNotFoundException
, StateSystemDisposedException
;