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
.experiment
;
15 import java
.util
.Collections
;
16 import java
.util
.Vector
;
18 import org
.eclipse
.linuxtools
.tmf
.component
.TmfEventProvider
;
19 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEvent
;
20 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimeRange
;
21 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimestamp
;
22 import org
.eclipse
.linuxtools
.tmf
.request
.ITmfDataRequest
;
23 import org
.eclipse
.linuxtools
.tmf
.request
.ITmfDataRequest
.ExecutionType
;
24 import org
.eclipse
.linuxtools
.tmf
.request
.ITmfEventRequest
;
25 import org
.eclipse
.linuxtools
.tmf
.request
.TmfDataRequest
;
26 import org
.eclipse
.linuxtools
.tmf
.request
.TmfEventRequest
;
27 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfExperimentSelectedSignal
;
28 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfExperimentUpdatedSignal
;
29 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfSignalHandler
;
30 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfSignalManager
;
31 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfTraceUpdatedSignal
;
32 import org
.eclipse
.linuxtools
.tmf
.trace
.ITmfContext
;
33 import org
.eclipse
.linuxtools
.tmf
.trace
.ITmfLocation
;
34 import org
.eclipse
.linuxtools
.tmf
.trace
.ITmfTrace
;
35 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfCheckpoint
;
36 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfContext
;
39 * <b><u>TmfExperiment</u></b>
41 * TmfExperiment presents a time-ordered, unified view of a set of TmfTraces
42 * that are part of a tracing experiment.
45 public class TmfExperiment
<T
extends TmfEvent
> extends TmfEventProvider
<T
> implements ITmfTrace
{
47 // ------------------------------------------------------------------------
49 // ------------------------------------------------------------------------
51 // The currently selected experiment
52 private static TmfExperiment
<?
> fCurrentExperiment
= null;
54 // The set of traces that constitute the experiment
55 private ITmfTrace
[] fTraces
;
57 // The total number of events
58 private long fNbEvents
;
60 // The experiment time range
61 private TmfTimeRange fTimeRange
;
63 // The experiment reference timestamp (default: Zero)
64 private TmfTimestamp fEpoch
;
66 // The experiment index
67 private Vector
<TmfCheckpoint
> fCheckpoints
= new Vector
<TmfCheckpoint
>();
69 private TmfExperimentContext fSavedContext
;
71 // ------------------------------------------------------------------------
73 // ------------------------------------------------------------------------
80 * @param indexPageSize
82 public TmfExperiment(Class
<T
> type
, String id
, ITmfTrace
[] traces
, TmfTimestamp epoch
, int indexPageSize
) {
83 this(type
, id
, traces
, TmfTimestamp
.Zero
, DEFAULT_INDEX_PAGE_SIZE
, false);
86 public TmfExperiment(Class
<T
> type
, String id
, ITmfTrace
[] traces
, TmfTimestamp epoch
, int indexPageSize
, boolean preIndexExperiment
) {
91 fIndexPageSize
= indexPageSize
;
93 if (preIndexExperiment
) indexExperiment(true);
103 public TmfExperiment(Class
<T
> type
, String id
, ITmfTrace
[] traces
) {
104 this(type
, id
, traces
, TmfTimestamp
.Zero
, DEFAULT_INDEX_PAGE_SIZE
);
111 * @param indexPageSize
113 public TmfExperiment(Class
<T
> type
, String id
, ITmfTrace
[] traces
, int indexPageSize
) {
114 this(type
, id
, traces
, TmfTimestamp
.Zero
, indexPageSize
);
117 public TmfExperiment(TmfExperiment
<T
> other
) {
118 super(other
.getName() + "(clone)", other
.fType
);
120 fEpoch
= other
.fEpoch
;
121 fIndexPageSize
= other
.fIndexPageSize
;
123 fTraces
= new ITmfTrace
[other
.fTraces
.length
];
124 for (int trace
= 0; trace
< other
.fTraces
.length
; trace
++) {
125 fTraces
[trace
] = other
.fTraces
[trace
].createTraceCopy();
128 fNbEvents
= other
.fNbEvents
;
129 fTimeRange
= other
.fTimeRange
;
132 public TmfExperiment
<T
> createTraceCopy() {
133 TmfExperiment
<T
> experiment
= new TmfExperiment
<T
>(this);
134 TmfSignalManager
.deregister(experiment
);
139 * Clears the experiment
142 public void dispose() {
143 if (fTraces
!= null) {
144 for (ITmfTrace trace
: fTraces
) {
149 if (fCheckpoints
!= null) {
150 fCheckpoints
.clear();
155 private static void setCurrentExperiment(TmfExperiment
<?
> experiment
) {
156 fCurrentExperiment
= experiment
;
159 // ------------------------------------------------------------------------
161 // ------------------------------------------------------------------------
163 public String
getPath() {
167 public long getNbEvents() {
171 public int getCacheSize() {
172 return fIndexPageSize
;
175 public TmfTimeRange
getTimeRange() {
179 public TmfTimestamp
getStartTime() {
180 return fTimeRange
.getStartTime();
183 public TmfTimestamp
getEndTime() {
184 return fTimeRange
.getEndTime();
187 public Vector
<TmfCheckpoint
> getCheckpoints() {
191 // ------------------------------------------------------------------------
193 // ------------------------------------------------------------------------
195 public static TmfExperiment
<?
> getCurrentExperiment() {
196 return fCurrentExperiment
;
199 public TmfTimestamp
getEpoch() {
203 public ITmfTrace
[] getTraces() {
208 * Returns the rank of the first event with the requested timestamp.
209 * If none, returns the index of the next event (if any).
214 public long getRank(TmfTimestamp timestamp
) {
215 TmfExperimentContext context
= seekEvent(timestamp
);
216 return context
.getRank();
220 * Returns the timestamp of the event at the requested index.
221 * If none, returns null.
226 public TmfTimestamp
getTimestamp(int index
) {
227 TmfExperimentContext context
= seekEvent(index
);
228 TmfEvent event
= getNextEvent(context
);
229 return (event
!= null) ? event
.getTimestamp() : null;
232 // ------------------------------------------------------------------------
234 // ------------------------------------------------------------------------
237 * Update the total number of events
239 private void updateNbEvents() {
241 for (ITmfTrace trace
: fTraces
) {
242 nbEvents
+= trace
.getNbEvents();
244 fNbEvents
= nbEvents
;
248 * Update the global time range
250 private void updateTimeRange() {
251 TmfTimestamp startTime
= fTimeRange
!= null ? fTimeRange
.getStartTime() : TmfTimestamp
.BigCrunch
;
252 TmfTimestamp endTime
= fTimeRange
!= null ? fTimeRange
.getEndTime() : TmfTimestamp
.BigBang
;
254 for (ITmfTrace trace
: fTraces
) {
255 TmfTimestamp traceStartTime
= trace
.getStartTime();
256 if (traceStartTime
.compareTo(startTime
, true) < 0)
257 startTime
= traceStartTime
;
258 TmfTimestamp traceEndTime
= trace
.getEndTime();
259 if (traceEndTime
.compareTo(endTime
, true) > 0)
260 endTime
= traceEndTime
;
262 fTimeRange
= new TmfTimeRange(startTime
, endTime
);
265 // ------------------------------------------------------------------------
267 // ------------------------------------------------------------------------
270 public ITmfContext
armRequest(ITmfDataRequest
<T
> request
) {
271 // Tracer.trace("Ctx: Arming request - start");
272 TmfTimestamp timestamp
= (request
instanceof ITmfEventRequest
<?
>) ?
273 ((ITmfEventRequest
<T
>) request
).getRange().getStartTime() : null;
274 TmfExperimentContext context
= (timestamp
!= null) ?
275 seekEvent(timestamp
) : seekEvent(request
.getIndex());
276 // Tracer.trace("Ctx: Arming request - done");
280 @SuppressWarnings("unchecked")
282 public T
getNext(ITmfContext context
) {
283 if (context
instanceof TmfExperimentContext
) {
284 return (T
) getNextEvent((TmfExperimentContext
) context
);
289 // ------------------------------------------------------------------------
290 // ITmfTrace trace positioning
291 // ------------------------------------------------------------------------
293 // Returns a brand new context based on the location provided
294 // and initializes the event queues
295 public synchronized TmfExperimentContext
seekLocation(ITmfLocation
<?
> location
) {
297 // Validate the location
298 if (location
!= null && !(location
instanceof TmfExperimentLocation
)) {
299 return null; // Throw an exception?
302 // Instantiate the location
303 TmfExperimentLocation expLocation
= (location
== null)
304 ?
new TmfExperimentLocation(new ITmfLocation
<?
>[fTraces
.length
], new long[fTraces
.length
])
305 : (TmfExperimentLocation
) location
.clone();
307 // Create and populate the context's traces contexts
308 TmfExperimentContext context
= new TmfExperimentContext(fTraces
, new TmfContext
[fTraces
.length
]);
309 // Tracer.trace("Ctx: SeekLocation - start");
312 for (int i
= 0; i
< fTraces
.length
; i
++) {
313 // Get the relevant trace attributes
314 ITmfLocation
<?
> traceLocation
= expLocation
.getLocation()[i
];
315 long traceRank
= expLocation
.getRanks()[i
];
317 // Set the corresponding sub-context
318 context
.getContexts()[i
] = fTraces
[i
].seekLocation(traceLocation
);
319 context
.getContexts()[i
].setRank(traceRank
);
322 // Set the trace location and read the corresponding event
323 expLocation
.getLocation()[i
] = context
.getContexts()[i
].getLocation();
324 context
.getEvents()[i
] = fTraces
[i
].parseEvent(context
.getContexts()[i
]);
327 // Tracer.trace("Ctx: SeekLocation - done");
330 context
.setLocation(expLocation
);
331 context
.setLastTrace(TmfExperimentContext
.NO_TRACE
);
332 context
.setRank(rank
);
334 fSavedContext
= new TmfExperimentContext(context
);
340 * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#seekEvent(org.eclipse.linuxtools.tmf.event.TmfTimestamp)
342 public synchronized TmfExperimentContext
seekEvent(TmfTimestamp timestamp
) {
344 // Tracer.trace("Ctx: seekEvent(TS) - start");
346 if (timestamp
== null) {
347 timestamp
= TmfTimestamp
.BigBang
;
350 // First, find the right checkpoint
351 int index
= Collections
.binarySearch(fCheckpoints
, new TmfCheckpoint(timestamp
, null));
353 // In the very likely case that the checkpoint was not found, bsearch
354 // returns its negated would-be location (not an offset...). From that
355 // index, we can then position the stream and get the event.
357 index
= Math
.max(0, -(index
+ 2));
360 // Position the experiment at the checkpoint
361 ITmfLocation
<?
> location
;
362 synchronized (fCheckpoints
) {
363 if (fCheckpoints
.size() > 0) {
364 if (index
>= fCheckpoints
.size()) {
365 index
= fCheckpoints
.size() - 1;
367 location
= fCheckpoints
.elementAt(index
).getLocation();
374 TmfExperimentContext context
= seekLocation(location
);
375 context
.setRank((long) index
* fIndexPageSize
);
377 // And locate the event
378 TmfExperimentContext nextEventContext
= new TmfExperimentContext(context
);
379 TmfEvent event
= parseEvent(nextEventContext
);
380 while (event
!= null && event
.getTimestamp().compareTo(timestamp
, false) < 0) {
381 context
= new TmfExperimentContext(nextEventContext
);
382 event
= getNextEvent(nextEventContext
);
386 if (nextEventContext
.getLastTrace() != TmfExperimentContext
.NO_TRACE
) {
387 nextEventContext
.setLastTrace(TmfExperimentContext
.NO_TRACE
);
388 nextEventContext
.updateRank(-1);
390 fSavedContext
= new TmfExperimentContext(nextEventContext
);
393 nextEventContext
.setLocation(null);
394 nextEventContext
.setRank(ITmfContext
.UNKNOWN_RANK
);
396 return nextEventContext
;
400 * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#seekEvent(long)
402 public synchronized TmfExperimentContext
seekEvent(long rank
) {
404 // Tracer.trace("Ctx: seekEvent(rank) - start");
406 // Position the stream at the previous checkpoint
407 int index
= (int) rank
/ fIndexPageSize
;
408 ITmfLocation
<?
> location
;
409 synchronized (fCheckpoints
) {
410 if (fCheckpoints
.size() == 0) {
414 if (index
>= fCheckpoints
.size()) {
415 index
= fCheckpoints
.size() - 1;
417 location
= fCheckpoints
.elementAt(index
).getLocation();
421 TmfExperimentContext context
= seekLocation(location
);
422 context
.setRank((long) index
* fIndexPageSize
);
424 // And locate the event
425 TmfExperimentContext nextEventContext
= new TmfExperimentContext(context
);
426 TmfEvent event
= parseEvent(nextEventContext
);
427 long pos
= context
.getRank();
428 while (event
!= null && pos
++ <= rank
) {
429 context
= new TmfExperimentContext(nextEventContext
);
430 event
= getNextEvent(nextEventContext
);
434 if (nextEventContext
.getLastTrace() != TmfExperimentContext
.NO_TRACE
) {
435 nextEventContext
.setLastTrace(TmfExperimentContext
.NO_TRACE
);
436 nextEventContext
.updateRank(-1);
438 fSavedContext
= new TmfExperimentContext(nextEventContext
);
441 nextEventContext
.setLocation(null);
442 nextEventContext
.setRank(ITmfContext
.UNKNOWN_RANK
);
444 return nextEventContext
;
446 // // And locate the event
447 // TmfExperimentContext nextEventContext = new TmfExperimentContext(context);
448 // TmfEvent event = parseEvent(nextEventContext);
449 // long pos = context.getRank();
450 // while (event != null && pos < rank) {
451 // event = getNextEvent(nextEventContext);
452 // context = new TmfExperimentContext(nextEventContext);
456 // if (event != null) {
457 // if (context.getLastTrace() != TmfExperimentContext.NO_TRACE) {
458 // context.setLastTrace(TmfExperimentContext.NO_TRACE);
459 // context.updateRank(-1);
461 // fSavedContext = new TmfExperimentContext(context);
464 // context.setLocation(null);
465 // context.setRank(ITmfContext.UNKNOWN_RANK);
471 * Scan the next events from all traces and return the next one
472 * in chronological order.
478 // private void dumpContext(TmfExperimentContext context, boolean isBefore) {
480 // TmfContext context0 = context.getContexts()[0];
481 // TmfEvent event0 = context.getEvents()[0];
482 // TmfExperimentLocation location0 = (TmfExperimentLocation) context.getLocation();
483 // long rank0 = context.getRank();
484 // int trace = context.getLastTrace();
486 // StringBuffer result = new StringBuffer("Ctx: " + (isBefore ? "B " : "A "));
488 // result.append("[Ctx: fLoc= " + context0.getLocation().toString() + ", fRnk= " + context0.getRank() + "] ");
489 // result.append("[Evt: " + event0.getTimestamp().toString() + "] ");
490 // result.append("[Loc: fLoc= " + location0.getLocation()[0].toString() + ", fRnk= " + location0.getRanks()[0] + "] ");
491 // result.append("[Rnk: " + rank0 + "], [Trc: " + trace + "]");
492 // Tracer.trace(result.toString());
495 public synchronized TmfEvent
getNextEvent(TmfContext context
) {
497 // Validate the context
498 if (!(context
instanceof TmfExperimentContext
)) {
499 return null; // Throw an exception?
502 if (!fSavedContext
.equals(context
)) {
503 // Tracer.trace("Ctx: Restoring context");
504 seekLocation(context
.getLocation());
507 TmfExperimentContext expContext
= (TmfExperimentContext
) context
;
509 // dumpContext(expContext, true);
511 // If an event was consumed previously, get the next one from that trace
512 int lastTrace
= expContext
.getLastTrace();
513 if (lastTrace
!= TmfExperimentContext
.NO_TRACE
) {
514 TmfContext traceContext
= expContext
.getContexts()[lastTrace
];
515 expContext
.getEvents()[lastTrace
] = expContext
.getTraces()[lastTrace
].getNextEvent(traceContext
);
516 expContext
.getEvents()[lastTrace
] = expContext
.getTraces()[lastTrace
].parseEvent(traceContext
);
518 TmfExperimentLocation expLocation
= (TmfExperimentLocation
) expContext
.getLocation();
519 traceContext
= expContext
.getContexts()[lastTrace
];
520 expLocation
.getLocation()[lastTrace
] = traceContext
.getLocation().clone();
521 expLocation
.getRanks()[lastTrace
] = traceContext
.getRank();
524 // Scan the candidate events and identify the "next" trace to read from
525 int trace
= TmfExperimentContext
.NO_TRACE
;
526 TmfTimestamp timestamp
= TmfTimestamp
.BigCrunch
;
527 for (int i
= 0; i
< expContext
.getTraces().length
; i
++) {
528 TmfEvent event
= expContext
.getEvents()[i
];
529 if (event
!= null && event
.getTimestamp() != null) {
530 TmfTimestamp otherTS
= event
.getTimestamp();
531 if (otherTS
.compareTo(timestamp
, true) < 0) {
538 // Update the experiment context and set the "next" event
539 TmfEvent event
= null;
541 updateIndex(expContext
, timestamp
);
542 expContext
.setLastTrace(trace
);
543 expContext
.updateRank(1);
544 event
= expContext
.getEvents()[trace
];
547 // if (event != null) {
548 // Tracer.trace("Exp: " + (expContext.getRank() - 1) + ": " + event.getTimestamp().toString());
549 // dumpContext(expContext, false);
550 // Tracer.trace("Ctx: Event returned= " + event.getTimestamp().toString());
553 fSavedContext
= new TmfExperimentContext(expContext
);
558 public synchronized void updateIndex(ITmfContext context
, TmfTimestamp timestamp
) {
559 // Build the index as we go along
560 long rank
= context
.getRank();
561 if (context
.isValidRank() && (rank
% fIndexPageSize
) == 0) {
562 // Determine the table position
563 long position
= rank
/ fIndexPageSize
;
564 // Add new entry at proper location (if empty)
565 if (fCheckpoints
.size() == position
) {
566 ITmfLocation
<?
> location
= context
.getLocation().clone();
567 fCheckpoints
.add(new TmfCheckpoint(timestamp
, location
));
568 // System.out.println(this + "[" + (fCheckpoints.size() - 1) + "] " + timestamp + ", " + location.toString());
574 * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#parseEvent(org.eclipse.linuxtools.tmf.trace.TmfContext)
576 public TmfEvent
parseEvent(TmfContext context
) {
578 // Validate the context
579 if (!(context
instanceof TmfExperimentContext
)) {
580 return null; // Throw an exception?
583 if (!fSavedContext
.equals(context
)) {
584 // Tracer.trace("Ctx: Restoring context");
585 seekLocation(context
.getLocation());
588 TmfExperimentContext expContext
= (TmfExperimentContext
) context
;
590 // If an event was consumed previously, get the next one from that trace
591 int lastTrace
= expContext
.getLastTrace();
592 if (lastTrace
!= TmfExperimentContext
.NO_TRACE
) {
593 TmfContext traceContext
= expContext
.getContexts()[lastTrace
];
594 expContext
.getEvents()[lastTrace
] = expContext
.getTraces()[lastTrace
].getNextEvent(traceContext
);
595 expContext
.getEvents()[lastTrace
] = expContext
.getTraces()[lastTrace
].parseEvent(traceContext
);
598 // Scan the candidate events and identify the "next" trace to read from
599 int trace
= TmfExperimentContext
.NO_TRACE
;
600 TmfTimestamp timestamp
= TmfTimestamp
.BigCrunch
;
601 for (int i
= 0; i
< expContext
.getTraces().length
; i
++) {
602 TmfEvent event
= expContext
.getEvents()[i
];
603 if (event
!= null && event
.getTimestamp() != null) {
604 TmfTimestamp otherTS
= event
.getTimestamp();
605 if (otherTS
.compareTo(timestamp
, true) < 0) {
612 TmfEvent event
= null;
614 event
= expContext
.getEvents()[trace
];
620 * @see java.lang.Object#toString()
623 public String
toString() {
624 return "[TmfExperiment (" + getName() + ")]";
627 // ------------------------------------------------------------------------
629 // ------------------------------------------------------------------------
632 * The experiment holds the globally ordered events of its set of traces.
633 * It is expected to provide access to each individual event by index i.e.
634 * it must be possible to request the Nth event of the experiment.
636 * The purpose of the index is to keep the information needed to rapidly
637 * restore the traces contexts at regular intervals (every INDEX_PAGE_SIZE
641 // The index page size
642 private static final int DEFAULT_INDEX_PAGE_SIZE
= 5000;
643 private final int fIndexPageSize
;
645 // private static BufferedWriter fEventLog = null;
646 // private static BufferedWriter openLogFile(String filename) {
647 // BufferedWriter outfile = null;
649 // outfile = new BufferedWriter(new FileWriter(filename));
650 // } catch (IOException e) {
651 // e.printStackTrace();
656 @SuppressWarnings("unchecked")
657 private void indexExperiment(boolean waitForCompletion
) {
659 fCheckpoints
.clear();
661 // fEventLog = openLogFile("TraceEvent.log");
663 ITmfEventRequest
<TmfEvent
> request
= new TmfEventRequest
<TmfEvent
>(TmfEvent
.class, TmfTimeRange
.Eternity
, TmfDataRequest
.ALL_DATA
, 1, ITmfDataRequest
.ExecutionType
.LONG
) {
665 // long indexingStart = System.nanoTime();
667 TmfTimestamp startTime
= null;
668 TmfTimestamp lastTime
= null;
671 public void handleData() {
672 TmfEvent
[] events
= getData();
673 if (events
.length
> 0) {
676 // if (fEventLog != null) {
677 // fEventLog.write(events[0].getTimestamp().toString());
678 // fEventLog.newLine();
679 // fEventLog.flush();
681 // } catch (IOException e) {
682 // e.printStackTrace();
685 TmfTimestamp ts
= events
[0].getTimestamp();
686 if (startTime
== null)
687 startTime
= new TmfTimestamp(ts
);
688 lastTime
= new TmfTimestamp(ts
);
690 if ((fNbRead
% DEFAULT_INDEX_PAGE_SIZE
) == 0) {
697 public void handleSuccess() {
700 // fEventLog.close();
702 // } catch (IOException e) {
703 // e.printStackTrace();
706 // long indexingEnd = System.nanoTime();
709 // System.out.println(System.currentTimeMillis() + ": Experiment indexing completed");
711 // long average = (indexingEnd - indexingStart) / fNbEvents;
712 // System.out.println(getName() + ": start=" + startTime + ", end=" + lastTime + ", elapsed=" + (indexingEnd * 1.0 - indexingStart) / 1000000000);
713 // System.out.println(getName() + ": nbEvents=" + fNbEvents + " (" + (average / 1000) + "." + (average % 1000) + " us/evt)");
715 // for (int i = 0; i < fCheckpoints.size(); i++) {
716 // TmfCheckpoint checkpoint = fCheckpoints.get(i);
717 // System.out.println("fCheckpoints[" + i + "] " + checkpoint.getTimestamp() + ", " + checkpoint.getLocation().toString());
721 private void updateExperiment() {
722 fTimeRange
= new TmfTimeRange(startTime
, new TmfTimestamp(lastTime
));
728 sendRequest((ITmfDataRequest
<T
>) request
);
729 if (waitForCompletion
)
731 request
.waitForCompletion();
732 } catch (InterruptedException e
) {
737 protected void notifyListeners() {
738 broadcast(new TmfExperimentUpdatedSignal(this, this)); // , null));
741 // ------------------------------------------------------------------------
743 // ------------------------------------------------------------------------
746 public void experimentSelected(TmfExperimentSelectedSignal
<T
> signal
) {
747 TmfExperiment
<?
> experiment
= signal
.getExperiment();
748 if (experiment
== this) {
749 setCurrentExperiment(experiment
);
750 indexExperiment(false);
758 public void experimentUpdated(TmfExperimentUpdatedSignal signal
) {
762 public void traceUpdated(TmfTraceUpdatedSignal signal
) {
763 // TODO: Incremental index update
768 broadcast(new TmfExperimentUpdatedSignal(this, this)); // , signal.getTrace()));
772 public void queueResult(T data
) throws InterruptedException
{
773 super.queueResult(data
);
776 // ------------------------------------------------------------------------
778 // ------------------------------------------------------------------------
781 protected void queueLongRequest(final ITmfDataRequest
<T
> request
) {
783 // TODO: Handle the data requests also...
784 if (!(request
instanceof ITmfEventRequest
<?
>)) {
785 super.queueRequest(request
);
789 final TmfExperiment
<T
> experiment
= this;
791 Thread thread
= new Thread() {
795 // final long requestStart = System.nanoTime();
797 final Integer
[] CHUNK_SIZE
= new Integer
[1];
798 CHUNK_SIZE
[0] = fIndexPageSize
+ 1;
800 final ITmfEventRequest
<T
> req
= (ITmfEventRequest
<T
>) request
;
802 final Integer
[] nbRead
= new Integer
[1];
805 // final TmfTimestamp[] timestamp = new TmfTimestamp[1];
806 // timestamp[0] = new TmfTimestamp(req.getRange().getStartTime());
807 // final TmfTimestamp endTS = req.getRange().getEndTime();
809 final Boolean
[] isFinished
= new Boolean
[1];
810 isFinished
[0] = Boolean
.FALSE
;
812 while (!isFinished
[0]) {
814 // TmfEventRequest<T> subRequest = new TmfEventRequest<T>(req.getDataType(), new TmfTimeRange(timestamp[0], endTS),
815 // requestedSize, req.getBlockize(), ExecutionType.LONG)
816 TmfDataRequest
<T
> subRequest
= new TmfDataRequest
<T
>(req
.getDataType(), nbRead
[0], CHUNK_SIZE
[0],
817 req
.getBlockize(), ExecutionType
.LONG
)
821 public void handleData() {
822 T
[] data
= getData();
824 // System.out.println("First event of the block: " + data[0].getTimestamp());
827 // Tracer.trace("Ndx: " + ((TmfEvent) data[0]).getTimestamp());
830 if (fNbRead
== CHUNK_SIZE
[0]) {
831 nbRead
[0] += fNbRead
;
832 // System.out.println("fNbRead=" + fNbRead + ", count=" + count +", total=" + nbRead[0] + ", TS=" + data[0].getTimestamp());
834 if (fNbRead
> CHUNK_SIZE
[0]) {
835 System
.out
.println("ERROR - Read too many events");
839 public void handleCompleted() {
840 // System.out.println("Request completed at: " + timestamp[0]);
841 if (fNbRead
< CHUNK_SIZE
[0]) {
843 isFinished
[0] = Boolean
.TRUE
;
844 nbRead
[0] += fNbRead
;
845 // System.out.println("fNbRead=" + fNbRead + ", count=" + count +", total=" + nbRead[0]);
847 super.handleCompleted();
851 if (!isFinished
[0]) {
852 experiment
.queueRequest(subRequest
);
855 subRequest
.waitForCompletion();
856 // System.out.println("Finished at " + timestamp[0]);
857 } catch (InterruptedException e
) {
861 // TmfTimestamp newTS = new TmfTimestamp(timestamp[0].getValue() + 1, timestamp[0].getScale(), timestamp[0].getPrecision());
862 // timestamp[0] = newTS;
863 CHUNK_SIZE
[0] = fIndexPageSize
;
864 // System.out.println("New timestamp: " + timestamp[0]);
867 // final long requestEnded = System.nanoTime();
868 // System.out.println("Background request completed. Elapsed= " + (requestEnded * 1.0 - requestStart) / 1000000000);