Work on TmfCheckpoint
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / ctfadaptor / CtfTmfTrace.java
CommitLineData
a3fc8213
AM
1package org.eclipse.linuxtools.tmf.core.ctfadaptor;
2
3import java.io.FileNotFoundException;
4import java.util.Vector;
5
6import org.eclipse.core.resources.IProject;
7import org.eclipse.core.resources.IResource;
8import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
9import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
10import org.eclipse.linuxtools.tmf.core.component.TmfEventProvider;
11import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
12import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
13import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
14import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
15import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest;
16import org.eclipse.linuxtools.tmf.core.signal.TmfSignal;
17import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager;
18import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
19import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
20import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
21import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpoint;
22
23public class CtfTmfTrace extends TmfEventProvider<CtfTmfEvent> implements
24 ITmfTrace<CtfTmfEvent> {
25
26 // ------------------------------------------------------------------------
27 // Constants
28 // ------------------------------------------------------------------------
29
30 // The default number of events to cache
31 // TODO: Make the DEFAULT_CACHE_SIZE a preference
32 public static final int DEFAULT_INDEX_PAGE_SIZE = 50000;
33
34 // ------------------------------------------------------------------------
35 // Attributes
36 // ------------------------------------------------------------------------
37
38 // the Ctf Trace
39 private CTFTrace fTrace;
40
41 // The cache page size AND checkpoints interval
42 protected int fIndexPageSize = DEFAULT_INDEX_PAGE_SIZE;
43
44 // The set of event stream checkpoints (for random access)
45 private Vector<TmfCheckpoint> fCheckpoints = new Vector<TmfCheckpoint>();
46
47 // The number of events collected
48 protected long fNbEvents = 0;
49
50 // The time span of the event stream
51 private ITmfTimestamp fStartTime = TmfTimestamp.BIG_CRUNCH;
52 private ITmfTimestamp fEndTime = TmfTimestamp.BIG_BANG;
53
54 // The trace resource
55 private IResource fResource;
56
57 /*
58 * Since in TMF, "traces" can read events, this trace here will have its own
59 * iterator. The user can instantiate extra iterator if they want to seek at
60 * many places at the same time.
61 */
62 protected CtfIterator iterator;
63
64 // ------------------------------------------------------------------------
65 // Constructors
66 // ------------------------------------------------------------------------
67
68 public CtfTmfTrace() {
69 super();
70 }
71
72 @Override
3118edf1 73 public void initTrace(String name, String path, Class<CtfTmfEvent> eventType)
a3fc8213
AM
74 throws FileNotFoundException {
75 try {
76 this.fTrace = new CTFTrace(path);
77 } catch (CTFReaderException e) {
78 /*
79 * If it failed at the init(), we can assume it's because the file
80 * was not found or was not recognized as a CTF trace. Throw into
81 * the new type of exception expected by the rest of TMF.
82 */
83 System.err.println("Cannot find file " + path); //$NON-NLS-1$
84 throw new FileNotFoundException(e.getMessage());
85 }
86 this.iterator = new CtfIterator(this, 0, 0);
87 setStartTime(iterator.getCurrentEvent().getTimestamp());
88 TmfSignalManager.register(this);
89 // this.currLocation.setTimestamp(this.fEvent.getTimestamp().getValue());
90 // this.fStartTime = new TmfSimpleTimestamp(this.currLocation
91 // .getLocation().getStartTime());
92 // this.fEndTime = new TmfSimpleTimestamp(this.currLocation
93 // .getLocation().getEndTime());
94 // setTimeRange(new TmfTimeRange(this.fStartTime.clone(),
95 // this.fEndTime.clone()));
96 }
97
98 @Override
8636b448 99 public void indexTrace(boolean waitForCompletion) {
a3fc8213
AM
100 }
101
102 @Override
103 public void dispose() {
104 TmfSignalManager.deregister(this);
105 }
106
107 @Override
108 public void broadcast(TmfSignal signal) {
109 TmfSignalManager.dispatchSignal(signal);
110 }
111
112 @Override
113 public boolean validate(IProject project, String path) {
114 try {
115 final CTFTrace temp = new CTFTrace(path);
116 return temp.majortIsSet(); // random test
90235d6b
AM
117 } catch (CTFReaderException e) {
118 /* Nope, not a CTF trace we can read */
119 return false;
a3fc8213 120 }
a3fc8213
AM
121 }
122
123 @Override
124 public CtfTmfTrace clone() throws CloneNotSupportedException {
125 CtfTmfTrace clone = null;
126 clone = (CtfTmfTrace) super.clone();
127 clone.setfCheckpoints(this.fCheckpoints);
128 clone.fStartTime = this.fStartTime.clone();
129 clone.fEndTime = this.fEndTime.clone();
130 clone.fTrace = this.fTrace;
131 return clone;
132 }
133
a3fc8213
AM
134 // ------------------------------------------------------------------------
135 // Accessors
136 // ------------------------------------------------------------------------
137
138 /**
139 * @return the trace path
140 */
141 @Override
142 public String getPath() {
143 return this.fTrace.getPath();
144 }
145
146 @Override
147 public String getName() {
148 String temp[] = this.fTrace.getPath().split(
149 System.getProperty("file.separator")); //$NON-NLS-1$
150 if (temp.length > 2) {
151 return temp[temp.length - 1];
152 }
153 return temp[0];
154 }
155
156 @Override
3118edf1 157 public int getIndexPageSize() {
a3fc8213
AM
158 return this.fIndexPageSize;
159 }
160
161 @Override
162 public long getNbEvents() {
163 return this.fNbEvents;
164 }
165
166 @Override
167 public TmfTimeRange getTimeRange() {
168 return new TmfTimeRange(this.fStartTime, this.fEndTime);
169 }
170
171 @Override
172 public ITmfTimestamp getStartTime() {
173 return this.fStartTime;
174 }
175
176 @Override
177 public ITmfTimestamp getEndTime() {
178 return this.fEndTime;
179 }
180
181 @Override
182 public ITmfLocation<?> getCurrentLocation() {
183 return iterator.getLocation();
184 }
185
186 @Override
187 public long getRank(ITmfTimestamp timestamp) {
188 ITmfContext context = seekEvent(timestamp);
189 return context.getRank();
190 }
191
192 // ------------------------------------------------------------------------
193 // Operators
194 // ------------------------------------------------------------------------
195
196 protected void setTimeRange(TmfTimeRange range) {
197 this.fStartTime = range.getStartTime();
198 this.fEndTime = range.getEndTime();
199 }
200
201 protected void setStartTime(ITmfTimestamp startTime) {
202 this.fStartTime = startTime;
203 }
204
205 protected void setEndTime(ITmfTimestamp endTime) {
206 this.fEndTime = endTime;
207 }
208
209 // ------------------------------------------------------------------------
210 // TmfProvider
211 // ------------------------------------------------------------------------
212
213 @Override
214 public ITmfContext armRequest(ITmfDataRequest<CtfTmfEvent> request) {
215 if ((request instanceof ITmfEventRequest<?>)
216 && !TmfTimestamp.BIG_BANG.equals(((ITmfEventRequest<CtfTmfEvent>) request).getRange().getStartTime())
217 && (request.getIndex() == 0)) {
218 ITmfContext context = seekEvent(((ITmfEventRequest<CtfTmfEvent>) request).getRange().getStartTime());
219 ((ITmfEventRequest<CtfTmfEvent>) request).setStartIndex((int) context.getRank());
220 return context;
221 }
222 return seekEvent(request.getIndex());
223 }
224
225 /**
226 * The trace reader keeps its own iterator: the "context" parameter here
227 * will be ignored.
228 *
229 * If you wish to specify a new context, instantiate a new CtfIterator and
230 * seek() it to where you want, and use that to read events.
231 *
232 * FIXME merge with getNextEvent below once they both use the same parameter
233 * type.
234 */
235 @Override
236 public CtfTmfEvent getNext(ITmfContext context) {
237 iterator.advance();
238 return iterator.getCurrentEvent();
239 }
240
241 // ------------------------------------------------------------------------
242 // ITmfTrace
243 // ------------------------------------------------------------------------
244
245 @Override
246 public ITmfContext seekLocation(ITmfLocation<?> location) {
247 iterator.setLocation(location);
248 return iterator;
249 }
250
251 @Override
252 public double getLocationRatio(ITmfLocation<?> location) {
253 return 0;
254 }
255
256 @Override
257 public long getStreamingInterval() {
258 return 0;
259 }
260
261 @Override
262 public ITmfContext seekEvent(ITmfTimestamp timestamp) {
263 iterator.seek(timestamp.getValue());
264 return iterator;
265 }
266
267 /**
268 * Seek by rank
269 */
270 @Override
271 public ITmfContext seekEvent(long rank) {
272 iterator.setRank(rank);
273 return iterator;
274 }
275
276 /**
277 * Seek rank ratio
278 */
279 @Override
280 public ITmfContext seekLocation(double ratio) {
281 iterator.seek((long) (this.fNbEvents * ratio));
282 return iterator;
283 }
284
285 @Override
286 public CtfTmfEvent getNextEvent(ITmfContext context) {
287 iterator.advance();
288 return iterator.getCurrentEvent();
289 }
290
291 @Override
292 public CtfTmfEvent parseEvent(ITmfContext context) {
293 return iterator.getCurrentEvent();
294 }
295
296 public Vector<TmfCheckpoint> getfCheckpoints() {
297 return this.fCheckpoints;
298 }
299
300 public void setfCheckpoints(Vector<TmfCheckpoint> fCheckpoints) {
301 this.fCheckpoints = fCheckpoints;
302 }
303
304 @Override
305 public IResource getResource() {
306 return this.fResource;
307 }
308
309 @Override
310 public void setResource(IResource fResource) {
311 this.fResource = fResource;
312 }
313
90235d6b 314 CTFTrace getCTFTrace() {
a3fc8213
AM
315 return fTrace;
316 }
8636b448 317
a3fc8213 318}
This page took 0.037906 seconds and 5 git commands to generate.