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
.core
.runtime
.CoreException
;
6 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFReaderException
;
7 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.CTFTrace
;
8 import org
.eclipse
.linuxtools
.tmf
.core
.component
.TmfEventProvider
;
9 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfTimestamp
;
10 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimeRange
;
11 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimestamp
;
12 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TmfTraceException
;
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
.statesystem
.StateSystem
;
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
;
22 public class CtfTmfTrace
extends TmfEventProvider
<CtfTmfEvent
> implements ITmfTrace
<CtfTmfEvent
> {
24 // ------------------------------------------------------------------------
26 // ------------------------------------------------------------------------
28 // ------------------------------------------------------------------------
30 // ------------------------------------------------------------------------
33 private CTFTrace fTrace
;
35 // The number of events collected
36 protected long fNbEvents
= 0;
38 // The time span of the event stream
39 private ITmfTimestamp fStartTime
= TmfTimestamp
.BIG_CRUNCH
;
40 private ITmfTimestamp fEndTime
= TmfTimestamp
.BIG_BANG
;
43 private IResource fResource
;
46 * Since in TMF, "traces" can read events, this trace here will have its own
47 * iterator. The user can instantiate extra iterator if they want to seek at
48 * many places at the same time.
50 protected CtfIterator iterator
;
52 /* Reference to the state system assigned to this trace */
53 protected StateSystem ss
= null;
55 // ------------------------------------------------------------------------
57 // ------------------------------------------------------------------------
59 public CtfTmfTrace() {
64 public void initTrace(final IResource resource
, final String path
, final Class
<CtfTmfEvent
> eventType
)
65 throws TmfTraceException
{
66 this.fResource
= resource
;
68 this.fTrace
= new CTFTrace(path
);
69 } catch (final CTFReaderException e
) {
71 * If it failed at the init(), we can assume it's because the file
72 * was not found or was not recognized as a CTF trace. Throw into
73 * the new type of exception expected by the rest of TMF.
75 throw new TmfTraceException(e
.getMessage());
77 this.iterator
= new CtfIterator(this, 0, 0);
78 setStartTime(iterator
.getCurrentEvent().getTimestamp());
79 TmfSignalManager
.register(this);
80 // this.currLocation.setTimestamp(this.fEvent.getTimestamp().getValue());
81 // this.fStartTime = new TmfSimpleTimestamp(this.currLocation
82 // .getLocation().getStartTime());
83 // this.fEndTime = new TmfSimpleTimestamp(this.currLocation
84 // .getLocation().getEndTime());
85 // setTimeRange(new TmfTimeRange(this.fStartTime.clone(),
86 // this.fEndTime.clone()));
90 /* Refresh the project, so it can pick up new files that got created. */
91 if ( resource
!= null) {
93 resource
.getProject().refreshLocal(IResource
.DEPTH_INFINITE
, null);
94 } catch (CoreException e
) {
95 throw new TmfTraceException(e
.getMessage());
101 public void dispose() {
102 TmfSignalManager
.deregister(this);
106 public void broadcast(final TmfSignal signal
) {
107 TmfSignalManager
.dispatchSignal(signal
);
111 public boolean validate(final IProject project
, final String path
) {
113 final CTFTrace temp
= new CTFTrace(path
);
114 return temp
.majortIsSet(); // random test
115 } catch (final CTFReaderException e
) {
116 /* Nope, not a CTF trace we can read */
122 public CtfTmfTrace
clone() throws CloneNotSupportedException
{
123 CtfTmfTrace clone
= null;
124 clone
= (CtfTmfTrace
) super.clone();
125 clone
.fStartTime
= this.fStartTime
.clone();
126 clone
.fEndTime
= this.fEndTime
.clone();
127 clone
.fTrace
= this.fTrace
;
131 // ------------------------------------------------------------------------
133 // ------------------------------------------------------------------------
136 * @return the trace path
139 public Class
<CtfTmfEvent
> getEventType() {
143 public int getNbEnvVars() {
144 return this.fTrace
.getEnvironment().size();
148 public String
[] getEnvNames() {
149 final String
[] s
= new String
[getNbEnvVars()];
150 return this.fTrace
.getEnvironment().keySet().toArray(s
);
153 public String
getEnvValue(final String key
) {
154 return this.fTrace
.getEnvironment().get(key
);
159 * @return the trace path
162 public String
getPath() {
163 return this.fTrace
.getPath();
167 public String
getName() {
168 final String temp
[] = this.fTrace
.getPath().split(
169 System
.getProperty("file.separator")); //$NON-NLS-1$
170 if (temp
.length
> 2) {
171 return temp
[temp
.length
- 1];
177 public int getCacheSize() {
178 return 50000; // not true, but it works
182 public long getNbEvents() {
183 return this.fNbEvents
;
187 public TmfTimeRange
getTimeRange() {
188 return new TmfTimeRange(this.fStartTime
, this.fEndTime
);
192 public ITmfTimestamp
getStartTime() {
193 return this.fStartTime
;
197 public ITmfTimestamp
getEndTime() {
198 return this.fEndTime
;
202 public ITmfLocation
<?
> getCurrentLocation() {
203 return iterator
.getLocation();
206 // ------------------------------------------------------------------------
208 // ------------------------------------------------------------------------
210 protected void setTimeRange(final TmfTimeRange range
) {
211 this.fStartTime
= range
.getStartTime();
212 this.fEndTime
= range
.getEndTime();
215 protected void setStartTime(final ITmfTimestamp startTime
) {
216 this.fStartTime
= startTime
;
219 protected void setEndTime(final ITmfTimestamp endTime
) {
220 this.fEndTime
= endTime
;
223 // ------------------------------------------------------------------------
225 // ------------------------------------------------------------------------
228 public ITmfContext
armRequest(final ITmfDataRequest
<CtfTmfEvent
> request
) {
229 if ((request
instanceof ITmfEventRequest
<?
>)
230 && !TmfTimestamp
.BIG_BANG
231 .equals(((ITmfEventRequest
<CtfTmfEvent
>) request
)
232 .getRange().getStartTime())
233 && (request
.getIndex() == 0)) {
234 final ITmfContext context
= seekEvent(((ITmfEventRequest
<CtfTmfEvent
>) request
)
235 .getRange().getStartTime());
236 ((ITmfEventRequest
<CtfTmfEvent
>) request
)
237 .setStartIndex((int) context
.getRank());
240 return seekEvent(request
.getIndex());
244 * The trace reader keeps its own iterator: the "context" parameter here
247 * If you wish to specify a new context, instantiate a new CtfIterator and
248 * seek() it to where you want, and use that to read events.
250 * FIXME merge with getNextEvent below once they both use the same parameter
254 public CtfTmfEvent
getNext(final ITmfContext context
) {
256 return iterator
.getCurrentEvent();
259 // ------------------------------------------------------------------------
261 // ------------------------------------------------------------------------
264 public ITmfContext
seekEvent(final ITmfLocation
<?
> location
) {
265 CtfLocation currentLocation
= (CtfLocation
) location
;
266 if (currentLocation
== null) {
267 currentLocation
= new CtfLocation(0L);
269 iterator
.setLocation(currentLocation
);
274 public double getLocationRatio(final ITmfLocation
<?
> location
) {
275 final CtfLocation curLocation
= (CtfLocation
) location
;
276 iterator
.seek(curLocation
.getLocation());
277 return ((double) iterator
.getCurrentEvent().getTimestampValue() - iterator
279 / (iterator
.getEndTime() - iterator
.getStartTime());
283 public long getStreamingInterval() {
288 public ITmfContext
seekEvent(final ITmfTimestamp timestamp
) {
289 iterator
.seek(timestamp
.getValue());
297 public ITmfContext
seekEvent(final long rank
) {
298 iterator
.setRank(rank
);
306 public ITmfContext
seekEvent(final double ratio
) {
307 iterator
.seek((long) (this.fNbEvents
* ratio
));
312 public CtfTmfEvent
readNextEvent(final ITmfContext context
) {
314 return iterator
.getCurrentEvent();
318 // public CtfTmfEvent parseEvent(final ITmfContext context) {
319 // return iterator.getCurrentEvent();
323 public IResource
getResource() {
324 return this.fResource
;
327 public StateSystem
getStateSystem() {
331 CTFTrace
getCTFTrace() {
335 protected void buildStateSystem() throws TmfTraceException
{
337 * Nothing is done in the basic implementation, please specify
338 * how/if to build a state system in derived classes.