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