Commit | Line | Data |
---|---|---|
5d10d135 ASL |
1 | /******************************************************************************* |
2 | * Copyright (c) 2009, 2010 Ericsson | |
0c32e4c5 | 3 | * |
5d10d135 ASL |
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 | |
0c32e4c5 | 8 | * |
5d10d135 ASL |
9 | * Contributors: |
10 | * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation | |
11 | *******************************************************************************/ | |
5945cec9 | 12 | package org.eclipse.linuxtools.internal.lttng.core.state.trace; |
5d10d135 ASL |
13 | |
14 | import java.util.Collections; | |
15 | import java.util.HashMap; | |
16 | import java.util.Vector; | |
17 | ||
9fa32496 | 18 | import org.eclipse.linuxtools.internal.lttng.core.Activator; |
5945cec9 | 19 | import org.eclipse.linuxtools.internal.lttng.core.TraceDebug; |
5945cec9 | 20 | import org.eclipse.linuxtools.internal.lttng.core.event.LttngSyntheticEvent; |
5945cec9 | 21 | import org.eclipse.linuxtools.internal.lttng.core.event.LttngSyntheticEvent.SequenceInd; |
d905a64a | 22 | import org.eclipse.linuxtools.internal.lttng.core.event.LttngTimestamp; |
5945cec9 FC |
23 | import org.eclipse.linuxtools.internal.lttng.core.model.LTTngTreeNode; |
24 | import org.eclipse.linuxtools.internal.lttng.core.request.ILttngSyntEventRequest; | |
25 | import org.eclipse.linuxtools.internal.lttng.core.request.IRequestStatusListener; | |
26 | import org.eclipse.linuxtools.internal.lttng.core.request.LttngSyntEventRequest; | |
27 | import org.eclipse.linuxtools.internal.lttng.core.state.LttngStateException; | |
28 | import org.eclipse.linuxtools.internal.lttng.core.state.evProcessor.ITransEventProcessor; | |
29 | import org.eclipse.linuxtools.internal.lttng.core.state.evProcessor.state.StateEventToHandlerFactory; | |
30 | import org.eclipse.linuxtools.internal.lttng.core.state.model.LttngTraceState; | |
31 | import org.eclipse.linuxtools.internal.lttng.core.state.model.StateModelFactory; | |
32 | import org.eclipse.linuxtools.internal.lttng.core.state.resource.ILttngStateContext; | |
33 | import org.eclipse.linuxtools.internal.lttng.core.trace.LTTngTextTrace; | |
34 | import org.eclipse.linuxtools.internal.lttng.core.trace.LTTngTrace; | |
0c32e4c5 | 35 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; |
4df4581d | 36 | import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; |
6c13869b FC |
37 | import org.eclipse.linuxtools.tmf.core.event.TmfEvent; |
38 | import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange; | |
39 | import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; | |
6c13869b FC |
40 | import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest; |
41 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; | |
42 | import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpoint; | |
d905a64a | 43 | import org.eclipse.linuxtools.tmf.core.trace.TmfContext; |
9e0640dc | 44 | import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment; |
6c13869b | 45 | import org.eclipse.linuxtools.tmf.core.trace.TmfLocation; |
5d10d135 | 46 | |
0c32e4c5 AM |
47 | public class StateTraceManager extends LTTngTreeNode implements |
48 | IStateTraceManager, ILttngStateContext { | |
5d10d135 ASL |
49 | |
50 | // constants | |
51 | private static final long DEFAULT_OFFSET = 0L; | |
52 | private static final int DEFAULT_CHUNK = 1; | |
53 | ||
54 | // configurable check point interval | |
b12f4544 | 55 | private static final long LTTNG_CHECK_POINT_INTERVAL = 50000L; |
5d10d135 ASL |
56 | private long fcheckPointInterval = LTTNG_CHECK_POINT_INTERVAL; |
57 | ||
0c32e4c5 | 58 | private TmfExperiment fExperiment = null; |
5d10d135 ASL |
59 | |
60 | // immutable Objects | |
0c32e4c5 | 61 | private final ITmfTrace fTrace; |
5d10d135 ASL |
62 | private int fcpuNumber = -1; |
63 | private final ITransEventProcessor fStateUpdateProcessor; | |
64 | ||
65 | // potentially thread shared | |
66 | private final HashMap<Long, LttngTraceState> stateCheckpointsList = new HashMap<Long, LttngTraceState>(); | |
67 | private final Vector<TmfCheckpoint> timestampCheckpointsList = new Vector<TmfCheckpoint>(); | |
68 | private LttngTraceState fStateModel; | |
550d787e | 69 | private LttngTraceState fCheckPointStateModel; |
5d10d135 ASL |
70 | |
71 | // locks | |
0c32e4c5 AM |
72 | private final Object fCheckPointsLock = new Object(); |
73 | private final Object fStateModelLock = new Object(); | |
74 | ||
5d10d135 | 75 | |
5d10d135 | 76 | |
5d10d135 ASL |
77 | // ======================================================================= |
78 | // Constructor | |
79 | // ======================================================================= | |
80 | /** | |
81 | * @param id | |
82 | * @param parent | |
83 | * @param name | |
84 | * @param trace | |
5d10d135 ASL |
85 | * @throws LttngStateException |
86 | */ | |
0c32e4c5 | 87 | public StateTraceManager(Long id, LTTngTreeNode parent, String name, ITmfTrace trace) throws LttngStateException { |
5d10d135 ASL |
88 | super(id, parent, name, trace); |
89 | ||
90 | if (trace == null) { | |
9c4eb5f7 | 91 | throw new LttngStateException("No TmfTrace object available!"); //$NON-NLS-1$ |
5d10d135 ASL |
92 | } |
93 | ||
94 | fTrace = trace; | |
5d10d135 | 95 | fStateUpdateProcessor = StateEventToHandlerFactory.getInstance(); |
550d787e | 96 | |
5d10d135 | 97 | init(); |
550d787e FC |
98 | |
99 | fStateModel = StateModelFactory.getStateEntryInstance(this); | |
100 | fStateModel.init(this); | |
101 | ||
102 | fCheckPointStateModel = StateModelFactory.getStateEntryInstance(this); | |
103 | fCheckPointStateModel.init(this); | |
5d10d135 ASL |
104 | } |
105 | ||
106 | // ======================================================================= | |
107 | // Methods | |
108 | // ======================================================================= | |
109 | @SuppressWarnings("unchecked") | |
110 | private void init() { | |
111 | // resolve the experiment | |
112 | Object obj = getParent().getValue(); | |
0c32e4c5 AM |
113 | if (obj != null && obj instanceof TmfExperiment) { |
114 | fExperiment = (TmfExperiment) obj; | |
5d10d135 ASL |
115 | } |
116 | ||
117 | // initialize the number of cpus | |
118 | if (fTrace instanceof LTTngTrace) { | |
119 | fcpuNumber = ((LTTngTrace) fTrace).getCpuNumber(); | |
120 | } else if (fTrace instanceof LTTngTextTrace) { | |
121 | fcpuNumber = ((LTTngTextTrace) fTrace).getCpuNumber(); | |
122 | } | |
123 | } | |
0c32e4c5 | 124 | |
5d10d135 | 125 | |
8827c197 | 126 | |
8827c197 | 127 | |
5d10d135 ASL |
128 | |
129 | /* | |
130 | * (non-Javadoc) | |
0c32e4c5 | 131 | * |
5d10d135 ASL |
132 | * @see org.eclipse.linuxtools.lttng.state.IStateManager#getEventLog() |
133 | */ | |
d4011df2 | 134 | @Override |
0c32e4c5 | 135 | public ITmfTrace getStateTrace() { |
5d10d135 ASL |
136 | return fTrace; |
137 | } | |
138 | ||
139 | /** | |
140 | * Save a checkpoint if it is needed at that point | |
141 | * <p> | |
142 | * The function will use "eventCount" internally to determine if a save was | |
143 | * needed | |
0c32e4c5 | 144 | * |
5d10d135 ASL |
145 | * @param eventCounter |
146 | * The event "count" or event "id" so far | |
147 | * @param eventTime | |
148 | * The timestamp of this event | |
0c32e4c5 | 149 | * |
5d10d135 ASL |
150 | * @return boolean True if a checkpoint was saved, false otherwise |
151 | */ | |
4df4581d | 152 | private void saveCheckPointIfNeeded(Long eventCounter, ITmfTimestamp eventTime) { |
5d10d135 ASL |
153 | // Save a checkpoint every LTTNG_STATE_SAVE_INTERVAL event |
154 | if ((eventCounter.longValue() % fcheckPointInterval) == 0) { | |
c1c69938 | 155 | |
5d10d135 | 156 | LttngTraceState stateCheckPoint; |
c1c69938 | 157 | synchronized (fCheckPointsLock) { |
550d787e | 158 | stateCheckPoint = fCheckPointStateModel.clone(); |
5d10d135 ASL |
159 | } |
160 | ||
9c4eb5f7 FC |
161 | TraceDebug.debug("Check point created here: " + eventCounter //$NON-NLS-1$ |
162 | + " -> " + eventTime.toString() + "************" //$NON-NLS-1$ //$NON-NLS-2$ | |
ce970a71 | 163 | + getStateTrace().getName() + " >>>>> Thread: " //$NON-NLS-1$ |
5d10d135 ASL |
164 | + Thread.currentThread().getId()); |
165 | ||
c1c69938 | 166 | synchronized (fCheckPointsLock) { |
5d10d135 ASL |
167 | // Save the checkpoint |
168 | stateCheckpointsList.put(eventCounter, stateCheckPoint); | |
169 | // Save correlation between timestamp and checkpoint index | |
170 | ||
d905a64a | 171 | timestampCheckpointsList.add(new TmfCheckpoint(new TmfTimestamp(eventTime), new TmfContext(new TmfLocation<Long>(eventCounter), eventCounter))); |
5d10d135 ASL |
172 | } |
173 | } | |
174 | } | |
175 | ||
176 | /** | |
177 | * @return the lttng_check_point_interval | |
178 | */ | |
179 | public long getCheckPointInterval() { | |
180 | return fcheckPointInterval; | |
181 | } | |
182 | ||
183 | /** | |
184 | * @param check_point_interval | |
185 | * , the lttng_check_point_interval to set | |
186 | */ | |
187 | public void setCheckPointInterval(long check_point_interval) { | |
188 | this.fcheckPointInterval = check_point_interval; | |
189 | } | |
190 | ||
736aecd5 ASL |
191 | /* |
192 | * (non-Javadoc) | |
0c32e4c5 | 193 | * |
550d787e FC |
194 | * @see org.eclipse.linuxtools.lttng.state.trace.IStateTraceManager# |
195 | * restoreCheckPointByTimestamp | |
736aecd5 | 196 | * (org.eclipse.linuxtools.tmf.event.TmfTimestamp) |
5d10d135 | 197 | */ |
d4011df2 | 198 | @Override |
5d10d135 | 199 | @SuppressWarnings("unchecked") |
4df4581d | 200 | public TmfCheckpoint restoreCheckPointByTimestamp(ITmfTimestamp eventTime) { |
736aecd5 | 201 | TmfTimeRange experimentRange = fExperiment.getTimeRange(); |
d905a64a | 202 | TmfCheckpoint checkpoint = new TmfCheckpoint(fTrace.getStartTime(), new TmfContext(new TmfLocation<Long>(0L), 0)); |
5d10d135 ASL |
203 | |
204 | // The GUI can have time limits higher than this log, since GUI can | |
b626c6f7 | 205 | // handle multiple logs. Ignore special null value of experiment time range. |
0c32e4c5 | 206 | if ((eventTime.getValue() < 0) || |
a4115405 | 207 | (!experimentRange.equals(TmfTimeRange.NULL_RANGE) && (eventTime.getValue() > experimentRange.getEndTime().getValue()))) { |
5d10d135 ASL |
208 | return null; |
209 | } | |
210 | ||
736aecd5 ASL |
211 | // The GUI can have time limits lower than this trace, since experiment |
212 | // can handle multiple traces | |
213 | if ((eventTime.getValue() < fTrace.getStartTime().getValue())) { | |
214 | eventTime = fTrace.getStartTime(); | |
5dbe4d3b | 215 | } |
736aecd5 | 216 | |
c1c69938 FC |
217 | LttngTraceState traceState; |
218 | synchronized (fCheckPointsLock) { | |
219 | Collections.sort(timestampCheckpointsList); | |
220 | // Initiate the compare with a checkpoint containing the target time | |
221 | // stamp to find | |
d905a64a | 222 | int index = Collections.binarySearch(timestampCheckpointsList, new TmfCheckpoint(eventTime, new TmfContext(new TmfLocation<Long>(0L), 0))); |
c1c69938 FC |
223 | // adjust index to round down to earlier checkpoint when exact match |
224 | // not | |
225 | // found | |
226 | index = getPrevIndex(index); | |
227 | ||
228 | if (index == 0) { | |
229 | // No checkpoint restore is needed, start with a brand new | |
230 | // TraceState | |
231 | traceState = StateModelFactory.getStateEntryInstance(this); | |
232 | } else { | |
233 | ||
234 | // Useful CheckPoint found | |
a79913eb | 235 | checkpoint = timestampCheckpointsList.get(index); |
c1c69938 FC |
236 | // get the location associated with the checkpoint |
237 | TmfLocation<Long> location = (TmfLocation<Long>) checkpoint.getLocation(); | |
238 | // reference a new copy of the checkpoint template | |
239 | traceState = stateCheckpointsList.get(location.getLocation()).clone(); | |
240 | } | |
241 | ||
5dbe4d3b | 242 | } |
5d10d135 | 243 | |
5dbe4d3b | 244 | // Restore the stored traceState |
c1c69938 | 245 | synchronized (fStateModelLock) { |
5dbe4d3b | 246 | fStateModel = traceState; |
5d10d135 ASL |
247 | } |
248 | ||
a79913eb FC |
249 | return checkpoint; |
250 | } | |
251 | ||
252 | /* (non-Javadoc) | |
253 | * @see org.eclipse.linuxtools.lttng.state.trace.IStateTraceManager#restoreCheckPointByIndex(long) | |
254 | */ | |
255 | @Override | |
256 | public TmfCheckpoint restoreCheckPointByIndex(long eventIndex) { | |
d905a64a | 257 | TmfCheckpoint checkpoint = new TmfCheckpoint(fTrace.getStartTime(), new TmfContext(new TmfLocation<Long>(0L), 0)); |
a79913eb FC |
258 | |
259 | LttngTraceState traceState; | |
260 | synchronized (fCheckPointsLock) { | |
261 | Collections.sort(timestampCheckpointsList); | |
262 | // Initiate the compare with a checkpoint containing the target time | |
263 | // stamp to find | |
d905a64a | 264 | int index = Collections.binarySearch(timestampCheckpointsList, new TmfCheckpoint(null, new TmfContext(new TmfLocation<Long>(eventIndex), eventIndex))); |
a79913eb FC |
265 | // adjust index to round down to earlier checkpoint when exact match not found |
266 | index = getPrevIndex(index); | |
267 | ||
268 | if (index == 0) { | |
269 | // No checkpoint restore is needed, start with a brand new | |
270 | // TraceState | |
271 | traceState = StateModelFactory.getStateEntryInstance(this); | |
272 | } else { | |
273 | ||
274 | // Useful CheckPoint found | |
275 | checkpoint = timestampCheckpointsList.get(index); | |
276 | // get the location associated with the checkpoint | |
277 | @SuppressWarnings("unchecked") | |
278 | TmfLocation<Long> location = (TmfLocation<Long>) checkpoint.getLocation(); | |
279 | // reference a new copy of the checkpoint template | |
280 | traceState = stateCheckpointsList.get(location.getLocation()).clone(); | |
281 | } | |
282 | ||
283 | } | |
284 | ||
285 | // Restore the stored traceState | |
286 | synchronized (fStateModelLock) { | |
287 | fStateModel = traceState; | |
288 | } | |
289 | ||
290 | return checkpoint; | |
5d10d135 ASL |
291 | } |
292 | ||
293 | /** | |
294 | * Adjust the result from a binary search to the round down position | |
0c32e4c5 | 295 | * |
5d10d135 ASL |
296 | * @param position |
297 | * if Negative is: (-(insertion point) -1) | |
298 | * @return position or if no match found, earlier than insertion point | |
299 | */ | |
300 | private int getPrevIndex(int position) { | |
301 | int roundDownPosition = position; | |
302 | if (position < 0) { | |
303 | roundDownPosition = -(position + 2); | |
304 | } | |
305 | ||
306 | roundDownPosition = roundDownPosition < 0 ? 0 : roundDownPosition; | |
307 | return roundDownPosition; | |
308 | } | |
309 | ||
5d10d135 ASL |
310 | // TODO: Remove this request type when the UI handle their own requests |
311 | /** | |
312 | * Request Event data of a specified time range | |
0c32e4c5 | 313 | * |
5d10d135 ASL |
314 | * @param timeWindow |
315 | * @param listener | |
316 | * @param processor | |
317 | * @return ILttngEventRequest The request made | |
318 | */ | |
550d787e | 319 | ILttngSyntEventRequest getDataRequestByTimeRange(TmfTimeRange timeWindow, IRequestStatusListener listener, |
5d10d135 ASL |
320 | final ITransEventProcessor processor) { |
321 | ||
550d787e FC |
322 | ILttngSyntEventRequest request = new StateTraceManagerRequest(timeWindow, DEFAULT_OFFSET, |
323 | TmfDataRequest.ALL_DATA, DEFAULT_CHUNK, listener, getExperimentTimeWindow(), processor) { | |
5d10d135 ASL |
324 | }; |
325 | ||
326 | return request; | |
327 | } | |
328 | ||
5d10d135 ASL |
329 | |
330 | /* | |
331 | * (non-Javadoc) | |
0c32e4c5 | 332 | * |
5d10d135 ASL |
333 | * @see |
334 | * org.eclipse.linuxtools.lttng.state.trace.IStateTraceManager#getStateModel | |
335 | * () | |
336 | */ | |
d4011df2 | 337 | @Override |
c1c69938 FC |
338 | public LttngTraceState getStateModel() { |
339 | LttngTraceState stateModel = null; | |
340 | synchronized (fStateModelLock) { | |
341 | stateModel = fStateModel; | |
5d10d135 | 342 | } |
c1c69938 | 343 | return stateModel; |
5d10d135 ASL |
344 | } |
345 | ||
550d787e FC |
346 | /* |
347 | * (non-Javadoc) | |
0c32e4c5 | 348 | * |
550d787e FC |
349 | * @see org.eclipse.linuxtools.lttng.state.trace.IStateTraceManager# |
350 | * getCheckPointStateModel() | |
351 | */ | |
d4011df2 | 352 | @Override |
c1c69938 FC |
353 | public LttngTraceState getCheckPointStateModel() { |
354 | LttngTraceState checkPointStateModel = null; | |
355 | synchronized (fCheckPointsLock) { | |
356 | checkPointStateModel = fCheckPointStateModel; | |
550d787e | 357 | } |
c1c69938 | 358 | return checkPointStateModel; |
550d787e FC |
359 | } |
360 | ||
5d10d135 ASL |
361 | /** |
362 | * @return the stateCheckpointsList | |
363 | */ | |
364 | HashMap<Long, LttngTraceState> getStateCheckpointsList() { | |
365 | return stateCheckpointsList; | |
366 | } | |
367 | ||
368 | /** | |
369 | * @return the timestampCheckpointsList | |
370 | */ | |
371 | Vector<TmfCheckpoint> getTimestampCheckpointsList() { | |
372 | return timestampCheckpointsList; | |
373 | } | |
374 | // ======================================================================= | |
375 | // Inner Class | |
376 | // ======================================================================= | |
377 | class StateTraceManagerRequest extends LttngSyntEventRequest { | |
378 | // ======================================================================= | |
379 | // Data | |
380 | // ======================================================================= | |
381 | final TmfEvent[] evt = new TmfEvent[1]; | |
382 | final ITransEventProcessor fprocessor; | |
383 | LttngSyntheticEvent synEvent; | |
384 | Long fCount = getSynEventCount(); | |
385 | ||
386 | // ======================================================================= | |
387 | // Constructor | |
388 | // ======================================================================= | |
550d787e FC |
389 | public StateTraceManagerRequest(TmfTimeRange range, long offset, int nbEvents, int maxBlockSize, |
390 | IRequestStatusListener listener, TmfTimeRange experimentTimeRange, ITransEventProcessor processor) { | |
5d10d135 | 391 | |
550d787e | 392 | super(range, offset, nbEvents, maxBlockSize, listener, experimentTimeRange, processor); |
5d10d135 | 393 | fprocessor = processor; |
9c4eb5f7 | 394 | TraceDebug.debug("Instance created for range: " + range.toString()); //$NON-NLS-1$ |
5d10d135 ASL |
395 | fCount = 0L; |
396 | } | |
397 | ||
398 | // ======================================================================= | |
399 | // Methods | |
400 | // ======================================================================= | |
401 | /* | |
402 | * (non-Javadoc) | |
0c32e4c5 | 403 | * |
5d10d135 ASL |
404 | * @see |
405 | * org.eclipse.linuxtools.lttng.request.LttngSyntEventRequest#handleData | |
406 | * () | |
407 | */ | |
408 | @Override | |
0c32e4c5 | 409 | public void handleData(ITmfEvent event) { |
f9673903 FC |
410 | super.handleData(event); |
411 | if (event != null) { | |
0c32e4c5 | 412 | synEvent = (LttngSyntheticEvent) event; |
5d10d135 ASL |
413 | if (synEvent.getSynType() == SequenceInd.AFTER) { |
414 | // Note : We call this function before incrementing | |
415 | // eventCount to save a default check point at the "0th" | |
416 | // event | |
417 | saveCheckPoint(fCount, synEvent.getTimestamp()); | |
418 | fCount++; | |
419 | ||
420 | if (TraceDebug.isDEBUG()) { | |
421 | if (fCount % 1000 == 0) { | |
9c4eb5f7 | 422 | TraceDebug.debug("handled: " + fCount + " sequence: " + synEvent.getSynType()); //$NON-NLS-1$ //$NON-NLS-2$ |
5d10d135 ASL |
423 | } |
424 | } | |
425 | } | |
426 | } | |
427 | } | |
428 | ||
429 | /** | |
430 | * To be overridden by active save e.g. check points, this no action | |
431 | * default is used for requests which do not require rebuilding of | |
432 | * checkpoints e.g. requiring data of a new time range selection | |
0c32e4c5 | 433 | * |
5d10d135 ASL |
434 | * @param count |
435 | * @param time | |
436 | */ | |
4df4581d | 437 | public void saveCheckPoint(Long count, ITmfTimestamp time) { |
5d10d135 ASL |
438 | |
439 | } | |
440 | } | |
441 | ||
442 | /* | |
443 | * (non-Javadoc) | |
0c32e4c5 | 444 | * |
5d10d135 ASL |
445 | * @see org.eclipse.linuxtools.lttng.state.resource.ILttngStateContext# |
446 | * getNumberOfCpus() | |
447 | */ | |
d4011df2 | 448 | @Override |
5d10d135 ASL |
449 | public int getNumberOfCpus() { |
450 | return fcpuNumber; | |
451 | } | |
452 | ||
453 | /* | |
454 | * (non-Javadoc) | |
0c32e4c5 | 455 | * |
5d10d135 ASL |
456 | * @see org.eclipse.linuxtools.lttng.state.resource.ILttngStateContext# |
457 | * getTraceTimeWindow() | |
458 | */ | |
d4011df2 | 459 | @Override |
5d10d135 ASL |
460 | public TmfTimeRange getTraceTimeWindow() { |
461 | if (fTrace != null) { | |
462 | return fTrace.getTimeRange(); | |
463 | ||
464 | } | |
465 | return null; | |
466 | } | |
467 | ||
468 | /* | |
469 | * (non-Javadoc) | |
0c32e4c5 | 470 | * |
5d10d135 ASL |
471 | * @see |
472 | * org.eclipse.linuxtools.lttng.state.resource.ILttngStateContext#getTraceId | |
473 | * () | |
474 | */ | |
d4011df2 | 475 | @Override |
5d10d135 ASL |
476 | public String getTraceId() { |
477 | if (fTrace != null) { | |
478 | return fTrace.getName(); | |
479 | } | |
480 | return null; | |
481 | } | |
482 | ||
483 | /* | |
484 | * (non-Javadoc) | |
0c32e4c5 | 485 | * |
5d10d135 ASL |
486 | * @see org.eclipse.linuxtools.lttng.state.trace.IStateTraceManager# |
487 | * getExperimentTimeWindow() | |
488 | */ | |
d4011df2 | 489 | @Override |
5d10d135 ASL |
490 | public TmfTimeRange getExperimentTimeWindow() { |
491 | if (fExperiment != null) { | |
492 | return fExperiment.getTimeRange(); | |
493 | } | |
494 | return null; | |
495 | } | |
496 | ||
497 | /* | |
498 | * (non-Javadoc) | |
0c32e4c5 | 499 | * |
5d10d135 ASL |
500 | * @see |
501 | * org.eclipse.linuxtools.lttng.state.trace.IStateTraceManager#getExperimentName | |
502 | * () | |
503 | */ | |
d4011df2 | 504 | @Override |
5d10d135 ASL |
505 | public String getExperimentName() { |
506 | return fExperiment.getName(); | |
507 | } | |
508 | ||
509 | /* | |
510 | * (non-Javadoc) | |
0c32e4c5 | 511 | * |
5d10d135 ASL |
512 | * @see |
513 | * org.eclipse.linuxtools.lttng.state.resource.ILttngStateContext#getTraceIdRef | |
514 | * () | |
515 | */ | |
d4011df2 | 516 | @Override |
0c32e4c5 | 517 | public ITmfTrace getTraceIdRef() { |
5d10d135 ASL |
518 | return fTrace; |
519 | } | |
550d787e FC |
520 | |
521 | /* | |
522 | * (non-Javadoc) | |
0c32e4c5 | 523 | * |
550d787e FC |
524 | * @see |
525 | * org.eclipse.linuxtools.lttng.state.trace.IStateTraceManager#clearCheckPoints | |
526 | * () | |
527 | */ | |
d4011df2 | 528 | @Override |
c1c69938 FC |
529 | public void clearCheckPoints() { |
530 | synchronized (fCheckPointsLock) { | |
550d787e FC |
531 | stateCheckpointsList.clear(); |
532 | timestampCheckpointsList.clear(); | |
533 | ||
534 | fCheckPointStateModel = StateModelFactory.getStateEntryInstance(this); | |
c1c69938 | 535 | |
550d787e FC |
536 | try { |
537 | fCheckPointStateModel.init(this); | |
538 | } catch (LttngStateException e) { | |
9fa32496 | 539 | Activator.getDefault().logError("Unexpected Error", e); //$NON-NLS-1$ |
550d787e FC |
540 | } |
541 | } | |
542 | } | |
543 | ||
544 | /* | |
545 | * (non-Javadoc) | |
0c32e4c5 | 546 | * |
550d787e FC |
547 | * @see |
548 | * org.eclipse.linuxtools.lttng.state.trace.IStateTraceManager#handleEvent | |
549 | * (org.eclipse.linuxtools.lttng.event.LttngSyntheticEvent, java.lang.Long) | |
550 | */ | |
d4011df2 | 551 | @Override |
550d787e FC |
552 | public void handleEvent(LttngSyntheticEvent synEvent, Long eventCount) { |
553 | fStateUpdateProcessor.process(synEvent, fCheckPointStateModel); | |
554 | ||
555 | // Save checkpoint as needed | |
556 | saveCheckPointIfNeeded(eventCount - 1, synEvent.getTimestamp()); | |
557 | } | |
558 | ||
559 | /* | |
560 | * (non-Javadoc) | |
0c32e4c5 | 561 | * |
550d787e FC |
562 | * @see java.lang.Object#toString() |
563 | */ | |
cb866e08 | 564 | @Override |
3b38ea61 | 565 | @SuppressWarnings("nls") |
550d787e FC |
566 | public String toString() { |
567 | StringBuilder sb = new StringBuilder(super.toString()); | |
568 | sb.append("\n\tTotal number of processes in the Shared State model: " + fStateModel.getProcesses().length | |
569 | + "\n\t" + "Total number of processes in the Check point State model: " | |
570 | + fCheckPointStateModel.getProcesses().length); | |
571 | ||
572 | TmfTimeRange traceTRange = fTrace.getTimeRange(); | |
573 | sb.append("\n\tTrace time interval for trace " + fTrace.getName() + "\n\t" | |
574 | + new LttngTimestamp(traceTRange.getStartTime())); | |
575 | sb.append(" - " + new LttngTimestamp(traceTRange.getEndTime())); | |
576 | sb.append("\n\tCheckPoints available at: "); | |
577 | for (TmfCheckpoint cpoint : timestampCheckpointsList) { | |
578 | sb.append("\n\t" + "Location: " + cpoint.getLocation() + " - " + cpoint.getTimestamp()); | |
579 | } | |
580 | ||
581 | return sb.toString(); | |
582 | } | |
583 | ||
b12f4544 FC |
584 | /* |
585 | * (non-Javadoc) | |
586 | * @see org.eclipse.linuxtools.lttng.state.resource.ILttngStateContext#getIdentifier() | |
587 | */ | |
588 | @Override | |
589 | public long getIdentifier() { | |
590 | return getId().longValue(); | |
591 | } | |
592 | ||
550d787e | 593 | } |