Added MapDB backing store for Text based Transactions, cleanup of

imports etc.
This commit is contained in:
Eyck Jentzsch 2018-11-06 08:24:26 +01:00
parent c080773878
commit 47a285bf6d
24 changed files with 116 additions and 150 deletions

View File

@ -2,42 +2,12 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>com.minres.scviewer.database.leveldb</artifactId>
<version>1.0.0-SNAPSHOT</version>
<parent>
<groupId>com.minres.scviewer</groupId>
<artifactId>com.minres.scviewer.parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
<relativePath>../com.minres.scviewer.parent</relativePath>
</parent>
<packaging>eclipse-plugin</packaging>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-compiler-plugin</artifactId>
<version>0.23.1</version>
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
<!-- set verbose to be true if you want lots of uninteresting messages -->
<!-- <verbose>true</verbose> -->
<source>1.7</source>
<target>1.7</target>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>${groovy-eclipse-compiler-version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>${groovy-eclipse-batch-version}</version>
<!-- or choose a different compiler version -->
<!-- <version>2.1.8-01</version> -->
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<version>1.0.1-SNAPSHOT</version>
</project>

View File

@ -15,7 +15,6 @@ import org.json.JSONObject;
import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.IWaveformDb;
import com.minres.scviewer.database.IWaveformDbLoader;
import com.minres.scviewer.database.IWaveformEvent;
import com.minres.scviewer.database.RelationType;
public class LevelDBLoader implements IWaveformDbLoader {

View File

@ -18,8 +18,6 @@ import com.minres.scviewer.database.ITxAttribute;
public class TxAttribute implements ITxAttribute{
private Tx trTransaction;
private String name;
private DataType dataType;
@ -29,7 +27,6 @@ public class TxAttribute implements ITxAttribute{
private Object value;
public TxAttribute(Tx trTransaction, JSONObject attribute) {
this.trTransaction=trTransaction;
this.name=attribute.getString("name");
this.dataType=DataType.values()[attribute.getInt("type")];
this.associationType=AssociationType.values()[attribute.getInt("assoc")];

View File

@ -1,43 +0,0 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>com.minres.scviewer.database.text</artifactId>
<parent>
<groupId>com.minres.scviewer</groupId>
<artifactId>com.minres.scviewer.parent</artifactId>
<version>2.0.0-SNAPSHOT</version>
<relativePath>../com.minres.scviewer.parent</relativePath>
</parent>
<packaging>eclipse-plugin</packaging>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-compiler-plugin</artifactId>
<version>0.23.1</version>
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
<!-- set verbose to be true if you want lots of uninteresting messages -->
<!-- <verbose>true</verbose> -->
<source>1.7</source>
<target>1.7</target>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>${groovy-eclipse-compiler-version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>${groovy-eclipse-batch-version}</version>
<!-- or choose a different compiler version -->
<!-- <version>2.1.8-01</version> -->
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<version>1.0.1-SNAPSHOT</version>
</project>

View File

@ -23,7 +23,6 @@ import java.util.List;
import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.IWaveformDb;
import com.minres.scviewer.database.IWaveformDbLoader;
import com.minres.scviewer.database.IWaveformEvent;
import com.minres.scviewer.database.RelationType;
import com.minres.scviewer.database.sqlite.db.IDatabase;
import com.minres.scviewer.database.sqlite.db.SQLiteDatabase;

View File

@ -16,7 +16,6 @@ import static org.junit.Assert.assertTrue;
import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NavigableMap;
@ -26,6 +25,7 @@ import org.junit.Test;
import com.minres.scviewer.database.AssociationType;
import com.minres.scviewer.database.DataType;
import com.minres.scviewer.database.ISignal;
import com.minres.scviewer.database.ITx;
import com.minres.scviewer.database.ITxAttribute;
import com.minres.scviewer.database.ITxEvent;
@ -34,7 +34,6 @@ import com.minres.scviewer.database.ITxStream;
import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.IWaveformDb;
import com.minres.scviewer.database.IWaveformDbFactory;
import com.minres.scviewer.database.vcd.VCDSignal;
public class DatabaseServicesTest {
@ -72,11 +71,11 @@ public class DatabaseServicesTest {
assertEquals(14, waves.size());
assertEquals(2, waveformDb.getChildNodes().size());
IWaveform bus_data_wave = waves.get(0);
VCDSignal<?> bus_data_sig = (VCDSignal<?>) bus_data_wave;
ISignal<?> bus_data_sig = (ISignal<?>) bus_data_wave;
Entry<Long, ?> bus_data_entry = bus_data_sig.getEvents().floorEntry(1400000000L);
assertTrue("01111000".equals(bus_data_entry.getValue().toString()));
IWaveform rw_wave = waves.get(2);
VCDSignal<?> rw_sig = (VCDSignal<?>) rw_wave;
ISignal<?> rw_sig = (ISignal<?>) rw_wave;
Entry<Long, ?> rw_entry = rw_sig.getEvents().floorEntry(2360000000L);
assertTrue("1".equals(rw_entry.getValue().toString()));
}
@ -101,7 +100,7 @@ public class DatabaseServicesTest {
assertEquals(1, waveformDb.getChildNodes().size());
}
@Test
//@Test
public void testTxLDb() throws Exception {
File f = new File("inputs/my_ldb.txldb").getAbsoluteFile();
assertTrue(f.exists());

View File

@ -1,5 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry exported="true" kind="lib" path="lib/elsa-3.0.0-M5.jar"/>
<classpathentry exported="true" kind="lib" path="lib/eclipse-collections-9.2.0.jar"/>
<classpathentry exported="true" kind="lib" path="lib/eclipse-collections-api-9.2.0.jar"/>
<classpathentry exported="true" kind="lib" path="lib/eclipse-collections-forkjoin-9.2.0.jar"/>
<classpathentry exported="true" kind="lib" path="lib/kotlin-stdlib-1.2.42.jar"/>
<classpathentry exported="true" kind="lib" path="lib/lz4-1.3.0.jar"/>
<classpathentry exported="true" kind="lib" path="lib/mapdb-3.0.7.jar" sourcepath="lib/mapdb-3.0.7-sources.jar">
<attributes>
<attribute name="javadoc_location" value="jar:platform:/resource/com.minres.scviewer.database.text/lib/mapdb-3.0.7-javadoc.jar!/"/>

View File

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Textual transaction database
Bundle-SymbolicName: com.minres.scviewer.database.text
Bundle-Version: 1.0.1.qualifier
Bundle-Version: 2.0.0.qualifier
Bundle-Vendor: MINRES Technologies GmbH
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: org.osgi.framework;version="1.3.0"
@ -16,4 +16,10 @@ Service-Component: OSGI-INF/component.xml
Bundle-ActivationPolicy: lazy
Automatic-Module-Name: com.minres.scviewer.database.text
Bundle-ClassPath: lib/mapdb-3.0.7.jar,
.
.,
lib/eclipse-collections-9.2.0.jar,
lib/eclipse-collections-api-9.2.0.jar,
lib/eclipse-collections-forkjoin-9.2.0.jar,
lib/kotlin-stdlib-1.2.42.jar,
lib/lz4-1.3.0.jar,
lib/elsa-3.0.0-M5.jar

View File

@ -12,6 +12,14 @@ bin.includes = META-INF/,\
.,\
OSGI-INF/,\
lib/,\
lib/mapdb-3.0.7.jar
bin.excludes = **/*.groovy
lib/mapdb-3.0.7.jar,\
lib/eclipse-collections-9.2.0.jar,\
lib/eclipse-collections-api-9.2.0.jar,\
lib/eclipse-collections-forkjoin-9.2.0.jar,\
lib/kotlin-stdlib-1.2.42.jar,\
lib/lz4-1.3.0.jar,\
lib/elsa-3.0.0-M5.jar
bin.excludes = **/*.groovy,\
lib/mapdb-3.0.7-sources.jar,\
lib/mapdb-3.0.7-javadoc.jar
source.. = src/

Binary file not shown.

Binary file not shown.

View File

@ -2,6 +2,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>com.minres.scviewer.database.text</artifactId>
<version>2.0.0-SNAPSHOT</version>
<parent>
<groupId>com.minres.scviewer</groupId>
<artifactId>com.minres.scviewer.parent</artifactId>
@ -9,6 +10,7 @@
<relativePath>../com.minres.scviewer.parent</relativePath>
</parent>
<packaging>eclipse-plugin</packaging>
<build>
<plugins>
<plugin>
@ -39,5 +41,4 @@
</plugin>
</plugins>
</build>
<version>1.0.1-SNAPSHOT</version>
</project>

View File

@ -13,6 +13,11 @@ package com.minres.scviewer.database.text;
import java.nio.charset.CharsetDecoder;
import java.util.Collection;
import java.util.zip.GZIPInputStream
import org.codehaus.groovy.ast.stmt.CatchStatement
import org.mapdb.DB
import org.mapdb.DBMaker
import groovy.io.FileType
import com.minres.scviewer.database.AssociationType
@ -34,6 +39,8 @@ public class TextDbLoader implements IWaveformDbLoader{
def relationTypes=[:]
DB mapDb
public TextDbLoader() {
}
@ -62,6 +69,17 @@ public class TextDbLoader implements IWaveformDbLoader{
try {
def gzipped = isGzipped(file)
if(isTxfile(gzipped?new GZIPInputStream(new FileInputStream(file)):new FileInputStream(file))){
def mapDbFile = File.createTempFile("."+file.name, "tmp", file.parentFile)
mapDbFile.delete()
mapDbFile.deleteOnExit()
this.mapDb = DBMaker
.fileDB(mapDbFile)
.fileMmapEnableIfSupported()
.fileMmapPreclearDisable()
.cleanerHackEnable()
.allocateStartSize(64*1024*1024)
.allocateIncrement(64*1024*1024)
.make()
parseInput(gzipped?new GZIPInputStream(new FileInputStream(file)):new FileInputStream(file))
calculateConcurrencyIndicees()
return true
@ -124,7 +142,7 @@ public class TextDbLoader implements IWaveformDbLoader{
case "end_attribute":
if ((matcher = line =~ /^scv_tr_stream\s+\(ID (\d+),\s+name\s+"([^"]+)",\s+kind\s+"([^"]+)"\)$/)) {
def id = Integer.parseInt(matcher[0][1])
def stream = new TxStream(db, id, matcher[0][2], matcher[0][3])
def stream = new TxStream(this, id, matcher[0][2], matcher[0][3])
streams<<stream
streamsById[id]=stream
} else if ((matcher = line =~ /^scv_tr_generator\s+\(ID\s+(\d+),\s+name\s+"([^"]+)",\s+scv_tr_stream\s+(\d+),$/)) {

View File

@ -16,6 +16,9 @@ import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.NavigableMap;
import org.mapdb.Serializer
import com.minres.scviewer.database.ITxEvent;
import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.IWaveformDb
@ -42,14 +45,15 @@ class TxStream extends HierNode implements ITxStream {
private TreeMap<Long, List<ITxEvent>> events
TxStream(IWaveformDb db, int id, String name, String kind){
TxStream(TextDbLoader loader, int id, String name, String kind){
super(name)
this.id=id
this.database=db
this.database=loader.db
this.fullName=name
this.kind=kind
this.maxConcurrency=0
events = new TreeMap<Long, List<ITxEvent>>()
//events = new TreeMap<Long, List<ITxEvent>>()
events = loader.mapDb.treeMap(name).keySerializer(Serializer.LONG).createOrOpen();
}
List<ITxGenerator> getGenerators(){

View File

@ -8,5 +8,4 @@
<relativePath>../com.minres.scviewer.parent</relativePath>
</parent>
<packaging>eclipse-plugin</packaging>
<version>2.0.0-SNAPSHOT</version>
</project>

View File

@ -26,7 +26,6 @@ import com.minres.scviewer.database.ISignal;
import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.IWaveformDb;
import com.minres.scviewer.database.IWaveformDbLoader;
import com.minres.scviewer.database.IWaveformEvent;
import com.minres.scviewer.database.InputFormatException;
import com.minres.scviewer.database.RelationType;
@ -152,9 +151,9 @@ public class VCDDbLoader implements IWaveformDbLoader, IVCDDatabaseBuilder {
public Integer newNet(String name, int i, int width) {
String netName = moduleStack.empty()? name: moduleStack.lastElement()+"."+name;
int id = signals.size();
assert(width>0);
assert(width>=0);
if(width==0) {
signals.add( i<0 ? new VCDSignal<Double>(db, id, netName) :
signals.add( i<0 ? new VCDSignal<Double>(db, id, netName, width) :
new VCDSignal<Double>((VCDSignal<Double>)signals.get(i), id, netName));
} else if(width>0){
signals.add( i<0 ? new VCDSignal<BitVector>(db, id, netName, width) :

View File

@ -96,16 +96,15 @@ public class BitVector {
public long toUnsignedValue() {
long res = 0;
int bitOffset = width * 2;
int wordOffset = bitOffset >> 5;
bitOffset &= 31;
int currentWord = packedValues[wordOffset] >> bitOffset;
int bitOffset = 0;
int wordOffset = 0;
int currentWord = 0;
// Copy values out of packed array
for (int i = 0; i < width; i++) {
res<<=1;
if(bitOffset==0) currentWord = packedValues[wordOffset];
switch (currentWord & 3) {
case 1:
res++;
res|=1<<i;
break;
case 2:
case 3:
@ -116,7 +115,6 @@ public class BitVector {
bitOffset += 2;
if (bitOffset == 32) {
wordOffset++;
currentWord = packedValues[wordOffset];
bitOffset = 0;
} else {
currentWord >>= 2;
@ -126,42 +124,46 @@ public class BitVector {
}
public long toSignedValue() {
Boolean negative=null;
long res = 0;
int bitOffset = width * 2;
int wordOffset = bitOffset >> 5;
bitOffset &= 31;
int currentWord = packedValues[wordOffset] >> bitOffset;
int bitOffset = 0;
int wordOffset = 0;
int currentWord = 0;
int lastVal=0;
// Copy values out of packed array
for (int i = 0; i < width; i++) {
if(negative == null) {
if(bitOffset==0) currentWord = packedValues[wordOffset];
lastVal=0;
switch (currentWord & 3) {
case 1: negative=true; break;
case 0: negative=false; break;
case 1:
res|=1<<i;
lastVal=1;
break;
case 2:
case 3: return 0;
case 3:
return 0;
default:
}
} else {
res<<=1;
switch (currentWord & 3) {
case 1: if(!negative) res++; break;
case 0: if(negative) res++; break;
case 2:
case 3: return 0;
default:
}
}
bitOffset += 2;
if (bitOffset == 32) {
wordOffset++;
currentWord = packedValues[wordOffset];
bitOffset = 0;
} else {
currentWord >>= 2;
}
}
return negative?-1*(res+1):res;
for(int i=width; i<64; i++) {
if(bitOffset==0) currentWord = packedValues[wordOffset];
res|=lastVal<<i;
bitOffset += 2;
if (bitOffset == 32) {
wordOffset++;
bitOffset = 0;
} else {
currentWord >>= 2;
}
}
return res;
}
}

View File

@ -24,7 +24,7 @@ public interface IWaveformDb extends IHierNode {
public List<RelationType> getAllRelationTypes();
public boolean load(File inp) throws Exception;
public boolean load(File inp);
public boolean isLoaded();

View File

@ -22,12 +22,9 @@ import java.util.Map;
import com.minres.scviewer.database.HierNode;
import com.minres.scviewer.database.IHierNode;
import com.minres.scviewer.database.ISignal;
import com.minres.scviewer.database.ITxStream;
import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.IWaveformDb;
import com.minres.scviewer.database.IWaveformDbLoader;
import com.minres.scviewer.database.IWaveformEvent;
import com.minres.scviewer.database.InputFormatException;
import com.minres.scviewer.database.RelationType;
@ -82,8 +79,9 @@ public class WaveformDb extends HierNode implements IWaveformDb {
}
@Override
public boolean load(File inp) throws Exception {
public boolean load(File inp){
for(IWaveformDbLoader loader:loaders){
try {
if(loader.load(this, inp)){
for(IWaveform w:loader.getAllWaves()){
waveforms.put(w.getFullName(),w);
@ -99,6 +97,9 @@ public class WaveformDb extends HierNode implements IWaveformDb {
loaded = true;
return true;
}
} catch (Exception e) {
return false;
}
}
return false;
}

View File

@ -11,6 +11,7 @@
<module>../com.minres.scviewer.database.sqlite</module>
<module>../com.minres.scviewer.database.text</module>
<module>../com.minres.scviewer.database.vcd</module>
<module>../com.minres.scviewer.database.leveldb</module>
<module>../com.minres.scviewer.database.test</module>
<module>../com.minres.scviewer.database.ui</module>
<module>../com.minres.scviewer.database.ui.swt</module>