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
.trace
.ITmfContext
;
17 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfLocation
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
20 public class CtfTmfTrace
extends TmfEventProvider
<CtfTmfEvent
> implements ITmfTrace
<CtfTmfEvent
> {
22 // ------------------------------------------------------------------------
24 // ------------------------------------------------------------------------
26 // ------------------------------------------------------------------------
28 // ------------------------------------------------------------------------
31 private CTFTrace fTrace
;
33 // The number of events collected
34 protected long fNbEvents
= 0;
36 // The time span of the event stream
37 private ITmfTimestamp fStartTime
= TmfTimestamp
.BIG_CRUNCH
;
38 private ITmfTimestamp fEndTime
= TmfTimestamp
.BIG_BANG
;
41 private IResource fResource
;
44 * Since in TMF, "traces" can read events, this trace here will have its own
45 * iterator. The user can instantiate extra iterator if they want to seek at
46 * many places at the same time.
48 protected CtfIterator iterator
;
50 // ------------------------------------------------------------------------
52 // ------------------------------------------------------------------------
54 public CtfTmfTrace() {
59 public void initTrace(final IResource resource
, final String path
, final Class
<CtfTmfEvent
> eventType
)
60 throws TmfTraceException
{
61 this.fResource
= resource
;
63 this.fTrace
= new CTFTrace(path
);
64 } catch (final CTFReaderException e
) {
66 * If it failed at the init(), we can assume it's because the file
67 * was not found or was not recognized as a CTF trace. Throw into
68 * the new type of exception expected by the rest of TMF.
70 throw new TmfTraceException(e
.getMessage());
72 this.iterator
= new CtfIterator(this, 0, 0);
73 setStartTime(iterator
.getCurrentEvent().getTimestamp());
74 TmfSignalManager
.register(this);
75 // this.currLocation.setTimestamp(this.fEvent.getTimestamp().getValue());
76 // this.fStartTime = new TmfSimpleTimestamp(this.currLocation
77 // .getLocation().getStartTime());
78 // this.fEndTime = new TmfSimpleTimestamp(this.currLocation
79 // .getLocation().getEndTime());
80 // setTimeRange(new TmfTimeRange(this.fStartTime.clone(),
81 // this.fEndTime.clone()));
85 public void dispose() {
86 TmfSignalManager
.deregister(this);
90 public void broadcast(final TmfSignal signal
) {
91 TmfSignalManager
.dispatchSignal(signal
);
95 public boolean validate(final IProject project
, final String path
) {
97 final CTFTrace temp
= new CTFTrace(path
);
98 return temp
.majortIsSet(); // random test
99 } catch (final CTFReaderException e
) {
100 /* Nope, not a CTF trace we can read */
106 public CtfTmfTrace
clone() throws CloneNotSupportedException
{
107 CtfTmfTrace clone
= null;
108 clone
= (CtfTmfTrace
) super.clone();
109 clone
.fStartTime
= this.fStartTime
.clone();
110 clone
.fEndTime
= this.fEndTime
.clone();
111 clone
.fTrace
= this.fTrace
;
115 // ------------------------------------------------------------------------
117 // ------------------------------------------------------------------------
120 * @return the trace path
123 public Class
<CtfTmfEvent
> getEventType() {
127 public int getNbEnvVars() {
128 return this.fTrace
.getEnvironment().size();
132 public String
[] getEnvNames() {
133 final String
[] s
= new String
[getNbEnvVars()];
134 return this.fTrace
.getEnvironment().keySet().toArray(s
);
137 public String
getEnvValue(final String key
) {
138 return this.fTrace
.getEnvironment().get(key
);
143 * @return the trace path
146 public String
getPath() {
147 return this.fTrace
.getPath();
151 public String
getName() {
152 final String temp
[] = this.fTrace
.getPath().split(
153 System
.getProperty("file.separator")); //$NON-NLS-1$
155 return temp
[temp
.length
- 1];
160 public int getCacheSize() {
161 return 50000; // not true, but it works
165 public long getNbEvents() {
166 return this.fNbEvents
;
170 public TmfTimeRange
getTimeRange() {
171 return new TmfTimeRange(this.fStartTime
, this.fEndTime
);
175 public ITmfTimestamp
getStartTime() {
176 return this.fStartTime
;
180 public ITmfTimestamp
getEndTime() {
181 return this.fEndTime
;
185 public ITmfLocation
<?
> getCurrentLocation() {
186 return iterator
.getLocation();
189 // ------------------------------------------------------------------------
191 // ------------------------------------------------------------------------
193 protected void setTimeRange(final TmfTimeRange range
) {
194 this.fStartTime
= range
.getStartTime();
195 this.fEndTime
= range
.getEndTime();
198 protected void setStartTime(final ITmfTimestamp startTime
) {
199 this.fStartTime
= startTime
;
202 protected void setEndTime(final ITmfTimestamp endTime
) {
203 this.fEndTime
= endTime
;
206 // ------------------------------------------------------------------------
208 // ------------------------------------------------------------------------
211 public ITmfContext
armRequest(final ITmfDataRequest
<CtfTmfEvent
> request
) {
212 if ((request
instanceof ITmfEventRequest
<?
>)
213 && !TmfTimestamp
.BIG_BANG
214 .equals(((ITmfEventRequest
<CtfTmfEvent
>) request
)
215 .getRange().getStartTime())
216 && (request
.getIndex() == 0)) {
217 final ITmfContext context
= seekEvent(((ITmfEventRequest
<CtfTmfEvent
>) request
)
218 .getRange().getStartTime());
219 ((ITmfEventRequest
<CtfTmfEvent
>) request
)
220 .setStartIndex((int) context
.getRank());
223 return seekEvent(request
.getIndex());
227 * The trace reader keeps its own iterator: the "context" parameter here
230 * If you wish to specify a new context, instantiate a new CtfIterator and
231 * seek() it to where you want, and use that to read events.
233 * FIXME merge with getNextEvent below once they both use the same parameter
237 public CtfTmfEvent
getNext(final ITmfContext context
) {
239 return iterator
.getCurrentEvent();
242 // ------------------------------------------------------------------------
244 // ------------------------------------------------------------------------
247 public ITmfContext
seekEvent(final ITmfLocation
<?
> location
) {
248 CtfLocation currentLocation
= (CtfLocation
) location
;
249 if (currentLocation
== null)
250 currentLocation
= new CtfLocation(0L);
251 iterator
.setLocation(currentLocation
);
256 public double getLocationRatio(final ITmfLocation
<?
> location
) {
257 final CtfLocation curLocation
= (CtfLocation
) location
;
258 iterator
.seek(curLocation
.getLocation());
259 return ((double) iterator
.getCurrentEvent().getTimestampValue() - iterator
261 / (iterator
.getEndTime() - iterator
.getStartTime());
265 public long getStreamingInterval() {
270 public ITmfContext
seekEvent(final ITmfTimestamp timestamp
) {
271 iterator
.seek(timestamp
.getValue());
279 public ITmfContext
seekEvent(final long rank
) {
280 iterator
.setRank(rank
);
288 public ITmfContext
seekEvent(final double ratio
) {
289 iterator
.seek((long) (this.fNbEvents
* ratio
));
294 public CtfTmfEvent
readNextEvent(final ITmfContext context
) {
296 return iterator
.getCurrentEvent();
300 // public CtfTmfEvent parseEvent(final ITmfContext context) {
301 // return iterator.getCurrentEvent();
305 public IResource
getResource() {
306 return this.fResource
;
309 CTFTrace
getCTFTrace() {