2010-09-09 Francois Chouinard <fchouinard@gmail.com> Temporary fix for Bug324876
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng / src / org / eclipse / linuxtools / lttng / trace / LTTngExperiment.java
CommitLineData
82e04272
FC
1/*******************************************************************************
2 * Copyright (c) 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 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
12
13package org.eclipse.linuxtools.lttng.trace;
14
15import org.eclipse.linuxtools.tmf.event.TmfEvent;
16import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
17import org.eclipse.linuxtools.tmf.experiment.TmfExperiment;
18import org.eclipse.linuxtools.tmf.experiment.TmfExperimentContext;
19import org.eclipse.linuxtools.tmf.experiment.TmfExperimentLocation;
20import org.eclipse.linuxtools.tmf.signal.TmfSignalManager;
21import org.eclipse.linuxtools.tmf.trace.ITmfTrace;
22import org.eclipse.linuxtools.tmf.trace.TmfContext;
23
24/**
25 * <b><u>LTTngExperiment</u></b>
26 * <p>
27 * Temporary class to resolve a basic incompatibility between TMF and LTTng.
28 * <p>
29 */
30public class LTTngExperiment<T extends TmfEvent> extends TmfExperiment<T> implements ITmfTrace {
31
32 private static final int DEFAULT_INDEX_PAGE_SIZE = 5000;
33
34 // ------------------------------------------------------------------------
35 // Constructors
36 // ------------------------------------------------------------------------
37
38 /**
39 * @param type
40 * @param id
41 * @param traces
42 * @param epoch
43 * @param indexPageSize
44 */
45 public LTTngExperiment(Class<T> type, String id, ITmfTrace[] traces, TmfTimestamp epoch, int indexPageSize) {
46 this(type, id, traces, TmfTimestamp.Zero, indexPageSize, false);
47 }
48
49 public LTTngExperiment(Class<T> type, String id, ITmfTrace[] traces, TmfTimestamp epoch, int indexPageSize, boolean preIndexExperiment) {
50 super(type, id, traces, epoch, indexPageSize, preIndexExperiment);
51 }
52
53 /**
54 * @param type
55 * @param id
56 * @param traces
57 */
58 public LTTngExperiment(Class<T> type, String id, ITmfTrace[] traces) {
59 this(type, id, traces, TmfTimestamp.Zero, DEFAULT_INDEX_PAGE_SIZE);
60 }
61
62 /**
63 * @param type
64 * @param id
65 * @param traces
66 * @param indexPageSize
67 */
68 public LTTngExperiment(Class<T> type, String id, ITmfTrace[] traces, int indexPageSize) {
69 this(type, id, traces, TmfTimestamp.Zero, indexPageSize);
70 }
71
72 public LTTngExperiment(LTTngExperiment<T> other) {
73 super(other.getName() + "(clone)", other.fType);
74
75 fEpoch = other.fEpoch;
76 fIndexPageSize = other.fIndexPageSize;
77
78 fTraces = new ITmfTrace[other.fTraces.length];
79 for (int trace = 0; trace < other.fTraces.length; trace++) {
80 fTraces[trace] = other.fTraces[trace].createTraceCopy();
81 }
82
83 fNbEvents = other.fNbEvents;
84 fTimeRange = other.fTimeRange;
85 }
86
87 @Override
88 public LTTngExperiment<T> createTraceCopy() {
89 LTTngExperiment<T> experiment = new LTTngExperiment<T>(this);
90 TmfSignalManager.deregister(experiment);
91 return experiment;
92 }
93
94 // ------------------------------------------------------------------------
95 // ITmfTrace trace positioning
96 // ------------------------------------------------------------------------
97
98 @Override
99 public synchronized TmfEvent getNextEvent(TmfContext context) {
100
101 // Validate the context
102 if (!(context instanceof TmfExperimentContext)) {
103 return null; // Throw an exception?
104 }
105
106 if (!fSavedContext.equals(context)) {
107// Tracer.trace("Ctx: Restoring context");
108 seekLocation(context.getLocation());
109 }
110
111 TmfExperimentContext expContext = (TmfExperimentContext) context;
112
113// dumpContext(expContext, true);
114
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);
121 }
122
123 // Scan the candidate events and identify the "next" trace to read from
124 int trace = TmfExperimentContext.NO_TRACE;
125 TmfTimestamp timestamp = TmfTimestamp.BigCrunch;
126 for (int i = 0; i < expContext.getTraces().length; i++) {
127 TmfEvent event = expContext.getEvents()[i];
128 if (event != null && event.getTimestamp() != null) {
129 TmfTimestamp otherTS = event.getTimestamp();
130 if (otherTS.compareTo(timestamp, true) < 0) {
131 trace = i;
132 timestamp = otherTS;
133 }
134 }
135 }
136
137 // Update the experiment context and set the "next" event
138 TmfEvent event = null;
139 if (trace != TmfExperimentContext.NO_TRACE) {
140// updateIndex(expContext, timestamp);
141
142 TmfContext traceContext = expContext.getContexts()[trace];
143 TmfExperimentLocation expLocation = (TmfExperimentLocation) expContext.getLocation();
144 expLocation.getLocation()[trace] = traceContext.getLocation().clone();
145
146 updateIndex(expContext, timestamp);
147
148 expLocation.getRanks()[trace] = traceContext.getRank();
149 expContext.setLastTrace(trace);
150 expContext.updateRank(1);
151 event = expContext.getEvents()[trace];
152 }
153
154// if (event != null) {
155// Tracer.trace("Exp: " + (expContext.getRank() - 1) + ": " + event.getTimestamp().toString());
156// dumpContext(expContext, false);
157// Tracer.trace("Ctx: Event returned= " + event.getTimestamp().toString());
158// }
159
160 fSavedContext = new TmfExperimentContext(expContext);
161
162 return event;
163 }
164
165 /* (non-Javadoc)
166 * @see java.lang.Object#toString()
167 */
168 @Override
169 public String toString() {
170 return "[LTTngExperiment (" + getName() + ")]";
171 }
172
173}
This page took 0.030559 seconds and 5 git commands to generate.