1 package org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
;
3 import org
.eclipse
.core
.resources
.IProject
;
4 import org
.eclipse
.core
.resources
.IResource
;
5 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
;
6 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFTrace
;
7 import org
.eclipse
.linuxtools
.tmf
.core
.component
.TmfEventProvider
;
8 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfTimestamp
;
9 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimeRange
;
10 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimestamp
;
11 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TmfTraceException
;
12 import org
.eclipse
.linuxtools
.tmf
.core
.request
.ITmfDataRequest
;
13 import org
.eclipse
.linuxtools
.tmf
.core
.request
.ITmfEventRequest
;
14 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignal
;
15 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfSignalManager
;
16 import org
.eclipse
.linuxtools
.tmf
.core
.statesystem
.StateSystem
;
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 /* Reference to the state system assigned to this trace */
52 protected StateSystem ss
= null;
54 // ------------------------------------------------------------------------
56 // ------------------------------------------------------------------------
58 public CtfTmfTrace() {
63 public void initTrace(final IResource resource
, final String path
, final Class
<CtfTmfEvent
> eventType
)
64 throws TmfTraceException
{
65 this.fResource
= resource
;
67 this.fTrace
= new CTFTrace(path
);
68 } catch (final CTFReaderException e
) {
70 * If it failed at the init(), we can assume it's because the file
71 * was not found or was not recognized as a CTF trace. Throw into
72 * the new type of exception expected by the rest of TMF.
74 throw new TmfTraceException(e
.getMessage());
76 this.iterator
= new CtfIterator(this, 0, 0);
77 setStartTime(iterator
.getCurrentEvent().getTimestamp());
78 TmfSignalManager
.register(this);
79 // this.currLocation.setTimestamp(this.fEvent.getTimestamp().getValue());
80 // this.fStartTime = new TmfSimpleTimestamp(this.currLocation
81 // .getLocation().getStartTime());
82 // this.fEndTime = new TmfSimpleTimestamp(this.currLocation
83 // .getLocation().getEndTime());
84 // setTimeRange(new TmfTimeRange(this.fStartTime.clone(),
85 // this.fEndTime.clone()));
91 public void dispose() {
92 TmfSignalManager
.deregister(this);
96 public void broadcast(final TmfSignal signal
) {
97 TmfSignalManager
.dispatchSignal(signal
);
101 public boolean validate(final IProject project
, final String path
) {
103 final CTFTrace temp
= new CTFTrace(path
);
104 return temp
.majortIsSet(); // random test
105 } catch (final 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 Class
<CtfTmfEvent
> getEventType() {
133 public int getNbEnvVars() {
134 return this.fTrace
.getEnvironment().size();
138 public String
[] getEnvNames() {
139 final String
[] s
= new String
[getNbEnvVars()];
140 return this.fTrace
.getEnvironment().keySet().toArray(s
);
143 public String
getEnvValue(final String key
) {
144 return this.fTrace
.getEnvironment().get(key
);
149 * @return the trace path
152 public String
getPath() {
153 return this.fTrace
.getPath();
157 public String
getName() {
158 final String temp
[] = this.fTrace
.getPath().split(
159 System
.getProperty("file.separator")); //$NON-NLS-1$
160 if (temp
.length
> 2) {
161 return temp
[temp
.length
- 1];
167 public int getCacheSize() {
168 return 50000; // not true, but it works
172 public long getNbEvents() {
173 return this.fNbEvents
;
177 public TmfTimeRange
getTimeRange() {
178 return new TmfTimeRange(this.fStartTime
, this.fEndTime
);
182 public ITmfTimestamp
getStartTime() {
183 return this.fStartTime
;
187 public ITmfTimestamp
getEndTime() {
188 return this.fEndTime
;
192 public ITmfLocation
<?
> getCurrentLocation() {
193 return iterator
.getLocation();
196 // ------------------------------------------------------------------------
198 // ------------------------------------------------------------------------
200 protected void setTimeRange(final TmfTimeRange range
) {
201 this.fStartTime
= range
.getStartTime();
202 this.fEndTime
= range
.getEndTime();
205 protected void setStartTime(final ITmfTimestamp startTime
) {
206 this.fStartTime
= startTime
;
209 protected void setEndTime(final ITmfTimestamp endTime
) {
210 this.fEndTime
= endTime
;
213 // ------------------------------------------------------------------------
215 // ------------------------------------------------------------------------
218 public ITmfContext
armRequest(final ITmfDataRequest
<CtfTmfEvent
> request
) {
219 if ((request
instanceof ITmfEventRequest
<?
>)
220 && !TmfTimestamp
.BIG_BANG
221 .equals(((ITmfEventRequest
<CtfTmfEvent
>) request
)
222 .getRange().getStartTime())
223 && (request
.getIndex() == 0)) {
224 final ITmfContext context
= seekEvent(((ITmfEventRequest
<CtfTmfEvent
>) request
)
225 .getRange().getStartTime());
226 ((ITmfEventRequest
<CtfTmfEvent
>) request
)
227 .setStartIndex((int) context
.getRank());
230 return seekEvent(request
.getIndex());
234 * The trace reader keeps its own iterator: the "context" parameter here
237 * If you wish to specify a new context, instantiate a new CtfIterator and
238 * seek() it to where you want, and use that to read events.
240 * FIXME merge with getNextEvent below once they both use the same parameter
244 public CtfTmfEvent
getNext(final ITmfContext context
) {
246 return iterator
.getCurrentEvent();
249 // ------------------------------------------------------------------------
251 // ------------------------------------------------------------------------
254 public ITmfContext
seekEvent(final ITmfLocation
<?
> location
) {
255 CtfLocation currentLocation
= (CtfLocation
) location
;
256 if (currentLocation
== null) {
257 currentLocation
= new CtfLocation(0L);
259 iterator
.setLocation(currentLocation
);
264 public double getLocationRatio(final ITmfLocation
<?
> location
) {
265 final CtfLocation curLocation
= (CtfLocation
) location
;
266 iterator
.seek(curLocation
.getLocation());
267 return ((double) iterator
.getCurrentEvent().getTimestampValue() - iterator
269 / (iterator
.getEndTime() - iterator
.getStartTime());
273 public long getStreamingInterval() {
278 public ITmfContext
seekEvent(final ITmfTimestamp timestamp
) {
279 iterator
.seek(timestamp
.getValue());
287 public ITmfContext
seekEvent(final long rank
) {
288 iterator
.setRank(rank
);
296 public ITmfContext
seekEvent(final double ratio
) {
297 iterator
.seek((long) (this.fNbEvents
* ratio
));
302 public CtfTmfEvent
readNextEvent(final ITmfContext context
) {
304 return iterator
.getCurrentEvent();
308 // public CtfTmfEvent parseEvent(final ITmfContext context) {
309 // return iterator.getCurrentEvent();
313 public IResource
getResource() {
314 return this.fResource
;
317 public StateSystem
getStateSystem() {
321 CTFTrace
getCTFTrace() {
325 protected void buildStateSystem() throws TmfTraceException
{
327 * Nothing is done in the basic implementation, please specify
328 * how/if to build a state system in derived classes.