Avoid printing the exception when CtfTmfTrace.validate() fails
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / ctfadaptor / CtfTmfTrace.java
1 package org.eclipse.linuxtools.tmf.core.ctfadaptor;
2
3 import java.io.FileNotFoundException;
4 import java.util.Vector;
5
6 import org.eclipse.core.resources.IProject;
7 import org.eclipse.core.resources.IResource;
8 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
9 import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
10 import org.eclipse.linuxtools.tmf.core.component.TmfEventProvider;
11 import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
12 import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
13 import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
14 import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
15 import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest;
16 import org.eclipse.linuxtools.tmf.core.signal.TmfSignal;
17 import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager;
18 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
19 import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
20 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
21 import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpoint;
22
23 public 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
73 public void initTrace(String name, String path, Class<CtfTmfEvent> eventType)
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
99 public void initTrace(String name, String path,
100 Class<CtfTmfEvent> eventType, int cacheSize)
101 throws FileNotFoundException {
102 this.initTrace(name, path, eventType);
103 }
104
105 @Override
106 public void initTrace(String name, String path,
107 Class<CtfTmfEvent> eventType, boolean indexTrace)
108 throws FileNotFoundException {
109 this.initTrace(name, path, eventType);
110 }
111
112 @Override
113 public void initTrace(String name, String path,
114 Class<CtfTmfEvent> eventType, int cacheSize, boolean indexTrace)
115 throws FileNotFoundException {
116 this.initTrace(name, path, eventType);
117 }
118
119 @Override
120 public void dispose() {
121 TmfSignalManager.deregister(this);
122 }
123
124 @Override
125 public void broadcast(TmfSignal signal) {
126 TmfSignalManager.dispatchSignal(signal);
127 }
128
129 @Override
130 public boolean validate(IProject project, String path) {
131 try {
132 final CTFTrace temp = new CTFTrace(path);
133 return temp.majortIsSet(); // random test
134 } catch (CTFReaderException e) {
135 /* Nope, not a CTF trace we can read */
136 return false;
137 }
138 }
139
140 @Override
141 public CtfTmfTrace clone() throws CloneNotSupportedException {
142 CtfTmfTrace clone = null;
143 clone = (CtfTmfTrace) super.clone();
144 clone.setfCheckpoints(this.fCheckpoints);
145 clone.fStartTime = this.fStartTime.clone();
146 clone.fEndTime = this.fEndTime.clone();
147 clone.fTrace = this.fTrace;
148 return clone;
149 }
150
151 @Override
152 public ITmfTrace<CtfTmfEvent> copy() {
153 // FIXME not yet implemented
154 return null;
155 }
156
157 // ------------------------------------------------------------------------
158 // Accessors
159 // ------------------------------------------------------------------------
160
161 /**
162 * @return the trace path
163 */
164 @Override
165 public String getPath() {
166 return this.fTrace.getPath();
167 }
168
169 @Override
170 public String getName() {
171 String temp[] = this.fTrace.getPath().split(
172 System.getProperty("file.separator")); //$NON-NLS-1$
173 if (temp.length > 2) {
174 return temp[temp.length - 1];
175 }
176 return temp[0];
177 }
178
179 @Override
180 public int getCacheSize() {
181 return this.fIndexPageSize;
182 }
183
184 @Override
185 public long getNbEvents() {
186 return this.fNbEvents;
187 }
188
189 @Override
190 public TmfTimeRange getTimeRange() {
191 return new TmfTimeRange(this.fStartTime, this.fEndTime);
192 }
193
194 @Override
195 public ITmfTimestamp getStartTime() {
196 return this.fStartTime;
197 }
198
199 @Override
200 public ITmfTimestamp getEndTime() {
201 return this.fEndTime;
202 }
203
204 @Override
205 public ITmfLocation<?> getCurrentLocation() {
206 return iterator.getLocation();
207 }
208
209 @Override
210 public long getRank(ITmfTimestamp timestamp) {
211 ITmfContext context = seekEvent(timestamp);
212 return context.getRank();
213 }
214
215 // ------------------------------------------------------------------------
216 // Operators
217 // ------------------------------------------------------------------------
218
219 protected void setTimeRange(TmfTimeRange range) {
220 this.fStartTime = range.getStartTime();
221 this.fEndTime = range.getEndTime();
222 }
223
224 protected void setStartTime(ITmfTimestamp startTime) {
225 this.fStartTime = startTime;
226 }
227
228 protected void setEndTime(ITmfTimestamp endTime) {
229 this.fEndTime = endTime;
230 }
231
232 // ------------------------------------------------------------------------
233 // TmfProvider
234 // ------------------------------------------------------------------------
235
236 @Override
237 public ITmfContext armRequest(ITmfDataRequest<CtfTmfEvent> request) {
238 if ((request instanceof ITmfEventRequest<?>)
239 && !TmfTimestamp.BIG_BANG.equals(((ITmfEventRequest<CtfTmfEvent>) request).getRange().getStartTime())
240 && (request.getIndex() == 0)) {
241 ITmfContext context = seekEvent(((ITmfEventRequest<CtfTmfEvent>) request).getRange().getStartTime());
242 ((ITmfEventRequest<CtfTmfEvent>) request).setStartIndex((int) context.getRank());
243 return context;
244 }
245 return seekEvent(request.getIndex());
246 }
247
248 /**
249 * The trace reader keeps its own iterator: the "context" parameter here
250 * will be ignored.
251 *
252 * If you wish to specify a new context, instantiate a new CtfIterator and
253 * seek() it to where you want, and use that to read events.
254 *
255 * FIXME merge with getNextEvent below once they both use the same parameter
256 * type.
257 */
258 @Override
259 public CtfTmfEvent getNext(ITmfContext context) {
260 iterator.advance();
261 return iterator.getCurrentEvent();
262 }
263
264 // ------------------------------------------------------------------------
265 // ITmfTrace
266 // ------------------------------------------------------------------------
267
268 @Override
269 public ITmfContext seekLocation(ITmfLocation<?> location) {
270 iterator.setLocation(location);
271 return iterator;
272 }
273
274 @Override
275 public double getLocationRatio(ITmfLocation<?> location) {
276 return 0;
277 }
278
279 @Override
280 public long getStreamingInterval() {
281 return 0;
282 }
283
284 @Override
285 public ITmfContext seekEvent(ITmfTimestamp timestamp) {
286 iterator.seek(timestamp.getValue());
287 return iterator;
288 }
289
290 /**
291 * Seek by rank
292 */
293 @Override
294 public ITmfContext seekEvent(long rank) {
295 iterator.setRank(rank);
296 return iterator;
297 }
298
299 /**
300 * Seek rank ratio
301 */
302 @Override
303 public ITmfContext seekLocation(double ratio) {
304 iterator.seek((long) (this.fNbEvents * ratio));
305 return iterator;
306 }
307
308 @Override
309 public CtfTmfEvent getNextEvent(ITmfContext context) {
310 iterator.advance();
311 return iterator.getCurrentEvent();
312 }
313
314 @Override
315 public CtfTmfEvent parseEvent(ITmfContext context) {
316 return iterator.getCurrentEvent();
317 }
318
319 public Vector<TmfCheckpoint> getfCheckpoints() {
320 return this.fCheckpoints;
321 }
322
323 public void setfCheckpoints(Vector<TmfCheckpoint> fCheckpoints) {
324 this.fCheckpoints = fCheckpoints;
325 }
326
327 @Override
328 public IResource getResource() {
329 return this.fResource;
330 }
331
332 @Override
333 public void setResource(IResource fResource) {
334 this.fResource = fResource;
335 }
336
337 CTFTrace getCTFTrace() {
338 return fTrace;
339 }
340 }
This page took 0.038705 seconds and 6 git commands to generate.