1 /*******************************************************************************
2 * Copyright (c) 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
.lttng
.trace
;
15 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEvent
;
16 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimestamp
;
17 import org
.eclipse
.linuxtools
.tmf
.experiment
.TmfExperiment
;
18 import org
.eclipse
.linuxtools
.tmf
.experiment
.TmfExperimentContext
;
19 import org
.eclipse
.linuxtools
.tmf
.experiment
.TmfExperimentLocation
;
20 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfSignalManager
;
21 import org
.eclipse
.linuxtools
.tmf
.trace
.ITmfTrace
;
22 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfContext
;
25 * <b><u>LTTngExperiment</u></b>
27 * Temporary class to resolve a basic incompatibility between TMF and LTTng.
30 public class LTTngExperiment
<T
extends TmfEvent
> extends TmfExperiment
<T
> implements ITmfTrace
{
32 private static final int DEFAULT_INDEX_PAGE_SIZE
= 50000;
34 // ------------------------------------------------------------------------
36 // ------------------------------------------------------------------------
43 * @param indexPageSize
45 public LTTngExperiment(Class
<T
> type
, String id
, ITmfTrace
[] traces
, TmfTimestamp epoch
, int indexPageSize
) {
46 this(type
, id
, traces
, TmfTimestamp
.Zero
, indexPageSize
, false);
49 public LTTngExperiment(Class
<T
> type
, String id
, ITmfTrace
[] traces
, TmfTimestamp epoch
, int indexPageSize
, boolean preIndexExperiment
) {
50 super(type
, id
, traces
, epoch
, indexPageSize
, preIndexExperiment
);
58 public LTTngExperiment(Class
<T
> type
, String id
, ITmfTrace
[] traces
) {
59 this(type
, id
, traces
, TmfTimestamp
.Zero
, DEFAULT_INDEX_PAGE_SIZE
);
66 * @param indexPageSize
68 public LTTngExperiment(Class
<T
> type
, String id
, ITmfTrace
[] traces
, int indexPageSize
) {
69 this(type
, id
, traces
, TmfTimestamp
.Zero
, indexPageSize
);
72 public LTTngExperiment(LTTngExperiment
<T
> other
) {
73 super(other
.getName() + "(clone)", other
.fType
); //$NON-NLS-1$
75 fEpoch
= other
.fEpoch
;
76 fIndexPageSize
= other
.fIndexPageSize
;
78 fTraces
= new ITmfTrace
[other
.fTraces
.length
];
79 for (int trace
= 0; trace
< other
.fTraces
.length
; trace
++) {
80 fTraces
[trace
] = other
.fTraces
[trace
].createTraceCopy();
83 fNbEvents
= other
.fNbEvents
;
84 fTimeRange
= other
.fTimeRange
;
88 public LTTngExperiment
<T
> createTraceCopy() {
89 LTTngExperiment
<T
> experiment
= new LTTngExperiment
<T
>(this);
90 TmfSignalManager
.deregister(experiment
);
94 // ------------------------------------------------------------------------
95 // ITmfTrace trace positioning
96 // ------------------------------------------------------------------------
99 public synchronized TmfEvent
getNextEvent(TmfContext context
) {
101 // Validate the context
102 if (!(context
instanceof TmfExperimentContext
)) {
103 return null; // Throw an exception?
106 if (!context
.equals(fExperimentContext
)) {
107 // Tracer.trace("Ctx: Restoring context");
108 seekLocation(context
.getLocation());
111 TmfExperimentContext expContext
= (TmfExperimentContext
) context
;
113 // dumpContext(expContext, true);
115 // If an event was consumed previously, get the next one from that trace
116 int lastTrace
= expContext
.getLastTrace();
117 if (lastTrace
!= TmfExperimentContext
.NO_TRACE
) {
118 TmfContext traceContext
= expContext
.getContexts()[lastTrace
];
119 expContext
.getEvents()[lastTrace
] = expContext
.getTraces()[lastTrace
].getNextEvent(traceContext
);
120 expContext
.setLastTrace(TmfExperimentContext
.NO_TRACE
);
123 // Scan the candidate events and identify the "next" trace to read from
124 TmfEvent eventArray
[] = expContext
.getEvents();
125 if (eventArray
== null) {
128 int trace
= TmfExperimentContext
.NO_TRACE
;
129 TmfTimestamp timestamp
= TmfTimestamp
.BigCrunch
;
130 if (eventArray
.length
== 1) {
131 if (eventArray
[0] != null) {
132 timestamp
= eventArray
[0].getTimestamp();
136 for (int i
= 0; i
< eventArray
.length
; i
++) {
137 TmfEvent event
= eventArray
[i
];
138 if (event
!= null && event
.getTimestamp() != null) {
139 TmfTimestamp otherTS
= event
.getTimestamp();
140 if (otherTS
.compareTo(timestamp
, true) < 0) {
148 // Update the experiment context and set the "next" event
149 TmfEvent event
= null;
150 if (trace
!= TmfExperimentContext
.NO_TRACE
) {
151 // updateIndex(expContext, timestamp);
153 TmfContext traceContext
= expContext
.getContexts()[trace
];
154 TmfExperimentLocation expLocation
= (TmfExperimentLocation
) expContext
.getLocation();
155 expLocation
.getLocation()[trace
] = traceContext
.getLocation();
157 updateIndex(expContext
, timestamp
);
159 expLocation
.getRanks()[trace
] = traceContext
.getRank();
160 expContext
.setLastTrace(trace
);
161 expContext
.updateRank(1);
162 event
= expContext
.getEvents()[trace
];
165 // if (event != null) {
166 // Tracer.trace("Exp: " + (expContext.getRank() - 1) + ": " + event.getTimestamp().toString());
167 // dumpContext(expContext, false);
168 // Tracer.trace("Ctx: Event returned= " + event.getTimestamp().toString());
175 * @see java.lang.Object#toString()
178 @SuppressWarnings("nls")
179 public String
toString() {
180 return "[LTTngExperiment (" + getName() + ")]";