/*******************************************************************************
- * Copyright (c) 2012, 2014 Ericsson
+ * Copyright (c) 2012, 2015 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
ITmfStateValue value;
testHtFile = File.createTempFile("test", ".ht");
- IStateHistoryBackend backend = new HistoryTreeBackend(testHtFile, 0, 0L);
- ss = new StateSystem("push-pop-test", backend, true);
+ IStateHistoryBackend backend = new HistoryTreeBackend("push-pop-test", testHtFile, 0, 0L);
+ ss = new StateSystem(backend, true);
/* Build the thing */
final int attrib = ss.getQuarkAbsoluteAndAdd("Test", "stack");
@Before
public void setupStateSystem() {
try {
- IStateHistoryBackend backend = new InMemoryBackend(START_TIME);
- fStateSystem = StateSystemFactory.newStateSystem(DUMMY_STRING, backend);
+ IStateHistoryBackend backend = new InMemoryBackend(DUMMY_STRING, START_TIME);
+ fStateSystem = StateSystemFactory.newStateSystem(backend);
int quark = fStateSystem.getQuarkAbsoluteAndAdd(DUMMY_STRING);
fStateSystem.modifyAttribute(1200L, TmfStateValue.newValueInt(10), quark);
/*******************************************************************************
- * Copyright (c) 2013, 2014 Ericsson
+ * Copyright (c) 2013, 2015 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
*/
@BeforeClass
public static void init() {
- fixture = new InMemoryBackend(0);
+ fixture = new InMemoryBackend("test-ss", 0);
for (int attribute = 0; attribute < NUMBER_OF_ATTRIBUTES; attribute++) {
for (int timeStart = 0; timeStart < 1000; timeStart++) {
try {
*/
public class StateSystem implements ITmfStateSystemBuilder {
- private final String ssid;
-
/* References to the inner structures */
private final AttributeTree attributeTree;
private final TransientState transState;
* 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 ssid
- * The ID of this statesystem. It should be unique.
* @param backend
* Back-end plugin to use
*/
- public StateSystem(@NonNull String ssid, @NonNull IStateHistoryBackend backend) {
- this.ssid = ssid;
+ public StateSystem(@NonNull IStateHistoryBackend backend) {
this.backend = backend;
this.transState = new TransientState(backend);
this.attributeTree = new AttributeTree(this);
/**
* General constructor
*
- * @param ssid
- * The ID of this statesystem. It should be unique.
* @param backend
* The "state history storage" back-end to use.
* @param newFile
* @throws IOException
* If there was a problem creating the new history file
*/
- public StateSystem(@NonNull String ssid, @NonNull IStateHistoryBackend backend, boolean newFile)
+ public StateSystem(@NonNull IStateHistoryBackend backend, boolean newFile)
throws IOException {
- this.ssid = ssid;
this.backend = backend;
this.transState = new TransientState(backend);
@Override
public String getSSID() {
- return ssid;
+ return backend.getSSID();
}
@Override
* New-file factory method. For when you build a state system with a new
* file, or if the back-end does not require a file on disk.
*
- * @param id
- * The ID of this statesystem. It should be unique.
* @param backend
* Back-end plugin to use
* @return The new state system
*/
- public static ITmfStateSystemBuilder newStateSystem(String id,
- IStateHistoryBackend backend) {
- return new StateSystem(id, backend);
+ public static ITmfStateSystemBuilder newStateSystem(IStateHistoryBackend backend) {
+ return new StateSystem(backend);
}
/**
* General factory method. The backend may try to open or create a file on
* disk (the file contents and location are defined by the backend).
*
- * @param id
- * The ID of this statesystem. It should be unique.
* @param backend
* The "state history storage" back-end to use.
* @param newFile
* @throws IOException
* If there was a problem creating the new history file
*/
- public static ITmfStateSystemBuilder newStateSystem(String id,
- IStateHistoryBackend backend, boolean newFile) throws IOException {
- return new StateSystem(id, backend, newFile);
+ public static ITmfStateSystemBuilder newStateSystem(IStateHistoryBackend backend,
+ boolean newFile) throws IOException {
+ return new StateSystem(backend, newFile);
}
}
*/
public interface IStateHistoryBackend {
+ /**
+ * Get the ID of the state system that populates this backend.
+ *
+ * @return The state system's ID.
+ */
+ @NonNull String getSSID();
+
/**
* Get the start time of this state history. This is usually the same as the
* start time of the originating trace.
import java.util.SortedSet;
import java.util.TreeSet;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval;
};
+ private final @NonNull String ssid;
private final TreeSet<ITmfStateInterval> intervals;
private final long startTime;
+
private volatile long latestTime;
/**
* Constructor
*
+ * @param ssid
+ * The state system's ID
* @param startTime
* The start time of this interval store
*/
- public InMemoryBackend(long startTime) {
+ public InMemoryBackend(@NonNull String ssid, long startTime) {
+ this.ssid = ssid;
this.startTime = startTime;
this.latestTime = startTime;
this.intervals = new TreeSet<>(END_COMPARATOR);
}
+ @Override
+ public String getSSID() {
+ return ssid;
+ }
+
@Override
public long getStartTime() {
return startTime;
import java.io.PrintWriter;
import java.util.List;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval;
import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
*/
public class NullBackend implements IStateHistoryBackend {
+ private final @NonNull String ssid;
+
/**
* Constructor
+ *
+ * @param ssid
+ * The state system's id
*/
- public NullBackend() {}
+ public NullBackend(@NonNull String ssid) {
+ this.ssid = ssid;
+ }
+
+ @Override
+ public String getSSID() {
+ return ssid;
+ }
@Override
public long getStartTime() {
import java.nio.channels.ClosedChannelException;
import java.util.List;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.tracecompass.internal.statesystem.core.backend.historytree.CoreNode;
import org.eclipse.tracecompass.internal.statesystem.core.backend.historytree.HTConfig;
import org.eclipse.tracecompass.internal.statesystem.core.backend.historytree.HTInterval;
*/
public class HistoryTreeBackend implements IStateHistoryBackend {
+ private final @NonNull String ssid;
+
/**
* The history tree that sits underneath.
*/
* Constructor for new history files. Use this when creating a new history
* from scratch.
*
+ * @param ssid
+ * The state system's ID
* @param newStateFile
* The filename/location where to store the state history (Should
* end in .ht)
* @throws IOException
* Thrown if we can't create the file for some reason
*/
- public HistoryTreeBackend(File newStateFile, int blockSize,
+ public HistoryTreeBackend(@NonNull String ssid, File newStateFile, int blockSize,
int maxChildren, int providerVersion, long startTime) throws IOException {
+ this.ssid = ssid;
final HTConfig conf = new HTConfig(newStateFile, blockSize, maxChildren,
providerVersion, startTime);
sht = new HistoryTree(conf);
* from scratch. This version supplies sane defaults for the configuration
* parameters.
*
+ * @param ssid
+ * The state system's id
* @param newStateFile
* The filename/location where to store the state history (Should
* end in .ht)
* @throws IOException
* Thrown if we can't create the file for some reason
*/
- public HistoryTreeBackend(File newStateFile, int providerVersion, long startTime)
+ public HistoryTreeBackend(@NonNull String ssid, File newStateFile, int providerVersion, long startTime)
throws IOException {
- this(newStateFile, 64 * 1024, 50, providerVersion, startTime);
+ this(ssid, newStateFile, 64 * 1024, 50, providerVersion, startTime);
}
/**
* Existing history constructor. Use this to open an existing state-file.
*
+ * @param ssid
+ * The state system's id
* @param existingStateFile
* Filename/location of the history we want to load
* @param providerVersion
* recognized, or if the version of the file does not match the
* expected providerVersion.
*/
- public HistoryTreeBackend(File existingStateFile, int providerVersion)
+ public HistoryTreeBackend(@NonNull String ssid, File existingStateFile, int providerVersion)
throws IOException {
+ this.ssid = ssid;
sht = new HistoryTree(existingStateFile, providerVersion);
fFinishedBuilding = true;
}
return sht;
}
+ @Override
+ public String getSSID() {
+ return ssid;
+ }
+
@Override
public long getStartTime() {
return sht.getTreeStart();
/*******************************************************************************
- * Copyright (c) 2012, 2014 Ericsson
+ * Copyright (c) 2012, 2015 Ericsson
* Copyright (c) 2010, 2011 École Polytechnique de Montréal
* Copyright (c) 2010, 2011 Alexandre Montplaisir <alexandre.montplaisir@gmail.com>
*
* 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.tracecompass.statesystem.core.backend.historytree;
* Note that it usually doesn't make sense to use a Threaded HT if you're
* opening an existing state-file, but you know what you're doing...
*
+ * @param ssid
+ * The state system's id
* @param newStateFile
* The name of the history file that will be created. Should end
* in ".ht"
* @throws IOException
* If there was a problem opening the history file for writing
*/
- public ThreadedHistoryTreeBackend(File newStateFile, int blockSize,
+ public ThreadedHistoryTreeBackend(@NonNull String ssid, File newStateFile, int blockSize,
int maxChildren, long startTime, int providerVersion, int queueSize)
throws IOException {
- super(newStateFile, blockSize, maxChildren, providerVersion, startTime);
+ super(ssid, newStateFile, blockSize, maxChildren, providerVersion, startTime);
intervalQueue = new ArrayBlockingQueue<>(queueSize);
shtThread = new Thread(this, "History Tree Thread"); //$NON-NLS-1$
* New State History constructor. This version provides default values for
* blockSize and maxChildren.
*
+ * @param ssid
+ * The state system's id
* @param newStateFile
* The name of the history file that will be created. Should end
* in ".ht"
* @throws IOException
* If there was a problem opening the history file for writing
*/
- public ThreadedHistoryTreeBackend(File newStateFile, long startTime,
+ public ThreadedHistoryTreeBackend(@NonNull String ssid, File newStateFile, long startTime,
int providerVersion, int queueSize) throws IOException {
- super(newStateFile, providerVersion, startTime);
+ super(ssid, newStateFile, providerVersion, startTime);
intervalQueue = new ArrayBlockingQueue<>(queueSize);
shtThread = new Thread(this, "History Tree Thread"); //$NON-NLS-1$
@BeforeClass
public static void init() {
TmfMipmapStateProviderStub mmp = new TmfMipmapStateProviderStub(RESOLUTION, Type.LONG);
- IStateHistoryBackend be = new InMemoryBackend(0);
- ITmfStateSystemBuilder ssb = StateSystemFactory.newStateSystem(SSID, be);
+ IStateHistoryBackend be = new InMemoryBackend(SSID, 0);
+ ITmfStateSystemBuilder ssb = StateSystemFactory.newStateSystem(be);
mmp.assignTargetStateSystem(ssb);
ssq = ssb;
public static void init() {
/* setup for INTEGER test */
TmfMipmapStateProviderStub mmpi = new TmfMipmapStateProviderStub(RESOLUTION, Type.INTEGER);
- IStateHistoryBackend bei = new InMemoryBackend(0);
- ITmfStateSystemBuilder ssbi = StateSystemFactory.newStateSystem(SSID, bei);
+ IStateHistoryBackend bei = new InMemoryBackend(SSID, 0);
+ ITmfStateSystemBuilder ssbi = StateSystemFactory.newStateSystem(bei);
mmpi.assignTargetStateSystem(ssbi);
ssqi = ssbi;
/* setup for DOUBLE test */
TmfMipmapStateProviderStub mmpd = new TmfMipmapStateProviderStub(RESOLUTION, Type.DOUBLE);
- IStateHistoryBackend bed = new InMemoryBackend(0);
- ITmfStateSystemBuilder ssbd = StateSystemFactory.newStateSystem(SSID, bed);
+ IStateHistoryBackend bed = new InMemoryBackend(SSID, 0);
+ ITmfStateSystemBuilder ssbd = StateSystemFactory.newStateSystem(bed);
mmpd.assignTargetStateSystem(ssbd);
ssqd = ssbd;
/*
*/
public class PartialHistoryBackend implements IStateHistoryBackend {
+ private final @NonNull String fSSID;
+
/**
* A partial history needs the state input plugin to re-generate state
* between checkpoints.
/**
* Constructor
*
+ * @param ssid
+ * The state system's ID
* @param partialInput
* The state change input object that was used to build the
* upstream state system. This partial history will make its own
* Configuration parameter indicating how many trace events there
* should be between each checkpoint
*/
- public PartialHistoryBackend(ITmfStateProvider partialInput, PartialStateSystem pss,
- IStateHistoryBackend realBackend, long granularity) {
+ public PartialHistoryBackend(@NonNull String ssid,
+ ITmfStateProvider partialInput,
+ PartialStateSystem pss,
+ IStateHistoryBackend realBackend,
+ long granularity) {
if (granularity <= 0 || partialInput == null || pss == null ||
partialInput.getAssignedStateSystem() != pss) {
throw new IllegalArgumentException();
final long startTime = realBackend.getStartTime();
+ fSSID = ssid;
fPartialInput = partialInput;
fPartialSS = pss;
/* The request will countDown the checkpoints latch once it's finished */
}
+ @Override
+ public String getSSID() {
+ return fSSID;
+ }
+
@Override
public long getStartTime() {
return fInnerHistory.getStartTime();
* We use a Null back end here : we only use this state system for its
* "ongoing" values, so no need to save the changes that are inserted.
*/
- super("partial", new NullBackend()); //$NON-NLS-1$
+ super(new NullBackend("partial")); //$NON-NLS-1$
}
/**
/* Load an existing history */
final int version = provider.getVersion();
try {
- IStateHistoryBackend backend = new HistoryTreeBackend(htFile, version);
+ IStateHistoryBackend backend = new HistoryTreeBackend(id, htFile, version);
fHtBackend = backend;
- fStateSystem = StateSystemFactory.newStateSystem(id, backend, false);
+ fStateSystem = StateSystemFactory.newStateSystem(backend, false);
fInitialized.countDown();
return;
} catch (IOException e) {
final int QUEUE_SIZE = 10000;
try {
- IStateHistoryBackend backend = new ThreadedHistoryTreeBackend(htFile,
+ IStateHistoryBackend backend = new ThreadedHistoryTreeBackend(id, htFile,
provider.getStartTime(), provider.getVersion(), QUEUE_SIZE);
fHtBackend = backend;
- fStateSystem = StateSystemFactory.newStateSystem(id, backend);
+ fStateSystem = StateSystemFactory.newStateSystem(backend);
provider.assignTargetStateSystem(fStateSystem);
build(provider);
} catch (IOException e) {
/* 2 */
IStateHistoryBackend realBackend = null;
try {
- realBackend = new ThreadedHistoryTreeBackend(htPartialFile,
+ realBackend = new ThreadedHistoryTreeBackend(id, htPartialFile,
provider.getStartTime(), provider.getVersion(), QUEUE_SIZE);
} catch (IOException e) {
throw new TmfTraceException(e.toString(), e);
partialProvider.assignTargetStateSystem(pss);
/* 3 */
+ String partialId = new String(id + ".partial"); //$NON-NLS-1$
IStateHistoryBackend partialBackend =
- new PartialHistoryBackend(partialProvider, pss, realBackend, granularity);
+ new PartialHistoryBackend(partialId, partialProvider, pss, realBackend, granularity);
/* 4 */
@SuppressWarnings("restriction")
org.eclipse.tracecompass.internal.statesystem.core.StateSystem realSS =
- (org.eclipse.tracecompass.internal.statesystem.core.StateSystem) StateSystemFactory.newStateSystem(id, partialBackend);
+ (org.eclipse.tracecompass.internal.statesystem.core.StateSystem) StateSystemFactory.newStateSystem(partialBackend);
/* 5 */
pss.assignUpstream(realSS);
* {@link ITmfStateSystem#queryOngoingState} will be available.
*/
private void createNullHistory(String id, ITmfStateProvider provider) {
- IStateHistoryBackend backend = new NullBackend();
+ IStateHistoryBackend backend = new NullBackend(id);
fHtBackend = backend;
- fStateSystem = StateSystemFactory.newStateSystem(id, backend);
+ fStateSystem = StateSystemFactory.newStateSystem(backend);
provider.assignTargetStateSystem(fStateSystem);
build(provider);
}
* to 2^31 intervals.
*/
private void createInMemoryHistory(String id, ITmfStateProvider provider) {
- IStateHistoryBackend backend = new InMemoryBackend(provider.getStartTime());
+ IStateHistoryBackend backend = new InMemoryBackend(id, provider.getStartTime());
fHtBackend = backend;
- fStateSystem = StateSystemFactory.newStateSystem(id, backend);
+ fStateSystem = StateSystemFactory.newStateSystem(backend);
provider.assignTargetStateSystem(fStateSystem);
build(provider);
}