1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 Ericsson
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 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.core
.experiment
;
15 import java
.io
.FileNotFoundException
;
16 import java
.util
.Collections
;
17 import java
.util
.Vector
;
19 import org
.eclipse
.core
.resources
.IProject
;
20 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
21 import org
.eclipse
.core
.runtime
.IStatus
;
22 import org
.eclipse
.core
.runtime
.Status
;
23 import org
.eclipse
.core
.runtime
.jobs
.Job
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.component
.TmfEventProvider
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEvent
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimeRange
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimestamp
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.request
.ITmfDataRequest
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.request
.ITmfEventRequest
;
30 import org
.eclipse
.linuxtools
.tmf
.core
.request
.TmfDataRequest
;
31 import org
.eclipse
.linuxtools
.tmf
.core
.request
.TmfEventRequest
;
32 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfExperimentDisposedSignal
;
33 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfExperimentRangeUpdatedSignal
;
34 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfExperimentSelectedSignal
;
35 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfExperimentUpdatedSignal
;
36 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignalHandler
;
37 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignalManager
;
38 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceUpdatedSignal
;
39 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
40 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfLocation
;
41 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
42 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfCheckpoint
;
43 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfContext
;
46 * <b><u>TmfExperiment</u></b>
48 * TmfExperiment presents a time-ordered, unified view of a set of TmfTraces that are part of a tracing experiment.
51 public class TmfExperiment
<T
extends TmfEvent
> extends TmfEventProvider
<T
> implements ITmfTrace
<T
> {
53 // ------------------------------------------------------------------------
55 // ------------------------------------------------------------------------
57 // The currently selected experiment
58 protected static TmfExperiment
<?
> fCurrentExperiment
= null;
60 // The set of traces that constitute the experiment
61 protected ITmfTrace
<T
>[] fTraces
;
63 // The total number of events
64 protected long fNbEvents
;
66 // The experiment time range
67 protected TmfTimeRange fTimeRange
;
69 // The experiment reference timestamp (default: Zero)
70 protected TmfTimestamp fEpoch
;
72 // The experiment index
73 protected Vector
<TmfCheckpoint
> fCheckpoints
= new Vector
<TmfCheckpoint
>();
75 // The current experiment context
76 protected TmfExperimentContext fExperimentContext
;
78 // ------------------------------------------------------------------------
80 // ------------------------------------------------------------------------
83 public boolean validate(IProject project
, String path
) {
88 public void initTrace(String path
, Class
<T
> eventType
) throws FileNotFoundException
{
92 public void initTrace(String path
, Class
<T
> eventType
, boolean indexTrace
) throws FileNotFoundException
{
96 public void initTrace(String path
, Class
<T
> eventType
, int cacheSize
) throws FileNotFoundException
{
100 public void initTrace(String path
, Class
<T
> eventType
, int cacheSize
, boolean indexTrace
) throws FileNotFoundException
{
108 * @param indexPageSize
110 public TmfExperiment(Class
<T
> type
, String id
, ITmfTrace
<T
>[] traces
, TmfTimestamp epoch
, int indexPageSize
) {
111 this(type
, id
, traces
, TmfTimestamp
.Zero
, indexPageSize
, false);
114 public TmfExperiment(Class
<T
> type
, String id
, ITmfTrace
<T
>[] traces
, TmfTimestamp epoch
, int indexPageSize
, boolean preIndexExperiment
) {
119 fIndexPageSize
= indexPageSize
;
120 fTimeRange
= TmfTimeRange
.Null
;
122 if (preIndexExperiment
) {
123 indexExperiment(true);
129 protected TmfExperiment(String id
, Class
<T
> type
) {
138 public TmfExperiment(Class
<T
> type
, String id
, ITmfTrace
<T
>[] traces
) {
139 this(type
, id
, traces
, TmfTimestamp
.Zero
, DEFAULT_INDEX_PAGE_SIZE
);
146 * @param indexPageSize
148 public TmfExperiment(Class
<T
> type
, String id
, ITmfTrace
<T
>[] traces
, int indexPageSize
) {
149 this(type
, id
, traces
, TmfTimestamp
.Zero
, indexPageSize
);
157 @SuppressWarnings("unchecked")
158 public TmfExperiment(TmfExperiment
<T
> other
) {
159 super(other
.getName() + "(clone)", other
.fType
); //$NON-NLS-1$
161 fEpoch
= other
.fEpoch
;
162 fIndexPageSize
= other
.fIndexPageSize
;
164 fTraces
= new ITmfTrace
[other
.fTraces
.length
];
165 for (int trace
= 0; trace
< other
.fTraces
.length
; trace
++) {
166 fTraces
[trace
] = other
.fTraces
[trace
].copy();
169 fNbEvents
= other
.fNbEvents
;
170 fTimeRange
= other
.fTimeRange
;
174 public TmfExperiment
<T
> copy() {
175 TmfExperiment
<T
> experiment
= new TmfExperiment
<T
>(this);
176 TmfSignalManager
.deregister(experiment
);
181 * Clears the experiment
184 @SuppressWarnings("rawtypes")
185 public synchronized void dispose() {
187 TmfExperimentDisposedSignal
<T
> signal
= new TmfExperimentDisposedSignal
<T
>(this, this);
190 if (fTraces
!= null) {
191 for (ITmfTrace trace
: fTraces
) {
196 if (fCheckpoints
!= null) {
197 fCheckpoints
.clear();
202 // ------------------------------------------------------------------------
204 // ------------------------------------------------------------------------
207 public long getNbEvents() {
212 public int getCacheSize() {
213 return fIndexPageSize
;
217 public TmfTimeRange
getTimeRange() {
222 public TmfTimestamp
getStartTime() {
223 return fTimeRange
.getStartTime();
227 public TmfTimestamp
getEndTime() {
228 return fTimeRange
.getEndTime();
231 public Vector
<TmfCheckpoint
> getCheckpoints() {
235 // ------------------------------------------------------------------------
237 // ------------------------------------------------------------------------
239 public static void setCurrentExperiment(TmfExperiment
<?
> experiment
) {
240 fCurrentExperiment
= experiment
;
243 public static TmfExperiment
<?
> getCurrentExperiment() {
244 return fCurrentExperiment
;
247 public TmfTimestamp
getEpoch() {
251 public ITmfTrace
<T
>[] getTraces() {
256 * Returns the rank of the first event with the requested timestamp. If none, returns the index of the next event
263 public long getRank(TmfTimestamp timestamp
) {
264 TmfExperimentContext context
= seekEvent(timestamp
);
265 return context
.getRank();
269 * Returns the timestamp of the event at the requested index. If none, returns null.
274 public TmfTimestamp
getTimestamp(int index
) {
275 TmfExperimentContext context
= seekEvent(index
);
276 TmfEvent event
= getNextEvent(context
);
277 return (event
!= null) ? event
.getTimestamp() : null;
280 // ------------------------------------------------------------------------
282 // ------------------------------------------------------------------------
285 * Update the global time range
287 protected void updateTimeRange() {
288 TmfTimestamp startTime
= fTimeRange
!= TmfTimeRange
.Null ? fTimeRange
.getStartTime() : TmfTimestamp
.BigCrunch
;
289 TmfTimestamp endTime
= fTimeRange
!= TmfTimeRange
.Null ? fTimeRange
.getEndTime() : TmfTimestamp
.BigBang
;
291 for (ITmfTrace
<T
> trace
: fTraces
) {
292 TmfTimestamp traceStartTime
= trace
.getStartTime();
293 if (traceStartTime
.compareTo(startTime
, true) < 0)
294 startTime
= traceStartTime
;
295 TmfTimestamp traceEndTime
= trace
.getEndTime();
296 if (traceEndTime
.compareTo(endTime
, true) > 0)
297 endTime
= traceEndTime
;
299 fTimeRange
= new TmfTimeRange(startTime
, endTime
);
302 // ------------------------------------------------------------------------
304 // ------------------------------------------------------------------------
306 public ITmfContext
armRequest(ITmfDataRequest
<T
> request
) {
307 // Tracer.trace("Ctx: Arming request - start");
308 TmfTimestamp timestamp
= (request
instanceof ITmfEventRequest
<?
>) ?
((ITmfEventRequest
<T
>) request
).getRange().getStartTime()
311 if (TmfTimestamp
.BigBang
.equals(timestamp
) || request
.getIndex() > 0) {
312 timestamp
= null; // use request index
315 TmfExperimentContext context
= null;
316 if (timestamp
!= null) {
318 context
= seekEvent(timestamp
);
319 ((ITmfEventRequest
<T
>) request
).setStartIndex((int) context
.getRank());
322 if ((fExperimentContext
!= null) && fExperimentContext
.getRank() == request
.getIndex()) {
323 // We are already at the right context -> no need to seek
324 context
= fExperimentContext
;
326 context
= seekEvent(request
.getIndex());
329 // Tracer.trace("Ctx: Arming request - done");
333 @SuppressWarnings("unchecked")
335 public T
getNext(ITmfContext context
) {
336 if (context
instanceof TmfExperimentContext
) {
337 return (T
) getNextEvent((TmfExperimentContext
) context
);
342 // ------------------------------------------------------------------------
343 // ITmfTrace trace positioning
344 // ------------------------------------------------------------------------
346 // Returns a brand new context based on the location provided
347 // and initializes the event queues
349 public synchronized TmfExperimentContext
seekLocation(ITmfLocation
<?
> location
) {
350 // Validate the location
351 if (location
!= null && !(location
instanceof TmfExperimentLocation
)) {
352 return null; // Throw an exception?
355 if (fTraces
== null) { // experiment has been disposed
359 // Instantiate the location
360 TmfExperimentLocation expLocation
= (location
== null) ?
new TmfExperimentLocation(new TmfLocationArray(
361 new ITmfLocation
<?
>[fTraces
.length
]), new long[fTraces
.length
]) : (TmfExperimentLocation
) location
.clone();
363 // Create and populate the context's traces contexts
364 TmfExperimentContext context
= new TmfExperimentContext(fTraces
, new TmfContext
[fTraces
.length
]);
365 // Tracer.trace("Ctx: SeekLocation - start");
368 for (int i
= 0; i
< fTraces
.length
; i
++) {
369 // Get the relevant trace attributes
370 ITmfLocation
<?
> traceLocation
= expLocation
.getLocation().locations
[i
];
371 long traceRank
= expLocation
.getRanks()[i
];
373 // Set the corresponding sub-context
374 context
.getContexts()[i
] = fTraces
[i
].seekLocation(traceLocation
);
375 context
.getContexts()[i
].setRank(traceRank
);
378 // Set the trace location and read the corresponding event
379 expLocation
.getLocation().locations
[i
] = context
.getContexts()[i
].getLocation();
380 context
.getEvents()[i
] = fTraces
[i
].getNextEvent(context
.getContexts()[i
]);
383 // Tracer.trace("Ctx: SeekLocation - done");
386 context
.setLocation(expLocation
);
387 context
.setLastTrace(TmfExperimentContext
.NO_TRACE
);
388 context
.setRank(rank
);
390 fExperimentContext
= context
;
398 * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#seekEvent(org.eclipse.linuxtools .tmf.event.TmfTimestamp)
401 public synchronized TmfExperimentContext
seekEvent(TmfTimestamp timestamp
) {
403 // Tracer.trace("Ctx: seekEvent(TS) - start");
405 if (timestamp
== null) {
406 timestamp
= TmfTimestamp
.BigBang
;
409 // First, find the right checkpoint
410 int index
= Collections
.binarySearch(fCheckpoints
, new TmfCheckpoint(timestamp
, null));
412 // In the very likely case that the checkpoint was not found, bsearch
413 // returns its negated would-be location (not an offset...). From that
414 // index, we can then position the stream and get the event.
416 index
= Math
.max(0, -(index
+ 2));
419 // Position the experiment at the checkpoint
420 ITmfLocation
<?
> location
;
421 synchronized (fCheckpoints
) {
422 if (fCheckpoints
.size() > 0) {
423 if (index
>= fCheckpoints
.size()) {
424 index
= fCheckpoints
.size() - 1;
426 location
= fCheckpoints
.elementAt(index
).getLocation();
432 TmfExperimentContext context
= seekLocation(location
);
433 context
.setRank((long) index
* fIndexPageSize
);
435 // And locate the event
436 TmfEvent event
= parseEvent(context
);
437 while (event
!= null && event
.getTimestamp().compareTo(timestamp
, false) < 0) {
438 getNextEvent(context
);
439 event
= parseEvent(context
);
443 context
.setLocation(null);
444 context
.setRank(ITmfContext
.UNKNOWN_RANK
);
453 * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#seekEvent(long)
456 public synchronized TmfExperimentContext
seekEvent(long rank
) {
458 // Tracer.trace("Ctx: seekEvent(rank) - start");
460 // Position the stream at the previous checkpoint
461 int index
= (int) rank
/ fIndexPageSize
;
462 ITmfLocation
<?
> location
;
463 synchronized (fCheckpoints
) {
464 if (fCheckpoints
.size() == 0) {
467 if (index
>= fCheckpoints
.size()) {
468 index
= fCheckpoints
.size() - 1;
470 location
= fCheckpoints
.elementAt(index
).getLocation();
474 TmfExperimentContext context
= seekLocation(location
);
475 context
.setRank((long) index
* fIndexPageSize
);
477 // And locate the event
478 TmfEvent event
= parseEvent(context
);
479 long pos
= context
.getRank();
480 while (event
!= null && pos
++ < rank
) {
481 getNextEvent(context
);
482 event
= parseEvent(context
);
486 context
.setLocation(null);
487 context
.setRank(ITmfContext
.UNKNOWN_RANK
);
494 public TmfContext
seekLocation(double ratio
) {
495 TmfContext context
= seekEvent((long) (ratio
* getNbEvents()));
500 public double getLocationRatio(ITmfLocation
<?
> location
) {
501 if (location
instanceof TmfExperimentLocation
) {
502 return (double) seekLocation(location
).getRank() / getNbEvents();
508 public ITmfLocation
<?
> getCurrentLocation() {
509 if (fExperimentContext
!= null) {
510 return fExperimentContext
.getLocation();
516 * Scan the next events from all traces and return the next one in chronological order.
522 // private void dumpContext(TmfExperimentContext context, boolean isBefore) {
524 // TmfContext context0 = context.getContexts()[0];
525 // TmfEvent event0 = context.getEvents()[0];
526 // TmfExperimentLocation location0 = (TmfExperimentLocation) context.getLocation();
527 // long rank0 = context.getRank();
528 // int trace = context.getLastTrace();
530 // StringBuffer result = new StringBuffer("Ctx: " + (isBefore ? "B " : "A "));
532 // result.append("[Ctx: fLoc= " + context0.getLocation().toString() + ", fRnk= " + context0.getRank() + "] ");
533 // result.append("[Evt: " + event0.getTimestamp().toString() + "] ");
534 // result.append("[Loc: fLoc= " + location0.getLocation()[0].toString() + ", fRnk= " + location0.getRanks()[0] + "] ");
535 // result.append("[Rnk: " + rank0 + "], [Trc: " + trace + "]");
536 // Tracer.trace(result.toString());
540 public synchronized TmfEvent
getNextEvent(TmfContext context
) {
542 // Validate the context
543 if (!(context
instanceof TmfExperimentContext
)) {
544 return null; // Throw an exception?
547 if (!context
.equals(fExperimentContext
)) {
548 // Tracer.trace("Ctx: Restoring context");
549 fExperimentContext
= seekLocation(context
.getLocation());
552 TmfExperimentContext expContext
= (TmfExperimentContext
) context
;
554 // dumpContext(expContext, true);
556 // If an event was consumed previously, get the next one from that trace
557 int lastTrace
= expContext
.getLastTrace();
558 if (lastTrace
!= TmfExperimentContext
.NO_TRACE
) {
559 TmfContext traceContext
= expContext
.getContexts()[lastTrace
];
560 expContext
.getEvents()[lastTrace
] = expContext
.getTraces()[lastTrace
].getNextEvent(traceContext
);
561 expContext
.setLastTrace(TmfExperimentContext
.NO_TRACE
);
564 // Scan the candidate events and identify the "next" trace to read from
565 TmfEvent eventArray
[] = expContext
.getEvents();
566 if (eventArray
== null) {
569 int trace
= TmfExperimentContext
.NO_TRACE
;
570 TmfTimestamp timestamp
= TmfTimestamp
.BigCrunch
;
571 if (eventArray
.length
== 1) {
572 if (eventArray
[0] != null) {
573 timestamp
= eventArray
[0].getTimestamp();
577 for (int i
= 0; i
< eventArray
.length
; i
++) {
578 TmfEvent event
= eventArray
[i
];
579 if (event
!= null && event
.getTimestamp() != null) {
580 TmfTimestamp otherTS
= event
.getTimestamp();
581 if (otherTS
.compareTo(timestamp
, true) < 0) {
588 // Update the experiment context and set the "next" event
589 TmfEvent event
= null;
590 if (trace
!= TmfExperimentContext
.NO_TRACE
) {
591 updateIndex(expContext
, timestamp
);
593 TmfContext traceContext
= expContext
.getContexts()[trace
];
594 TmfExperimentLocation expLocation
= (TmfExperimentLocation
) expContext
.getLocation();
595 // expLocation.getLocation()[trace] = traceContext.getLocation().clone();
596 expLocation
.getLocation().locations
[trace
] = traceContext
.getLocation();
598 // updateIndex(expContext, timestamp);
600 expLocation
.getRanks()[trace
] = traceContext
.getRank();
601 expContext
.setLastTrace(trace
);
602 expContext
.updateRank(1);
603 event
= expContext
.getEvents()[trace
];
604 fExperimentContext
= expContext
;
607 // if (event != null) {
608 // Tracer.trace("Exp: " + (expContext.getRank() - 1) + ": " + event.getTimestamp().toString());
609 // dumpContext(expContext, false);
610 // Tracer.trace("Ctx: Event returned= " + event.getTimestamp().toString());
616 public synchronized void updateIndex(ITmfContext context
, TmfTimestamp timestamp
) {
617 // Build the index as we go along
618 long rank
= context
.getRank();
619 if (context
.isValidRank() && (rank
% fIndexPageSize
) == 0) {
620 // Determine the table position
621 long position
= rank
/ fIndexPageSize
;
622 // Add new entry at proper location (if empty)
623 if (fCheckpoints
.size() == position
) {
624 ITmfLocation
<?
> location
= context
.getLocation().clone();
625 fCheckpoints
.add(new TmfCheckpoint(timestamp
.clone(), location
));
626 // System.out.println(this + "[" + (fCheckpoints.size() - 1) + "] " + timestamp + ", "
627 // + location.toString());
635 * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#parseEvent(org.eclipse.linuxtools .tmf.trace.TmfContext)
638 public TmfEvent
parseEvent(TmfContext context
) {
640 // Validate the context
641 if (!(context
instanceof TmfExperimentContext
)) {
642 return null; // Throw an exception?
645 if (!context
.equals(fExperimentContext
)) {
646 // Tracer.trace("Ctx: Restoring context");
647 seekLocation(context
.getLocation());
650 TmfExperimentContext expContext
= (TmfExperimentContext
) context
;
652 // If an event was consumed previously, get the next one from that trace
653 int lastTrace
= expContext
.getLastTrace();
654 if (lastTrace
!= TmfExperimentContext
.NO_TRACE
) {
655 TmfContext traceContext
= expContext
.getContexts()[lastTrace
];
656 expContext
.getEvents()[lastTrace
] = expContext
.getTraces()[lastTrace
].getNextEvent(traceContext
);
657 expContext
.setLastTrace(TmfExperimentContext
.NO_TRACE
);
658 fExperimentContext
= (TmfExperimentContext
) context
;
661 // Scan the candidate events and identify the "next" trace to read from
662 int trace
= TmfExperimentContext
.NO_TRACE
;
663 TmfTimestamp timestamp
= TmfTimestamp
.BigCrunch
;
664 for (int i
= 0; i
< expContext
.getTraces().length
; i
++) {
665 TmfEvent event
= expContext
.getEvents()[i
];
666 if (event
!= null && event
.getTimestamp() != null) {
667 TmfTimestamp otherTS
= event
.getTimestamp();
668 if (otherTS
.compareTo(timestamp
, true) < 0) {
675 TmfEvent event
= null;
676 if (trace
!= TmfExperimentContext
.NO_TRACE
) {
677 event
= expContext
.getEvents()[trace
];
686 * @see java.lang.Object#toString()
689 @SuppressWarnings("nls")
690 public String
toString() {
691 return "[TmfExperiment (" + getName() + ")]";
694 // ------------------------------------------------------------------------
696 // ------------------------------------------------------------------------
699 * The experiment holds the globally ordered events of its set of traces. It is expected to provide access to each
700 * individual event by index i.e. it must be possible to request the Nth event of the experiment.
702 * The purpose of the index is to keep the information needed to rapidly restore the traces contexts at regular
703 * intervals (every INDEX_PAGE_SIZE event).
706 // The index page size
707 private static final int DEFAULT_INDEX_PAGE_SIZE
= 5000;
708 protected int fIndexPageSize
;
709 protected boolean fIndexing
= false;
710 protected TmfTimeRange fIndexingPendingRange
= TmfTimeRange
.Null
;
712 // private static BufferedWriter fEventLog = null;
713 // private static BufferedWriter openLogFile(String filename) {
714 // BufferedWriter outfile = null;
716 // outfile = new BufferedWriter(new FileWriter(filename));
717 // } catch (IOException e) {
718 // e.printStackTrace();
723 protected boolean isIndexingBusy() {
724 synchronized (fCheckpoints
) {
729 protected void indexExperiment(boolean waitForCompletion
) {
730 indexExperiment(waitForCompletion
, 0, TmfTimeRange
.Eternity
);
733 @SuppressWarnings("unchecked")
734 protected void indexExperiment(boolean waitForCompletion
, final int index
, final TmfTimeRange timeRange
) {
736 synchronized (fCheckpoints
) {
743 final Job job
= new Job("Indexing " + getName() + "...") { //$NON-NLS-1$ //$NON-NLS-2$
745 protected IStatus
run(IProgressMonitor monitor
) {
746 while (!monitor
.isCanceled()) {
749 } catch (InterruptedException e
) {
750 return Status
.OK_STATUS
;
754 return Status
.OK_STATUS
;
759 // fEventLog = openLogFile("TraceEvent.log");
760 // System.out.println(System.currentTimeMillis() + ": Experiment indexing started");
762 ITmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, timeRange
, index
, TmfDataRequest
.ALL_DATA
,
763 fIndexPageSize
, ITmfDataRequest
.ExecutionType
.BACKGROUND
) { // PATA FOREGROUND
765 // long indexingStart = System.nanoTime();
767 TmfTimestamp startTime
= (fTimeRange
== TmfTimeRange
.Null
) ?
null : fTimeRange
.getStartTime();
768 TmfTimestamp lastTime
= (fTimeRange
== TmfTimeRange
.Null
) ?
null : fTimeRange
.getEndTime();
769 long initialNbEvents
= fNbEvents
;
772 public void handleStarted() {
773 super.handleStarted();
777 public void handleData(TmfEvent event
) {
778 super.handleData(event
);
780 TmfTimestamp ts
= event
.getTimestamp();
781 if (startTime
== null)
782 startTime
= new TmfTimestamp(ts
);
783 lastTime
= new TmfTimestamp(ts
);
784 if ((getNbRead() % fIndexPageSize
) == 1 && getNbRead() != 1) {
791 public void handleSuccess() {
792 // long indexingEnd = System.nanoTime();
794 if (getRange() != TmfTimeRange
.Eternity
) {
795 lastTime
= getRange().getEndTime();
798 // System.out.println(System.currentTimeMillis() + ": Experiment indexing completed");
800 // long average = (indexingEnd - indexingStart) / fNbEvents;
801 // System.out.println(getName() + ": start=" + startTime + ", end=" + lastTime + ", elapsed="
802 // + (indexingEnd * 1.0 - indexingStart) / 1000000000);
803 // System.out.println(getName() + ": nbEvents=" + fNbEvents + " (" + (average / 1000) + "."
804 // + (average % 1000) + " us/evt)");
805 super.handleSuccess();
809 public void handleCompleted() {
811 super.handleCompleted();
812 synchronized (fCheckpoints
) {
814 if (fIndexingPendingRange
!= TmfTimeRange
.Null
) {
815 indexExperiment(false, (int) fNbEvents
, fIndexingPendingRange
);
816 fIndexingPendingRange
= TmfTimeRange
.Null
;
821 private void updateExperiment() {
822 int nbRead
= getNbRead();
823 if (startTime
!= null) {
824 fTimeRange
= new TmfTimeRange(startTime
, new TmfTimestamp(lastTime
));
827 // updateTimeRange();
829 fNbEvents
= initialNbEvents
+ nbRead
;
835 sendRequest((ITmfDataRequest
<T
>) request
);
836 if (waitForCompletion
)
838 request
.waitForCompletion();
839 } catch (InterruptedException e
) {
844 protected void notifyListeners() {
845 broadcast(new TmfExperimentUpdatedSignal(this, this)); // , null));
846 broadcast(new TmfExperimentRangeUpdatedSignal(this, this, fTimeRange
)); // , null));
849 // ------------------------------------------------------------------------
851 // ------------------------------------------------------------------------
854 public void experimentSelected(TmfExperimentSelectedSignal
<T
> signal
) {
855 TmfExperiment
<?
> experiment
= signal
.getExperiment();
856 if (experiment
== this) {
857 setCurrentExperiment(experiment
);
858 indexExperiment(false);
863 public void experimentUpdated(TmfExperimentUpdatedSignal signal
) {
867 public void traceUpdated(TmfTraceUpdatedSignal signal
) {
868 for (ITmfTrace
<T
> trace
: fTraces
) {
869 if (trace
== signal
.getTrace()) {
870 synchronized (fCheckpoints
) {
872 if (fIndexingPendingRange
== TmfTimeRange
.Null
) {
873 fIndexingPendingRange
= signal
.getRange();
875 TmfTimestamp startTime
= fIndexingPendingRange
.getStartTime();
876 TmfTimestamp endTime
= fIndexingPendingRange
.getEndTime();
877 if (signal
.getRange().getStartTime().compareTo(startTime
) < 0) {
878 startTime
= signal
.getRange().getStartTime();
880 if (signal
.getRange().getEndTime().compareTo(endTime
) > 0) {
881 endTime
= signal
.getRange().getEndTime();
883 fIndexingPendingRange
= new TmfTimeRange(startTime
, endTime
);
888 indexExperiment(false, (int) fNbEvents
, signal
.getRange());
895 public String
getPath() {
896 // TODO Auto-generated method stub