testHtFile = File.createTempFile("test", ".ht");
IStateHistoryBackend backend = new HistoryTreeBackend(testHtFile, 0, 0L);
- ss = new StateSystem(backend, true);
+ ss = new StateSystem("push-pop-test", backend, true);
/* Build the thing */
final int attrib = ss.getQuarkAbsoluteAndAdd("Test", "stack");
import java.util.List;
import java.util.Random;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.linuxtools.internal.tmf.core.statesystem.StateSystem;
import org.eclipse.linuxtools.internal.tmf.core.statesystem.backends.IStateHistoryBackend;
import org.eclipse.linuxtools.internal.tmf.core.statesystem.backends.InMemoryBackend;
*
*/
public class TmfMipmapStateProviderTest {
+
+ @NonNull private static final String SSID = "mimap-test";
private static final String TEST_ATTRIBUTE_NAME = TmfMipmapStateProviderStub.TEST_ATTRIBUTE_NAME;
private static final int NB_LEVELS = 4;
private static final long START_TIME = 1000L;
public static void init() {
TmfMipmapStateProviderStub mmp = new TmfMipmapStateProviderStub(RESOLUTION, Type.LONG);
IStateHistoryBackend be = new InMemoryBackend(0);
- ssq = new StateSystem(be);
+ ssq = new StateSystem(SSID, be);
mmp.assignTargetStateSystem(ssq);
for (long time = START_TIME; time <= END_TIME; time += INTERVAL) {
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.linuxtools.internal.tmf.core.statesystem.StateSystem;
import org.eclipse.linuxtools.internal.tmf.core.statesystem.backends.IStateHistoryBackend;
import org.eclipse.linuxtools.internal.tmf.core.statesystem.backends.InMemoryBackend;
*
*/
public class TmfMipmapStateProviderWeightedTest {
+
+ @NonNull private static final String SSID = "mipmap-test";
private static final String TEST_ATTRIBUTE_NAME = TmfMipmapStateProviderStub.TEST_ATTRIBUTE_NAME;
private static final long END_TIME = 250000L;
private static final long INTERVAL = 1000L;
/* setup for INTEGER test */
TmfMipmapStateProviderStub mmpi = new TmfMipmapStateProviderStub(RESOLUTION, Type.INTEGER);
IStateHistoryBackend bei = new InMemoryBackend(0);
- ssqi = new StateSystem(bei);
+ ssqi = new StateSystem(SSID, bei);
mmpi.assignTargetStateSystem(ssqi);
/* setup for DOUBLE test */
TmfMipmapStateProviderStub mmpd = new TmfMipmapStateProviderStub(RESOLUTION, Type.DOUBLE);
IStateHistoryBackend bed = new InMemoryBackend(0);
- ssqd = new StateSystem(bed);
+ ssqd = new StateSystem(SSID, bed);
mmpd.assignTargetStateSystem(ssqd);
/*
* Every 10,000 ns chunk contains the following states:
*/
public static ITmfStateSystemBuilder openExistingHistory(
@NonNull IStateHistoryBackend hb) throws IOException {
- return new StateSystem(hb, false);
+ return new StateSystem("legacy-state-system", hb, false); //$NON-NLS-1$
}
/**
*/
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 IStateHistoryBackend backend) {
+ public StateSystem(@NonNull String ssid, @NonNull IStateHistoryBackend backend) {
+ this.ssid = ssid;
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 IStateHistoryBackend backend, boolean newFile)
+ public StateSystem(@NonNull String ssid, @NonNull IStateHistoryBackend backend, boolean newFile)
throws IOException {
+ this.ssid = ssid;
this.backend = backend;
this.transState = new TransientState(backend);
}
}
+ @Override
+ public String getSSID() {
+ return ssid;
+ }
+
@Override
public boolean isCancelled() {
return buildCancelled;
* 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(new NullBackend());
+ super("partial", new NullBackend()); //$NON-NLS-1$
}
/**
*/
public interface ITmfStateSystem {
+ /**
+ * Get the ID of this state system.
+ *
+ * @return The state system's ID
+ * @since 3.0
+ */
+ String getSSID();
+
/**
* Return the start time of this history. It usually matches the start time
* of the original trace.
implements ITmfAnalysisModuleWithStateSystems {
private static final String EXTENSION = ".ht"; //$NON-NLS-1$
+ private static final String UNDEFINED_ID = "undefined"; //$NON-NLS-1$
private final CountDownLatch fInitialized = new CountDownLatch(1);
IProgressMonitor mon = (monitor == null ? new NullProgressMonitor() : monitor);
final ITmfStateProvider provider = createStateProvider();
+ String id = getId();
+ if (id == null) {
+ /* The analysis module does not specify an ID, use a generic one */
+ id = UNDEFINED_ID;
+ }
+
/* FIXME: State systems should make use of the monitor, to be cancelled */
try {
/* Get the state system according to backend */
case FULL:
directory = TmfTraceManager.getSupplementaryFileDir(getTrace());
htFile = new File(directory + getSsFileName());
- createFullHistory(provider, htFile);
+ createFullHistory(id, provider, htFile);
break;
case PARTIAL:
directory = TmfTraceManager.getSupplementaryFileDir(getTrace());
htFile = new File(directory + getSsFileName());
- createPartialHistory(provider, htFile);
+ createPartialHistory(id, provider, htFile);
break;
case INMEM:
- createInMemoryHistory(provider);
+ createInMemoryHistory(id, provider);
break;
case NULL:
- createNullHistory(provider);
+ createNullHistory(id, provider);
break;
default:
break;
* exists, it will be opened directly. If not, it will be created from
* scratch.
*/
- private void createFullHistory(ITmfStateProvider provider, File htFile) throws TmfTraceException {
+ private void createFullHistory(String id, ITmfStateProvider provider, File htFile) throws TmfTraceException {
/* If the target file already exists, do not rebuild it uselessly */
// TODO for now we assume it's complete. Might be a good idea to check
/* Load an existing history */
final int version = provider.getVersion();
try {
- fHtBackend = new HistoryTreeBackend(htFile, version);
- fStateSystem = new StateSystem(fHtBackend, false);
+ IStateHistoryBackend backend = new HistoryTreeBackend(htFile, version);
+ fHtBackend = backend;
+ fStateSystem = new StateSystem(id, backend, false);
fInitialized.countDown();
return;
} catch (IOException e) {
final int QUEUE_SIZE = 10000;
try {
- fHtBackend = new ThreadedHistoryTreeBackend(htFile,
+ IStateHistoryBackend backend = new ThreadedHistoryTreeBackend(htFile,
provider.getStartTime(), provider.getVersion(), QUEUE_SIZE);
- fStateSystem = new StateSystem(fHtBackend);
+ fHtBackend = backend;
+ fStateSystem = new StateSystem(id, backend);
provider.assignTargetStateSystem(fStateSystem);
build(provider);
} catch (IOException e) {
* underneath, (which are much slower), so this might not be a good fit for
* a use case where you have to do lots of single queries.
*/
- private void createPartialHistory(ITmfStateProvider provider, File htPartialFile)
+ private void createPartialHistory(String id, ITmfStateProvider provider, File htPartialFile)
throws TmfTraceException {
/*
* The order of initializations is very tricky (but very important!)
new PartialHistoryBackend(partialProvider, pss, realBackend, granularity);
/* 4 */
- StateSystem realSS = new StateSystem(partialBackend);
+ StateSystem realSS = new StateSystem(id, partialBackend);
/* 5 */
pss.assignUpstream(realSS);
* no history intervals will be saved anywhere, and as such only
* {@link ITmfStateSystem#queryOngoingState} will be available.
*/
- private void createNullHistory(ITmfStateProvider provider) {
- fHtBackend = new NullBackend();
- fStateSystem = new StateSystem(fHtBackend);
+ private void createNullHistory(String id, ITmfStateProvider provider) {
+ IStateHistoryBackend backend = new NullBackend();
+ fHtBackend = backend;
+ fStateSystem = new StateSystem(id, backend);
provider.assignTargetStateSystem(fStateSystem);
build(provider);
}
* only be done for very small state system, and will be naturally limited
* to 2^31 intervals.
*/
- private void createInMemoryHistory(ITmfStateProvider provider) {
- fHtBackend = new InMemoryBackend(provider.getStartTime());
- fStateSystem = new StateSystem(fHtBackend);
+ private void createInMemoryHistory(String id, ITmfStateProvider provider) {
+ IStateHistoryBackend backend = new InMemoryBackend(provider.getStartTime());
+ fHtBackend = backend;
+ fStateSystem = new StateSystem(id, backend);
provider.assignTargetStateSystem(fStateSystem);
build(provider);
}
import java.io.File;
import java.io.IOException;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.linuxtools.internal.tmf.core.statesystem.HistoryBuilder;
import org.eclipse.linuxtools.internal.tmf.core.statesystem.StateSystem;
import org.eclipse.linuxtools.internal.tmf.core.statesystem.backends.IStateHistoryBackend;
/** "static" class */
private TmfStateSystemFactory() {}
+ @NonNull private static final String SSID = "legacy-state-system"; //$NON-NLS-1$
+
/** Size of the blocking queue to use when building a state history */
private static final int QUEUE_SIZE = 10000;
try {
htBackend = new ThreadedHistoryTreeBackend(htFile,
stateProvider.getStartTime(), stateProvider.getVersion(), QUEUE_SIZE);
- StateSystem ss = new StateSystem(htBackend);
+ StateSystem ss = new StateSystem(SSID, htBackend);
stateProvider.assignTargetStateSystem(ss);
builder = new HistoryBuilder(stateProvider, ss, htBackend, buildManually);
} catch (IOException e) {
*/
public static ITmfStateSystem newNullHistory(ITmfStateProvider stateProvider) {
IStateHistoryBackend backend = new NullBackend();
- StateSystem ss = new StateSystem(backend);
+ StateSystem ss = new StateSystem(SSID, backend);
stateProvider.assignTargetStateSystem(ss);
HistoryBuilder builder = new HistoryBuilder(stateProvider, ss, backend, true);
public static ITmfStateSystem newInMemHistory(ITmfStateProvider stateProvider,
boolean buildManually) {
IStateHistoryBackend backend = new InMemoryBackend(stateProvider.getStartTime());
- StateSystem ss = new StateSystem(backend);
+ StateSystem ss = new StateSystem(SSID, backend);
stateProvider.assignTargetStateSystem(ss);
HistoryBuilder builder = new HistoryBuilder(stateProvider, ss, backend, buildManually);
new PartialHistoryBackend(partialProvider, pss, realBackend, granularity);
/* 4 */
- StateSystem realSS = new StateSystem(partialBackend);
+ StateSystem realSS = new StateSystem(SSID, partialBackend);
/* 5 */
pss.assignUpstream(realSS);