1 package org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
;
3 import java
.io
.FileNotFoundException
;
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
;
21 public class CtfTmfTrace
extends TmfEventProvider
<CtfTmfEvent
> implements
22 ITmfTrace
<CtfTmfEvent
> {
24 // ------------------------------------------------------------------------
26 // ------------------------------------------------------------------------
28 // ------------------------------------------------------------------------
30 // ------------------------------------------------------------------------
33 private CTFTrace fTrace
;
35 // The number of events collected
36 protected long fNbEvents
= 0;
38 // The time span of the event stream
39 private ITmfTimestamp fStartTime
= TmfTimestamp
.BIG_CRUNCH
;
40 private ITmfTimestamp fEndTime
= TmfTimestamp
.BIG_BANG
;
43 private IResource fResource
;
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.
50 protected CtfIterator iterator
;
52 // ------------------------------------------------------------------------
54 // ------------------------------------------------------------------------
56 public CtfTmfTrace() {
60 @SuppressWarnings("unused")
62 public void initTrace(String name
, String path
, Class
<CtfTmfEvent
> eventType
)
63 throws FileNotFoundException
{
65 this.fTrace
= new CTFTrace(path
);
66 } catch (CTFReaderException e
) {
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.
72 throw new FileNotFoundException(e
.getMessage());
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()));
86 @SuppressWarnings("unused")
88 public void indexTrace(boolean waitForCompletion
) {
93 public void dispose() {
94 TmfSignalManager
.deregister(this);
98 public void broadcast(TmfSignal signal
) {
99 TmfSignalManager
.dispatchSignal(signal
);
102 @SuppressWarnings("unused")
104 public boolean validate(IProject project
, String path
) {
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 */
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
;
124 // ------------------------------------------------------------------------
126 // ------------------------------------------------------------------------
129 * @return the trace path
132 public String
getPath() {
133 return this.fTrace
.getPath();
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];
147 public int getIndexPageSize() {
148 return 50000; //not true, but it works
152 public long getNbEvents() {
153 return this.fNbEvents
;
157 public TmfTimeRange
getTimeRange() {
158 return new TmfTimeRange(this.fStartTime
, this.fEndTime
);
162 public ITmfTimestamp
getStartTime() {
163 return this.fStartTime
;
167 public ITmfTimestamp
getEndTime() {
168 return this.fEndTime
;
172 public ITmfLocation
<?
> getCurrentLocation() {
173 return iterator
.getLocation();
177 public long getRank(ITmfTimestamp timestamp
) {
178 ITmfContext context
= seekEvent(timestamp
);
179 return context
.getRank();
182 // ------------------------------------------------------------------------
184 // ------------------------------------------------------------------------
186 protected void setTimeRange(TmfTimeRange range
) {
187 this.fStartTime
= range
.getStartTime();
188 this.fEndTime
= range
.getEndTime();
191 protected void setStartTime(ITmfTimestamp startTime
) {
192 this.fStartTime
= startTime
;
195 protected void setEndTime(ITmfTimestamp endTime
) {
196 this.fEndTime
= endTime
;
199 // ------------------------------------------------------------------------
201 // ------------------------------------------------------------------------
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());
216 return seekEvent(request
.getIndex());
220 * The trace reader keeps its own iterator: the "context" parameter here
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.
226 * FIXME merge with getNextEvent below once they both use the same parameter
229 @SuppressWarnings("unused")
231 public CtfTmfEvent
getNext(ITmfContext context
) {
233 return iterator
.getCurrentEvent();
236 // ------------------------------------------------------------------------
238 // ------------------------------------------------------------------------
241 public ITmfContext
seekLocation(ITmfLocation
<?
> location
) {
242 CtfLocation currentLocation
= (CtfLocation
) location
;
243 if (currentLocation
== null) {
244 currentLocation
= new CtfLocation(0L);
246 iterator
.setLocation(currentLocation
);
251 public double getLocationRatio(ITmfLocation
<?
> location
) {
252 CtfLocation curLocation
= (CtfLocation
) location
;
253 iterator
.seek(curLocation
.getLocation());
254 return ((double) iterator
.getCurrentEvent().getTimestampValue() - iterator
256 / (iterator
.getEndTime() - iterator
.getStartTime());
260 public long getStreamingInterval() {
265 public ITmfContext
seekEvent(ITmfTimestamp timestamp
) {
266 iterator
.seek(timestamp
.getValue());
274 public ITmfContext
seekEvent(long rank
) {
275 iterator
.setRank(rank
);
283 public ITmfContext
seekLocation(double ratio
) {
284 iterator
.seek((long) (this.fNbEvents
* ratio
));
288 @SuppressWarnings("unused")
290 public CtfTmfEvent
getNextEvent( ITmfContext context
) {
292 return iterator
.getCurrentEvent();
295 @SuppressWarnings("unused")
297 public CtfTmfEvent
parseEvent(ITmfContext context
) {
298 return iterator
.getCurrentEvent();
302 public IResource
getResource() {
303 return this.fResource
;
307 public void setResource(IResource fResource
) {
308 this.fResource
= fResource
;
311 CTFTrace
getCTFTrace() {