X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=org.eclipse.linuxtools.tmf.core%2Fsrc%2Forg%2Feclipse%2Flinuxtools%2Ftmf%2Fcore%2Fctfadaptor%2FCtfTmfTrace.java;h=be3f94d45792899f06e4a2e407a6d41bccbd3b9c;hb=4a1108602318db28683d50e17642d73074a10c1b;hp=3ed9a41b10f3015b4a30d5c9a91dda9bc9f21c68;hpb=a1a24d68af309c40728b2043638f47552c41a156;p=deliverable%2Ftracecompass.git diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java index 3ed9a41b10..be3f94d457 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java @@ -1,95 +1,112 @@ +/******************************************************************************* + * Copyright (c) 2012 Ericsson + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: Matthew Khouzam - Initial API and implementation + *******************************************************************************/ + + package org.eclipse.linuxtools.tmf.core.ctfadaptor; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; +import org.eclipse.linuxtools.ctf.core.event.EventDeclaration; +import org.eclipse.linuxtools.ctf.core.event.EventDefinition; import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException; import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; -import org.eclipse.linuxtools.tmf.core.component.TmfEventProvider; -import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; -import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange; +import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTimestamp.TimestampType; +import org.eclipse.linuxtools.tmf.core.event.ITmfEventField; import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; -import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest; -import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest; -import org.eclipse.linuxtools.tmf.core.signal.TmfSignal; -import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager; import org.eclipse.linuxtools.tmf.core.statesystem.IStateSystemQuerier; import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; +import org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser; import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation; -import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; - -public class CtfTmfTrace extends TmfEventProvider implements ITmfTrace { - - // ------------------------------------------------------------------------ - // Constants - // ------------------------------------------------------------------------ - - // ------------------------------------------------------------------------ - // Attributes - // ------------------------------------------------------------------------ +import org.eclipse.linuxtools.tmf.core.trace.TmfTrace; - // the Ctf Trace - private CTFTrace fTrace; - - // The number of events collected - protected long fNbEvents = 0; - - // The time span of the event stream - private ITmfTimestamp fStartTime = TmfTimestamp.BIG_CRUNCH; - private ITmfTimestamp fEndTime = TmfTimestamp.BIG_BANG; +public class CtfTmfTrace extends TmfTrace implements ITmfEventParser{ - // The trace resource - private IResource fResource; - - /* - * Since in TMF, "traces" can read events, this trace here will have its own - * iterator. The user can instantiate extra iterator if they want to seek at - * many places at the same time. + //------------------------------------------- + // Constants + //------------------------------------------- + /** + * Default cache size for CTF traces */ - protected CtfIterator iterator; + protected static final int DEFAULT_CACHE_SIZE = 50000; + + //------------------------------------------- + // Fields + //------------------------------------------- - /* Reference to the state system assigned to this trace */ + /** Reference to the state system assigned to this trace */ protected IStateSystemQuerier ss = null; - // ------------------------------------------------------------------------ - // Constructors - // ------------------------------------------------------------------------ - - public CtfTmfTrace() { - super(); - } + /* Reference to the CTF Trace */ + private CTFTrace fTrace; - @SuppressWarnings("unused") + //------------------------------------------- + // TmfTrace Overrides + //------------------------------------------- + /** + * Method initTrace. + * @param resource IResource + * @param path String + * @param eventType Class + * @throws TmfTraceException + * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#initTrace(IResource, String, Class) + */ @Override public void initTrace(final IResource resource, final String path, final Class eventType) throws TmfTraceException { - this.fResource = resource; + /* + * Set the cache size. This has to be done before the call to super() + * because the super needs to know the cache size. + */ + setCacheSize(); + super.initTrace(resource, path, eventType); + EventDeclaration ed; + ITmfEventField eventField; + + @SuppressWarnings("unused") + CtfTmfEventType type; + try { this.fTrace = new CTFTrace(path); + for( int i =0 ; i< this.fTrace.getNbEventTypes(); i++) { + ed = this.fTrace.getEventType(i); + eventField = parseDeclaration(ed); + /* + * Populate the event manager with event types that are there in + * the beginning. + */ + type = new CtfTmfEventType(ed.getName(), eventField); + } + + /* Set the start and (current) end times for this trace */ + final CtfIterator iterator = new CtfIterator(this, 0, 0); + if(iterator.getLocation().equals(CtfIterator.NULL_LOCATION)) { + /* Handle the case where the trace is empty */ + this.setStartTime(TmfTimestamp.BIG_BANG); + } else { + this.setStartTime(iterator.getCurrentEvent().getTimestamp()); + this.setEndTime(iterator.getCurrentEvent().getTimestamp()); + } + } catch (final CTFReaderException e) { /* * If it failed at the init(), we can assume it's because the file * was not found or was not recognized as a CTF trace. Throw into * the new type of exception expected by the rest of TMF. */ - throw new TmfTraceException(e.getMessage()); + throw new TmfTraceException(e.getMessage(), e); } - this.iterator = new CtfIterator(this, 0, 0); - setStartTime(TmfTimestamp.BIG_BANG); - if( !this.iterator.getLocation().equals(CtfIterator.nullLocation)) { - setStartTime(iterator.getCurrentEvent().getTimestamp()); - } - TmfSignalManager.register(this); - // this.currLocation.setTimestamp(this.fEvent.getTimestamp().getValue()); - // this.fStartTime = new TmfSimpleTimestamp(this.currLocation - // .getLocation().getStartTime()); - // this.fEndTime = new TmfSimpleTimestamp(this.currLocation - // .getLocation().getEndTime()); - // setTimeRange(new TmfTimeRange(this.fStartTime.clone(), - // this.fEndTime.clone())); + //FIXME This should be called via the ExperimentUpdated signal buildStateSystem(); /* Refresh the project, so it can pick up new files that got created. */ @@ -97,24 +114,20 @@ public class CtfTmfTrace extends TmfEventProvider implements ITmfTr try { resource.getProject().refreshLocal(IResource.DEPTH_INFINITE, null); } catch (CoreException e) { - throw new TmfTraceException(e.getMessage()); + throw new TmfTraceException(e.getMessage(), e); } } } + /** + * Method validate. + * @param project IProject + * @param path String + * @return boolean + * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#validate(IProject, String) + */ @Override - public void dispose() { - TmfSignalManager.deregister(this); - } - - @Override - public void broadcast(final TmfSignal signal) { - TmfSignalManager.dispatchSignal(signal); - } - - @SuppressWarnings("unused") - @Override - public boolean validate(final IProject project, final String path) { + public boolean validate(@SuppressWarnings("unused") final IProject project, final String path) { try { final CTFTrace temp = new CTFTrace(path); return temp.majortIsSet(); // random test @@ -124,233 +137,195 @@ public class CtfTmfTrace extends TmfEventProvider implements ITmfTr } } - @Override - public CtfTmfTrace clone() throws CloneNotSupportedException { - CtfTmfTrace clone = null; - clone = (CtfTmfTrace) super.clone(); - clone.fStartTime = this.fStartTime.clone(); - clone.fEndTime = this.fEndTime.clone(); - clone.fTrace = this.fTrace; - return clone; - } - - // ------------------------------------------------------------------------ - // Accessors - // ------------------------------------------------------------------------ - /** - * @return the trace path + * Method getCurrentLocation. This is not applicable in CTF + * @return null, since the trace has no knowledge of the current location + * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getCurrentLocation() */ @Override - public Class getEventType() { - return fType; - } - - public int getNbEnvVars() { - return this.fTrace.getEnvironment().size(); + public ITmfLocation getCurrentLocation() { + return null; } - public String[] getEnvNames() { - final String[] s = new String[getNbEnvVars()]; - return this.fTrace.getEnvironment().keySet().toArray(s); - } - public String getEnvValue(final String key) { - return this.fTrace.getEnvironment().get(key); + @Override + public double getLocationRatio(ITmfLocation location) { + final CtfLocation curLocation = (CtfLocation) location; + CtfIterator iterator = new CtfIterator(this); + iterator.seek(curLocation.getLocation()); + return ((double) iterator.getCurrentEvent().getTimestampValue() - iterator + .getStartTime()) + / (iterator.getEndTime() - iterator.getStartTime()); } - /** - * @return the trace path + * Method seekEvent. + * @param location ITmfLocation + * @return ITmfContext + * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#seekEvent(ITmfLocation) */ @Override - public String getPath() { - return this.fTrace.getPath(); - } - - @Override - public String getName() { - String traceName = (fResource != null) ? fResource.getName() : null; - // If no resource was provided, extract the display name the trace path - if (traceName == null) { - final String path = this.fTrace.getPath(); - final int sep = path.lastIndexOf(IPath.SEPARATOR); - traceName = (sep >= 0) ? path.substring(sep + 1) : path; + public ITmfContext seekEvent(final ITmfLocation location) { + CtfLocation currentLocation = (CtfLocation) location; + CtfIterator context = new CtfIterator(this); + /* + * The rank is set to 0 if the iterator seeks the beginning. If not, it + * will be set to UNKNOWN_RANK, since CTF traces don't support seeking + * by rank for now. + */ + if (currentLocation == null) { + currentLocation = new CtfLocation(0L); + context.setRank(0); } - return traceName; - } - - @Override - public int getCacheSize() { - return 50000; // not true, but it works - } - - @Override - public long getNbEvents() { - return this.fNbEvents; - } - - @Override - public TmfTimeRange getTimeRange() { - return new TmfTimeRange(this.fStartTime, this.fEndTime); + if (currentLocation.getLocation() == CtfLocation.INVALID_LOCATION) { + ((CtfTmfTimestamp) getEndTime()).setType(TimestampType.NANOS); + currentLocation.setLocation(getEndTime().getValue() + 1); + } + context.setLocation(currentLocation); + if(context.getRank() != 0) + context.setRank(ITmfContext.UNKNOWN_RANK); + return context; } - @Override - public ITmfTimestamp getStartTime() { - return this.fStartTime; - } @Override - public ITmfTimestamp getEndTime() { - return this.fEndTime; + public ITmfContext seekEvent(double ratio) { + CtfIterator context = new CtfIterator(this); + context.seek((long) (this.getNbEvents() * ratio)); + context.setRank(ITmfContext.UNKNOWN_RANK); + return context; } + /** + * Method readNextEvent. + * @param context ITmfContext + * @return CtfTmfEvent + * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getNext(ITmfContext) + */ @Override - public ITmfLocation getCurrentLocation() { - return iterator.getLocation(); - } - - // ------------------------------------------------------------------------ - // Operators - // ------------------------------------------------------------------------ - - protected void setTimeRange(final TmfTimeRange range) { - this.fStartTime = range.getStartTime(); - this.fEndTime = range.getEndTime(); - } - - protected void setStartTime(final ITmfTimestamp startTime) { - this.fStartTime = startTime; - } + public synchronized CtfTmfEvent getNext(final ITmfContext context) { + CtfTmfEvent event = null; + if (context instanceof CtfIterator) { + CtfIterator ctfIterator = (CtfIterator) context; + event = ctfIterator.getCurrentEvent(); + + if (event != null) { + updateAttributes(context, event.getTimestamp()); + ctfIterator.advance(); + ctfIterator.increaseRank(); + } + } - protected void setEndTime(final ITmfTimestamp endTime) { - this.fEndTime = endTime; + return event; } - // ------------------------------------------------------------------------ - // TmfProvider - // ------------------------------------------------------------------------ - - @Override - public ITmfContext armRequest(final ITmfDataRequest request) { - if ((request instanceof ITmfEventRequest) - && !TmfTimestamp.BIG_BANG - .equals(((ITmfEventRequest) request) - .getRange().getStartTime()) - && (request.getIndex() == 0)) { - final ITmfContext context = seekEvent(((ITmfEventRequest) request) - .getRange().getStartTime()); - ((ITmfEventRequest) request) - .setStartIndex((int) context.getRank()); - return context; - } - return seekEvent(request.getIndex()); + /** + * Suppressing the warning, because the 'throws' will usually happen in + * sub-classes. + * @throws TmfTraceException + */ + @SuppressWarnings({ "static-method", "unused" }) + protected void buildStateSystem() throws TmfTraceException { + /* + * Nothing is done in the basic implementation, please specify + * how/if to build a state system in derived classes. + */ + return; } /** - * The trace reader keeps its own iterator: the "context" parameter here - * will be ignored. + * Method getStateSystem. * - * If you wish to specify a new context, instantiate a new CtfIterator and - * seek() it to where you want, and use that to read events. - * - * FIXME merge with getNextEvent below once they both use the same parameter - * type. + * @return IStateSystemQuerier */ - @SuppressWarnings("unused") - @Override - public CtfTmfEvent getNext(final ITmfContext context) { - iterator.advance(); - return iterator.getCurrentEvent(); + public IStateSystemQuerier getStateSystem() { + return this.ss; } - // ------------------------------------------------------------------------ - // ITmfTrace - // ------------------------------------------------------------------------ - - @Override - public ITmfContext seekEvent(final ITmfLocation location) { - CtfLocation currentLocation = (CtfLocation) location; - if (currentLocation == null) { - currentLocation = new CtfLocation(0L); - } - if( !iterator.getLocation().equals(CtfIterator.nullLocation)) { - iterator.setLocation(currentLocation); - } - return iterator; + /** + * + * @param ed + * @return + */ + private static ITmfEventField parseDeclaration(EventDeclaration ed) { + EventDefinition eventDef = ed.createDefinition(null); + return new CtfTmfContent(ITmfEventField.ROOT_FIELD_ID, + CtfTmfEvent.parseFields(eventDef)); } - @Override - public double getLocationRatio(final ITmfLocation location) { - final CtfLocation curLocation = (CtfLocation) location; - iterator.seek(curLocation.getLocation()); - return ((double) iterator.getCurrentEvent().getTimestampValue() - iterator - .getStartTime()) - / (iterator.getEndTime() - iterator.getStartTime()); + /** + * gets the CTFtrace that this is wrapping + * @return the CTF trace + */ + public CTFTrace getCTFTrace() { + return fTrace; } - @Override - public long getStreamingInterval() { - return 0; - } - @Override - public ITmfContext seekEvent(final ITmfTimestamp timestamp) { - iterator.seek(timestamp.getValue()); - return iterator; + //------------------------------------------- + // Environment Parameters + //------------------------------------------- + /** + * Method getNbEnvVars. + * + * @return int + */ + public int getNbEnvVars() { + return this.fTrace.getEnvironment().size(); } /** - * Seek by rank + * Method getEnvNames. + * + * @return String[] */ - @Override - public ITmfContext seekEvent(final long rank) { - iterator.setRank(rank); - return iterator; + public String[] getEnvNames() { + final String[] s = new String[getNbEnvVars()]; + return this.fTrace.getEnvironment().keySet().toArray(s); } /** - * Seek rank ratio + * Method getEnvValue. + * + * @param key + * String + * @return String */ - @Override - public ITmfContext seekEvent(final double ratio) { - iterator.seek((long) (this.fNbEvents * ratio)); - return iterator; + public String getEnvValue(final String key) { + return this.fTrace.getEnvironment().get(key); } - @SuppressWarnings("unused") - @Override - public CtfTmfEvent readNextEvent(final ITmfContext context) { - iterator.advance(); - return iterator.getCurrentEvent(); - } + //------------------------------------------- + // Clocks + //------------------------------------------- - @Override - public IResource getResource() { - return this.fResource; + public long getOffset(){ + if( fTrace != null ) { + return fTrace.getOffset(); + } + return 0; } - public IStateSystemQuerier getStateSystem() { - return this.ss; - } + //------------------------------------------- + // Parser + //------------------------------------------- - CTFTrace getCTFTrace() { - return fTrace; + @Override + public CtfTmfEvent parseEvent(ITmfContext context) { + CtfTmfEvent event = null; + if( context instanceof CtfIterator ){ + CtfIterator itt = (CtfIterator) context; + event = itt.getCurrentEvent(); + } + return event; } - - + /** - * Suppressing the warning, because the 'throws' will usually happen in - * sub-classes. + * Sets the cache size for a CtfTmfTrace. */ - @SuppressWarnings({ "unused", "static-method" }) - protected void buildStateSystem() throws TmfTraceException { - /* - * Nothing is done in the basic implementation, please specify - * how/if to build a state system in derived classes. - */ - return; + protected void setCacheSize() { + setCacheSize(DEFAULT_CACHE_SIZE); } }