May 31
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng / src / org / eclipse / linuxtools / lttng / state / trace / StateTraceManager.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 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 * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation
11 *******************************************************************************/
12 package org.eclipse.linuxtools.lttng.state.trace;
13
14 import java.util.Collections;
15 import java.util.HashMap;
16 import java.util.Vector;
17
18 import org.eclipse.linuxtools.lttng.TraceDebug;
19 import org.eclipse.linuxtools.lttng.event.LttngEvent;
20 import org.eclipse.linuxtools.lttng.event.LttngSyntheticEvent;
21 import org.eclipse.linuxtools.lttng.event.LttngSyntheticEvent.SequenceInd;
22 import org.eclipse.linuxtools.lttng.event.LttngTimestamp;
23 import org.eclipse.linuxtools.lttng.model.LTTngTreeNode;
24 import org.eclipse.linuxtools.lttng.request.ILttngSyntEventRequest;
25 import org.eclipse.linuxtools.lttng.request.IRequestStatusListener;
26 import org.eclipse.linuxtools.lttng.request.LttngSyntEventRequest;
27 import org.eclipse.linuxtools.lttng.state.LttngStateException;
28 import org.eclipse.linuxtools.lttng.state.evProcessor.ITransEventProcessor;
29 import org.eclipse.linuxtools.lttng.state.evProcessor.state.StateEventToHandlerFactory;
30 import org.eclipse.linuxtools.lttng.state.model.LttngTraceState;
31 import org.eclipse.linuxtools.lttng.state.model.StateModelFactory;
32 import org.eclipse.linuxtools.lttng.state.resource.ILttngStateContext;
33 import org.eclipse.linuxtools.lttng.trace.LTTngTextTrace;
34 import org.eclipse.linuxtools.lttng.trace.LTTngTrace;
35 import org.eclipse.linuxtools.tmf.component.TmfEventProvider;
36 import org.eclipse.linuxtools.tmf.event.TmfEvent;
37 import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
38 import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
39 import org.eclipse.linuxtools.tmf.experiment.TmfExperiment;
40 import org.eclipse.linuxtools.tmf.request.TmfDataRequest;
41 import org.eclipse.linuxtools.tmf.signal.TmfExperimentUpdatedSignal;
42 import org.eclipse.linuxtools.tmf.trace.ITmfTrace;
43 import org.eclipse.linuxtools.tmf.trace.TmfCheckpoint;
44 import org.eclipse.linuxtools.tmf.trace.TmfLocation;
45
46 public class StateTraceManager extends LTTngTreeNode implements
47 IStateTraceManager, ILttngStateContext {
48
49 // constants
50 private static final long DEFAULT_OFFSET = 0L;
51 private static final int DEFAULT_CHUNK = 1;
52
53 // configurable check point interval
54 private static final long LTTNG_CHECK_POINT_INTERVAL = 15000L;
55 private long fcheckPointInterval = LTTNG_CHECK_POINT_INTERVAL;
56
57 private TmfExperiment<LttngEvent> fExperiment = null;
58
59 // immutable Objects
60 private final ITmfTrace fTrace;
61 private final TmfTimestamp fCheckPointsStartTime;
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;
69 private LttngTraceState fCheckPointStateModel;
70 private int selectionCount = 0;
71
72 // locks
73 private Object checkPointsLock = new Object();
74
75 /**
76 * Could be fixed to trace level from received trace, however preparation
77 * for multiple threads is necessary, a common synthetic event provider at
78 * experiment level is a good start although can be adjusted externally
79 */
80 private TmfEventProvider<LttngSyntheticEvent> fSynEventProvider;
81
82
83 // =======================================================================
84 // Constructor
85 // =======================================================================
86 /**
87 * @param id
88 * @param parent
89 * @param name
90 * @param trace
91 * @param stateModel
92 * @param eventProvider
93 * @throws LttngStateException
94 */
95 public StateTraceManager(Long id, LTTngTreeNode parent, String name,
96 ITmfTrace trace,
97 TmfEventProvider<LttngSyntheticEvent> eventProvider)
98 throws LttngStateException {
99 super(id, parent, name, trace);
100
101 if (trace == null) {
102 throw new LttngStateException("No TmfTrace object available!");
103 }
104
105 fTrace = trace;
106 fCheckPointsStartTime = trace.getStartTime().clone();
107 fStateUpdateProcessor = StateEventToHandlerFactory.getInstance();
108 fSynEventProvider = eventProvider;
109
110 init();
111
112 fStateModel = StateModelFactory.getStateEntryInstance(this);
113 fStateModel.init(this);
114
115 fCheckPointStateModel = StateModelFactory.getStateEntryInstance(this);
116 fCheckPointStateModel.init(this);
117 }
118
119 // =======================================================================
120 // Methods
121 // =======================================================================
122 @SuppressWarnings("unchecked")
123 private void init() {
124 // resolve the experiment
125 Object obj = getParent().getValue();
126 if (obj != null && obj instanceof TmfExperiment<?>) {
127 fExperiment = (TmfExperiment<LttngEvent>) obj;
128 }
129
130 // initialize the number of cpus
131 if (fTrace instanceof LTTngTrace) {
132 fcpuNumber = ((LTTngTrace) fTrace).getCpuNumber();
133 } else if (fTrace instanceof LTTngTextTrace) {
134 fcpuNumber = ((LTTngTextTrace) fTrace).getCpuNumber();
135 }
136 }
137
138 /*
139 * (non-Javadoc)
140 *
141 * @see org.eclipse.linuxtools.lttng.signal.ILttExperimentSelectedListener#
142 * experimentSelected(java.lang.Object,
143 * org.eclipse.linuxtools.tmf.experiment.TmfExperiment)
144 */
145 public void experimentSelected(Object source,
146 TmfExperiment<LttngEvent> experiment) {
147 // Only update experiment is needed for the time being
148 }
149
150 /*
151 * (non-Javadoc)
152 *
153 * @see org.eclipse.linuxtools.lttng.signal.ILttExperimentSelectedListener#
154 * experimentUpdated
155 * (org.eclipse.linuxtools.tmf.signal.TmfExperimentUpdatedSignal)
156 */
157 public void experimentUpdated(TmfExperimentUpdatedSignal signal, boolean wait) {
158 // initialise check points once per new experiment selection
159
160 synchronized (checkPointsLock) {
161 stateCheckpointsList.clear();
162 timestampCheckpointsList.clear();
163 }
164
165 // requested time window from trace start to end, this to
166 // make sure one thread is used so the events arrive in order for proper
167 // building of the checkpoints
168 TmfTimeRange adjustedRange = new TmfTimeRange(fCheckPointsStartTime, fTrace.getTimeRange().getEndTime());
169
170 // Obtain a dataRequest to pass to the processRequest function
171 ILttngSyntEventRequest request = getDataRequestStateSave(adjustedRange,
172 null, fStateUpdateProcessor);
173 request.setclearDataInd(true);
174 request.startRequestInd(fSynEventProvider);
175 if (wait) {
176 try {
177 request.waitForCompletion();
178 } catch (InterruptedException e) {
179 e.printStackTrace();
180 }
181 }
182 }
183
184 // /*
185 // * (non-Javadoc)
186 // *
187 // * @see org.eclipse.linuxtools.lttng.state.trace.IStateTraceManager#
188 // * executeDataRequest(org.eclipse.linuxtools.tmf.event.TmfTimeRange,
189 // * java.lang.Object,
190 // * org.eclipse.linuxtools.lttng.request.IRequestStatusListener,
191 // * org.eclipse.linuxtools.lttng.state.evProcessor.ITransEventProcessor)
192 // */
193 // public ILttngSyntEventRequest executeDataRequest(TmfTimeRange trange,
194 // Object source,
195 // IRequestStatusListener listener, ITransEventProcessor processor) {
196 // TmfTimestamp restoredStartTime = restoreCheckPointByTimestamp(trange
197 // .getStartTime());
198 // // Adjust the time range to consider rewinding to the start time
199 // trange = new TmfTimeRange(restoredStartTime, trange.getEndTime());
200 // // Get a data request for the time range we want (nearest checkpoint
201 // // to timestamp wanted)
202 //
203 // // Process request to that point
204 // ILttngSyntEventRequest request = getDataRequestByTimeRange(trange,
205 // listener, processor);
206 // request.setSource(source);
207 //
208 // // don't wait for completion i.e. allow cancellations
209 // request.startRequestInd(fSynEventProvider);
210 // // fSynEventProvider
211 // // .sendRequest((TmfDataRequest<LttngSyntheticEvent>) request);
212 //
213 // if (TraceDebug.isDEBUG()) {
214 // TraceDebug
215 // .debug(" Time Window requested, (start adjusted to checkpoint): "
216 // + trange.getStartTime()
217 // + "-"
218 // + trange.getEndTime()
219 // + " Total number of processes in the State provider: "
220 // + fStateModel.getProcesses().length + " Completed");
221 // }
222 //
223 // return request;
224 // }
225
226 /*
227 * (non-Javadoc)
228 *
229 * @see org.eclipse.linuxtools.lttng.state.IStateManager#getEventLog()
230 */
231 public ITmfTrace getTrace() {
232 return fTrace;
233 }
234
235 /**
236 * Save a checkpoint if it is needed at that point
237 * <p>
238 * The function will use "eventCount" internally to determine if a save was
239 * needed
240 *
241 * @param eventCounter
242 * The event "count" or event "id" so far
243 * @param eventTime
244 * The timestamp of this event
245 *
246 * @return boolean True if a checkpoint was saved, false otherwise
247 */
248 private void saveCheckPointIfNeeded(Long eventCounter,
249 TmfTimestamp eventTime) {
250 // Save a checkpoint every LTTNG_STATE_SAVE_INTERVAL event
251 if ((eventCounter.longValue() % fcheckPointInterval) == 0) {
252 LttngTraceState stateCheckPoint;
253 synchronized (fCheckPointStateModel) {
254 stateCheckPoint = fCheckPointStateModel.clone();
255 }
256
257 TraceDebug.debug("Check point created here: " + eventCounter
258 + " -> " + eventTime.toString() + "************"
259 + getTrace().getName() + " >>>>> Thread: "
260 + Thread.currentThread().getId());
261
262 synchronized (checkPointsLock) {
263 // Save the checkpoint
264 stateCheckpointsList.put(eventCounter, stateCheckPoint);
265 // Save correlation between timestamp and checkpoint index
266
267 timestampCheckpointsList.add(new TmfCheckpoint(
268 new TmfTimestamp(eventTime), new TmfLocation<Long>(
269 eventCounter)));
270 }
271 }
272 }
273
274 /**
275 * @return the lttng_check_point_interval
276 */
277 public long getCheckPointInterval() {
278 return fcheckPointInterval;
279 }
280
281 /**
282 * @param check_point_interval
283 * , the lttng_check_point_interval to set
284 */
285 public void setCheckPointInterval(long check_point_interval) {
286 this.fcheckPointInterval = check_point_interval;
287 }
288
289 /* (non-Javadoc)
290 * @see org.eclipse.linuxtools.lttng.state.trace.IStateTraceManager#restoreCheckPointByTimestamp(org.eclipse.linuxtools.tmf.event.TmfTimestamp)
291 */
292 @SuppressWarnings("unchecked")
293 public TmfTimestamp restoreCheckPointByTimestamp(TmfTimestamp eventTime) { TmfTimeRange experimentRange = fExperiment.getTimeRange();
294 TmfTimestamp nearestTimeStamp = fTrace.getStartTime();
295
296 // The GUI can have time limits higher than this log, since GUI can
297 // handle multiple logs
298 if ((eventTime.getValue() < 0)
299 || (eventTime.getValue() > experimentRange.getEndTime().getValue())) {
300 return null;
301 }
302
303 // // The GUI can have time limits lower than this trace, since experiment
304 // // can handle multiple traces
305 // if ((eventTime.getValue() < fTrace.getStartTime().getValue())) {
306 // eventTime = fTrace.getStartTime();
307 // }
308 //
309 // // Sort the checkpoints, required before the binary search
310 // Collections.sort(timestampCheckpointsList);
311 // // Initiate the compare with a checkpoint containing the target time
312 // // stamp to find
313 // int index = Collections.binarySearch(timestampCheckpointsList,
314 // new TmfCheckpoint(eventTime, new TmfLocation<Long>(0L)));
315 // // adjust index to round down to earlier checkpoint when exact match not
316 // // found
317 // index = getPrevIndex(index);
318 //
319 LttngTraceState traceState;
320 // if (index == 0) {
321 // // No checkpoint restore is needed, start with a brand new
322 // // TraceState
323 // traceState = StateModelFactory.getStateEntryInstance(this);
324
325 // The reference to fCheckPointsStartTime is used as the indicator to
326 // identify a state check point building request
327 if (eventTime == fCheckPointsStartTime) {
328 // indicates state checkpoint building request
329 nearestTimeStamp = fCheckPointsStartTime;
330 // starting from the trace start time with an empty state model
331 traceState = StateModelFactory.getStateEntryInstance(this);
332 // update the instance field variable pointing the the check point
333 // building state model
334 synchronized (fCheckPointStateModel) {
335 fCheckPointStateModel = traceState;
336 }
337
338 } else {
339 // synchronized (checkPointsLock) {
340 // // Useful CheckPoint found
341 // TmfCheckpoint checkpoint = timestampCheckpointsList.get(index);
342 // nearestTimeStamp = checkpoint.getTimestamp();
343 // // get the location associated with the checkpoint
344 // TmfLocation<Long> location = (TmfLocation<Long>) checkpoint
345 // .getLocation();
346 // // reference a new copy of the checkpoint template
347 // traceState = stateCheckpointsList.get(location.getLocation())
348 // .clone();
349 // The GUI requests can have time limits lower than this trace,
350 // since experiment can handle multiple traces
351 if ((eventTime.getValue() < fTrace.getStartTime().getValue())) {
352 eventTime = fTrace.getStartTime();
353 }
354 // }
355
356 // // Restore the stored traceState
357 // synchronized (fStateModel) {
358 // fStateModel = traceState;
359 // Sort the checkpoints, required before the binary search
360 Collections.sort(timestampCheckpointsList);
361 // Initiate the compare with a checkpoint containing the target time
362 // stamp to find
363 int index = Collections.binarySearch(timestampCheckpointsList, new TmfCheckpoint(eventTime,
364 new TmfLocation<Long>(0L)));
365 // adjust index to round down to earlier checkpoint when exact match
366 // not
367 // found
368 index = getPrevIndex(index);
369
370 if (index == 0) {
371 // No checkpoint restore is needed, start with a brand new
372 // TraceState
373 traceState = StateModelFactory.getStateEntryInstance(this);
374 } else {
375 synchronized (checkPointsLock) {
376 // Useful CheckPoint found
377 TmfCheckpoint checkpoint = timestampCheckpointsList.get(index);
378 nearestTimeStamp = checkpoint.getTimestamp();
379 // get the location associated with the checkpoint
380 TmfLocation<Long> location = (TmfLocation<Long>) checkpoint.getLocation();
381 // reference a new copy of the checkpoint template
382 traceState = stateCheckpointsList.get(location.getLocation()).clone();
383 }
384 }
385
386 // Restore the stored traceState
387 synchronized (fStateModel) {
388 fStateModel = traceState;
389 }
390 }
391
392 return nearestTimeStamp;
393 }
394
395 /**
396 * Adjust the result from a binary search to the round down position
397 *
398 * @param position
399 * if Negative is: (-(insertion point) -1)
400 * @return position or if no match found, earlier than insertion point
401 */
402 private int getPrevIndex(int position) {
403 int roundDownPosition = position;
404 if (position < 0) {
405 roundDownPosition = -(position + 2);
406 }
407
408 roundDownPosition = roundDownPosition < 0 ? 0 : roundDownPosition;
409 return roundDownPosition;
410 }
411
412
413 // TODO: Remove this request type when the UI handle their own requests
414 /**
415 * Request Event data of a specified time range
416 *
417 * @param timeWindow
418 * @param listener
419 * @param processor
420 * @return ILttngEventRequest The request made
421 */
422 ILttngSyntEventRequest getDataRequestByTimeRange(TmfTimeRange timeWindow,
423 IRequestStatusListener listener,
424 final ITransEventProcessor processor) {
425
426 ILttngSyntEventRequest request = new StateTraceManagerRequest(timeWindow,
427 DEFAULT_OFFSET, TmfDataRequest.ALL_DATA, DEFAULT_CHUNK,
428 listener, getExperimentTimeWindow(), processor) {
429 };
430
431 return request;
432 }
433
434 private ILttngSyntEventRequest getDataRequestStateSave(TmfTimeRange timeWindow,
435 IRequestStatusListener requestListener,
436 final ITransEventProcessor processor) {
437
438 // Create the new request and override the handlePartialResult function
439 ILttngSyntEventRequest request = new StateTraceManagerRequest(timeWindow,
440 DEFAULT_OFFSET, TmfDataRequest.ALL_DATA, DEFAULT_CHUNK,
441 requestListener, getExperimentTimeWindow(), processor) {
442
443 /* (non-Javadoc)
444 * @see org.eclipse.linuxtools.lttng.request.LttngSyntEventRequest#handleCompleted()
445 */
446 @Override
447 public void handleCompleted() {
448 if (isCancelled() || isFailed()) {
449 // No notification to end request handlers
450 } else {
451 // Indicates that trace selection has successfully completed
452 // i.e. check points have been already build if the number
453 // of events exceeded the interval
454 setTraceSelectCount(getTraceSelectCount() + 1);
455 }
456
457 super.handleCompleted();
458
459 if (TraceDebug.isDEBUG()) {
460 StringBuilder sb = new StringBuilder(
461 "Check Point build Request completed"
462 + "\n\tEventCount: "
463 + fprocessor.getStateUpdateCount()
464 + "\tEvents for a different trace state received: "
465 + fprocessor.getFilteredOutEventCount()
466 + "\n\t"
467 + fStateModel.getProcesses().length
468 + "\n\t"
469 + "Total number of processes in the Check point State model: "
470 + fCheckPointStateModel.getProcesses().length);
471
472 TmfTimeRange logTimes = fTrace.getTimeRange();
473 sb.append("\n\tTrace time interval for trace "
474 + fTrace.getName()
475 + "\n\t"
476 + new LttngTimestamp(logTimes.getStartTime()));
477 sb.append(" - " + new LttngTimestamp(logTimes.getEndTime()));
478 sb.append("\n\tRequested Time: "
479 + getRange().getStartTime().toString() + " - "
480 + getRange().getEndTime().toString());
481 sb.append("\n\tCheckPoints available at: ");
482 for (TmfCheckpoint cpoint : timestampCheckpointsList) {
483 sb.append("\n\t" + "Location: " + cpoint.getLocation()
484 + " - " + cpoint.getTimestamp());
485 }
486
487 TraceDebug.debug(sb.toString());
488 }
489 }
490
491 /* (non-Javadoc)
492 * @see org.eclipse.linuxtools.lttng.state.trace.StateTraceManager.StateTraceManagerRequest#saveCheckPoint(java.lang.Long, org.eclipse.linuxtools.tmf.event.TmfTimestamp)
493 */
494 @Override
495 public void saveCheckPoint(Long count, TmfTimestamp time) {
496 saveCheckPointIfNeeded(count, time);
497 }
498
499 };
500
501 return request;
502 }
503
504 /**
505 *
506 * @return
507 */
508 private synchronized int getTraceSelectCount() {
509 return selectionCount;
510 }
511
512 /**
513 * @param value
514 */
515 private synchronized void setTraceSelectCount(int value) {
516 selectionCount = value;
517 }
518
519 /*
520 * (non-Javadoc)
521 *
522 * @see
523 * org.eclipse.linuxtools.lttng.state.trace.IStateTraceManager#getStateModel
524 * ()
525 */
526 public LttngTraceState getStateModel() {
527 synchronized (fStateModel) {
528 return fStateModel;
529 }
530 }
531
532 /*
533 * (non-Javadoc)
534 *
535 * @see
536 * org.eclipse.linuxtools.lttng.state.trace.IStateTraceManager#getStateModel
537 * (org.eclipse.linuxtools.tmf.event.TmfTimestamp)
538 */
539 public LttngTraceState getStateModel(TmfTimestamp checkPointReference) {
540 // validate
541 if (checkPointReference == null) {
542 return null;
543 }
544
545 // Only two state models supported at this time e.g. one for checkpoint
546 // building and the second one is shared for UI requests which are
547 // either coalesced or sequential (i.e. within the same trace data
548 // provider)
549 if (checkPointReference == fCheckPointsStartTime) {
550 synchronized (fCheckPointStateModel) {
551 return fCheckPointStateModel;
552 }
553 } else {
554 synchronized (fStateModel) {
555 return fStateModel;
556 }
557 }
558 }
559
560 /**
561 * @return the stateCheckpointsList
562 */
563 HashMap<Long, LttngTraceState> getStateCheckpointsList() {
564 return stateCheckpointsList;
565 }
566
567 /**
568 * @return the timestampCheckpointsList
569 */
570 Vector<TmfCheckpoint> getTimestampCheckpointsList() {
571 return timestampCheckpointsList;
572 }
573 // =======================================================================
574 // Inner Class
575 // =======================================================================
576 class StateTraceManagerRequest extends LttngSyntEventRequest {
577 // =======================================================================
578 // Data
579 // =======================================================================
580 final TmfEvent[] evt = new TmfEvent[1];
581 final ITransEventProcessor fprocessor;
582 LttngSyntheticEvent synEvent;
583 Long fCount = getSynEventCount();
584
585 // =======================================================================
586 // Constructor
587 // =======================================================================
588 public StateTraceManagerRequest(TmfTimeRange range, long offset,
589 int nbEvents, int maxBlockSize,
590 IRequestStatusListener listener,
591 TmfTimeRange experimentTimeRange, ITransEventProcessor processor) {
592
593 super(range, offset, nbEvents, maxBlockSize, listener,
594 experimentTimeRange, processor);
595 fprocessor = processor;
596 TraceDebug.debug("Instance created for range: " + range.toString());
597 fCount = 0L;
598 }
599
600 // =======================================================================
601 // Methods
602 // =======================================================================
603 /*
604 * (non-Javadoc)
605 *
606 * @see
607 * org.eclipse.linuxtools.lttng.request.LttngSyntEventRequest#handleData
608 * ()
609 */
610 @Override
611 public void handleData() {
612 TmfEvent[] result = getData();
613
614 evt[0] = (result.length > 0) ? result[0] : null;
615 if (evt[0] != null) {
616 synEvent = (LttngSyntheticEvent) evt[0];
617 if (synEvent.getSynType() == SequenceInd.AFTER) {
618 // Note : We call this function before incrementing
619 // eventCount to save a default check point at the "0th"
620 // event
621 saveCheckPoint(fCount, synEvent.getTimestamp());
622 fCount++;
623
624 if (TraceDebug.isDEBUG()) {
625 if (fCount % 1000 == 0) {
626 TraceDebug.debug("handled: " + fCount
627 + " sequence: " + synEvent.getSynType());
628 }
629 }
630 }
631 }
632 }
633
634 /**
635 * To be overridden by active save e.g. check points, this no action
636 * default is used for requests which do not require rebuilding of
637 * checkpoints e.g. requiring data of a new time range selection
638 *
639 * @param count
640 * @param time
641 */
642 public void saveCheckPoint(Long count, TmfTimestamp time) {
643
644 }
645 }
646
647 /*
648 * (non-Javadoc)
649 *
650 * @see org.eclipse.linuxtools.lttng.state.resource.ILttngStateContext#
651 * getNumberOfCpus()
652 */
653 public int getNumberOfCpus() {
654 return fcpuNumber;
655 }
656
657 /*
658 * (non-Javadoc)
659 *
660 * @see org.eclipse.linuxtools.lttng.state.resource.ILttngStateContext#
661 * getTraceTimeWindow()
662 */
663 public TmfTimeRange getTraceTimeWindow() {
664 if (fTrace != null) {
665 return fTrace.getTimeRange();
666
667 }
668 return null;
669 }
670
671 /*
672 * (non-Javadoc)
673 *
674 * @see
675 * org.eclipse.linuxtools.lttng.state.resource.ILttngStateContext#getTraceId
676 * ()
677 */
678 public String getTraceId() {
679 if (fTrace != null) {
680 return fTrace.getName();
681 }
682 return null;
683 }
684
685 /*
686 * (non-Javadoc)
687 *
688 * @see org.eclipse.linuxtools.lttng.state.trace.IStateTraceManager#
689 * getExperimentTimeWindow()
690 */
691 public TmfTimeRange getExperimentTimeWindow() {
692 if (fExperiment != null) {
693 return fExperiment.getTimeRange();
694 }
695 return null;
696 }
697
698 /*
699 * (non-Javadoc)
700 *
701 * @see
702 * org.eclipse.linuxtools.lttng.state.trace.IStateTraceManager#getExperimentName
703 * ()
704 */
705 public String getExperimentName() {
706 return fExperiment.getName();
707 }
708
709 /*
710 * (non-Javadoc)
711 *
712 * @see
713 * org.eclipse.linuxtools.lttng.state.resource.ILttngStateContext#getTraceIdRef
714 * ()
715 */
716 public ITmfTrace getTraceIdRef() {
717 return fTrace;
718 }
719
720 /*
721 * (non-Javadoc)
722 *
723 * @see
724 * org.eclipse.linuxtools.lttng.state.trace.IStateTraceManager#clearCheckPoints
725 * ()
726 */
727 public void clearCheckPoints() {
728 synchronized (checkPointsLock) {
729 stateCheckpointsList.clear();
730 timestampCheckpointsList.clear();
731
732 fCheckPointStateModel = StateModelFactory
733 .getStateEntryInstance(this);
734 try {
735 fCheckPointStateModel.init(this);
736 } catch (LttngStateException e) {
737 e.printStackTrace();
738 }
739 }
740 }
741
742 /*
743 * (non-Javadoc)
744 *
745 * @see
746 * org.eclipse.linuxtools.lttng.state.trace.IStateTraceManager#handleEvent
747 * (org.eclipse.linuxtools.lttng.event.LttngSyntheticEvent, java.lang.Long)
748 */
749 public void handleEvent(LttngSyntheticEvent synEvent, Long eventCount) {
750 fStateUpdateProcessor.process(synEvent, fCheckPointStateModel);
751
752 // Save checkpoint as needed
753 saveCheckPointIfNeeded(eventCount - 1, synEvent.getTimestamp());
754 }
755
756 /*
757 * (non-Javadoc)
758 *
759 * @see java.lang.Object#toString()
760 */
761 public String toString() {
762 StringBuilder sb = new StringBuilder(super.toString());
763 sb.append("\n\tTotal number of processes in the Shared State model: " + fStateModel.getProcesses().length
764 + "\n\t" + "Total number of processes in the Check point State model: "
765 + fCheckPointStateModel.getProcesses().length);
766
767 TmfTimeRange traceTRange = fTrace.getTimeRange();
768 sb.append("\n\tTrace time interval for trace " + fTrace.getName() + "\n\t"
769 + new LttngTimestamp(traceTRange.getStartTime()));
770 sb.append(" - " + new LttngTimestamp(traceTRange.getEndTime()));
771 sb.append("\n\tCheckPoints available at: ");
772 for (TmfCheckpoint cpoint : timestampCheckpointsList) {
773 sb.append("\n\t" + "Location: " + cpoint.getLocation() + " - " + cpoint.getTimestamp());
774 }
775
776 return sb.toString();
777 }
778
779 }
This page took 0.056348 seconds and 5 git commands to generate.