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 ITmfTrace
<CtfTmfEvent
> {
23 // ------------------------------------------------------------------------
25 // ------------------------------------------------------------------------
27 // ------------------------------------------------------------------------
29 // ------------------------------------------------------------------------
32 private CTFTrace fTrace
;
34 // The number of events collected
35 protected long fNbEvents
= 0;
37 // The time span of the event stream
38 private ITmfTimestamp fStartTime
= TmfTimestamp
.BIG_CRUNCH
;
39 private ITmfTimestamp fEndTime
= TmfTimestamp
.BIG_BANG
;
42 private IResource fResource
;
45 * Since in TMF, "traces" can read events, this trace here will have its own
46 * iterator. The user can instantiate extra iterator if they want to seek at
47 * many places at the same time.
49 protected CtfIterator iterator
;
51 // ------------------------------------------------------------------------
53 // ------------------------------------------------------------------------
55 public CtfTmfTrace() {
60 public void initTrace(final IResource resource
, final String path
, final Class
<CtfTmfEvent
> eventType
)
61 throws FileNotFoundException
{
62 this.fResource
= resource
;
64 this.fTrace
= new CTFTrace(path
);
65 } catch (final 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 throw new FileNotFoundException(e
.getMessage());
73 this.iterator
= new CtfIterator(this, 0, 0);
74 setStartTime(iterator
.getCurrentEvent().getTimestamp());
75 TmfSignalManager
.register(this);
76 // this.currLocation.setTimestamp(this.fEvent.getTimestamp().getValue());
77 // this.fStartTime = new TmfSimpleTimestamp(this.currLocation
78 // .getLocation().getStartTime());
79 // this.fEndTime = new TmfSimpleTimestamp(this.currLocation
80 // .getLocation().getEndTime());
81 // setTimeRange(new TmfTimeRange(this.fStartTime.clone(),
82 // this.fEndTime.clone()));
86 public void dispose() {
87 TmfSignalManager
.deregister(this);
91 public void broadcast(final TmfSignal signal
) {
92 TmfSignalManager
.dispatchSignal(signal
);
96 public boolean validate(final IProject project
, final String path
) {
98 final CTFTrace temp
= new CTFTrace(path
);
99 return temp
.majortIsSet(); // random test
100 } catch (final CTFReaderException e
) {
101 /* Nope, not a CTF trace we can read */
107 public CtfTmfTrace
clone() throws CloneNotSupportedException
{
108 CtfTmfTrace clone
= null;
109 clone
= (CtfTmfTrace
) super.clone();
110 clone
.fStartTime
= this.fStartTime
.clone();
111 clone
.fEndTime
= this.fEndTime
.clone();
112 clone
.fTrace
= this.fTrace
;
116 // ------------------------------------------------------------------------
118 // ------------------------------------------------------------------------
121 * @return the trace path
124 public Class
<CtfTmfEvent
> getEventType() {
128 public int getNbEnvVars() {
129 return this.fTrace
.getEnvironment().size();
133 public String
[] getEnvNames() {
134 final String
[] s
= new String
[getNbEnvVars()];
135 return this.fTrace
.getEnvironment().keySet().toArray(s
);
138 public String
getEnvValue(final String key
) {
139 return this.fTrace
.getEnvironment().get(key
);
144 * @return the trace path
147 public String
getPath() {
148 return this.fTrace
.getPath();
152 public String
getName() {
153 final String temp
[] = this.fTrace
.getPath().split(
154 System
.getProperty("file.separator")); //$NON-NLS-1$
156 return temp
[temp
.length
- 1];
161 public int getCacheSize() {
162 return 50000; // not true, but it works
166 public long getNbEvents() {
167 return this.fNbEvents
;
171 public TmfTimeRange
getTimeRange() {
172 return new TmfTimeRange(this.fStartTime
, this.fEndTime
);
176 public ITmfTimestamp
getStartTime() {
177 return this.fStartTime
;
181 public ITmfTimestamp
getEndTime() {
182 return this.fEndTime
;
186 public ITmfLocation
<?
> getCurrentLocation() {
187 return iterator
.getLocation();
190 // ------------------------------------------------------------------------
192 // ------------------------------------------------------------------------
194 protected void setTimeRange(final TmfTimeRange range
) {
195 this.fStartTime
= range
.getStartTime();
196 this.fEndTime
= range
.getEndTime();
199 protected void setStartTime(final ITmfTimestamp startTime
) {
200 this.fStartTime
= startTime
;
203 protected void setEndTime(final ITmfTimestamp endTime
) {
204 this.fEndTime
= endTime
;
207 // ------------------------------------------------------------------------
209 // ------------------------------------------------------------------------
212 public ITmfContext
armRequest(final ITmfDataRequest
<CtfTmfEvent
> request
) {
213 if ((request
instanceof ITmfEventRequest
<?
>)
214 && !TmfTimestamp
.BIG_BANG
215 .equals(((ITmfEventRequest
<CtfTmfEvent
>) request
)
216 .getRange().getStartTime())
217 && (request
.getIndex() == 0)) {
218 final ITmfContext context
= seekEvent(((ITmfEventRequest
<CtfTmfEvent
>) request
)
219 .getRange().getStartTime());
220 ((ITmfEventRequest
<CtfTmfEvent
>) request
)
221 .setStartIndex((int) context
.getRank());
224 return seekEvent(request
.getIndex());
228 * The trace reader keeps its own iterator: the "context" parameter here
231 * If you wish to specify a new context, instantiate a new CtfIterator and
232 * seek() it to where you want, and use that to read events.
234 * FIXME merge with getNextEvent below once they both use the same parameter
238 public CtfTmfEvent
getNext(final ITmfContext context
) {
240 return iterator
.getCurrentEvent();
243 // ------------------------------------------------------------------------
245 // ------------------------------------------------------------------------
248 public ITmfContext
seekEvent(final ITmfLocation
<?
> location
) {
249 CtfLocation currentLocation
= (CtfLocation
) location
;
250 if (currentLocation
== null)
251 currentLocation
= new CtfLocation(0L);
252 iterator
.setLocation(currentLocation
);
257 public double getLocationRatio(final ITmfLocation
<?
> location
) {
258 final CtfLocation curLocation
= (CtfLocation
) location
;
259 iterator
.seek(curLocation
.getLocation());
260 return ((double) iterator
.getCurrentEvent().getTimestampValue() - iterator
262 / (iterator
.getEndTime() - iterator
.getStartTime());
266 public long getStreamingInterval() {
271 public ITmfContext
seekEvent(final ITmfTimestamp timestamp
) {
272 iterator
.seek(timestamp
.getValue());
280 public ITmfContext
seekEvent(final long rank
) {
281 iterator
.setRank(rank
);
289 public ITmfContext
seekEvent(final double ratio
) {
290 iterator
.seek((long) (this.fNbEvents
* ratio
));
295 public CtfTmfEvent
readEvent(final ITmfContext context
) {
297 return iterator
.getCurrentEvent();
301 // public CtfTmfEvent parseEvent(final ITmfContext context) {
302 // return iterator.getCurrentEvent();
306 public IResource
getResource() {
307 return this.fResource
;
310 CTFTrace
getCTFTrace() {