Commit | Line | Data |
---|---|---|
a52fde77 | 1 | /******************************************************************************* |
e13bd4cd | 2 | * Copyright (c) 2012, 2015 Ericsson |
a52fde77 AM |
3 | * Copyright (c) 2010, 2011 École Polytechnique de Montréal |
4 | * Copyright (c) 2010, 2011 Alexandre Montplaisir <alexandre.montplaisir@gmail.com> | |
5df842b3 | 5 | * |
a52fde77 AM |
6 | * All rights reserved. This program and the accompanying materials are |
7 | * made available under the terms of the Eclipse Public License v1.0 which | |
8 | * accompanies this distribution, and is available at | |
9 | * http://www.eclipse.org/legal/epl-v10.html | |
5df842b3 | 10 | * |
e13bd4cd PT |
11 | * Contributors: |
12 | * Alexandre Montplaisir - Initial API and implementation | |
13 | * Patrick Tasse - Add message to exceptions | |
a52fde77 AM |
14 | *******************************************************************************/ |
15 | ||
e894a508 | 16 | package org.eclipse.tracecompass.internal.statesystem.core; |
a52fde77 | 17 | |
8d1346f0 AM |
18 | import java.io.File; |
19 | import java.io.IOException; | |
a52fde77 | 20 | import java.io.PrintWriter; |
8d1346f0 | 21 | import java.util.ArrayList; |
f94a0bac | 22 | import java.util.LinkedList; |
a52fde77 | 23 | import java.util.List; |
16576a7e | 24 | import java.util.concurrent.CountDownLatch; |
9287b6a2 | 25 | import java.util.concurrent.TimeUnit; |
a52fde77 | 26 | |
2e21b6d8 | 27 | import org.eclipse.jdt.annotation.NonNull; |
e894a508 AM |
28 | import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder; |
29 | import org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend; | |
30 | import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException; | |
31 | import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException; | |
32 | import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException; | |
33 | import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException; | |
34 | import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval; | |
e894a508 | 35 | import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue; |
e894a508 | 36 | import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue.Type; |
1dd75589 | 37 | import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue; |
a52fde77 AM |
38 | |
39 | /** | |
8d1346f0 AM |
40 | * This is the core class of the Generic State System. It contains all the |
41 | * methods to build and query a state history. It's exposed externally through | |
42 | * the IStateSystemQuerier and IStateSystemBuilder interfaces, depending if the | |
43 | * user needs read-only access or read-write access. | |
5df842b3 | 44 | * |
8d1346f0 AM |
45 | * When building, DON'T FORGET to call .closeHistory() when you are done |
46 | * inserting intervals, or the storage backend will have no way of knowing it | |
47 | * can close and write itself to disk, and its thread will keep running. | |
5df842b3 | 48 | * |
a52fde77 | 49 | * @author alexmont |
5df842b3 | 50 | * |
a52fde77 | 51 | */ |
f1f86dfb | 52 | public class StateSystem implements ITmfStateSystemBuilder { |
a52fde77 AM |
53 | |
54 | /* References to the inner structures */ | |
8d1346f0 AM |
55 | private final AttributeTree attributeTree; |
56 | private final TransientState transState; | |
57 | private final IStateHistoryBackend backend; | |
a52fde77 | 58 | |
16576a7e AM |
59 | /* Latch tracking if the state history is done building or not */ |
60 | private final CountDownLatch finishedLatch = new CountDownLatch(1); | |
61 | ||
1a4205d9 | 62 | private boolean buildCancelled = false; |
96345c5a | 63 | private boolean isDisposed = false; |
1a4205d9 | 64 | |
f9a76cac AM |
65 | /** |
66 | * New-file constructor. For when you build a state system with a new file, | |
67 | * or if the back-end does not require a file on disk. | |
68 | * | |
69 | * @param backend | |
70 | * Back-end plugin to use | |
71 | */ | |
b2f62cb5 | 72 | public StateSystem(@NonNull IStateHistoryBackend backend) { |
f9a76cac AM |
73 | this.backend = backend; |
74 | this.transState = new TransientState(backend); | |
75 | this.attributeTree = new AttributeTree(this); | |
76 | } | |
77 | ||
a52fde77 | 78 | /** |
8d1346f0 AM |
79 | * General constructor |
80 | * | |
81 | * @param backend | |
f9a76cac | 82 | * The "state history storage" back-end to use. |
8d1346f0 AM |
83 | * @param newFile |
84 | * Put true if this is a new history started from scratch. It is | |
85 | * used to tell the state system where to get its attribute tree. | |
86 | * @throws IOException | |
87 | * If there was a problem creating the new history file | |
a52fde77 | 88 | */ |
b2f62cb5 | 89 | public StateSystem(@NonNull IStateHistoryBackend backend, boolean newFile) |
8d1346f0 AM |
90 | throws IOException { |
91 | this.backend = backend; | |
92 | this.transState = new TransientState(backend); | |
a52fde77 | 93 | |
8d1346f0 AM |
94 | if (newFile) { |
95 | attributeTree = new AttributeTree(this); | |
96 | } else { | |
97 | /* We're opening an existing file */ | |
98 | this.attributeTree = new AttributeTree(this, backend.supplyAttributeTreeReader()); | |
99 | transState.setInactive(); | |
16576a7e AM |
100 | finishedLatch.countDown(); /* The history is already built */ |
101 | } | |
102 | } | |
103 | ||
84a9548a AM |
104 | @Override |
105 | public String getSSID() { | |
b2f62cb5 | 106 | return backend.getSSID(); |
84a9548a AM |
107 | } |
108 | ||
16576a7e | 109 | @Override |
2002c638 AM |
110 | public boolean isCancelled() { |
111 | return buildCancelled; | |
112 | } | |
113 | ||
114 | @Override | |
115 | public void waitUntilBuilt() { | |
16576a7e AM |
116 | try { |
117 | finishedLatch.await(); | |
118 | } catch (InterruptedException e) { | |
119 | e.printStackTrace(); | |
8d1346f0 | 120 | } |
1a4205d9 AM |
121 | } |
122 | ||
9287b6a2 AM |
123 | @Override |
124 | public boolean waitUntilBuilt(long timeout) { | |
125 | boolean ret = false; | |
126 | try { | |
127 | ret = finishedLatch.await(timeout, TimeUnit.MILLISECONDS); | |
128 | } catch (InterruptedException e) { | |
129 | e.printStackTrace(); | |
130 | } | |
131 | return ret; | |
132 | } | |
133 | ||
1a4205d9 AM |
134 | @Override |
135 | public synchronized void dispose() { | |
96345c5a | 136 | isDisposed = true; |
1a4205d9 AM |
137 | if (transState.isActive()) { |
138 | transState.setInactive(); | |
139 | buildCancelled = true; | |
140 | } | |
141 | backend.dispose(); | |
a52fde77 AM |
142 | } |
143 | ||
8d1346f0 AM |
144 | //-------------------------------------------------------------------------- |
145 | // General methods related to the attribute tree | |
146 | //-------------------------------------------------------------------------- | |
147 | ||
339d27b4 AM |
148 | /** |
149 | * Get the attribute tree associated with this state system. This should be | |
150 | * the only way of accessing it (and if subclasses want to point to a | |
151 | * different attribute tree than their own, they should only need to | |
152 | * override this). | |
153 | * | |
154 | * @return The attribute tree | |
155 | */ | |
156 | public AttributeTree getAttributeTree() { | |
157 | return attributeTree; | |
158 | } | |
159 | ||
8d1346f0 AM |
160 | /** |
161 | * Method used by the attribute tree when creating new attributes, to keep | |
162 | * the attribute count in the transient state in sync. | |
163 | */ | |
bcec0116 | 164 | public void addEmptyAttribute() { |
8d1346f0 AM |
165 | transState.addEmptyEntry(); |
166 | } | |
167 | ||
168 | @Override | |
4623f57f | 169 | public int getNbAttributes() { |
339d27b4 | 170 | return getAttributeTree().getNbAttributes(); |
4623f57f AM |
171 | } |
172 | ||
8d1346f0 AM |
173 | @Override |
174 | public String getAttributeName(int attributeQuark) { | |
339d27b4 | 175 | return getAttributeTree().getAttributeName(attributeQuark); |
8d1346f0 AM |
176 | } |
177 | ||
178 | @Override | |
179 | public String getFullAttributePath(int attributeQuark) { | |
339d27b4 | 180 | return getAttributeTree().getFullAttributeName(attributeQuark); |
8d1346f0 AM |
181 | } |
182 | ||
34638411 AM |
183 | @Override |
184 | public String[] getFullAttributePathArray(int attributeQuark) { | |
185 | return getAttributeTree().getFullAttributePathArray(attributeQuark); | |
186 | } | |
187 | ||
8d1346f0 AM |
188 | //-------------------------------------------------------------------------- |
189 | // Methods related to the storage backend | |
190 | //-------------------------------------------------------------------------- | |
a52fde77 | 191 | |
8d1346f0 AM |
192 | @Override |
193 | public long getStartTime() { | |
194 | return backend.getStartTime(); | |
195 | } | |
196 | ||
197 | @Override | |
198 | public long getCurrentEndTime() { | |
199 | return backend.getEndTime(); | |
200 | } | |
201 | ||
202 | @Override | |
203 | public void closeHistory(long endTime) throws TimeRangeException { | |
204 | File attributeTreeFile; | |
205 | long attributeTreeFilePos; | |
206 | long realEndTime = endTime; | |
207 | ||
208 | if (realEndTime < backend.getEndTime()) { | |
209 | /* | |
210 | * This can happen (empty nodes pushing the border further, etc.) | |
211 | * but shouldn't be too big of a deal. | |
212 | */ | |
213 | realEndTime = backend.getEndTime(); | |
214 | } | |
215 | transState.closeTransientState(realEndTime); | |
216 | backend.finishedBuilding(realEndTime); | |
217 | ||
218 | attributeTreeFile = backend.supplyAttributeTreeWriterFile(); | |
219 | attributeTreeFilePos = backend.supplyAttributeTreeWriterFilePosition(); | |
220 | if (attributeTreeFile != null) { | |
221 | /* | |
222 | * If null was returned, we simply won't save the attribute tree, | |
223 | * too bad! | |
224 | */ | |
339d27b4 | 225 | getAttributeTree().writeSelf(attributeTreeFile, attributeTreeFilePos); |
8d1346f0 | 226 | } |
16576a7e | 227 | finishedLatch.countDown(); /* Mark the history as finished building */ |
8d1346f0 AM |
228 | } |
229 | ||
230 | //-------------------------------------------------------------------------- | |
231 | // Quark-retrieving methods | |
232 | //-------------------------------------------------------------------------- | |
233 | ||
234 | @Override | |
a52fde77 AM |
235 | public int getQuarkAbsolute(String... attribute) |
236 | throws AttributeNotFoundException { | |
339d27b4 | 237 | return getAttributeTree().getQuarkDontAdd(-1, attribute); |
a52fde77 AM |
238 | } |
239 | ||
8d1346f0 | 240 | @Override |
a52fde77 | 241 | public int getQuarkAbsoluteAndAdd(String... attribute) { |
339d27b4 | 242 | return getAttributeTree().getQuarkAndAdd(-1, attribute); |
a52fde77 AM |
243 | } |
244 | ||
8d1346f0 | 245 | @Override |
a52fde77 AM |
246 | public int getQuarkRelative(int startingNodeQuark, String... subPath) |
247 | throws AttributeNotFoundException { | |
339d27b4 | 248 | return getAttributeTree().getQuarkDontAdd(startingNodeQuark, subPath); |
a52fde77 AM |
249 | } |
250 | ||
8d1346f0 | 251 | @Override |
a52fde77 | 252 | public int getQuarkRelativeAndAdd(int startingNodeQuark, String... subPath) { |
339d27b4 | 253 | return getAttributeTree().getQuarkAndAdd(startingNodeQuark, subPath); |
a52fde77 AM |
254 | } |
255 | ||
8d1346f0 | 256 | @Override |
c66426fd | 257 | public List<Integer> getSubAttributes(int quark, boolean recursive) |
0a9de3d2 | 258 | throws AttributeNotFoundException { |
339d27b4 | 259 | return getAttributeTree().getSubAttributes(quark, recursive); |
0a9de3d2 AM |
260 | } |
261 | ||
5206c858 AM |
262 | @Override |
263 | public List<Integer> getSubAttributes(int quark, boolean recursive, String pattern) | |
264 | throws AttributeNotFoundException { | |
265 | List<Integer> all = getSubAttributes(quark, recursive); | |
266 | List<Integer> ret = new LinkedList<>(); | |
267 | for (Integer attQuark : all) { | |
268 | String name = getAttributeName(attQuark.intValue()); | |
269 | if (name.matches(pattern)) { | |
270 | ret.add(attQuark); | |
271 | } | |
272 | } | |
273 | return ret; | |
274 | } | |
275 | ||
0fdd2c45 FG |
276 | @Override |
277 | public int getParentAttributeQuark(int quark) { | |
278 | return getAttributeTree().getParentAttributeQuark(quark); | |
279 | } | |
280 | ||
8d1346f0 | 281 | @Override |
f94a0bac | 282 | public List<Integer> getQuarks(String... pattern) { |
a4524c1b AM |
283 | List<Integer> quarks = new LinkedList<>(); |
284 | List<String> prefix = new LinkedList<>(); | |
285 | List<String> suffix = new LinkedList<>(); | |
f94a0bac AM |
286 | boolean split = false; |
287 | String[] prefixStr; | |
288 | String[] suffixStr; | |
289 | List<Integer> directChildren; | |
290 | int startingAttribute; | |
291 | ||
292 | /* Fill the "prefix" and "suffix" parts of the pattern around the '*' */ | |
293 | for (String entry : pattern) { | |
294 | if (entry.equals("*")) { //$NON-NLS-1$ | |
295 | if (split) { | |
296 | /* | |
297 | * Split was already true? This means there was more than | |
298 | * one wildcard. This is not supported, return an empty | |
299 | * list. | |
300 | */ | |
301 | return quarks; | |
302 | } | |
303 | split = true; | |
304 | continue; | |
305 | } | |
306 | ||
307 | if (split) { | |
308 | suffix.add(entry); | |
309 | } else { | |
310 | prefix.add(entry); | |
311 | } | |
312 | } | |
313 | prefixStr = prefix.toArray(new String[prefix.size()]); | |
314 | suffixStr = suffix.toArray(new String[suffix.size()]); | |
315 | ||
316 | /* | |
317 | * If there was no wildcard, we'll only return the one matching | |
318 | * attribute, if there is one. | |
319 | */ | |
cb42195c | 320 | if (!split) { |
f94a0bac AM |
321 | int quark; |
322 | try { | |
323 | quark = getQuarkAbsolute(prefixStr); | |
324 | } catch (AttributeNotFoundException e) { | |
325 | /* It's fine, we'll just return the empty List */ | |
326 | return quarks; | |
327 | } | |
328 | quarks.add(quark); | |
329 | return quarks; | |
330 | } | |
331 | ||
332 | try { | |
333 | if (prefix.size() == 0) { | |
334 | /* | |
335 | * If 'prefix' is empty, this means the wildcard was the first | |
336 | * element. Look for the root node's sub-attributes. | |
337 | */ | |
338 | startingAttribute = -1; | |
339 | } else { | |
340 | startingAttribute = getQuarkAbsolute(prefixStr); | |
341 | } | |
339d27b4 | 342 | directChildren = getSubAttributes(startingAttribute, false); |
f94a0bac AM |
343 | } catch (AttributeNotFoundException e) { |
344 | /* That attribute path did not exist, return the empty array */ | |
345 | return quarks; | |
346 | } | |
347 | ||
348 | /* | |
349 | * Iterate of all the sub-attributes, and only keep those who match the | |
350 | * 'suffix' part of the initial pattern. | |
351 | */ | |
352 | for (int childQuark : directChildren) { | |
353 | int matchingQuark; | |
354 | try { | |
355 | matchingQuark = getQuarkRelative(childQuark, suffixStr); | |
356 | } catch (AttributeNotFoundException e) { | |
357 | continue; | |
358 | } | |
359 | quarks.add(matchingQuark); | |
360 | } | |
361 | ||
362 | return quarks; | |
363 | } | |
364 | ||
8d1346f0 AM |
365 | //-------------------------------------------------------------------------- |
366 | // Methods related to insertions in the history | |
367 | //-------------------------------------------------------------------------- | |
a52fde77 | 368 | |
8d1346f0 | 369 | @Override |
a52fde77 | 370 | public void modifyAttribute(long t, ITmfStateValue value, int attributeQuark) |
7e0b2b56 AM |
371 | throws TimeRangeException, AttributeNotFoundException, |
372 | StateValueTypeException { | |
feea3b3c AM |
373 | if (value == null) { |
374 | /* | |
375 | * TODO Replace with @NonNull parameter (will require fixing all the | |
376 | * state providers!) | |
377 | */ | |
378 | throw new IllegalArgumentException(); | |
379 | } | |
a52fde77 AM |
380 | transState.processStateChange(t, value, attributeQuark); |
381 | } | |
382 | ||
8d1346f0 | 383 | @Override |
a52fde77 AM |
384 | public void incrementAttribute(long t, int attributeQuark) |
385 | throws StateValueTypeException, TimeRangeException, | |
386 | AttributeNotFoundException { | |
359eeba0 PT |
387 | ITmfStateValue stateValue = queryOngoingState(attributeQuark); |
388 | int prevValue = 0; | |
389 | /* if the attribute was previously null, start counting at 0 */ | |
390 | if (!stateValue.isNull()) { | |
391 | prevValue = stateValue.unboxInt(); | |
280bbdbb | 392 | } |
a52fde77 AM |
393 | modifyAttribute(t, TmfStateValue.newValueInt(prevValue + 1), |
394 | attributeQuark); | |
395 | } | |
396 | ||
8d1346f0 | 397 | @Override |
a52fde77 AM |
398 | public void pushAttribute(long t, ITmfStateValue value, int attributeQuark) |
399 | throws TimeRangeException, AttributeNotFoundException, | |
400 | StateValueTypeException { | |
0126a8ca | 401 | int stackDepth; |
a52fde77 AM |
402 | int subAttributeQuark; |
403 | ITmfStateValue previousSV = transState.getOngoingStateValue(attributeQuark); | |
404 | ||
405 | if (previousSV.isNull()) { | |
406 | /* | |
407 | * If the StateValue was null, this means this is the first time we | |
408 | * use this attribute. Leave stackDepth at 0. | |
409 | */ | |
cb42195c | 410 | stackDepth = 0; |
b67a2540 | 411 | } else if (previousSV.getType() == Type.INTEGER) { |
a52fde77 AM |
412 | /* Previous value was an integer, all is good, use it */ |
413 | stackDepth = previousSV.unboxInt(); | |
a52fde77 AM |
414 | } else { |
415 | /* Previous state of this attribute was another type? Not good! */ | |
e13bd4cd | 416 | throw new StateValueTypeException(getSSID() + " Quark:" + attributeQuark + ", Type:" + previousSV.getType() + ", Expected:" + Type.INTEGER); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
90a25ebe AM |
417 | } |
418 | ||
e8251298 | 419 | if (stackDepth >= 100000) { |
90a25ebe | 420 | /* |
a0f8fb9b FW |
421 | * Limit stackDepth to 100000, to avoid having Attribute Trees grow |
422 | * out of control due to buggy insertions | |
90a25ebe | 423 | */ |
e13bd4cd PT |
424 | String message = " Stack limit reached, not pushing"; //$NON-NLS-1$ |
425 | throw new AttributeNotFoundException(getSSID() + " Quark:" + attributeQuark + message); //$NON-NLS-1$ | |
a52fde77 AM |
426 | } |
427 | ||
428 | stackDepth++; | |
0126a8ca | 429 | subAttributeQuark = getQuarkRelativeAndAdd(attributeQuark, String.valueOf(stackDepth)); |
a52fde77 | 430 | |
5896eb76 | 431 | modifyAttribute(t, TmfStateValue.newValueInt(stackDepth), attributeQuark); |
90a25ebe | 432 | modifyAttribute(t, value, subAttributeQuark); |
a52fde77 AM |
433 | } |
434 | ||
8d1346f0 | 435 | @Override |
5896eb76 | 436 | public ITmfStateValue popAttribute(long t, int attributeQuark) |
a52fde77 AM |
437 | throws AttributeNotFoundException, TimeRangeException, |
438 | StateValueTypeException { | |
e2eac108 | 439 | /* These are the state values of the stack-attribute itself */ |
e13bd4cd | 440 | ITmfStateValue previousSV = transState.getOngoingStateValue(attributeQuark); |
a52fde77 AM |
441 | |
442 | if (previousSV.isNull()) { | |
e2eac108 AM |
443 | /* |
444 | * Trying to pop an empty stack. This often happens at the start of | |
445 | * traces, for example when we see a syscall_exit, without having | |
446 | * the corresponding syscall_entry in the trace. Just ignore | |
447 | * silently. | |
448 | */ | |
5896eb76 | 449 | return null; |
90a25ebe | 450 | } |
b67a2540 | 451 | if (previousSV.getType() != Type.INTEGER) { |
a52fde77 | 452 | /* |
b67a2540 AM |
453 | * The existing value was not an integer (which is expected for |
454 | * stack tops), this doesn't look like a valid stack attribute. | |
a52fde77 | 455 | */ |
e13bd4cd | 456 | throw new StateValueTypeException(getSSID() + " Quark:" + attributeQuark + ", Type:" + previousSV.getType() + ", Expected:" + Type.INTEGER); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
a52fde77 AM |
457 | } |
458 | ||
0126a8ca | 459 | int stackDepth = previousSV.unboxInt(); |
90a25ebe | 460 | |
e2eac108 | 461 | if (stackDepth <= 0) { |
a52fde77 | 462 | /* This on the other hand should not happen... */ |
e13bd4cd | 463 | throw new StateValueTypeException(getSSID() + " Quark:" + attributeQuark + ", Stack depth:" + stackDepth); //$NON-NLS-1$//$NON-NLS-2$ |
a52fde77 AM |
464 | } |
465 | ||
e2eac108 | 466 | /* The attribute should already exist at this point */ |
0126a8ca | 467 | int subAttributeQuark = getQuarkRelative(attributeQuark, String.valueOf(stackDepth)); |
5896eb76 | 468 | ITmfStateValue poppedValue = queryOngoingState(subAttributeQuark); |
a52fde77 | 469 | |
e2eac108 AM |
470 | /* Update the state value of the stack-attribute */ |
471 | ITmfStateValue nextSV; | |
a0f8fb9b | 472 | if (--stackDepth == 0) { |
359eeba0 | 473 | /* Store a null state value */ |
e2eac108 AM |
474 | nextSV = TmfStateValue.nullValue(); |
475 | } else { | |
476 | nextSV = TmfStateValue.newValueInt(stackDepth); | |
477 | } | |
478 | modifyAttribute(t, nextSV, attributeQuark); | |
479 | ||
480 | /* Delete the sub-attribute that contained the user's state value */ | |
a52fde77 | 481 | removeAttribute(t, subAttributeQuark); |
e2eac108 | 482 | |
5896eb76 | 483 | return poppedValue; |
a52fde77 AM |
484 | } |
485 | ||
8d1346f0 | 486 | @Override |
a52fde77 AM |
487 | public void removeAttribute(long t, int attributeQuark) |
488 | throws TimeRangeException, AttributeNotFoundException { | |
feea3b3c AM |
489 | if (attributeQuark < 0) { |
490 | throw new IllegalArgumentException(); | |
491 | } | |
c66426fd AM |
492 | |
493 | /* | |
feea3b3c | 494 | * Nullify our children first, recursively. We pass 'false' because we |
c66426fd AM |
495 | * handle the recursion ourselves. |
496 | */ | |
feea3b3c | 497 | List<Integer> childAttributes = getSubAttributes(attributeQuark, false); |
0126a8ca | 498 | for (int childNodeQuark : childAttributes) { |
feea3b3c AM |
499 | if (attributeQuark == childNodeQuark) { |
500 | /* Something went very wrong when building out attribute tree */ | |
501 | throw new IllegalStateException(); | |
502 | } | |
a52fde77 AM |
503 | removeAttribute(t, childNodeQuark); |
504 | } | |
505 | /* Nullify ourselves */ | |
7e0b2b56 | 506 | try { |
feea3b3c | 507 | transState.processStateChange(t, TmfStateValue.nullValue(), attributeQuark); |
7e0b2b56 | 508 | } catch (StateValueTypeException e) { |
50678114 AM |
509 | /* |
510 | * Will not happen since we're inserting null values only, but poor | |
511 | * compiler has no way of knowing this... | |
7e0b2b56 | 512 | */ |
cb42195c | 513 | throw new IllegalStateException(e); |
7e0b2b56 | 514 | } |
a52fde77 AM |
515 | } |
516 | ||
8d1346f0 AM |
517 | //-------------------------------------------------------------------------- |
518 | // "Current" query/update methods | |
519 | //-------------------------------------------------------------------------- | |
a52fde77 | 520 | |
8d1346f0 | 521 | @Override |
a52fde77 AM |
522 | public ITmfStateValue queryOngoingState(int attributeQuark) |
523 | throws AttributeNotFoundException { | |
524 | return transState.getOngoingStateValue(attributeQuark); | |
525 | } | |
526 | ||
602c0697 AM |
527 | @Override |
528 | public long getOngoingStartTime(int attribute) | |
529 | throws AttributeNotFoundException { | |
530 | return transState.getOngoingStartTime(attribute); | |
531 | } | |
532 | ||
8d1346f0 | 533 | @Override |
a52fde77 AM |
534 | public void updateOngoingState(ITmfStateValue newValue, int attributeQuark) |
535 | throws AttributeNotFoundException { | |
536 | transState.changeOngoingStateValue(attributeQuark, newValue); | |
537 | } | |
538 | ||
66866869 AM |
539 | /** |
540 | * Modify the whole "ongoing state" (state values + start times). This can | |
541 | * be used when "seeking" a state system to a different point in the trace | |
542 | * (and restoring the known stateInfo at this location). Use with care! | |
543 | * | |
544 | * @param newStateIntervals | |
545 | * The new List of state values to use as ongoing state info | |
546 | */ | |
feea3b3c | 547 | protected void replaceOngoingState(@NonNull List<ITmfStateInterval> newStateIntervals) { |
66866869 | 548 | transState.replaceOngoingState(newStateIntervals); |
a0f8fb9b | 549 | } |
66866869 | 550 | |
8d1346f0 AM |
551 | //-------------------------------------------------------------------------- |
552 | // Regular query methods (sent to the back-end) | |
553 | //-------------------------------------------------------------------------- | |
554 | ||
555 | @Override | |
556 | public synchronized List<ITmfStateInterval> queryFullState(long t) | |
96345c5a AM |
557 | throws TimeRangeException, StateSystemDisposedException { |
558 | if (isDisposed) { | |
559 | throw new StateSystemDisposedException(); | |
560 | } | |
561 | ||
e62a23a9 AM |
562 | final int nbAttr = getNbAttributes(); |
563 | List<ITmfStateInterval> stateInfo = new ArrayList<>(nbAttr); | |
8d1346f0 AM |
564 | |
565 | /* Bring the size of the array to the current number of attributes */ | |
e62a23a9 | 566 | for (int i = 0; i < nbAttr; i++) { |
8d1346f0 AM |
567 | stateInfo.add(null); |
568 | } | |
569 | ||
8d1346f0 AM |
570 | /* |
571 | * If we are currently building the history, also query the "ongoing" | |
572 | * states for stuff that might not yet be written to the history. | |
573 | */ | |
574 | if (transState.isActive()) { | |
575 | transState.doQuery(stateInfo, t); | |
576 | } | |
577 | ||
e62a23a9 AM |
578 | /* Query the storage backend */ |
579 | backend.doQuery(stateInfo, t); | |
580 | ||
8d1346f0 AM |
581 | /* |
582 | * We should have previously inserted an interval for every attribute. | |
8d1346f0 | 583 | */ |
e62a23a9 AM |
584 | for (ITmfStateInterval interval : stateInfo) { |
585 | if (interval == null) { | |
586 | throw new IllegalStateException("Incoherent interval storage"); //$NON-NLS-1$ | |
8d1346f0 AM |
587 | } |
588 | } | |
589 | return stateInfo; | |
50678114 AM |
590 | } |
591 | ||
8d1346f0 AM |
592 | @Override |
593 | public ITmfStateInterval querySingleState(long t, int attributeQuark) | |
96345c5a AM |
594 | throws AttributeNotFoundException, TimeRangeException, |
595 | StateSystemDisposedException { | |
596 | if (isDisposed) { | |
597 | throw new StateSystemDisposedException(); | |
598 | } | |
8d1346f0 | 599 | |
09e6fd9b AM |
600 | ITmfStateInterval ret = transState.getIntervalAt(t, attributeQuark); |
601 | if (ret == null) { | |
602 | /* | |
603 | * The transient state did not have the information, let's look into | |
604 | * the backend next. | |
605 | */ | |
8d1346f0 AM |
606 | ret = backend.doSingularQuery(t, attributeQuark); |
607 | } | |
608 | ||
8d1346f0 | 609 | if (ret == null) { |
e62a23a9 AM |
610 | /* |
611 | * If we did our job correctly, there should be intervals for every | |
612 | * possible attribute, over all the valid time range. | |
613 | */ | |
614 | throw new IllegalStateException("Incoherent interval storage"); //$NON-NLS-1$ | |
8d1346f0 AM |
615 | } |
616 | return ret; | |
617 | } | |
618 | ||
8d1346f0 AM |
619 | //-------------------------------------------------------------------------- |
620 | // Debug methods | |
621 | //-------------------------------------------------------------------------- | |
622 | ||
623 | static void logMissingInterval(int attribute, long timestamp) { | |
bcec0116 | 624 | Activator.getDefault().logInfo("No data found in history for attribute " + //$NON-NLS-1$ |
8d1346f0 AM |
625 | attribute + " at time " + timestamp + //$NON-NLS-1$ |
626 | ", returning dummy interval"); //$NON-NLS-1$ | |
a52fde77 AM |
627 | } |
628 | ||
629 | /** | |
630 | * Print out the contents of the inner structures. | |
5df842b3 | 631 | * |
a52fde77 AM |
632 | * @param writer |
633 | * The PrintWriter in which to print the output | |
634 | */ | |
feea3b3c | 635 | public void debugPrint(@NonNull PrintWriter writer) { |
339d27b4 | 636 | getAttributeTree().debugPrint(writer); |
a52fde77 | 637 | transState.debugPrint(writer); |
8d1346f0 | 638 | backend.debugPrint(writer); |
a52fde77 AM |
639 | } |
640 | ||
8d1346f0 | 641 | } |