diff options
author | Matthew Khouzam | 2017-11-16 18:18:22 +0000 |
---|---|---|
committer | Matthew Khouzam | 2017-11-21 18:50:07 +0000 |
commit | 22a3158bc036a7c7096d2affe2d0dfd41606eae5 (patch) | |
tree | e19e72d78999a19609b91146f744abebe7ce3b4d | |
parent | ceb43494d558dfedd052c1b7dd98188cfeb3af7b (diff) | |
download | org.eclipse.tracecompass-22a3158bc036a7c7096d2affe2d0dfd41606eae5.tar.gz org.eclipse.tracecompass-22a3158bc036a7c7096d2affe2d0dfd41606eae5.tar.xz org.eclipse.tracecompass-22a3158bc036a7c7096d2affe2d0dfd41606eae5.zip |
ctf: No longer throw NPEs when file is erased while trace is being read.
As the iterator can be null in the case the something goes wrong (file
is deleted), we check the iterator before using it to avoid NPEs.
Errors are still logged.
Bug 527097
Change-Id: I20c98bc747de56c5bf88257305f80d0151e804fe
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/111739
Reviewed-by: Hudson CI
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
(cherry picked from commit a4587baa53b4ddf33766f4bbf2bcc6288c6e55a4)
Reviewed-on: https://git.eclipse.org/r/111973
3 files changed, 32 insertions, 14 deletions
diff --git a/ctf/org.eclipse.tracecompass.tmf.ctf.core/src/org/eclipse/tracecompass/internal/tmf/ctf/core/trace/iterator/CtfIteratorManager.java b/ctf/org.eclipse.tracecompass.tmf.ctf.core/src/org/eclipse/tracecompass/internal/tmf/ctf/core/trace/iterator/CtfIteratorManager.java index b580652350..286be34146 100644 --- a/ctf/org.eclipse.tracecompass.tmf.ctf.core/src/org/eclipse/tracecompass/internal/tmf/ctf/core/trace/iterator/CtfIteratorManager.java +++ b/ctf/org.eclipse.tracecompass.tmf.ctf.core/src/org/eclipse/tracecompass/internal/tmf/ctf/core/trace/iterator/CtfIteratorManager.java @@ -22,6 +22,7 @@ import java.util.Random; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tracecompass.internal.tmf.ctf.core.Activator; import org.eclipse.tracecompass.tmf.ctf.core.context.CtfLocationInfo; import org.eclipse.tracecompass.tmf.ctf.core.context.CtfTmfContext; @@ -72,21 +73,20 @@ public class CtfIteratorManager { } /** - * This needs explaining: the iterator table is effectively a cache. - * Originally the contexts had a 1 to 1 structure with the file handles of a - * trace. This failed since there is a limit to how many file handles we can - * have opened simultaneously. Then a round-robin scheme was implemented, - * this lead up to a two competing contexts syncing up and using the same - * file handler, causing horrible slowdowns. Now a random replacement - * algorithm is selected. This is the same as used by arm processors, and it - * works quite well when many cores so this looks promising for very - * multi-threaded systems. + * This needs explaining: the iterator table is effectively a cache. Originally + * the contexts had a 1 to 1 structure with the file handles of a trace. This + * failed since there is a limit to how many file handles we can have opened + * simultaneously. Then a round-robin scheme was implemented, this lead up to a + * two competing contexts syncing up and using the same file handler, causing + * horrible slowdowns. Now a random replacement algorithm is selected. This is + * the same as used by arm processors, and it works quite well when many cores + * so this looks promising for very multi-threaded systems. * * @param context * the context to look up - * @return the iterator referring to the context + * @return the iterator referring to the context or null in the case of an error */ - public CtfIterator getIterator(final CtfTmfContext context) { + public @Nullable CtfIterator getIterator(final CtfTmfContext context) { /* * if the element is in the map, we don't need to do anything else. */ @@ -103,6 +103,9 @@ public class CtfIteratorManager { * if we're not full yet, just add an element. */ iter = (CtfIterator) fTrace.createIterator(); + if (iter == null) { + return null; + } addElement(context, iter); } else { diff --git a/ctf/org.eclipse.tracecompass.tmf.ctf.core/src/org/eclipse/tracecompass/tmf/ctf/core/context/CtfTmfContext.java b/ctf/org.eclipse.tracecompass.tmf.ctf.core/src/org/eclipse/tracecompass/tmf/ctf/core/context/CtfTmfContext.java index b80b185c27..42cea658e9 100644 --- a/ctf/org.eclipse.tracecompass.tmf.ctf.core/src/org/eclipse/tracecompass/tmf/ctf/core/context/CtfTmfContext.java +++ b/ctf/org.eclipse.tracecompass.tmf.ctf.core/src/org/eclipse/tracecompass/tmf/ctf/core/context/CtfTmfContext.java @@ -13,6 +13,7 @@ package org.eclipse.tracecompass.tmf.ctf.core.context; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tracecompass.internal.tmf.ctf.core.trace.iterator.CtfIterator; import org.eclipse.tracecompass.tmf.core.trace.ITmfContext; import org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation; @@ -78,6 +79,9 @@ public class CtfTmfContext implements ITmfContext { fCurLocation = ctfLocation; } else { CtfIterator iterator = getIterator(); + if(iterator == null) { + return; + } iterator.seek(ctfLocation.getLocationInfo()); fCurLocation = iterator.getLocation(); } @@ -118,7 +122,8 @@ public class CtfTmfContext implements ITmfContext { * @return The event or null */ public synchronized CtfTmfEvent getCurrentEvent() { - return getIterator().getCurrentEvent(); + CtfIterator iterator = getIterator(); + return iterator == null ? null : iterator.getCurrentEvent(); } /** @@ -129,6 +134,9 @@ public class CtfTmfContext implements ITmfContext { public synchronized boolean advance() { final CtfLocationInfo curLocationData = fCurLocation.getLocationInfo(); CtfIterator iterator = getIterator(); + if( iterator == null) { + return false; + } boolean retVal = iterator.advance(); CtfTmfEvent currentEvent = iterator.getCurrentEvent(); @@ -160,6 +168,9 @@ public class CtfTmfContext implements ITmfContext { */ public synchronized boolean seek(final long timestamp) { CtfIterator iterator = getIterator(); + if( iterator == null) { + return false; + } boolean ret = iterator.seek(timestamp); fCurLocation = iterator.getLocation(); return ret; @@ -174,7 +185,8 @@ public class CtfTmfContext implements ITmfContext { */ public synchronized boolean seek(final CtfLocationInfo location) { fCurLocation = new CtfLocation(location); - return getIterator().seek(location); + CtfIterator iterator = getIterator(); + return iterator == null ? false : iterator.seek(location); } // ------------------------------------------- @@ -187,7 +199,7 @@ public class CtfTmfContext implements ITmfContext { * * @return an iterator */ - private CtfIterator getIterator() { + private @Nullable CtfIterator getIterator() { return (CtfIterator) fTrace.createIteratorFromContext(this); } } diff --git a/ctf/org.eclipse.tracecompass.tmf.ctf.core/src/org/eclipse/tracecompass/tmf/ctf/core/trace/CtfTmfTrace.java b/ctf/org.eclipse.tracecompass.tmf.ctf.core/src/org/eclipse/tracecompass/tmf/ctf/core/trace/CtfTmfTrace.java index fefb7ebaef..1061f81228 100644 --- a/ctf/org.eclipse.tracecompass.tmf.ctf.core/src/org/eclipse/tracecompass/tmf/ctf/core/trace/CtfTmfTrace.java +++ b/ctf/org.eclipse.tracecompass.tmf.ctf.core/src/org/eclipse/tracecompass/tmf/ctf/core/trace/CtfTmfTrace.java @@ -230,6 +230,9 @@ public class CtfTmfTrace extends TmfTrace * that type in the TmfEventTypeManager */ try (CtfIterator iter = fIteratorManager.getIterator(ctx)) { + if(iter == null) { + throw new TmfTraceException("Failed to get CTF Iterator for path " + path); //$NON-NLS-1$ + } Set<@NonNull ITmfEventField> streamContextNames = new HashSet<>(); for (IEventDeclaration ied : iter.getEventDeclarations()) { CtfTmfEventType ctfTmfEventType = fContainedEventTypes.get(ied.getName()); |