From 09e864961e8d654f64eb07270a0df9beab6b3b9f Mon Sep 17 00:00:00 2001 From: Francois Chouinard Date: Wed, 18 Apr 2012 17:52:54 -0400 Subject: [PATCH] Refactor TmfTrace and dependencies - remove indexTrace() --- .../lttng/core/trace/LTTngTextTrace.java | 3 +- .../internal/lttng/core/trace/LTTngTrace.java | 13 +- .../internal/lttng/stubs/LTTngTraceStub.java | 5 +- .../tmf/tests/stubs/trace/TmfTraceStub.java | 43 +- .../tmf/core/ctfadaptor/CtfTmfTrace.java | 5 - .../tmf/core/experiment/TmfExperiment.java | 6 - .../linuxtools/tmf/core/trace/ITmfTrace.java | 26 +- .../linuxtools/tmf/core/trace/TmfTrace.java | 480 ++++++++---------- .../tmf/ui/parsers/custom/CustomTxtTrace.java | 57 ++- .../tmf/ui/parsers/custom/CustomXmlTrace.java | 75 ++- .../handlers/OpenExperimentHandler.java | 1 - .../ui/project/handlers/OpenTraceHandler.java | 2 - .../tmf/ui/editors/EventsViewEditor.java | 1 - .../tmf/ui/editors/TmfEventsEditor.java | 4 - .../tmf/ui/views/histogram/Histogram.java | 125 +++-- 15 files changed, 422 insertions(+), 424 deletions(-) diff --git a/org.eclipse.linuxtools.lttng.core/src/org/eclipse/linuxtools/internal/lttng/core/trace/LTTngTextTrace.java b/org.eclipse.linuxtools.lttng.core/src/org/eclipse/linuxtools/internal/lttng/core/trace/LTTngTextTrace.java index 82f4c60281..12ee63d012 100644 --- a/org.eclipse.linuxtools.lttng.core/src/org/eclipse/linuxtools/internal/lttng/core/trace/LTTngTextTrace.java +++ b/org.eclipse.linuxtools.lttng.core/src/org/eclipse/linuxtools/internal/lttng/core/trace/LTTngTextTrace.java @@ -57,7 +57,8 @@ public class LTTngTextTrace extends TmfTrace { } 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(); diff --git a/org.eclipse.linuxtools.lttng.core/src/org/eclipse/linuxtools/internal/lttng/core/trace/LTTngTrace.java b/org.eclipse.linuxtools.lttng.core/src/org/eclipse/linuxtools/internal/lttng/core/trace/LTTngTrace.java index bef92c2c70..83d48c5589 100644 --- a/org.eclipse.linuxtools.lttng.core/src/org/eclipse/linuxtools/internal/lttng/core/trace/LTTngTrace.java +++ b/org.eclipse.linuxtools.lttng.core/src/org/eclipse/linuxtools/internal/lttng/core/trace/LTTngTrace.java @@ -116,7 +116,13 @@ public class LTTngTrace extends TmfTrace { @Override public synchronized void initTrace(final IResource resource, final String path, final Class 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 eventType) + throws FileNotFoundException { try { currentJniTrace = JniTraceFactory.getJniTrace(path, traceLibPath, SHOW_LTT_DEBUG_DEFAULT); } catch (final Exception e) { @@ -288,8 +294,9 @@ public class LTTngTrace extends TmfTrace { 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; diff --git a/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/internal/lttng/stubs/LTTngTraceStub.java b/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/internal/lttng/stubs/LTTngTraceStub.java index c6cd728554..be33a23094 100644 --- a/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/internal/lttng/stubs/LTTngTraceStub.java +++ b/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/internal/lttng/stubs/LTTngTraceStub.java @@ -64,10 +64,11 @@ public class LTTngTraceStub extends TmfTrace { * @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); } // ======================================================================== diff --git a/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/trace/TmfTraceStub.java b/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/trace/TmfTraceStub.java index b1e62ac2cd..c28cbe01d8 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/trace/TmfTraceStub.java +++ b/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/trace/TmfTraceStub.java @@ -86,7 +86,8 @@ public class TmfTraceStub extends TmfTrace { * @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(); } @@ -100,7 +101,8 @@ public class TmfTraceStub extends TmfTrace { * @throws FileNotFoundException */ public TmfTraceStub(final String path, final int cacheSize, final boolean waitForCompletion, final ITmfEventParser 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; } @@ -109,7 +111,8 @@ public class TmfTraceStub extends TmfTrace { * 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...) @@ -145,23 +148,29 @@ public class TmfTraceStub extends TmfTrace { @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) 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) 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{ 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 15adda286c..bfcd90e6e0 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 @@ -82,11 +82,6 @@ public class CtfTmfTrace extends TmfEventProvider implements ITmfTr // this.fEndTime.clone())); } - @Override - public void indexTrace(final boolean waitForCompletion) { - // do nothing - } - @Override public void dispose() { TmfSignalManager.deregister(this); diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperiment.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperiment.java index 3af5ebf15e..bdb48815ae 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperiment.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/experiment/TmfExperiment.java @@ -750,12 +750,6 @@ public class TmfExperiment extends TmfEventProvider impl } } - @Override - public void indexTrace(final boolean waitForCompletion) { - if (waitForCompletion) - initializeStreamingMonitor(); - } - @SuppressWarnings("unchecked") private void indexExperiment(final boolean waitForCompletion, final int index, final TmfTimeRange timeRange) { diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTrace.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTrace.java index 490a8ccbeb..c1ee9be3e7 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTrace.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTrace.java @@ -190,7 +190,7 @@ public interface ITmfTrace extends ITmfDataProvider { /** * Position the trace at the event located at the specified ratio in the * trace file. - * + *

* 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. @@ -203,7 +203,13 @@ public interface ITmfTrace extends ITmfDataProvider { /** * 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. + *

+ * A null timestamp is interpreted as seeking for the first event of the + * trace. + *

+ * 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 @@ -212,6 +218,9 @@ public interface ITmfTrace extends ITmfDataProvider { /** * Position the trace at the 'rank'th event in the trace. + *

+ * 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 @@ -240,19 +249,6 @@ public interface ITmfTrace extends ITmfDataProvider { */ 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); - - // ------------------------------------------------------------------------ // ------------------------------------------------------------------------ diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTrace.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTrace.java index 8c3b045506..200ac7ae63 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTrace.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTrace.java @@ -1,5 +1,5 @@ /******************************************************************************* - * 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 @@ -39,9 +39,11 @@ import org.eclipse.linuxtools.tmf.core.signal.TmfTraceUpdatedSignal; /** * TmfTrace *

- * Abstract implementation of ITmfTrace. It should be sufficient to extend this class and provide implementation for - * getCurrentLocation() and seekLocation(), as well as a proper parser, to have a working - * concrete implementation. + * Abstract implementation of ITmfTrace. + *

+ * It should be sufficient to extend this class and provide implementations for + * getCurrentLocation() and seekLocation(), as well + * as a proper parser, to have a working concrete implementation. */ public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace { @@ -58,6 +60,9 @@ public abstract class TmfTrace extends TmfEventProvider // Attributes // ------------------------------------------------------------------------ + // The resource used for persistent properties for this trace + private IResource fResource; + // The trace path private String fPath; @@ -81,9 +86,6 @@ public abstract class TmfTrace extends TmfEventProvider */ protected long fStreamingInterval = 0; - // The resource used for persistent properties for this trace - private IResource fResource; - // ------------------------------------------------------------------------ // Construction // ------------------------------------------------------------------------ @@ -102,12 +104,10 @@ public abstract class TmfTrace extends TmfEventProvider * @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 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 type, final String path, final int indexPageSize) throws FileNotFoundException { + this(resource, type, path, 0, indexPageSize); } /** @@ -117,17 +117,14 @@ public abstract class TmfTrace extends TmfEventProvider * @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 type, final String path, final long interval, - final int indexPageSize, final boolean indexTrace) throws FileNotFoundException { + protected TmfTrace(final IResource resource, final Class 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); } /** @@ -139,52 +136,23 @@ public abstract class TmfTrace extends TmfEventProvider 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 clone() { - // TmfTrace clone = null; - // try { - // clone = (TmfTrace) 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 type) throws FileNotFoundException { + protected void initialize(final IResource resource, final String path, final Class type) throws FileNotFoundException { fResource = resource; fPath = path; String traceName = (resource != null) ? resource.getName() : null; @@ -193,17 +161,24 @@ public abstract class TmfTrace extends TmfEventProvider 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 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) { @@ -212,93 +187,209 @@ public abstract class TmfTrace extends TmfEventProvider } // ------------------------------------------------------------------------ - // 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 getType() { - return fType; + return (Class) 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()); + } + } + } } // ------------------------------------------------------------------------ @@ -313,21 +404,21 @@ public abstract class TmfTrace extends TmfEventProvider * 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; } @@ -352,13 +443,15 @@ public abstract class TmfTrace extends TmfEventProvider 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(); + } } } @@ -386,110 +479,18 @@ public abstract class TmfTrace extends TmfEventProvider // Submit the request and wait for completion if required sendRequest((ITmfDataRequest) 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 // ------------------------------------------------------------------------ @@ -548,75 +549,40 @@ public abstract class TmfTrace extends TmfEventProvider 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; } } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/parsers/custom/CustomTxtTrace.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/parsers/custom/CustomTxtTrace.java index a18a564ec9..3447e2444b 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/parsers/custom/CustomTxtTrace.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/parsers/custom/CustomTxtTrace.java @@ -46,7 +46,7 @@ public class CustomTxtTrace extends TmfTrace { } public CustomTxtTrace(final IResource resource, final CustomTxtTraceDefinition definition, final String path, final int pageSize) throws FileNotFoundException { - super(resource, CustomTxtEvent.class, path, (pageSize > 0) ? pageSize : DEFAULT_CACHE_SIZE, true); + super(resource, CustomTxtEvent.class, path, (pageSize > 0) ? pageSize : DEFAULT_CACHE_SIZE); fDefinition = definition; fEventType = new CustomTxtEventType(fDefinition); } @@ -64,8 +64,9 @@ public class CustomTxtTrace extends TmfTrace { BufferedRandomAccessFile raFile = null; try { raFile = new BufferedRandomAccessFile(getPath(), "r"); //$NON-NLS-1$ - if (location != null && location.getLocation() instanceof Long) + if (location != null && location.getLocation() instanceof Long) { raFile.seek((Long)location.getLocation()); + } String line; long rawPos = raFile.getFilePointer(); while ((line = raFile.getNextLine()) != null) { @@ -91,11 +92,12 @@ public class CustomTxtTrace extends TmfTrace { e.printStackTrace(); return context; } finally { - if (raFile != null) + if (raFile != null) { try { raFile.close(); } catch (final IOException e) { } + } } } @@ -108,7 +110,9 @@ public class CustomTxtTrace extends TmfTrace { long pos = (long) (ratio * raFile.length()); while (pos > 0) { raFile.seek(pos - 1); - if (raFile.read() == '\n') break; + if (raFile.read() == '\n') { + break; + } pos--; } final ITmfLocation location = new TmfLocation(pos); @@ -122,11 +126,12 @@ public class CustomTxtTrace extends TmfTrace { e.printStackTrace(); return new CustomTxtTraceContext(NULL_LOCATION, ITmfContext.INITIAL_RANK); } finally { - if (raFile != null) + if (raFile != null) { try { raFile.close(); } catch (final IOException e) { } + } } } @@ -143,11 +148,12 @@ public class CustomTxtTrace extends TmfTrace { } catch (final IOException e) { e.printStackTrace(); } finally { - if (raFile != null) + if (raFile != null) { try { raFile.close(); } catch (final IOException e) { } + } } return 0; } @@ -189,13 +195,14 @@ public class CustomTxtTrace extends TmfTrace { synchronized (context.raFile) { try { - if (context.raFile.getFilePointer() != context.nextLineLocation) + if (context.raFile.getFilePointer() != context.nextLineLocation) { context.raFile.seek(context.nextLineLocation); + } String line; long rawPos = context.raFile.getFilePointer(); while ((line = context.raFile.getNextLine()) != null) { boolean processed = false; - if (currentInput == null) + if (currentInput == null) { for (final InputLine input : getFirstLines()) { final Matcher matcher = input.getPattern().matcher(line); if (matcher.find()) { @@ -207,10 +214,10 @@ public class CustomTxtTrace extends TmfTrace { return event; } } - else { + } else { if (countMap.get(currentInput) >= currentInput.getMinCount()) { final List nextInputs = currentInput.getNextInputs(countMap); - if (nextInputs.size() == 0 || nextInputs.get(nextInputs.size() - 1).getMinCount() == 0) + if (nextInputs.size() == 0 || nextInputs.get(nextInputs.size() - 1).getMinCount() == 0) { for (final InputLine input : getFirstLines()) { final Matcher matcher = input.getPattern().matcher(line); if (matcher.find()) { @@ -222,20 +229,23 @@ public class CustomTxtTrace extends TmfTrace { return event; } } + } for (final InputLine input : nextInputs) { final Matcher matcher = input.getPattern().matcher(line); if (matcher.find()) { event.processGroups(input, matcher); currentInput = input; - if (countMap.get(currentInput) == null) + if (countMap.get(currentInput) == null) { countMap.put(currentInput, 1); - else + } else { countMap.put(currentInput, countMap.get(currentInput) + 1); + } Iterator iter = countMap.keySet().iterator(); while (iter.hasNext()) { final InputLine inputLine = iter.next(); - if (inputLine.level > currentInput.level) + if (inputLine.level > currentInput.level) { iter.remove(); + } } if (currentInput.childrenInputs != null && currentInput.childrenInputs.size() > 0) { currentInput = currentInput.childrenInputs.get(0); @@ -243,16 +253,19 @@ public class CustomTxtTrace extends TmfTrace { } else if (countMap.get(currentInput) >= currentInput.getMaxCount()) if (currentInput.getNextInputs(countMap).size() > 0) { currentInput = currentInput.getNextInputs(countMap).get(0); - if (countMap.get(currentInput) == null) + if (countMap.get(currentInput) == null) { countMap.put(currentInput, 0); + } iter = countMap.keySet().iterator(); while (iter.hasNext()) { final InputLine inputLine = iter.next(); - if (inputLine.level > currentInput.level) + if (inputLine.level > currentInput.level) { iter.remove(); + } } - } else + } else { currentInput = null; + } processed = true; break; } @@ -269,16 +282,19 @@ public class CustomTxtTrace extends TmfTrace { } else if (countMap.get(currentInput) >= currentInput.getMaxCount()) if (currentInput.getNextInputs(countMap).size() > 0) { currentInput = currentInput.getNextInputs(countMap).get(0); - if (countMap.get(currentInput) == null) + if (countMap.get(currentInput) == null) { countMap.put(currentInput, 0); + } final Iterator iter = countMap.keySet().iterator(); while (iter.hasNext()) { final InputLine inputLine = iter.next(); - if (inputLine.level > currentInput.level) + if (inputLine.level > currentInput.level) { iter.remove(); + } } - } else + } else { currentInput = null; + } } ((StringBuffer) event.getContent().getValue()).append("\n").append(line); //$NON-NLS-1$ } @@ -290,8 +306,9 @@ public class CustomTxtTrace extends TmfTrace { } } for(final Entry entry : countMap.entrySet()) - if (entry.getValue() < entry.getKey().getMinCount()) + if (entry.getValue() < entry.getKey().getMinCount()) { event = null; + } context.setLocation(NULL_LOCATION); return event; } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/parsers/custom/CustomXmlTrace.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/parsers/custom/CustomXmlTrace.java index 5801281955..9cf7ebb113 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/parsers/custom/CustomXmlTrace.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/parsers/custom/CustomXmlTrace.java @@ -59,7 +59,7 @@ public class CustomXmlTrace extends TmfTrace { } public CustomXmlTrace(final IResource resource, final CustomXmlTraceDefinition definition, final String path, final int pageSize) throws FileNotFoundException { - super(null, CustomXmlEvent.class, path, (pageSize > 0) ? pageSize : DEFAULT_CACHE_SIZE, true); + super(null, CustomXmlEvent.class, path, (pageSize > 0) ? pageSize : DEFAULT_CACHE_SIZE); fDefinition = definition; fEventType = new CustomXmlEventType(fDefinition); fRecordInputElement = getRecordInputElement(fDefinition.rootInputElement); @@ -77,8 +77,9 @@ public class CustomXmlTrace extends TmfTrace { return context; try { context.raFile = new BufferedRandomAccessFile(getPath(), "r"); //$NON-NLS-1$ - if (location != null && location.getLocation() instanceof Long) + if (location != null && location.getLocation() instanceof Long) { context.raFile.seek((Long)location.getLocation()); + } String line; final String recordElementStart = "<" + fRecordInputElement.elementName; //$NON-NLS-1$ @@ -111,7 +112,9 @@ public class CustomXmlTrace extends TmfTrace { long pos = (long) (ratio * raFile.length()); while (pos > 0) { raFile.seek(pos - 1); - if (raFile.read() == '\n') break; + if (raFile.read() == '\n') { + break; + } pos--; } final ITmfLocation location = new TmfLocation(pos); @@ -125,11 +128,12 @@ public class CustomXmlTrace extends TmfTrace { e.printStackTrace(); return new CustomXmlTraceContext(NULL_LOCATION, ITmfContext.INITIAL_RANK); } finally { - if (raFile != null) + if (raFile != null) { try { raFile.close(); } catch (final IOException e) { } + } } } @@ -146,11 +150,12 @@ public class CustomXmlTrace extends TmfTrace { } catch (final IOException e) { e.printStackTrace(); } finally { - if (raFile != null) + if (raFile != null) { try { raFile.close(); } catch (final IOException e) { } + } } return 0; } @@ -185,7 +190,9 @@ public class CustomXmlTrace extends TmfTrace { CustomXmlEvent event = null; try { if (context.raFile.getFilePointer() != (Long)context.getLocation().getLocation() + 1) + { context.raFile.seek((Long)context.getLocation().getLocation() + 1); // +1 is for the < + } final StringBuffer elementBuffer = new StringBuffer("<"); //$NON-NLS-1$ readElement(elementBuffer, context.raFile); final Element element = parseElementBuffer(elementBuffer); @@ -261,23 +268,25 @@ public class CustomXmlTrace extends TmfTrace { numRead++; final char c = (char)i; buffer.append(c); - if (c == '"') + if (c == '"') { readQuote(buffer, raFile, '"'); - else if (c == '\'') + } else if (c == '\'') { readQuote(buffer, raFile, '\''); - else if (c == '<') + } else if (c == '<') { readElement(buffer, raFile); - else if (c == '/' && numRead == 1) + } else if (c == '/' && numRead == 1) { break; // found "') - if (buffer.charAt(buffer.length() - 2) == '/') + } else if (i == '>') + if (buffer.charAt(buffer.length() - 2) == '/') { break; // found "/>" - else if (startTagClosed) + } else if (startTagClosed) { break; // found "<...>..." - else + } + else { startTagClosed = true; // found "<...>" + } } return; } catch (final IOException e) { @@ -292,7 +301,9 @@ public class CustomXmlTrace extends TmfTrace { final char c = (char)i; buffer.append(c); if (c == eq) + { break; // found matching end-quote + } } return; } catch (final IOException e) { @@ -308,8 +319,10 @@ public class CustomXmlTrace extends TmfTrace { numRead++; final char c = (char)i; buffer.append(c); - if (c == '>' && numRead >= 2 && buffer.substring(buffer.length() - 3, buffer.length() - 1).equals("--")) //$NON-NLS-1$ + if (c == '>' && numRead >= 2 && buffer.substring(buffer.length() - 3, buffer.length() - 1).equals("--")) + { break; // found "-->" + } } return; } catch (final IOException e) { @@ -323,24 +336,26 @@ public class CustomXmlTrace extends TmfTrace { for (int i = 0; i < nodeList.getLength(); i++) { final Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { - if (separator == null) + if (separator == null) { separator = " | "; //$NON-NLS-1$ - else + } else { buffer.append(separator); + } final Element element = (Element) node; - if (element.hasChildNodes() == false) + if (element.hasChildNodes() == false) { buffer.append(element.getNodeName()); - else if (element.getChildNodes().getLength() == 1 && element.getFirstChild().getNodeType() == Node.TEXT_NODE) + } else if (element.getChildNodes().getLength() == 1 && element.getFirstChild().getNodeType() == Node.TEXT_NODE) { buffer.append(element.getNodeName() + ":" + element.getFirstChild().getNodeValue().trim()); //$NON-NLS-1$ - else { + } else { buffer.append(element.getNodeName()); buffer.append(" [ "); //$NON-NLS-1$ parseElement(element, buffer); buffer.append(" ]"); //$NON-NLS-1$ } } else if (node.getNodeType() == Node.TEXT_NODE) - if (node.getNodeValue().trim().length() != 0) + if (node.getNodeValue().trim().length() != 0) { buffer.append(node.getNodeValue().trim()); + } } return buffer; } @@ -348,12 +363,13 @@ public class CustomXmlTrace extends TmfTrace { public InputElement getRecordInputElement(final InputElement inputElement) { if (inputElement.logEntry) return inputElement; - else if (inputElement.childElements != null) + else if (inputElement.childElements != null) { for (final InputElement childInputElement : inputElement.childElements) { final InputElement recordInputElement = getRecordInputElement(childInputElement); if (recordInputElement != null) return recordInputElement; } + } return null; } @@ -365,22 +381,27 @@ public class CustomXmlTrace extends TmfTrace { } private void parseElement(final Element element, final CustomXmlEvent event, final InputElement inputElement) { - if (inputElement.inputName != null && !inputElement.inputName.equals(CustomXmlTraceDefinition.TAG_IGNORE)) + if (inputElement.inputName != null && !inputElement.inputName.equals(CustomXmlTraceDefinition.TAG_IGNORE)) { event.parseInput(parseElement(element, new StringBuffer()).toString(), inputElement.inputName, inputElement.inputAction, inputElement.inputFormat); - if (inputElement.attributes != null) - for (final InputAttribute attribute : inputElement.attributes) + } + if (inputElement.attributes != null) { + for (final InputAttribute attribute : inputElement.attributes) { event.parseInput(element.getAttribute(attribute.attributeName), attribute.inputName, attribute.inputAction, attribute.inputFormat); + } + } final NodeList childNodes = element.getChildNodes(); - if (inputElement.childElements != null) + if (inputElement.childElements != null) { for (int i = 0; i < childNodes.getLength(); i++) { final Node node = childNodes.item(i); - if (node instanceof Element) + if (node instanceof Element) { for (final InputElement child : inputElement.childElements) if (node.getNodeName().equals(child.elementName)) { parseElement((Element) node, event, child); break; } + } } + } return; } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenExperimentHandler.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenExperimentHandler.java index cf867e1bfc..ef0a53e96d 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenExperimentHandler.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenExperimentHandler.java @@ -172,7 +172,6 @@ public class OpenExperimentHandler extends AbstractHandler { } 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 { diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenTraceHandler.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenTraceHandler.java index bc73cb2cec..425dc2fe39 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenTraceHandler.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenTraceHandler.java @@ -136,8 +136,6 @@ public class OpenTraceHandler extends AbstractHandler { 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; diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/editors/EventsViewEditor.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/editors/EventsViewEditor.java index a0576c9066..f145e550b9 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/editors/EventsViewEditor.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/editors/EventsViewEditor.java @@ -188,7 +188,6 @@ public class EventsViewEditor extends TmfEditor { 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 }; diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/editors/TmfEventsEditor.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/editors/TmfEventsEditor.java index 497b53f521..da21b9d841 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/editors/TmfEventsEditor.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/editors/TmfEventsEditor.java @@ -137,7 +137,6 @@ public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReus experiment.setBookmarksFile(fFile); fTrace = experiment; experiment.initTrace(null, null, null); - experiment.indexTrace(true); break; } } @@ -157,7 +156,6 @@ public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReus throw new PartInitException(Messages.OpenTraceHandler_NoTraceType); try { trace.initTrace(traceElement.getResource(), traceElement.getLocation().getPath(), traceEvent.getClass()); - trace.indexTrace(false); } catch (final FileNotFoundException e) { } fTrace = trace; @@ -178,7 +176,6 @@ public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReus throw new PartInitException(Messages.OpenTraceHandler_NoTraceType); try { trace.initTrace(traceElement.getResource(), traceElement.getLocation().getPath(), traceEvent.getClass()); - trace.indexTrace(false); } catch (final FileNotFoundException e) { } fTrace = trace; @@ -463,7 +460,6 @@ public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReus final TmfEvent event = (TmfEvent) ce.createExecutableExtension(TmfTraceType.EVENT_TYPE_ATTR); final String path = fFile.getLocationURI().getPath(); fTrace.initTrace(null, path, event.getClass()); - fTrace.indexTrace(false); break; } } catch (final InvalidRegistryObjectException e) { diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/Histogram.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/Histogram.java index 76a1fc71b8..0398916fb7 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/Histogram.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/Histogram.java @@ -85,7 +85,7 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi // Timestamp scale (nanosecond) public static final byte TIME_SCALE = -9; - + public static final int HISTOGRAM_BAR_WIDTH = 1; // ------------------------------------------------------------------------ @@ -114,7 +114,7 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi // Construction // ------------------------------------------------------------------------ - public Histogram(TmfView view, Composite parent) { + public Histogram(final TmfView view, final Composite parent) { fParentView = view; createWidget(parent); @@ -134,7 +134,7 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi fDataModel.removeHistogramListener(this); } - private void createWidget(Composite parent) { + private void createWidget(final Composite parent) { final Color labelColor = parent.getBackground(); final Font fFont = adjustFont(parent); @@ -145,7 +145,7 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi // Define the histogram // -------------------------------------------------------------------- - GridLayout gridLayout = new GridLayout(); + final GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 3; gridLayout.marginHeight = 0; gridLayout.marginWidth = 0; @@ -154,7 +154,7 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi 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 @@ -200,7 +200,7 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi 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); @@ -228,11 +228,11 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi 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()); } @@ -251,7 +251,7 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi public long getTimeLimit() { return fDataModel.getTimeLimit(); } - + public HistogramDataModel getDataModel() { return fDataModel; } @@ -274,7 +274,7 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi * * @param timestamp */ - public void countEvent(long eventCount, long timestamp) { + public void countEvent(final long eventCount, final long timestamp) { fDataModel.countEvent(eventCount, timestamp); } @@ -283,7 +283,7 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi * * @param timestamp */ - public void setCurrentEvent(long timestamp) { + public void setCurrentEvent(final long timestamp) { fCurrentEventTime = (timestamp > 0) ? timestamp : 0; fDataModel.setCurrentEventNotifyListeners(timestamp); } @@ -294,11 +294,11 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi * @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) } } @@ -309,7 +309,7 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi * @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); @@ -320,7 +320,7 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi * * @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; @@ -372,29 +372,30 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi */ @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(); + } } } }); - } } // ------------------------------------------------------------------------ @@ -402,7 +403,7 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi // ------------------------------------------------------------------------ private void updateCurrentEventTime() { - long bucketStartTime = getTimestamp(fScaledData.fCurrentBucket); + final long bucketStartTime = getTimestamp(fScaledData.fCurrentBucket); ((HistogramView) fParentView).updateCurrentEventTime(bucketStartTime); } @@ -413,11 +414,11 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi 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) @@ -431,23 +432,23 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi } // 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); @@ -455,17 +456,16 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi // 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; @@ -473,14 +473,14 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi 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); @@ -492,12 +492,12 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi // ------------------------------------------------------------------------ @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) { } // ------------------------------------------------------------------------ @@ -505,11 +505,11 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi // ------------------------------------------------------------------------ @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(); @@ -517,7 +517,7 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi } @Override - public void mouseUp(MouseEvent event) { + public void mouseUp(final MouseEvent event) { } // ------------------------------------------------------------------------ @@ -525,31 +525,30 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi // ------------------------------------------------------------------------ @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$ @@ -565,12 +564,12 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi // ------------------------------------------------------------------------ @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(); } } -- 2.34.1