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
22 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 // ------------------------------------------------------------------------
54 // ------------------------------------------------------------------------
56 public CtfTmfTrace() {
60 @SuppressWarnings("unused")
62 public void initTrace(String name
, String path
, Class
<CtfTmfEvent
> eventType
)
63 throws FileNotFoundException
{
65 this.fTrace
= new CTFTrace(path
);
66 } catch (CTFReaderException e
) {
68 * If it failed at the init(), we can assume it's because the file
69 * was not found or was not recognized as a CTF trace. Throw into
70 * the new type of exception expected by the rest of TMF.
72 throw new FileNotFoundException(e
.getMessage());
74 this.iterator
= new CtfIterator(this, 0, 0);
75 setStartTime(iterator
.getCurrentEvent().getTimestamp());
76 TmfSignalManager
.register(this);
77 // this.currLocation.setTimestamp(this.fEvent.getTimestamp().getValue());
78 // this.fStartTime = new TmfSimpleTimestamp(this.currLocation
79 // .getLocation().getStartTime());
80 // this.fEndTime = new TmfSimpleTimestamp(this.currLocation
81 // .getLocation().getEndTime());
82 // setTimeRange(new TmfTimeRange(this.fStartTime.clone(),
83 // this.fEndTime.clone()));
86 @SuppressWarnings("unused")
88 public void indexTrace(boolean waitForCompletion
) {
93 public void dispose() {
94 TmfSignalManager
.deregister(this);
98 public void broadcast(TmfSignal signal
) {
99 TmfSignalManager
.dispatchSignal(signal
);
102 @SuppressWarnings("unused")
104 public boolean validate(IProject project
, String path
) {
106 final CTFTrace temp
= new CTFTrace(path
);
107 return temp
.majortIsSet(); // random test
108 } catch (CTFReaderException e
) {
109 /* Nope, not a CTF trace we can read */
115 public CtfTmfTrace
clone() throws CloneNotSupportedException
{
116 CtfTmfTrace clone
= null;
117 clone
= (CtfTmfTrace
) super.clone();
118 clone
.fStartTime
= this.fStartTime
.clone();
119 clone
.fEndTime
= this.fEndTime
.clone();
120 clone
.fTrace
= this.fTrace
;
124 // ------------------------------------------------------------------------
126 // ------------------------------------------------------------------------
128 public int getNbEnvVars() {
129 return this.fTrace
.getEnvironment().size();
133 public String
[] getEnvNames() {
134 String
[] s
= new String
[getNbEnvVars()];
135 return this.fTrace
.getEnvironment().keySet().toArray(s
);
138 public String
getEnvValue(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 String temp
[] = this.fTrace
.getPath().split(
154 System
.getProperty("file.separator")); //$NON-NLS-1$
155 if (temp
.length
> 2) {
156 return temp
[temp
.length
- 1];
162 public int getIndexPageSize() {
163 return 50000; // not true, but it works
167 public long getNbEvents() {
168 return this.fNbEvents
;
172 public TmfTimeRange
getTimeRange() {
173 return new TmfTimeRange(this.fStartTime
, this.fEndTime
);
177 public ITmfTimestamp
getStartTime() {
178 return this.fStartTime
;
182 public ITmfTimestamp
getEndTime() {
183 return this.fEndTime
;
187 public ITmfLocation
<?
> getCurrentLocation() {
188 return iterator
.getLocation();
192 public long getRank(ITmfTimestamp timestamp
) {
193 ITmfContext context
= seekEvent(timestamp
);
194 return context
.getRank();
197 // ------------------------------------------------------------------------
199 // ------------------------------------------------------------------------
201 protected void setTimeRange(TmfTimeRange range
) {
202 this.fStartTime
= range
.getStartTime();
203 this.fEndTime
= range
.getEndTime();
206 protected void setStartTime(ITmfTimestamp startTime
) {
207 this.fStartTime
= startTime
;
210 protected void setEndTime(ITmfTimestamp endTime
) {
211 this.fEndTime
= endTime
;
214 // ------------------------------------------------------------------------
216 // ------------------------------------------------------------------------
219 public ITmfContext
armRequest(ITmfDataRequest
<CtfTmfEvent
> request
) {
220 if ((request
instanceof ITmfEventRequest
<?
>)
221 && !TmfTimestamp
.BIG_BANG
222 .equals(((ITmfEventRequest
<CtfTmfEvent
>) request
)
223 .getRange().getStartTime())
224 && (request
.getIndex() == 0)) {
225 ITmfContext context
= seekEvent(((ITmfEventRequest
<CtfTmfEvent
>) request
)
226 .getRange().getStartTime());
227 ((ITmfEventRequest
<CtfTmfEvent
>) request
)
228 .setStartIndex((int) context
.getRank());
231 return seekEvent(request
.getIndex());
235 * The trace reader keeps its own iterator: the "context" parameter here
238 * If you wish to specify a new context, instantiate a new CtfIterator and
239 * seek() it to where you want, and use that to read events.
241 * FIXME merge with getNextEvent below once they both use the same parameter
244 @SuppressWarnings("unused")
246 public CtfTmfEvent
getNext(ITmfContext context
) {
248 return iterator
.getCurrentEvent();
251 // ------------------------------------------------------------------------
253 // ------------------------------------------------------------------------
256 public ITmfContext
seekLocation(ITmfLocation
<?
> location
) {
257 CtfLocation currentLocation
= (CtfLocation
) location
;
258 if (currentLocation
== null) {
259 currentLocation
= new CtfLocation(0L);
261 iterator
.setLocation(currentLocation
);
266 public double getLocationRatio(ITmfLocation
<?
> location
) {
267 CtfLocation curLocation
= (CtfLocation
) location
;
268 iterator
.seek(curLocation
.getLocation());
269 return ((double) iterator
.getCurrentEvent().getTimestampValue() - iterator
271 / (iterator
.getEndTime() - iterator
.getStartTime());
275 public long getStreamingInterval() {
280 public ITmfContext
seekEvent(ITmfTimestamp timestamp
) {
281 iterator
.seek(timestamp
.getValue());
289 public ITmfContext
seekEvent(long rank
) {
290 iterator
.setRank(rank
);
298 public ITmfContext
seekLocation(double ratio
) {
299 iterator
.seek((long) (this.fNbEvents
* ratio
));
303 @SuppressWarnings("unused")
305 public CtfTmfEvent
getNextEvent(ITmfContext context
) {
307 return iterator
.getCurrentEvent();
310 @SuppressWarnings("unused")
312 public CtfTmfEvent
parseEvent(ITmfContext context
) {
313 return iterator
.getCurrentEvent();
317 public IResource
getResource() {
318 return this.fResource
;
322 public void setResource(IResource fResource
) {
323 this.fResource
= fResource
;
326 CTFTrace
getCTFTrace() {