1 package org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
;
3 import java
.io
.FileNotFoundException
;
4 import java
.util
.Vector
;
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
;
23 public class CtfTmfTrace
extends TmfEventProvider
<CtfTmfEvent
> implements
24 ITmfTrace
<CtfTmfEvent
> {
26 // ------------------------------------------------------------------------
28 // ------------------------------------------------------------------------
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;
34 // ------------------------------------------------------------------------
36 // ------------------------------------------------------------------------
39 private CTFTrace fTrace
;
41 // The cache page size AND checkpoints interval
42 protected int fIndexPageSize
= DEFAULT_INDEX_PAGE_SIZE
;
44 // The set of event stream checkpoints (for random access)
45 private Vector
<TmfCheckpoint
> fCheckpoints
= new Vector
<TmfCheckpoint
>();
47 // The number of events collected
48 protected long fNbEvents
= 0;
50 // The time span of the event stream
51 private ITmfTimestamp fStartTime
= TmfTimestamp
.BIG_CRUNCH
;
52 private ITmfTimestamp fEndTime
= TmfTimestamp
.BIG_BANG
;
55 private IResource fResource
;
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.
62 protected CtfIterator iterator
;
64 // ------------------------------------------------------------------------
66 // ------------------------------------------------------------------------
68 public CtfTmfTrace() {
73 public void initTrace(String name
, String path
, Class
<CtfTmfEvent
> eventType
)
74 throws FileNotFoundException
{
76 this.fTrace
= new CTFTrace(path
);
77 } catch (CTFReaderException e
) {
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.
83 System
.err
.println("Cannot find file " + path
); //$NON-NLS-1$
84 throw new FileNotFoundException(e
.getMessage());
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()));
99 public void indexTrace(boolean waitForCompletion
) {
103 public void dispose() {
104 TmfSignalManager
.deregister(this);
108 public void broadcast(TmfSignal signal
) {
109 TmfSignalManager
.dispatchSignal(signal
);
113 public boolean validate(IProject project
, String path
) {
115 final CTFTrace temp
= new CTFTrace(path
);
116 return temp
.majortIsSet(); // random test
117 } catch (CTFReaderException e
) {
118 /* Nope, not a CTF trace we can read */
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
;
134 // ------------------------------------------------------------------------
136 // ------------------------------------------------------------------------
139 * @return the trace path
142 public String
getPath() {
143 return this.fTrace
.getPath();
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];
157 public int getIndexPageSize() {
158 return this.fIndexPageSize
;
162 public long getNbEvents() {
163 return this.fNbEvents
;
167 public TmfTimeRange
getTimeRange() {
168 return new TmfTimeRange(this.fStartTime
, this.fEndTime
);
172 public ITmfTimestamp
getStartTime() {
173 return this.fStartTime
;
177 public ITmfTimestamp
getEndTime() {
178 return this.fEndTime
;
182 public ITmfLocation
<?
> getCurrentLocation() {
183 return iterator
.getLocation();
187 public long getRank(ITmfTimestamp timestamp
) {
188 ITmfContext context
= seekEvent(timestamp
);
189 return context
.getRank();
192 // ------------------------------------------------------------------------
194 // ------------------------------------------------------------------------
196 protected void setTimeRange(TmfTimeRange range
) {
197 this.fStartTime
= range
.getStartTime();
198 this.fEndTime
= range
.getEndTime();
201 protected void setStartTime(ITmfTimestamp startTime
) {
202 this.fStartTime
= startTime
;
205 protected void setEndTime(ITmfTimestamp endTime
) {
206 this.fEndTime
= endTime
;
209 // ------------------------------------------------------------------------
211 // ------------------------------------------------------------------------
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());
222 return seekEvent(request
.getIndex());
226 * The trace reader keeps its own iterator: the "context" parameter here
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.
232 * FIXME merge with getNextEvent below once they both use the same parameter
236 public CtfTmfEvent
getNext(ITmfContext context
) {
238 return iterator
.getCurrentEvent();
241 // ------------------------------------------------------------------------
243 // ------------------------------------------------------------------------
246 public ITmfContext
seekLocation(ITmfLocation
<?
> location
) {
247 iterator
.setLocation(location
);
252 public double getLocationRatio(ITmfLocation
<?
> location
) {
257 public long getStreamingInterval() {
262 public ITmfContext
seekEvent(ITmfTimestamp timestamp
) {
263 iterator
.seek(timestamp
.getValue());
271 public ITmfContext
seekEvent(long rank
) {
272 iterator
.setRank(rank
);
280 public ITmfContext
seekLocation(double ratio
) {
281 iterator
.seek((long) (this.fNbEvents
* ratio
));
286 public CtfTmfEvent
getNextEvent(ITmfContext context
) {
288 return iterator
.getCurrentEvent();
292 public CtfTmfEvent
parseEvent(ITmfContext context
) {
293 return iterator
.getCurrentEvent();
296 public Vector
<TmfCheckpoint
> getfCheckpoints() {
297 return this.fCheckpoints
;
300 public void setfCheckpoints(Vector
<TmfCheckpoint
> fCheckpoints
) {
301 this.fCheckpoints
= fCheckpoints
;
305 public IResource
getResource() {
306 return this.fResource
;
310 public void setResource(IResource fResource
) {
311 this.fResource
= fResource
;
314 CTFTrace
getCTFTrace() {