}
public LTTngTextTrace(final IResource resource, final String path, final boolean skipIndexing) throws Exception {
- super(null, LttngEvent.class, path, 1, !skipIndexing);
+ // super(null, LttngEvent.class, path, 1, !skipIndexing);
+ super(null, LttngEvent.class, path, 1);
tracepath = path;
traceTypes = new HashMap<String, LttngEventType>();
@Override
public synchronized void initTrace(final IResource resource, final String path, final Class<LttngEvent> eventType)
throws FileNotFoundException {
- super.initTrace(resource, path, eventType);
+ super.initialize(resource, path, eventType);
+ initialize(resource, path, eventType);
+ }
+
+ @Override
+ protected synchronized void initialize(final IResource resource, final String path, final Class<LttngEvent> eventType)
+ throws FileNotFoundException {
try {
currentJniTrace = JniTraceFactory.getJniTrace(path, traceLibPath, SHOW_LTT_DEBUG_DEFAULT);
} catch (final Exception e) {
public LTTngTrace(final IResource resource, final String path, final String traceLibPath, final boolean waitForCompletion,
final boolean bypassIndexing)
throws Exception {
- super(resource, LttngEvent.class, path, CHECKPOINT_PAGE_SIZE, false);
- initTrace(resource, path, LttngEvent.class);
+ // super(resource, LttngEvent.class, path, CHECKPOINT_PAGE_SIZE, false);
+ super(resource, LttngEvent.class, path, CHECKPOINT_PAGE_SIZE);
+ initialize(resource, path, LttngEvent.class);
if (!bypassIndexing)
indexTrace(false);
this.traceLibPath = traceLibPath;
* @throws FileNotFoundException
*/
public LTTngTraceStub(final IResource resource, final int cacheSize) throws FileNotFoundException {
- super(resource, LttngEvent.class, resource.getName(), cacheSize, true);
+ // super(resource, LttngEvent.class, resource.getName(), cacheSize, true);
+ super(resource, LttngEvent.class, resource.getName(), cacheSize);
fTrace = new RandomAccessFile(resource.getName(), "r");
fParser = new LTTngEventParserStub();
- // indexTrace(true);
+ indexTrace(true);
}
// ========================================================================
* @throws FileNotFoundException
*/
public TmfTraceStub(final String path, final int cacheSize, final boolean waitForCompletion) throws FileNotFoundException {
- super(null, TmfEvent.class, path, cacheSize, false);
+ // super(null, TmfEvent.class, path, cacheSize, false);
+ super(null, TmfEvent.class, path, cacheSize);
fTrace = new RandomAccessFile(path, "r");
fParser = new TmfEventParserStub();
}
* @throws FileNotFoundException
*/
public TmfTraceStub(final String path, final int cacheSize, final boolean waitForCompletion, final ITmfEventParser<TmfEvent> parser) throws FileNotFoundException {
- super(null, TmfEvent.class, path, cacheSize, false);
+ // super(null, TmfEvent.class, path, cacheSize, false);
+ super(null, TmfEvent.class, path, cacheSize);
fTrace = new RandomAccessFile(path, "r");
fParser = parser;
}
* Copy constructor
*/
public TmfTraceStub(final TmfTraceStub trace) throws FileNotFoundException {
- super(trace.getResource(), TmfEvent.class, trace.getPath(), trace.getIndexPageSize(), false);
+ // super(trace.getResource(), TmfEvent.class, trace.getPath(), trace.getIndexPageSize(), false);
+ super(trace.getResource(), TmfEvent.class, trace.getPath(), trace.getIndexPageSize());
fTrace = new RandomAccessFile(getPath(), "r");
fParser = new TmfEventParserStub();
// This is really not pretty (the object is not constructed yet...)
@Override
@SuppressWarnings("unchecked")
public TmfContext seekLocation(final ITmfLocation<?> location) {
- fLock.lock();
try {
- if (fTrace != null) {
- // Position the trace at the requested location and
- // returns the corresponding context
- long loc = 0;
- long rank = 0;
- if (location != null) {
- loc = ((TmfLocation<Long>) location).getLocation();
- rank = ITmfContext.UNKNOWN_RANK;
+ fLock.lock();
+ try {
+ if (fTrace != null) {
+ // Position the trace at the requested location and
+ // returns the corresponding context
+ long loc = 0;
+ long rank = 0;
+ if (location != null) {
+ loc = ((TmfLocation<Long>) location).getLocation();
+ rank = ITmfContext.UNKNOWN_RANK;
+ }
+ if (loc != fTrace.getFilePointer())
+ fTrace.seek(loc);
+ final TmfContext context = new TmfContext(getCurrentLocation(), rank);
+ return context;
}
- if (loc != fTrace.getFilePointer())
- fTrace.seek(loc);
- final TmfContext context = new TmfContext(getCurrentLocation(), rank);
- return context;
+ } catch (final IOException e) {
+ e.printStackTrace();
+ } catch (final NullPointerException e) {
+ e.printStackTrace();
}
- } catch (final IOException e) {
+ } catch (final NullPointerException e) {
e.printStackTrace();
}
finally{
// this.fEndTime.clone()));
}
- @Override
- public void indexTrace(final boolean waitForCompletion) {
- // do nothing
- }
-
@Override
public void dispose() {
TmfSignalManager.deregister(this);
}
}
- @Override
- public void indexTrace(final boolean waitForCompletion) {
- if (waitForCompletion)
- initializeStreamingMonitor();
- }
-
@SuppressWarnings("unchecked")
private void indexExperiment(final boolean waitForCompletion, final int index, final TmfTimeRange timeRange) {
/**
* Position the trace at the event located at the specified ratio in the
* trace file.
- *
+ * <p>
* The notion of ratio (0.0 <= r <= 1.0) is trace specific and left
* voluntarily vague. Typically, it would refer to the event proportional
* rank (arguably more intuitive) or timestamp in the trace file.
/**
* Position the trace at the first event with the specified timestamp. If
* there is no event with the requested timestamp, a context pointing to
- * the chronologically next event is returned.
+ * the next chronological event is returned.
+ * <p>
+ * A null timestamp is interpreted as seeking for the first event of the
+ * trace.
+ * <p>
+ * If the requested timestamp is beyond the last trace event, the context
+ * returned will yield a null event if used in a subsequent read.
*
* @param timestamp the timestamp of desired event
* @return a context which can later be used to read the corresponding event
/**
* Position the trace at the 'rank'th event in the trace.
+ * <p>
+ * If the requested rank is beyond the last trace event, the context
+ * returned will yield a null event if used in a subsequent read.
*
* @param rank the event rank
* @return a context which can later be used to read the corresponding event
*/
public ITmfEvent parseEvent(ITmfContext context);
- // ------------------------------------------------------------------------
- // Indexing
- // ------------------------------------------------------------------------
-
- /**
- * Start the trace indexing, optionally wait for the index to be fully
- * built before returning.
- *
- * @param waitForCompletion true for synchronous indexing
- */
- public void indexTrace(boolean waitForCompletion);
-
-
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
/*******************************************************************************
- * Copyright (c) 2009, 2010 Ericsson
+ * Copyright (c) 2009, 2010, 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
/**
* <b><u>TmfTrace</u></b>
* <p>
- * Abstract implementation of ITmfTrace. It should be sufficient to extend this class and provide implementation for
- * <code>getCurrentLocation()</code> and <code>seekLocation()</code>, as well as a proper parser, to have a working
- * concrete implementation.
+ * Abstract implementation of ITmfTrace.
+ * <p>
+ * It should be sufficient to extend this class and provide implementations for
+ * <code>getCurrentLocation()</code> and <code>seekLocation()</code>, as well
+ * as a proper parser, to have a working concrete implementation.
*/
public abstract class TmfTrace<T extends ITmfEvent> extends TmfEventProvider<T> implements ITmfTrace<T> {
// Attributes
// ------------------------------------------------------------------------
+ // The resource used for persistent properties for this trace
+ private IResource fResource;
+
// The trace path
private String fPath;
*/
protected long fStreamingInterval = 0;
- // The resource used for persistent properties for this trace
- private IResource fResource;
-
// ------------------------------------------------------------------------
// Construction
// ------------------------------------------------------------------------
* @param type the trace event type
* @param path the trace path
* @param pageSize the trace index page size
- * @param indexTrace whether to start indexing the trace or not
* @throws FileNotFoundException
*/
- protected TmfTrace(final IResource resource, final Class<T> type, final String path, final int indexPageSize,
- final boolean indexTrace) throws FileNotFoundException {
- this(resource, type, path, 0, indexPageSize, indexTrace);
+ protected TmfTrace(final IResource resource, final Class<T> type, final String path, final int indexPageSize) throws FileNotFoundException {
+ this(resource, type, path, 0, indexPageSize);
}
/**
* @param type the trace event type
* @param path the trace path
* @param pageSize the trace index page size
- * @param indexTrace whether to start indexing the trace or not
* @throws FileNotFoundException
*/
- protected TmfTrace(final IResource resource, final Class<T> type, final String path, final long interval,
- final int indexPageSize, final boolean indexTrace) throws FileNotFoundException {
+ protected TmfTrace(final IResource resource, final Class<T> type, final String path, final long interval, final int indexPageSize) throws FileNotFoundException
+ {
super();
- initTrace(resource, path, type);
fStreamingInterval = interval;
fIndexPageSize = (indexPageSize > 0) ? indexPageSize : DEFAULT_INDEX_PAGE_SIZE;
- if (indexTrace)
- indexTrace(false);
+ initialize(resource, path, type);
}
/**
super();
if (trace == null)
throw new IllegalArgumentException();
- initTrace(trace.getResource(), trace.getPath(), trace.getType());
fStreamingInterval = getStreamingInterval();
fIndexPageSize = getIndexPageSize();
+ initialize(trace.getResource(), trace.getPath(), trace.getType());
indexTrace(false);
}
- // //
- // ------------------------------------------------------------------------
- // // Cloneable
- // //
- // ------------------------------------------------------------------------
- //
- // /* (non-Javadoc)
- // * @see java.lang.Object#clone()
- // */
- // @Override
- // @SuppressWarnings("unchecked")
- // public TmfTrace<T> clone() {
- // TmfTrace<T> clone = null;
- // try {
- // clone = (TmfTrace<T>) super.clone();
- // // clone.fTrace = fTrace;
- // // clone.fRank = fRank;
- // // clone.fTimestamp = fTimestamp != null ? fTimestamp.clone() : null;
- // // clone.fSource = fSource;
- // // clone.fType = fType != null ? fType.clone() : null;
- // // clone.fContent = fContent != null ? fContent.clone() : null;
- // // clone.fReference = fReference;
- // } catch (final CloneNotSupportedException e) {
- // }
- // return clone;
- // }
-
// ------------------------------------------------------------------------
- // ITmfTrace - initializers
+ // ITmfTrace - Initializers
// ------------------------------------------------------------------------
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#initTrace(java.lang.String
- * , java.lang.String, java.lang.Class)
+ /**
+ * @param resource
+ * @param path
+ * @param type
+ * @throws FileNotFoundException
*/
- @Override
- public void initTrace(final IResource resource, final String path, final Class<T> type) throws FileNotFoundException {
+ protected void initialize(final IResource resource, final String path, final Class<T> type) throws FileNotFoundException {
fResource = resource;
fPath = path;
String traceName = (resource != null) ? resource.getName() : null;
if (path != null) {
final int sep = path.lastIndexOf(Path.SEPARATOR);
traceName = (sep >= 0) ? path.substring(sep + 1) : path;
- } else
+ }
+ else {
traceName = ""; //$NON-NLS-1$
+ }
super.init(traceName, type);
}
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#validate(org.eclipse.
- * core.resources.IProject, java.lang.String)
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#initTrace(org.eclipse.core.resources.IResource, java.lang.String, java.lang.Class)
+ */
+ @Override
+ public void initTrace(final IResource resource, final String path, final Class<T> type) throws FileNotFoundException {
+ initialize(resource, path, type);
+ indexTrace(false);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#validate(org.eclipse.core.resources.IProject, java.lang.String)
*/
@Override
public boolean validate(final IProject project, final String path) {
}
// ------------------------------------------------------------------------
- // ITmfTrace - accessors
+ // ITmfTrace - Basic getters
// ------------------------------------------------------------------------
- /**
- * @return the trace path
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.core.component.TmfDataProvider#getType()
*/
@Override
+ @SuppressWarnings("unchecked")
public Class<T> getType() {
- return fType;
+ return (Class<T>) super.getType();
}
- /**
- * @return the trace path
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getResource()
*/
@Override
- public String getPath() {
- return fPath;
+ public IResource getResource() {
+ return fResource;
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getResource()
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getPath()
*/
@Override
- public IResource getResource() {
- return fResource;
+ public String getPath() {
+ return fPath;
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.linuxtools.tmf.stream.ITmfEventStream#getNbEvents()
+ // ------------------------------------------------------------------------
+ // ITmfTrace - Trace characteristics getters
+ // ------------------------------------------------------------------------
+
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getNbEvents()
*/
@Override
- public synchronized long getNbEvents() {
+ public long getNbEvents() {
return fNbEvents;
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.linuxtools.tmf.stream.ITmfEventStream#getTimeRange()
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getTimeRange()
*/
@Override
public TmfTimeRange getTimeRange() {
return new TmfTimeRange(fStartTime, fEndTime);
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#getStartTime()
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getStartTime()
*/
@Override
public ITmfTimestamp getStartTime() {
- return fStartTime.clone();
+ return new TmfTimestamp(fStartTime);
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#getEndTime()
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getEndTime()
*/
@Override
public ITmfTimestamp getEndTime() {
- return fEndTime.clone();
+ return new TmfTimestamp(fEndTime);
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#getStreamingInterval()
+ // ------------------------------------------------------------------------
+ // ITmfTrace - Seek operations (returning a reading context)
+ // ------------------------------------------------------------------------
+
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#seekEvent(org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp)
*/
@Override
- public long getStreamingInterval() {
- return fStreamingInterval;
+ public ITmfContext seekEvent(final ITmfTimestamp timestamp) {
+
+ // A null timestamp indicates to seek the first event
+ if (timestamp == null)
+ return seekLocation(null);
+
+ // Find the checkpoint at or before the requested timestamp.
+ // In the very likely event that the timestamp is not at a checkpoint
+ // boundary, bsearch will return index = (- (insertion point + 1)).
+ // It is then trivial to compute the index of the previous checkpoint.
+ int index = Collections.binarySearch(fCheckpoints, new TmfCheckpoint(timestamp, null));
+ if (index < 0) {
+ index = Math.max(0, -(index + 2));
+ }
+
+ // Position the trace at the checkpoint
+ final ITmfContext context = seekCheckpoint(index);
+
+ // And locate the requested event context
+ final ITmfContext nextEventContext = context.clone(); // Must use clone() to get the right subtype...
+ ITmfEvent event = getNextEvent(nextEventContext);
+ while (event != null && event.getTimestamp().compareTo(timestamp, false) < 0) {
+ context.setLocation(nextEventContext.getLocation().clone());
+ context.increaseRank();
+ event = getNextEvent(nextEventContext);
+ }
+ return context;
}
- /*
- * (non-Javadoc)
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#seekEvent(long)
+ */
+ @Override
+ public ITmfContext seekEvent(final long rank) {
+
+ // A rank <= 0 indicates to seek the first event
+ if (rank <= 0)
+ return seekLocation(null);
+
+ // Find the checkpoint at or before the requested rank.
+ final int index = (int) rank / fIndexPageSize;
+ final ITmfContext context = seekCheckpoint(index);
+
+ // And locate the requested event context
+ long pos = context.getRank();
+ if (pos < rank) {
+ ITmfEvent event = getNextEvent(context);
+ while (event != null && ++pos < rank) {
+ event = getNextEvent(context);
+ }
+ }
+ return context;
+ }
+
+
+ /**
+ * Position the trace at the given checkpoint
*
- * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getIndexPageSize()
+ * @param index the checkpoint index
+ * @return the corresponding context
+ */
+ private ITmfContext seekCheckpoint(int index) {
+ ITmfLocation<?> location;
+ synchronized (fCheckpoints) {
+ if (!fCheckpoints.isEmpty()) {
+ if (index >= fCheckpoints.size()) {
+ index = fCheckpoints.size() - 1;
+ }
+ location = fCheckpoints.elementAt(index).getLocation();
+ } else {
+ location = null;
+ }
+ }
+ final ITmfContext context = seekLocation(location);
+ context.setRank(index * fIndexPageSize);
+ return context;
+ }
+
+ // ------------------------------------------------------------------------
+ // ITmfTrace - Read operations (returning an actual event)
+ // ------------------------------------------------------------------------
+
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getNextEvent(org.eclipse.linuxtools.tmf.core.trace.ITmfContext)
*/
@Override
- public int getIndexPageSize() {
- return fIndexPageSize;
+ public synchronized ITmfEvent getNextEvent(final ITmfContext context) {
+ // parseEvent() does not update the context
+ final ITmfEvent event = parseEvent(context);
+ if (event != null) {
+ updateIndex(context, context.getRank(), event.getTimestamp());
+ context.setLocation(getCurrentLocation());
+ context.increaseRank();
+ processEvent(event);
+ }
+ return event;
+ }
+
+ /**
+ * Hook for special processing by the concrete class (called by
+ * getNextEvent())
+ *
+ * @param event
+ */
+ protected void processEvent(final ITmfEvent event) {
+ // Do nothing by default
+ }
+
+ protected synchronized void updateIndex(final ITmfContext context, final long rank, final ITmfTimestamp timestamp) {
+ if (fStartTime.compareTo(timestamp, false) > 0) {
+ fStartTime = timestamp;
+ }
+ if (fEndTime.compareTo(timestamp, false) < 0) {
+ fEndTime = timestamp;
+ }
+ if (context.hasValidRank()) {
+ if (fNbEvents <= rank) {
+ fNbEvents = rank + 1;
+ }
+ // Build the index as we go along
+ if ((rank % fIndexPageSize) == 0) {
+ // Determine the table position
+ final long position = rank / fIndexPageSize;
+ // Add new entry at proper location (if empty)
+ if (fCheckpoints.size() == position) {
+ final ITmfLocation<?> location = context.getLocation().clone();
+ fCheckpoints.add(new TmfCheckpoint(timestamp.clone(), location));
+ // System.out.println(getName() + "[" + (fCheckpoints.size() + "] " + timestamp + ", " + location.toString());
+ }
+ }
+ }
}
// ------------------------------------------------------------------------
* fIndexPageSize holds the event interval (default INDEX_PAGE_SIZE).
*/
- @Override
@SuppressWarnings({ "unchecked" })
- public void indexTrace(final boolean waitForCompletion) {
+ protected void indexTrace(final boolean waitForCompletion) {
// The monitoring job
final Job job = new Job("Indexing " + getName() + "...") { //$NON-NLS-1$ //$NON-NLS-2$
@Override
protected IStatus run(final IProgressMonitor monitor) {
- while (!monitor.isCanceled())
+ while (!monitor.isCanceled()) {
try {
Thread.sleep(100);
} catch (final InterruptedException e) {
return Status.OK_STATUS;
}
+ }
monitor.done();
return Status.OK_STATUS;
}
super.handleData(event);
if (event != null) {
final ITmfTimestamp timestamp = event.getTimestamp();
- if (startTime == null)
+ if (startTime == null) {
startTime = timestamp.clone();
+ }
lastTime = timestamp.clone();
// Update the trace status at regular intervals
- if ((getNbRead() % fIndexPageSize) == 0)
+ if ((getNbRead() % fIndexPageSize) == 0) {
updateTraceStatus();
+ }
}
}
// Submit the request and wait for completion if required
sendRequest((ITmfDataRequest<T>) request);
- if (waitForCompletion)
+ if (waitForCompletion) {
try {
request.waitForCompletion();
} catch (final InterruptedException e) {
}
+ }
}
private void notifyListeners() {
broadcast(new TmfTraceUpdatedSignal(this, this, new TmfTimeRange(fStartTime, fEndTime)));
}
- // ------------------------------------------------------------------------
- // ITmfTrace - seek operations
- // ------------------------------------------------------------------------
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#seekEvent(org.eclipse
- * .linuxtools.tmf.core.event.ITmfTimestamp)
- */
- @Override
- public ITmfContext seekEvent(final ITmfTimestamp ts) {
-
- ITmfTimestamp timestamp = ts;
- if (timestamp == null)
- timestamp = TmfTimestamp.BIG_BANG;
-
- // First, find the right checkpoint
- int index = Collections.binarySearch(fCheckpoints, new TmfCheckpoint(timestamp, null));
-
- // In the very likely case that the checkpoint was not found, bsearch
- // returns its negated would-be location (not an offset...). From that
- // index, we can then position the stream and get the event.
- if (index < 0)
- index = Math.max(0, -(index + 2));
-
- // Position the stream at the checkpoint
- ITmfLocation<?> location;
- synchronized (fCheckpoints) {
- if (!fCheckpoints.isEmpty()) {
- if (index >= fCheckpoints.size())
- index = fCheckpoints.size() - 1;
- location = fCheckpoints.elementAt(index).getLocation();
- } else
- location = null;
- }
- final ITmfContext context = seekLocation(location);
- context.setRank(index * fIndexPageSize);
-
- // And locate the event
- final ITmfContext nextEventContext = context.clone(); // Must use
- // clone() to get
- // the right
- // subtype...
- ITmfEvent event = getNextEvent(nextEventContext);
- while (event != null && event.getTimestamp().compareTo(timestamp, false) < 0) {
- context.setLocation(nextEventContext.getLocation().clone());
- context.increaseRank();
- event = getNextEvent(nextEventContext);
- }
-
- return context;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#seekEvent(long)
- */
- @Override
- public ITmfContext seekEvent(final long rank) {
-
- // Position the stream at the previous checkpoint
- int index = (int) rank / fIndexPageSize;
- ITmfLocation<?> location;
- synchronized (fCheckpoints) {
- if (fCheckpoints.isEmpty())
- location = null;
- else {
- if (index >= fCheckpoints.size())
- index = fCheckpoints.size() - 1;
- location = fCheckpoints.elementAt(index).getLocation();
- }
- }
-
- final ITmfContext context = seekLocation(location);
- long pos = index * fIndexPageSize;
- context.setRank(pos);
-
- if (pos < rank) {
- ITmfEvent event = getNextEvent(context);
- while (event != null && ++pos < rank)
- event = getNextEvent(context);
- }
-
- return context;
- }
-
- // ------------------------------------------------------------------------
- // Operations
- // ------------------------------------------------------------------------
-
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
return null;
}
+
// ------------------------------------------------------------------------
- // ITmfTrace
+ // toString
// ------------------------------------------------------------------------
/*
* (non-Javadoc)
*
- * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#getNextEvent(org.eclipse.
- * linuxtools.tmf.trace.ITmfTrace.TraceContext)
+ * @see java.lang.Object#toString()
*/
@Override
- public synchronized ITmfEvent getNextEvent(final ITmfContext context) {
- // parseEvent() does not update the context
- final ITmfEvent event = parseEvent(context);
- if (event != null) {
- updateIndex(context, context.getRank(), event.getTimestamp());
- context.setLocation(getCurrentLocation());
- context.increaseRank();
- processEvent(event);
- }
- return event;
+ @SuppressWarnings("nls")
+ public String toString() {
+ return "[TmfTrace (" + getName() + ")]";
}
- protected synchronized void updateIndex(final ITmfContext context, final long rank, final ITmfTimestamp timestamp) {
- if (fStartTime.compareTo(timestamp, false) > 0)
- fStartTime = timestamp;
- if (fEndTime.compareTo(timestamp, false) < 0)
- fEndTime = timestamp;
- if (context.hasValidRank()) {
- if (fNbEvents <= rank)
- fNbEvents = rank + 1;
- // Build the index as we go along
- if ((rank % fIndexPageSize) == 0) {
- // Determine the table position
- final long position = rank / fIndexPageSize;
- // Add new entry at proper location (if empty)
- if (fCheckpoints.size() == position) {
- final ITmfLocation<?> location = context.getLocation().clone();
- fCheckpoints.add(new TmfCheckpoint(timestamp.clone(), location));
- // System.out.println(getName() + "[" + (fCheckpoints.size()
- // - 1) + "] " + timestamp + ", " + location.toString());
- }
- }
- }
- }
+ // ------------------------------------------------------------------------
+ // ITmfTrace - Trace TBD getters
+ // ------------------------------------------------------------------------
- /**
- * Hook for special processing by the concrete class (called by
- * getNextEvent())
- *
- * @param event
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getStreamingInterval()
*/
- protected void processEvent(final ITmfEvent event) {
- // Do nothing by default
+ @Override
+ public long getStreamingInterval() {
+ return fStreamingInterval;
}
- // ------------------------------------------------------------------------
- // toString
- // ------------------------------------------------------------------------
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getIndexPageSize()
*/
@Override
- @SuppressWarnings("nls")
- public String toString() {
- return "[TmfTrace (" + getName() + ")]";
+ public int getIndexPageSize() {
+ return fIndexPageSize;
}
}
}\r
\r
public CustomTxtTrace(final IResource resource, final CustomTxtTraceDefinition definition, final String path, final int pageSize) throws FileNotFoundException {\r
- super(resource, CustomTxtEvent.class, path, (pageSize > 0) ? pageSize : DEFAULT_CACHE_SIZE, true);\r
+ super(resource, CustomTxtEvent.class, path, (pageSize > 0) ? pageSize : DEFAULT_CACHE_SIZE);\r
fDefinition = definition;\r
fEventType = new CustomTxtEventType(fDefinition);\r
}\r
BufferedRandomAccessFile raFile = null;\r
try {\r
raFile = new BufferedRandomAccessFile(getPath(), "r"); //$NON-NLS-1$\r
- if (location != null && location.getLocation() instanceof Long)\r
+ if (location != null && location.getLocation() instanceof Long) {\r
raFile.seek((Long)location.getLocation());\r
+ }\r
String line;\r
long rawPos = raFile.getFilePointer();\r
while ((line = raFile.getNextLine()) != null) {\r
e.printStackTrace();\r
return context;\r
} finally {\r
- if (raFile != null)\r
+ if (raFile != null) {\r
try {\r
raFile.close();\r
} catch (final IOException e) {\r
}\r
+ }\r
}\r
\r
}\r
long pos = (long) (ratio * raFile.length());\r
while (pos > 0) {\r
raFile.seek(pos - 1);\r
- if (raFile.read() == '\n') break;\r
+ if (raFile.read() == '\n') {\r
+ break;\r
+ }\r
pos--;\r
}\r
final ITmfLocation<?> location = new TmfLocation<Long>(pos);\r
e.printStackTrace();\r
return new CustomTxtTraceContext(NULL_LOCATION, ITmfContext.INITIAL_RANK);\r
} finally {\r
- if (raFile != null)\r
+ if (raFile != null) {\r
try {\r
raFile.close();\r
} catch (final IOException e) {\r
}\r
+ }\r
}\r
}\r
\r
} catch (final IOException e) {\r
e.printStackTrace();\r
} finally {\r
- if (raFile != null)\r
+ if (raFile != null) {\r
try {\r
raFile.close();\r
} catch (final IOException e) {\r
}\r
+ }\r
}\r
return 0;\r
}\r
\r
synchronized (context.raFile) {\r
try {\r
- if (context.raFile.getFilePointer() != context.nextLineLocation)\r
+ if (context.raFile.getFilePointer() != context.nextLineLocation) {\r
context.raFile.seek(context.nextLineLocation);\r
+ }\r
String line;\r
long rawPos = context.raFile.getFilePointer();\r
while ((line = context.raFile.getNextLine()) != null) {\r
boolean processed = false;\r
- if (currentInput == null)\r
+ if (currentInput == null) {\r
for (final InputLine input : getFirstLines()) {\r
final Matcher matcher = input.getPattern().matcher(line);\r
if (matcher.find()) {\r
return event;\r
}\r
}\r
- else {\r
+ } else {\r
if (countMap.get(currentInput) >= currentInput.getMinCount()) {\r
final List<InputLine> nextInputs = currentInput.getNextInputs(countMap);\r
- if (nextInputs.size() == 0 || nextInputs.get(nextInputs.size() - 1).getMinCount() == 0)\r
+ if (nextInputs.size() == 0 || nextInputs.get(nextInputs.size() - 1).getMinCount() == 0) {\r
for (final InputLine input : getFirstLines()) {\r
final Matcher matcher = input.getPattern().matcher(line);\r
if (matcher.find()) {\r
return event;\r
}\r
}\r
+ }\r
for (final InputLine input : nextInputs) {\r
final Matcher matcher = input.getPattern().matcher(line);\r
if (matcher.find()) {\r
event.processGroups(input, matcher);\r
currentInput = input;\r
- if (countMap.get(currentInput) == null)\r
+ if (countMap.get(currentInput) == null) {\r
countMap.put(currentInput, 1);\r
- else\r
+ } else {\r
countMap.put(currentInput, countMap.get(currentInput) + 1);\r
+ }\r
Iterator<InputLine> iter = countMap.keySet().iterator();\r
while (iter.hasNext()) {\r
final InputLine inputLine = iter.next();\r
- if (inputLine.level > currentInput.level)\r
+ if (inputLine.level > currentInput.level) {\r
iter.remove();\r
+ }\r
}\r
if (currentInput.childrenInputs != null && currentInput.childrenInputs.size() > 0) {\r
currentInput = currentInput.childrenInputs.get(0);\r
} else if (countMap.get(currentInput) >= currentInput.getMaxCount())\r
if (currentInput.getNextInputs(countMap).size() > 0) {\r
currentInput = currentInput.getNextInputs(countMap).get(0);\r
- if (countMap.get(currentInput) == null)\r
+ if (countMap.get(currentInput) == null) {\r
countMap.put(currentInput, 0);\r
+ }\r
iter = countMap.keySet().iterator();\r
while (iter.hasNext()) {\r
final InputLine inputLine = iter.next();\r
- if (inputLine.level > currentInput.level)\r
+ if (inputLine.level > currentInput.level) {\r
iter.remove();\r
+ }\r
}\r
- } else\r
+ } else {\r
currentInput = null;\r
+ }\r
processed = true;\r
break;\r
}\r
} else if (countMap.get(currentInput) >= currentInput.getMaxCount())\r
if (currentInput.getNextInputs(countMap).size() > 0) {\r
currentInput = currentInput.getNextInputs(countMap).get(0);\r
- if (countMap.get(currentInput) == null)\r
+ if (countMap.get(currentInput) == null) {\r
countMap.put(currentInput, 0);\r
+ }\r
final Iterator<InputLine> iter = countMap.keySet().iterator();\r
while (iter.hasNext()) {\r
final InputLine inputLine = iter.next();\r
- if (inputLine.level > currentInput.level)\r
+ if (inputLine.level > currentInput.level) {\r
iter.remove();\r
+ }\r
}\r
- } else\r
+ } else {\r
currentInput = null;\r
+ }\r
}\r
((StringBuffer) event.getContent().getValue()).append("\n").append(line); //$NON-NLS-1$\r
}\r
}\r
}\r
for(final Entry<InputLine, Integer> entry : countMap.entrySet())\r
- if (entry.getValue() < entry.getKey().getMinCount())\r
+ if (entry.getValue() < entry.getKey().getMinCount()) {\r
event = null;\r
+ }\r
context.setLocation(NULL_LOCATION);\r
return event;\r
}\r
}\r
\r
public CustomXmlTrace(final IResource resource, final CustomXmlTraceDefinition definition, final String path, final int pageSize) throws FileNotFoundException {\r
- super(null, CustomXmlEvent.class, path, (pageSize > 0) ? pageSize : DEFAULT_CACHE_SIZE, true);\r
+ super(null, CustomXmlEvent.class, path, (pageSize > 0) ? pageSize : DEFAULT_CACHE_SIZE);\r
fDefinition = definition;\r
fEventType = new CustomXmlEventType(fDefinition);\r
fRecordInputElement = getRecordInputElement(fDefinition.rootInputElement);\r
return context;\r
try {\r
context.raFile = new BufferedRandomAccessFile(getPath(), "r"); //$NON-NLS-1$\r
- if (location != null && location.getLocation() instanceof Long)\r
+ if (location != null && location.getLocation() instanceof Long) {\r
context.raFile.seek((Long)location.getLocation());\r
+ }\r
\r
String line;\r
final String recordElementStart = "<" + fRecordInputElement.elementName; //$NON-NLS-1$\r
long pos = (long) (ratio * raFile.length());\r
while (pos > 0) {\r
raFile.seek(pos - 1);\r
- if (raFile.read() == '\n') break;\r
+ if (raFile.read() == '\n') {\r
+ break;\r
+ }\r
pos--;\r
}\r
final ITmfLocation<?> location = new TmfLocation<Long>(pos);\r
e.printStackTrace();\r
return new CustomXmlTraceContext(NULL_LOCATION, ITmfContext.INITIAL_RANK);\r
} finally {\r
- if (raFile != null)\r
+ if (raFile != null) {\r
try {\r
raFile.close();\r
} catch (final IOException e) {\r
}\r
+ }\r
}\r
}\r
\r
} catch (final IOException e) {\r
e.printStackTrace();\r
} finally {\r
- if (raFile != null)\r
+ if (raFile != null) {\r
try {\r
raFile.close();\r
} catch (final IOException e) {\r
}\r
+ }\r
}\r
return 0;\r
}\r
CustomXmlEvent event = null;\r
try {\r
if (context.raFile.getFilePointer() != (Long)context.getLocation().getLocation() + 1)\r
+ {\r
context.raFile.seek((Long)context.getLocation().getLocation() + 1); // +1 is for the <\r
+ }\r
final StringBuffer elementBuffer = new StringBuffer("<"); //$NON-NLS-1$\r
readElement(elementBuffer, context.raFile);\r
final Element element = parseElementBuffer(elementBuffer);\r
numRead++;\r
final char c = (char)i;\r
buffer.append(c);\r
- if (c == '"')\r
+ if (c == '"') {\r
readQuote(buffer, raFile, '"');\r
- else if (c == '\'')\r
+ } else if (c == '\'') {\r
readQuote(buffer, raFile, '\'');\r
- else if (c == '<')\r
+ } else if (c == '<') {\r
readElement(buffer, raFile);\r
- else if (c == '/' && numRead == 1)\r
+ } else if (c == '/' && numRead == 1) {\r
break; // found "</"\r
- else if (c == '-' && numRead == 3 && buffer.substring(buffer.length() - 3, buffer.length() - 1).equals("!-")) //$NON-NLS-1$\r
+ } else if (c == '-' && numRead == 3 && buffer.substring(buffer.length() - 3, buffer.length() - 1).equals("!-")) {\r
readComment(buffer, raFile); // found "<!--"\r
- else if (i == '>')\r
- if (buffer.charAt(buffer.length() - 2) == '/')\r
+ } else if (i == '>')\r
+ if (buffer.charAt(buffer.length() - 2) == '/') {\r
break; // found "/>"\r
- else if (startTagClosed)\r
+ } else if (startTagClosed) {\r
break; // found "<...>...</...>"\r
- else\r
+ }\r
+ else {\r
startTagClosed = true; // found "<...>"\r
+ }\r
}\r
return;\r
} catch (final IOException e) {\r
final char c = (char)i;\r
buffer.append(c);\r
if (c == eq)\r
+ {\r
break; // found matching end-quote\r
+ }\r
}\r
return;\r
} catch (final IOException e) {\r
numRead++;\r
final char c = (char)i;\r
buffer.append(c);\r
- if (c == '>' && numRead >= 2 && buffer.substring(buffer.length() - 3, buffer.length() - 1).equals("--")) //$NON-NLS-1$\r
+ if (c == '>' && numRead >= 2 && buffer.substring(buffer.length() - 3, buffer.length() - 1).equals("--"))\r
+ {\r
break; // found "-->"\r
+ }\r
}\r
return;\r
} catch (final IOException e) {\r
for (int i = 0; i < nodeList.getLength(); i++) {\r
final Node node = nodeList.item(i);\r
if (node.getNodeType() == Node.ELEMENT_NODE) {\r
- if (separator == null)\r
+ if (separator == null) {\r
separator = " | "; //$NON-NLS-1$\r
- else\r
+ } else {\r
buffer.append(separator);\r
+ }\r
final Element element = (Element) node;\r
- if (element.hasChildNodes() == false)\r
+ if (element.hasChildNodes() == false) {\r
buffer.append(element.getNodeName());\r
- else if (element.getChildNodes().getLength() == 1 && element.getFirstChild().getNodeType() == Node.TEXT_NODE)\r
+ } else if (element.getChildNodes().getLength() == 1 && element.getFirstChild().getNodeType() == Node.TEXT_NODE) {\r
buffer.append(element.getNodeName() + ":" + element.getFirstChild().getNodeValue().trim()); //$NON-NLS-1$\r
- else {\r
+ } else {\r
buffer.append(element.getNodeName());\r
buffer.append(" [ "); //$NON-NLS-1$\r
parseElement(element, buffer);\r
buffer.append(" ]"); //$NON-NLS-1$\r
}\r
} else if (node.getNodeType() == Node.TEXT_NODE)\r
- if (node.getNodeValue().trim().length() != 0)\r
+ if (node.getNodeValue().trim().length() != 0) {\r
buffer.append(node.getNodeValue().trim());\r
+ }\r
}\r
return buffer;\r
}\r
public InputElement getRecordInputElement(final InputElement inputElement) {\r
if (inputElement.logEntry)\r
return inputElement;\r
- else if (inputElement.childElements != null)\r
+ else if (inputElement.childElements != null) {\r
for (final InputElement childInputElement : inputElement.childElements) {\r
final InputElement recordInputElement = getRecordInputElement(childInputElement);\r
if (recordInputElement != null)\r
return recordInputElement;\r
}\r
+ }\r
return null;\r
}\r
\r
}\r
\r
private void parseElement(final Element element, final CustomXmlEvent event, final InputElement inputElement) {\r
- if (inputElement.inputName != null && !inputElement.inputName.equals(CustomXmlTraceDefinition.TAG_IGNORE))\r
+ if (inputElement.inputName != null && !inputElement.inputName.equals(CustomXmlTraceDefinition.TAG_IGNORE)) {\r
event.parseInput(parseElement(element, new StringBuffer()).toString(), inputElement.inputName, inputElement.inputAction, inputElement.inputFormat);\r
- if (inputElement.attributes != null)\r
- for (final InputAttribute attribute : inputElement.attributes)\r
+ }\r
+ if (inputElement.attributes != null) {\r
+ for (final InputAttribute attribute : inputElement.attributes) {\r
event.parseInput(element.getAttribute(attribute.attributeName), attribute.inputName, attribute.inputAction, attribute.inputFormat);\r
+ }\r
+ }\r
final NodeList childNodes = element.getChildNodes();\r
- if (inputElement.childElements != null)\r
+ if (inputElement.childElements != null) {\r
for (int i = 0; i < childNodes.getLength(); i++) {\r
final Node node = childNodes.item(i);\r
- if (node instanceof Element)\r
+ if (node instanceof Element) {\r
for (final InputElement child : inputElement.childElements)\r
if (node.getNodeName().equals(child.elementName)) {\r
parseElement((Element) node, event, child);\r
break;\r
}\r
+ }\r
}\r
+ }\r
return;\r
}\r
\r
} else
activePage.openEditor(editorInput, editorId);
experiment.initTrace(null, null, null);
- experiment.indexTrace(true);
IDE.setDefaultEditor(file, editorId);
// editor should dispose the experiment on close
} else {
try {
trace.initTrace(fTrace.getResource(), fTrace.getLocation().getPath(), traceEvent.getClass());
- if (usesEditor)
- trace.indexTrace(false);
} catch (final FileNotFoundException e) {
displayErrorMsg(Messages.OpenTraceHandler_NoTrace);
return null;
throw new PartInitException(Messages.OpenTraceHandler_NoTraceType);
try {
trace.initTrace(traceElement.getResource(), traceElement.getLocation().getPath(), traceEvent.getClass());
- trace.indexTrace(false);
} catch (final FileNotFoundException e) {
}
final ITmfTrace[] traces = new ITmfTrace[] { trace };
experiment.setBookmarksFile(fFile);\r
fTrace = experiment;\r
experiment.initTrace(null, null, null);\r
- experiment.indexTrace(true);\r
break;\r
}\r
}\r
throw new PartInitException(Messages.OpenTraceHandler_NoTraceType);\r
try {\r
trace.initTrace(traceElement.getResource(), traceElement.getLocation().getPath(), traceEvent.getClass());\r
- trace.indexTrace(false);\r
} catch (final FileNotFoundException e) {\r
}\r
fTrace = trace;\r
throw new PartInitException(Messages.OpenTraceHandler_NoTraceType);\r
try {\r
trace.initTrace(traceElement.getResource(), traceElement.getLocation().getPath(), traceEvent.getClass());\r
- trace.indexTrace(false);\r
} catch (final FileNotFoundException e) {\r
}\r
fTrace = trace;\r
final TmfEvent event = (TmfEvent) ce.createExecutableExtension(TmfTraceType.EVENT_TYPE_ATTR);\r
final String path = fFile.getLocationURI().getPath();\r
fTrace.initTrace(null, path, event.getClass());\r
- fTrace.indexTrace(false);\r
break;\r
}\r
} catch (final InvalidRegistryObjectException e) {\r
// Timestamp scale (nanosecond)
public static final byte TIME_SCALE = -9;
-
+
public static final int HISTOGRAM_BAR_WIDTH = 1;
// ------------------------------------------------------------------------
// Construction
// ------------------------------------------------------------------------
- public Histogram(TmfView view, Composite parent) {
+ public Histogram(final TmfView view, final Composite parent) {
fParentView = view;
createWidget(parent);
fDataModel.removeHistogramListener(this);
}
- private void createWidget(Composite parent) {
+ private void createWidget(final Composite parent) {
final Color labelColor = parent.getBackground();
final Font fFont = adjustFont(parent);
// Define the histogram
// --------------------------------------------------------------------
- GridLayout gridLayout = new GridLayout();
+ final GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 3;
gridLayout.marginHeight = 0;
gridLayout.marginWidth = 0;
gridLayout.verticalSpacing = 0;
gridLayout.marginLeft = 0;
gridLayout.marginRight = 0;
- Composite composite = new Composite(parent, SWT.FILL);
+ final Composite composite = new Composite(parent, SWT.FILL);
composite.setLayout(gridLayout);
// Use all the horizontal space
gridData = new GridData(initalWidth, SWT.DEFAULT);
gridData.horizontalAlignment = SWT.RIGHT;
gridData.verticalAlignment = SWT.BOTTOM;
- Text dummyText = new Text(composite, SWT.READ_ONLY);
+ final Text dummyText = new Text(composite, SWT.READ_ONLY);
dummyText.setFont(fFont);
dummyText.setBackground(labelColor);
dummyText.setEditable(false);
fTimeRangeEndText.setLayoutData(gridData);
}
- private Font adjustFont(Composite composite) {
+ private Font adjustFont(final Composite composite) {
// Reduce font size for a more pleasing rendering
- int fontSizeAdjustment = -2;
- Font font = composite.getFont();
- FontData fontData = font.getFontData()[0];
+ final int fontSizeAdjustment = -2;
+ final Font font = composite.getFont();
+ final FontData fontData = font.getFontData()[0];
return new Font(font.getDevice(), fontData.getName(), fontData.getHeight() + fontSizeAdjustment, fontData.getStyle());
}
public long getTimeLimit() {
return fDataModel.getTimeLimit();
}
-
+
public HistogramDataModel getDataModel() {
return fDataModel;
}
*
* @param timestamp
*/
- public void countEvent(long eventCount, long timestamp) {
+ public void countEvent(final long eventCount, final long timestamp) {
fDataModel.countEvent(eventCount, timestamp);
}
*
* @param timestamp
*/
- public void setCurrentEvent(long timestamp) {
+ public void setCurrentEvent(final long timestamp) {
fCurrentEventTime = (timestamp > 0) ? timestamp : 0;
fDataModel.setCurrentEventNotifyListeners(timestamp);
}
* @param offset offset from the left on the histogram
* @return the start timestamp of the corresponding bucket
*/
- public synchronized long getTimestamp(int offset) {
+ public synchronized long getTimestamp(final int offset) {
assert offset > 0 && offset < fScaledData.fWidth;
try {
return fDataModel.getFirstBucketTime() + fScaledData.fBucketDuration * offset;
- } catch (Exception e) {
+ } catch (final Exception e) {
return 0; // TODO: Fix that racing condition (NPE)
}
}
* @param timestamp the timestamp
* @return the offset of the corresponding bucket (-1 if invalid)
*/
- public synchronized int getOffset(long timestamp) {
+ public synchronized int getOffset(final long timestamp) {
if (timestamp < fDataModel.getFirstBucketTime() || timestamp > fDataModel.getEndTime())
return -1;
return (int) ((timestamp - fDataModel.getFirstBucketTime()) / fScaledData.fBucketDuration);
*
* @param keyCode the SWT key code
*/
- protected void moveCursor(int keyCode) {
+ protected void moveCursor(final int keyCode) {
if (fScaledData.fCurrentBucket == HistogramScaledData.OUT_OF_RANGE_BUCKET)
return;
*/
@Override
public void modelUpdated() {
- if (!fCanvas.isDisposed() && fCanvas.getDisplay() != null) {
+ if (!fCanvas.isDisposed() && fCanvas.getDisplay() != null)
fCanvas.getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
if (!fCanvas.isDisposed()) {
// Retrieve and normalize the data
- int canvasWidth = fCanvas.getBounds().width;
- int canvasHeight = fCanvas.getBounds().height;
+ final int canvasWidth = fCanvas.getBounds().width;
+ final int canvasHeight = fCanvas.getBounds().height;
if (canvasWidth <= 0 || canvasHeight <= 0)
return;
fDataModel.setCurrentEvent(fCurrentEventTime);
fScaledData = fDataModel.scaleTo(canvasWidth, canvasHeight, HISTOGRAM_BAR_WIDTH);
- fCanvas.redraw();
- // Display histogram and update X-,Y-axis labels
- fTimeRangeStartText.setText(HistogramUtils.nanosecondsToString(fDataModel.getFirstBucketTime()));
- fTimeRangeEndText.setText(HistogramUtils.nanosecondsToString(fDataModel.getEndTime()));
- fMaxNbEventsText.setText(Long.toString(fScaledData.fMaxValue));
- // The Y-axis area might need to be re-sized
- fMaxNbEventsText.getParent().layout();
+ if (fScaledData != null) {
+ fCanvas.redraw();
+ // Display histogram and update X-,Y-axis labels
+ fTimeRangeStartText.setText(HistogramUtils.nanosecondsToString(fDataModel.getFirstBucketTime()));
+ fTimeRangeEndText.setText(HistogramUtils.nanosecondsToString(fDataModel.getEndTime()));
+ fMaxNbEventsText.setText(Long.toString(fScaledData.fMaxValue));
+ // The Y-axis area might need to be re-sized
+ fMaxNbEventsText.getParent().layout();
+ }
}
}
});
- }
}
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
private void updateCurrentEventTime() {
- long bucketStartTime = getTimestamp(fScaledData.fCurrentBucket);
+ final long bucketStartTime = getTimestamp(fScaledData.fCurrentBucket);
((HistogramView) fParentView).updateCurrentEventTime(bucketStartTime);
}
protected final String IMAGE_KEY = "double-buffer-image"; //$NON-NLS-1$
@Override
- public void paintControl(PaintEvent event) {
+ public void paintControl(final PaintEvent event) {
// Get the geometry
- int canvasWidth = fCanvas.getBounds().width;
- int canvasHeight = fCanvas.getBounds().height;
+ final int canvasWidth = fCanvas.getBounds().width;
+ final int canvasHeight = fCanvas.getBounds().height;
// Make sure we have something to draw upon
if (canvasWidth <= 0 || canvasHeight <= 0)
}
// Draw the histogram on its canvas
- GC imageGC = new GC(image);
+ final GC imageGC = new GC(image);
formatImage(imageGC, image);
event.gc.drawImage(image, 0, 0);
imageGC.dispose();
}
- private void formatImage(GC imageGC, Image image) {
+ private void formatImage(final GC imageGC, final Image image) {
if (fScaledData == null)
return;
- HistogramScaledData scaledData = new HistogramScaledData(fScaledData);
+ final HistogramScaledData scaledData = new HistogramScaledData(fScaledData);
try {
// Get drawing boundaries
- int width = image.getBounds().width;
- int height = image.getBounds().height;
+ final int width = image.getBounds().width;
+ final int height = image.getBounds().height;
// Clear the drawing area
imageGC.setBackground(fBackgroundColor);
// Draw the histogram bars
imageGC.setBackground(fHistoBarColor);
- int limit = width < scaledData.fWidth ? width : scaledData.fWidth;
+ final int limit = width < scaledData.fWidth ? width : scaledData.fWidth;
for (int i = 1; i < limit; i++) {
- int value = (int) (scaledData.fData[i] * scaledData.fScalingFactor);
+ final int value = (int) (scaledData.fData[i] * scaledData.fScalingFactor);
imageGC.fillRectangle(i, height - value, 1, value);
}
// Draw the current event bar
- int currentBucket = scaledData.fCurrentBucket;
- if (currentBucket >= 0 && currentBucket < limit) {
+ final int currentBucket = scaledData.fCurrentBucket;
+ if (currentBucket >= 0 && currentBucket < limit)
drawDelimiter(imageGC, fCurrentEventColor, height, currentBucket);
- }
// Add a dashed line as a delimiter (at the right of the last bar)
int lastEventIndex = limit - 1;
lastEventIndex--;
lastEventIndex += (lastEventIndex < limit - 1) ? 1 : 0;
drawDelimiter(imageGC, fLastEventColor, height, lastEventIndex);
- } catch (Exception e) {
+ } catch (final Exception e) {
// Do nothing
}
}
- private void drawDelimiter(GC imageGC, Color color, int height, int index) {
+ private void drawDelimiter(final GC imageGC, final Color color, final int height, final int index) {
imageGC.setBackground(color);
- int dash = height / 4;
+ final int dash = height / 4;
imageGC.fillRectangle(index, 0 * dash, 1, dash - 1);
imageGC.fillRectangle(index, 1 * dash, 1, dash - 1);
imageGC.fillRectangle(index, 2 * dash, 1, dash - 1);
// ------------------------------------------------------------------------
@Override
- public void keyPressed(KeyEvent event) {
+ public void keyPressed(final KeyEvent event) {
moveCursor(event.keyCode);
}
@Override
- public void keyReleased(KeyEvent event) {
+ public void keyReleased(final KeyEvent event) {
}
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
@Override
- public void mouseDoubleClick(MouseEvent event) {
+ public void mouseDoubleClick(final MouseEvent event) {
}
@Override
- public void mouseDown(MouseEvent event) {
+ public void mouseDown(final MouseEvent event) {
if (fDataModel.getNbEvents() > 0 && fScaledData.fLastBucket >= event.x) {
fScaledData.fCurrentBucket = event.x;
updateCurrentEventTime();
}
@Override
- public void mouseUp(MouseEvent event) {
+ public void mouseUp(final MouseEvent event) {
}
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
@Override
- public void mouseEnter(MouseEvent event) {
+ public void mouseEnter(final MouseEvent event) {
}
@Override
- public void mouseExit(MouseEvent event) {
+ public void mouseExit(final MouseEvent event) {
}
@Override
- public void mouseHover(MouseEvent event) {
+ public void mouseHover(final MouseEvent event) {
if (fDataModel.getNbEvents() > 0 && fScaledData != null && fScaledData.fLastBucket >= event.x) {
- String tooltip = formatToolTipLabel(event.x);
+ final String tooltip = formatToolTipLabel(event.x);
fCanvas.setToolTipText(tooltip);
}
}
- private String formatToolTipLabel(int index) {
+ private String formatToolTipLabel(final int index) {
long startTime = fScaledData.getBucketStartTime(fScaledData.fCurrentBucket);
- // negative values are possible if time values came into the model in decreasing order
- if (startTime < 0) {
+ // negative values are possible if time values came into the model in decreasing order
+ if (startTime < 0)
startTime = 0;
- }
- long endTime = fScaledData.getBucketEndTime(fScaledData.fCurrentBucket);
- int nbEvents = (index >= 0) ? fScaledData.fData[index] : 0;
+ final long endTime = fScaledData.getBucketEndTime(fScaledData.fCurrentBucket);
+ final int nbEvents = (index >= 0) ? fScaledData.fData[index] : 0;
- StringBuffer buffer = new StringBuffer();
+ final StringBuffer buffer = new StringBuffer();
buffer.append("Range = ["); //$NON-NLS-1$
buffer.append(HistogramUtils.nanosecondsToString(startTime));
buffer.append(","); //$NON-NLS-1$
// ------------------------------------------------------------------------
@Override
- public void controlMoved(ControlEvent event) {
+ public void controlMoved(final ControlEvent event) {
fDataModel.complete();
}
@Override
- public void controlResized(ControlEvent event) {
+ public void controlResized(final ControlEvent event) {
fDataModel.complete();
}
}