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() {
61 public void initTrace(String name
, String path
, Class
<CtfTmfEvent
> eventType
)
62 throws FileNotFoundException
{
64 this.fTrace
= new CTFTrace(path
);
65 } catch (CTFReaderException e
) {
67 * If it failed at the init(), we can assume it's because the file
68 * was not found or was not recognized as a CTF trace. Throw into
69 * the new type of exception expected by the rest of TMF.
71 System
.err
.println("Cannot find file " + path
); //$NON-NLS-1$
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()));
87 public void indexTrace(boolean waitForCompletion
) {
91 public void dispose() {
92 TmfSignalManager
.deregister(this);
96 public void broadcast(TmfSignal signal
) {
97 TmfSignalManager
.dispatchSignal(signal
);
101 public boolean validate(IProject project
, String path
) {
103 final CTFTrace temp
= new CTFTrace(path
);
104 return temp
.majortIsSet(); // random test
105 } catch (CTFReaderException e
) {
106 /* Nope, not a CTF trace we can read */
112 public CtfTmfTrace
clone() throws CloneNotSupportedException
{
113 CtfTmfTrace clone
= null;
114 clone
= (CtfTmfTrace
) super.clone();
115 clone
.fStartTime
= this.fStartTime
.clone();
116 clone
.fEndTime
= this.fEndTime
.clone();
117 clone
.fTrace
= this.fTrace
;
121 // ------------------------------------------------------------------------
123 // ------------------------------------------------------------------------
126 * @return the trace path
129 public String
getPath() {
130 return this.fTrace
.getPath();
134 public String
getName() {
135 String temp
[] = this.fTrace
.getPath().split(
136 System
.getProperty("file.separator")); //$NON-NLS-1$
137 if (temp
.length
> 2) {
138 return temp
[temp
.length
- 1];
144 public int getIndexPageSize() {
145 return this.fIndexPageSize
;
149 public long getNbEvents() {
150 return this.fNbEvents
;
154 public TmfTimeRange
getTimeRange() {
155 return new TmfTimeRange(this.fStartTime
, this.fEndTime
);
159 public ITmfTimestamp
getStartTime() {
160 return this.fStartTime
;
164 public ITmfTimestamp
getEndTime() {
165 return this.fEndTime
;
169 public ITmfLocation
<?
> getCurrentLocation() {
170 return iterator
.getLocation();
174 public long getRank(ITmfTimestamp timestamp
) {
175 ITmfContext context
= seekEvent(timestamp
);
176 return context
.getRank();
179 // ------------------------------------------------------------------------
181 // ------------------------------------------------------------------------
183 protected void setTimeRange(TmfTimeRange range
) {
184 this.fStartTime
= range
.getStartTime();
185 this.fEndTime
= range
.getEndTime();
188 protected void setStartTime(ITmfTimestamp startTime
) {
189 this.fStartTime
= startTime
;
192 protected void setEndTime(ITmfTimestamp endTime
) {
193 this.fEndTime
= endTime
;
196 // ------------------------------------------------------------------------
198 // ------------------------------------------------------------------------
201 public ITmfContext
armRequest(ITmfDataRequest
<CtfTmfEvent
> request
) {
202 if ((request
instanceof ITmfEventRequest
<?
>)
203 && !TmfTimestamp
.BIG_BANG
204 .equals(((ITmfEventRequest
<CtfTmfEvent
>) request
)
205 .getRange().getStartTime())
206 && (request
.getIndex() == 0)) {
207 ITmfContext context
= seekEvent(((ITmfEventRequest
<CtfTmfEvent
>) request
)
208 .getRange().getStartTime());
209 ((ITmfEventRequest
<CtfTmfEvent
>) request
)
210 .setStartIndex((int) context
.getRank());
213 return seekEvent(request
.getIndex());
217 * The trace reader keeps its own iterator: the "context" parameter here
220 * If you wish to specify a new context, instantiate a new CtfIterator and
221 * seek() it to where you want, and use that to read events.
223 * FIXME merge with getNextEvent below once they both use the same parameter
227 public CtfTmfEvent
getNext(ITmfContext context
) {
229 return iterator
.getCurrentEvent();
232 // ------------------------------------------------------------------------
234 // ------------------------------------------------------------------------
237 public ITmfContext
seekLocation(ITmfLocation
<?
> location
) {
238 iterator
.setLocation(location
);
243 public double getLocationRatio(ITmfLocation
<?
> location
) {
244 CtfIterator curLocation
= (CtfIterator
) location
;
245 return ((double) curLocation
.getCurrentEvent().getTimestampValue() -
246 curLocation
.getStartTime())
247 / (curLocation
.getEndTime() - curLocation
.getStartTime());
251 public long getStreamingInterval() {
256 public ITmfContext
seekEvent(ITmfTimestamp timestamp
) {
257 iterator
.seek(timestamp
.getValue());
265 public ITmfContext
seekEvent(long rank
) {
266 iterator
.setRank(rank
);
274 public ITmfContext
seekLocation(double ratio
) {
275 iterator
.seek((long) (this.fNbEvents
* ratio
));
280 public CtfTmfEvent
getNextEvent(ITmfContext context
) {
282 return iterator
.getCurrentEvent();
286 public CtfTmfEvent
parseEvent(ITmfContext context
) {
287 return iterator
.getCurrentEvent();
291 public IResource
getResource() {
292 return this.fResource
;
296 public void setResource(IResource fResource
) {
297 this.fResource
= fResource
;
300 CTFTrace
getCTFTrace() {