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 initTrace(String name
, String path
,
100 Class
<CtfTmfEvent
> eventType
, int cacheSize
)
101 throws FileNotFoundException
{
102 this.initTrace(name
, path
, eventType
);
106 public void initTrace(String name
, String path
,
107 Class
<CtfTmfEvent
> eventType
, boolean indexTrace
)
108 throws FileNotFoundException
{
109 this.initTrace(name
, path
, eventType
);
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
);
120 public void dispose() {
121 TmfSignalManager
.deregister(this);
125 public void broadcast(TmfSignal signal
) {
126 TmfSignalManager
.dispatchSignal(signal
);
130 public boolean validate(IProject project
, String path
) {
132 final CTFTrace temp
= new CTFTrace(path
);
133 return temp
.majortIsSet(); // random test
134 } catch (Exception e
) {
135 // TODO Auto-generated catch block
142 public CtfTmfTrace
clone() throws CloneNotSupportedException
{
143 CtfTmfTrace clone
= null;
144 clone
= (CtfTmfTrace
) super.clone();
145 clone
.setfCheckpoints(this.fCheckpoints
);
146 clone
.fStartTime
= this.fStartTime
.clone();
147 clone
.fEndTime
= this.fEndTime
.clone();
148 clone
.fTrace
= this.fTrace
;
153 public ITmfTrace
<CtfTmfEvent
> copy() {
154 // FIXME not yet implemented
158 // ------------------------------------------------------------------------
160 // ------------------------------------------------------------------------
163 * @return the trace path
166 public String
getPath() {
167 return this.fTrace
.getPath();
171 public String
getName() {
172 String temp
[] = this.fTrace
.getPath().split(
173 System
.getProperty("file.separator")); //$NON-NLS-1$
174 if (temp
.length
> 2) {
175 return temp
[temp
.length
- 1];
181 public int getCacheSize() {
182 return this.fIndexPageSize
;
186 public long getNbEvents() {
187 return this.fNbEvents
;
191 public TmfTimeRange
getTimeRange() {
192 return new TmfTimeRange(this.fStartTime
, this.fEndTime
);
196 public ITmfTimestamp
getStartTime() {
197 return this.fStartTime
;
201 public ITmfTimestamp
getEndTime() {
202 return this.fEndTime
;
206 public ITmfLocation
<?
> getCurrentLocation() {
207 return iterator
.getLocation();
211 public long getRank(ITmfTimestamp timestamp
) {
212 ITmfContext context
= seekEvent(timestamp
);
213 return context
.getRank();
216 // ------------------------------------------------------------------------
218 // ------------------------------------------------------------------------
220 protected void setTimeRange(TmfTimeRange range
) {
221 this.fStartTime
= range
.getStartTime();
222 this.fEndTime
= range
.getEndTime();
225 protected void setStartTime(ITmfTimestamp startTime
) {
226 this.fStartTime
= startTime
;
229 protected void setEndTime(ITmfTimestamp endTime
) {
230 this.fEndTime
= endTime
;
233 // ------------------------------------------------------------------------
235 // ------------------------------------------------------------------------
238 public ITmfContext
armRequest(ITmfDataRequest
<CtfTmfEvent
> request
) {
239 if ((request
instanceof ITmfEventRequest
<?
>)
240 && !TmfTimestamp
.BIG_BANG
.equals(((ITmfEventRequest
<CtfTmfEvent
>) request
).getRange().getStartTime())
241 && (request
.getIndex() == 0)) {
242 ITmfContext context
= seekEvent(((ITmfEventRequest
<CtfTmfEvent
>) request
).getRange().getStartTime());
243 ((ITmfEventRequest
<CtfTmfEvent
>) request
).setStartIndex((int) context
.getRank());
246 return seekEvent(request
.getIndex());
250 * The trace reader keeps its own iterator: the "context" parameter here
253 * If you wish to specify a new context, instantiate a new CtfIterator and
254 * seek() it to where you want, and use that to read events.
256 * FIXME merge with getNextEvent below once they both use the same parameter
260 public CtfTmfEvent
getNext(ITmfContext context
) {
262 return iterator
.getCurrentEvent();
265 // ------------------------------------------------------------------------
267 // ------------------------------------------------------------------------
270 public ITmfContext
seekLocation(ITmfLocation
<?
> location
) {
271 iterator
.setLocation(location
);
276 public double getLocationRatio(ITmfLocation
<?
> location
) {
281 public long getStreamingInterval() {
286 public ITmfContext
seekEvent(ITmfTimestamp timestamp
) {
287 iterator
.seek(timestamp
.getValue());
295 public ITmfContext
seekEvent(long rank
) {
296 iterator
.setRank(rank
);
304 public ITmfContext
seekLocation(double ratio
) {
305 iterator
.seek((long) (this.fNbEvents
* ratio
));
310 public CtfTmfEvent
getNextEvent(ITmfContext context
) {
312 return iterator
.getCurrentEvent();
316 public CtfTmfEvent
parseEvent(ITmfContext context
) {
317 return iterator
.getCurrentEvent();
320 public Vector
<TmfCheckpoint
> getfCheckpoints() {
321 return this.fCheckpoints
;
324 public void setfCheckpoints(Vector
<TmfCheckpoint
> fCheckpoints
) {
325 this.fCheckpoints
= fCheckpoints
;
329 public IResource
getResource() {
330 return this.fResource
;
334 public void setResource(IResource fResource
) {
335 this.fResource
= fResource
;
338 public CTFTrace
getCTFTrace() {