diff options
Diffstat (limited to 'lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf')
14 files changed, 356 insertions, 18 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/HistoryBuilder.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/HistoryBuilder.java index de62ee1da3..edd2aac2eb 100644 --- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/HistoryBuilder.java +++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/HistoryBuilder.java @@ -14,6 +14,7 @@ package org.eclipse.linuxtools.internal.tmf.core.statesystem; import java.io.IOException; +import org.eclipse.linuxtools.internal.tmf.core.statesystem.backends.IStateHistoryBackend; import org.eclipse.linuxtools.tmf.core.component.TmfComponent; import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange; @@ -54,26 +55,22 @@ public class HistoryBuilder extends TmfComponent { * @param stateChangeInput * The input plugin to use. This is required. * @param backend - * The backend storage to use. + * The back-end storage to use. * @param buildManually * Should we build this history in-band or not. True means we * will start the building ourselves and block the caller until * construction is done. False (out-of-band) means we will start * listening for the signal and return immediately. Another * signal will be sent when finished. - * @throws IOException - * Is thrown if anything went wrong (usually with the storage - * backend) */ public HistoryBuilder(IStateChangeInput stateChangeInput, - IStateHistoryBackend backend, boolean buildManually) - throws IOException { + IStateHistoryBackend backend, boolean buildManually) { if (stateChangeInput == null || backend == null) { throw new IllegalArgumentException(); } sci = stateChangeInput; hb = backend; - ss = new StateSystem(hb, true); + ss = new StateSystem(hb); sci.assignTargetStateSystem(ss); diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/StateSystem.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/StateSystem.java index a77c8557ab..c2891b51aa 100644 --- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/StateSystem.java +++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/StateSystem.java @@ -23,6 +23,7 @@ import java.util.concurrent.CountDownLatch; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.linuxtools.internal.tmf.core.Activator; +import org.eclipse.linuxtools.internal.tmf.core.statesystem.backends.IStateHistoryBackend; import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException; import org.eclipse.linuxtools.tmf.core.exceptions.StateSystemDisposedException; import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException; @@ -60,10 +61,23 @@ public class StateSystem implements ITmfStateSystemBuilder { private boolean isDisposed = false; /** + * New-file constructor. For when you build a state system with a new file, + * or if the back-end does not require a file on disk. + * + * @param backend + * Back-end plugin to use + */ + public StateSystem(IStateHistoryBackend backend) { + this.backend = backend; + this.transState = new TransientState(backend); + this.attributeTree = new AttributeTree(this); + } + + /** * General constructor * * @param backend - * The "state history storage" backend to use. + * The "state history storage" back-end to use. * @param newFile * Put true if this is a new history started from scratch. It is * used to tell the state system where to get its attribute tree. diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/TransientState.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/TransientState.java index 26f163cc90..0b9f66a310 100644 --- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/TransientState.java +++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/TransientState.java @@ -16,6 +16,7 @@ import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; +import org.eclipse.linuxtools.internal.tmf.core.statesystem.backends.IStateHistoryBackend; import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException; import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException; import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException; diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/IStateHistoryBackend.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/IStateHistoryBackend.java index 4a44e154b7..8877018241 100644 --- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/IStateHistoryBackend.java +++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/IStateHistoryBackend.java @@ -10,7 +10,7 @@ * *******************************************************************************/ -package org.eclipse.linuxtools.internal.tmf.core.statesystem; +package org.eclipse.linuxtools.internal.tmf.core.statesystem.backends; import java.io.File; import java.io.FileInputStream; diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/InMemoryBackend.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/InMemoryBackend.java new file mode 100644 index 0000000000..3ff4038f35 --- /dev/null +++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/InMemoryBackend.java @@ -0,0 +1,203 @@ +/******************************************************************************* + * Copyright (c) 2013 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexandre Montplaisir - Initial API and implementation + ******************************************************************************/ + +package org.eclipse.linuxtools.internal.tmf.core.statesystem.backends; + +import java.io.File; +import java.io.FileInputStream; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException; +import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException; +import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval; +import org.eclipse.linuxtools.tmf.core.interval.TmfIntervalEndComparator; +import org.eclipse.linuxtools.tmf.core.interval.TmfStateInterval; +import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue; + +/** + * State history back-end that stores its intervals in RAM only. It cannot be + * saved to disk, which means we need to rebuild it every time we re-open a + * trace. But it's relatively quick to build, so this shouldn't be a problem in + * most cases. + * + * This should only be used with very small state histories (and/or, very small + * traces). Since it's stored in standard Collections, it's limited to 2^31 + * intervals. + * + * @author Alexandre Montplaisir + */ +public class InMemoryBackend implements IStateHistoryBackend { + + private final static Comparator<ITmfStateInterval> endComparator = + new TmfIntervalEndComparator(); + + private final List<ITmfStateInterval> intervals; + private final long startTime; + private long latestTime; + + /** + * Constructor + * + * @param startTime + * The start time of this interval store + */ + public InMemoryBackend(long startTime) { + this.startTime = startTime; + this.latestTime = startTime; + this.intervals = new ArrayList<ITmfStateInterval>(); + } + + @Override + public long getStartTime() { + return startTime; + } + + @Override + public long getEndTime() { + return latestTime; + } + + @Override + public void insertPastState(long stateStartTime, long stateEndTime, + int quark, ITmfStateValue value) throws TimeRangeException { + /* Make sure the passed start/end times make sense */ + if (stateStartTime > stateEndTime || stateStartTime < startTime) { + throw new TimeRangeException(); + } + + ITmfStateInterval interval = new TmfStateInterval(stateStartTime, stateEndTime, quark, value); + + /* Update the "latest seen time" */ + if (stateEndTime > latestTime) { + latestTime = stateEndTime; + } + + /* Add the interval into the-array */ + intervals.add(interval); + } + + + @Override + public void doQuery(List<ITmfStateInterval> currentStateInfo, long t) + throws TimeRangeException { + if (!checkValidTime(t)) { + throw new TimeRangeException(); + } + + /* + * The intervals are sorted by end time, so we can binary search to get + * the first possible interval, then only compare their start times. + */ + ITmfStateInterval entry; + for (int i = binarySearchEndTime(intervals, t); i < intervals.size(); i++) { + entry = intervals.get(i); + if (entry.getStartTime() <= t) { + /* Add this interval to the returned values */ + currentStateInfo.set(entry.getAttribute(), entry); + } + } + } + + @Override + public ITmfStateInterval doSingularQuery(long t, int attributeQuark) + throws TimeRangeException, AttributeNotFoundException { + if (!checkValidTime(t)) { + throw new TimeRangeException(); + } + + /* + * The intervals are sorted by end time, so we can binary search to get + * the first possible interval, then only compare their start times. + */ + ITmfStateInterval entry; + for (int i = binarySearchEndTime(intervals, t); i < intervals.size(); i++) { + entry = intervals.get(i); + if (entry.getStartTime() <= t && entry.getAttribute() == attributeQuark) { + /* This is the droid we are looking for */ + return entry; + } + } + throw new AttributeNotFoundException(); + } + + @Override + public boolean checkValidTime(long t) { + if (t >= startTime && t <= latestTime) { + return true; + } + return false; + } + + @Override + public void finishedBuilding(long endTime) throws TimeRangeException { + /* Nothing to do */ + } + + @Override + public FileInputStream supplyAttributeTreeReader() { + /* Saving to disk not supported */ + return null; + } + + @Override + public File supplyAttributeTreeWriterFile() { + /* Saving to disk not supported */ + return null; + } + + @Override + public long supplyAttributeTreeWriterFilePosition() { + /* Saving to disk not supported */ + return -1; + } + + @Override + public void removeFiles() { + /* Nothing to do */ + } + + @Override + public void dispose() { + /* Nothing to do */ + } + + @Override + public void debugPrint(PrintWriter writer) { + writer.println(intervals.toString()); + } + + private static int binarySearchEndTime(List<ITmfStateInterval> list, long time) { + ITmfStateInterval dummyInterval = new TmfStateInterval(-1, time, -1, null); + int mid = Collections.binarySearch(list, dummyInterval, endComparator); + + /* The returned value is < 0 if the exact key was not found. */ + if (mid < 0) { + mid = -mid; + } + + /* + * Collections.binarySearch doesn't guarantee which element is returned + * if it falls on one of many equal ones. So make sure we are at the + * first one provided. + */ + while ((mid > 0) && + (list.get(mid).getEndTime() == list.get(mid-1).getEndTime())) { + mid--; + } + return mid; + } + +} diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/NullBackend.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/NullBackend.java new file mode 100644 index 0000000000..88c3cc9701 --- /dev/null +++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/NullBackend.java @@ -0,0 +1,123 @@ +/******************************************************************************* + * Copyright (c) 2013 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexandre Montplaisir - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.internal.tmf.core.statesystem.backends; + +import java.io.File; +import java.io.FileInputStream; +import java.io.PrintWriter; +import java.util.List; + +import org.eclipse.linuxtools.internal.tmf.core.statesystem.StateSystem; +import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval; +import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue; + +/** + * An implement of a state history back-end to simply discards *all* the + * intervals it receives. Obviously, no queries can be done on it. It is useful + * for using with a {@link StateSystem} on which you will only want to do + * "ongoing" requests. + * + * @author Alexandre Montplaisir + */ +public class NullBackend implements IStateHistoryBackend { + + /** + * Constructor + */ + public NullBackend() {} + + @Override + public long getStartTime() { + return 0; + } + + @Override + public long getEndTime() { + return 0; + } + + /** + * The interval will be discarded when using a null backend. + */ + @Override + public void insertPastState(long stateStartTime, long stateEndTime, + int quark, ITmfStateValue value) { + /* The interval is always discarded. */ + } + + @Override + public void finishedBuilding(long endTime) { + /* Nothing to do */ + } + + @Override + public FileInputStream supplyAttributeTreeReader() { + return null; + } + + @Override + public File supplyAttributeTreeWriterFile() { + return null; + } + + @Override + public long supplyAttributeTreeWriterFilePosition() { + return -1; + } + + @Override + public void removeFiles() { + /* Nothing to do */ + } + + @Override + public void dispose() { + /* Nothing to do */ + } + + /** + * Null back-ends cannot run queries. Nothing will be put in + * currentStateInfo. + */ + @Override + public void doQuery(List<ITmfStateInterval> currentStateInfo, long t) { + /* Cannot do past queries */ + } + + /** + * Null back-ends cannot run queries. 'null' will be returned. + * + * @return Always returns null. + */ + @Override + public ITmfStateInterval doSingularQuery(long t, int attributeQuark) { + /* Cannot do past queries */ + return null; + } + + /** + * Null back-ends cannot run queries. + * + * @return Always returns false. + */ + @Override + public boolean checkValidTime(long t) { + /* Cannot do past queries */ + return false; + } + + @Override + public void debugPrint(PrintWriter writer) { + writer.println("Null history backend"); //$NON-NLS-1$ + } +} diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/historytree/CoreNode.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/CoreNode.java index 21866f377a..f2e2cf0f20 100644 --- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/historytree/CoreNode.java +++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/CoreNode.java @@ -10,7 +10,7 @@ * *******************************************************************************/ -package org.eclipse.linuxtools.internal.tmf.core.statesystem.historytree; +package org.eclipse.linuxtools.internal.tmf.core.statesystem.backends.historytree; import java.nio.ByteBuffer; diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/historytree/HTConfig.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HTConfig.java index 126750b322..9bdbfb3366 100644 --- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/historytree/HTConfig.java +++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HTConfig.java @@ -10,7 +10,7 @@ * *******************************************************************************/ -package org.eclipse.linuxtools.internal.tmf.core.statesystem.historytree; +package org.eclipse.linuxtools.internal.tmf.core.statesystem.backends.historytree; import java.io.File; diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/historytree/HTInterval.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HTInterval.java index 0432f4e2de..5312c62812 100644 --- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/historytree/HTInterval.java +++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HTInterval.java @@ -10,7 +10,7 @@ * *******************************************************************************/ -package org.eclipse.linuxtools.internal.tmf.core.statesystem.historytree; +package org.eclipse.linuxtools.internal.tmf.core.statesystem.backends.historytree; import java.io.IOException; import java.nio.ByteBuffer; diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/historytree/HTNode.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HTNode.java index 12b10724c0..465b252475 100644 --- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/historytree/HTNode.java +++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HTNode.java @@ -10,7 +10,7 @@ * *******************************************************************************/ -package org.eclipse.linuxtools.internal.tmf.core.statesystem.historytree; +package org.eclipse.linuxtools.internal.tmf.core.statesystem.backends.historytree; import java.io.IOException; import java.io.PrintWriter; diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/historytree/HT_IO.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HT_IO.java index 7495eb1b2f..b9994825e0 100644 --- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/historytree/HT_IO.java +++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HT_IO.java @@ -10,7 +10,7 @@ * *******************************************************************************/ -package org.eclipse.linuxtools.internal.tmf.core.statesystem.historytree; +package org.eclipse.linuxtools.internal.tmf.core.statesystem.backends.historytree; import java.io.File; import java.io.FileInputStream; diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/historytree/HistoryTree.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HistoryTree.java index 576b0490b7..ac04265bbe 100644 --- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/historytree/HistoryTree.java +++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HistoryTree.java @@ -10,7 +10,7 @@ * *******************************************************************************/ -package org.eclipse.linuxtools.internal.tmf.core.statesystem.historytree; +package org.eclipse.linuxtools.internal.tmf.core.statesystem.backends.historytree; import java.io.File; import java.io.FileInputStream; diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/historytree/HistoryTreeBackend.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HistoryTreeBackend.java index d794831301..ef13e62d3b 100644 --- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/historytree/HistoryTreeBackend.java +++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HistoryTreeBackend.java @@ -10,7 +10,7 @@ * *******************************************************************************/ -package org.eclipse.linuxtools.internal.tmf.core.statesystem.historytree; +package org.eclipse.linuxtools.internal.tmf.core.statesystem.backends.historytree; import java.io.File; import java.io.FileInputStream; @@ -19,7 +19,7 @@ import java.io.PrintWriter; import java.nio.channels.ClosedChannelException; import java.util.List; -import org.eclipse.linuxtools.internal.tmf.core.statesystem.IStateHistoryBackend; +import org.eclipse.linuxtools.internal.tmf.core.statesystem.backends.IStateHistoryBackend; import org.eclipse.linuxtools.tmf.core.exceptions.StateSystemDisposedException; import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException; import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval; diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/historytree/ThreadedHistoryTreeBackend.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/ThreadedHistoryTreeBackend.java index 820a44a933..5bc09c7855 100644 --- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/historytree/ThreadedHistoryTreeBackend.java +++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/ThreadedHistoryTreeBackend.java @@ -10,7 +10,7 @@ * *******************************************************************************/ -package org.eclipse.linuxtools.internal.tmf.core.statesystem.historytree; +package org.eclipse.linuxtools.internal.tmf.core.statesystem.backends.historytree; import java.io.File; import java.io.IOException; |