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 (CTFReaderException e
) {
135 /* Nope, not a CTF trace we can read */
141 public CtfTmfTrace
clone() throws CloneNotSupportedException
{
142 CtfTmfTrace clone
= null;
143 clone
= (CtfTmfTrace
) super.clone();
144 clone
.setfCheckpoints(this.fCheckpoints
);
145 clone
.fStartTime
= this.fStartTime
.clone();
146 clone
.fEndTime
= this.fEndTime
.clone();
147 clone
.fTrace
= this.fTrace
;
152 public ITmfTrace
<CtfTmfEvent
> copy() {
153 // FIXME not yet implemented
157 // ------------------------------------------------------------------------
159 // ------------------------------------------------------------------------
162 * @return the trace path
165 public String
getPath() {
166 return this.fTrace
.getPath();
170 public String
getName() {
171 String temp
[] = this.fTrace
.getPath().split(
172 System
.getProperty("file.separator")); //$NON-NLS-1$
173 if (temp
.length
> 2) {
174 return temp
[temp
.length
- 1];
180 public int getCacheSize() {
181 return this.fIndexPageSize
;
185 public long getNbEvents() {
186 return this.fNbEvents
;
190 public TmfTimeRange
getTimeRange() {
191 return new TmfTimeRange(this.fStartTime
, this.fEndTime
);
195 public ITmfTimestamp
getStartTime() {
196 return this.fStartTime
;
200 public ITmfTimestamp
getEndTime() {
201 return this.fEndTime
;
205 public ITmfLocation
<?
> getCurrentLocation() {
206 return iterator
.getLocation();
210 public long getRank(ITmfTimestamp timestamp
) {
211 ITmfContext context
= seekEvent(timestamp
);
212 return context
.getRank();
215 // ------------------------------------------------------------------------
217 // ------------------------------------------------------------------------
219 protected void setTimeRange(TmfTimeRange range
) {
220 this.fStartTime
= range
.getStartTime();
221 this.fEndTime
= range
.getEndTime();
224 protected void setStartTime(ITmfTimestamp startTime
) {
225 this.fStartTime
= startTime
;
228 protected void setEndTime(ITmfTimestamp endTime
) {
229 this.fEndTime
= endTime
;
232 // ------------------------------------------------------------------------
234 // ------------------------------------------------------------------------
237 public ITmfContext
armRequest(ITmfDataRequest
<CtfTmfEvent
> request
) {
238 if ((request
instanceof ITmfEventRequest
<?
>)
239 && !TmfTimestamp
.BIG_BANG
.equals(((ITmfEventRequest
<CtfTmfEvent
>) request
).getRange().getStartTime())
240 && (request
.getIndex() == 0)) {
241 ITmfContext context
= seekEvent(((ITmfEventRequest
<CtfTmfEvent
>) request
).getRange().getStartTime());
242 ((ITmfEventRequest
<CtfTmfEvent
>) request
).setStartIndex((int) context
.getRank());
245 return seekEvent(request
.getIndex());
249 * The trace reader keeps its own iterator: the "context" parameter here
252 * If you wish to specify a new context, instantiate a new CtfIterator and
253 * seek() it to where you want, and use that to read events.
255 * FIXME merge with getNextEvent below once they both use the same parameter
259 public CtfTmfEvent
getNext(ITmfContext context
) {
261 return iterator
.getCurrentEvent();
264 // ------------------------------------------------------------------------
266 // ------------------------------------------------------------------------
269 public ITmfContext
seekLocation(ITmfLocation
<?
> location
) {
270 iterator
.setLocation(location
);
275 public double getLocationRatio(ITmfLocation
<?
> location
) {
280 public long getStreamingInterval() {
285 public ITmfContext
seekEvent(ITmfTimestamp timestamp
) {
286 iterator
.seek(timestamp
.getValue());
294 public ITmfContext
seekEvent(long rank
) {
295 iterator
.setRank(rank
);
303 public ITmfContext
seekLocation(double ratio
) {
304 iterator
.seek((long) (this.fNbEvents
* ratio
));
309 public CtfTmfEvent
getNextEvent(ITmfContext context
) {
311 return iterator
.getCurrentEvent();
315 public CtfTmfEvent
parseEvent(ITmfContext context
) {
316 return iterator
.getCurrentEvent();
319 public Vector
<TmfCheckpoint
> getfCheckpoints() {
320 return this.fCheckpoints
;
323 public void setfCheckpoints(Vector
<TmfCheckpoint
> fCheckpoints
) {
324 this.fCheckpoints
= fCheckpoints
;
328 public IResource
getResource() {
329 return this.fResource
;
333 public void setResource(IResource fResource
) {
334 this.fResource
= fResource
;
337 CTFTrace
getCTFTrace() {