Non-working version

This commit is contained in:
Eyck Jentzsch 2018-08-27 23:10:52 +02:00
parent 73c257af03
commit 397863875e
20 changed files with 213 additions and 97 deletions

View File

@ -1,3 +1,4 @@
eclipse.preferences.version=1
encoding//src/com/minres/scviewer/database/test/DatabaseServicesPerformanceTest.java=UTF-8
encoding//src/com/minres/scviewer/database/test/DatabaseServicesTest.java=UTF-8
encoding/<project>=UTF-8

View File

@ -16,18 +16,18 @@
<booleanAttribute key="includeOptional" value="true"/>
<stringAttribute key="location" value="${workspace_loc}/../junit-workspace"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/com.minres.scviewer.database.test"/>
<listEntry value="/com.minres.scviewer.database.test/src/com/minres/scviewer/database/test/DatabaseServicesTest.java"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="4"/>
<listEntry value="1"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value="=com.minres.scviewer.database.test"/>
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/>
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value=""/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="com.minres.scviewer.database.test.DatabaseServicesTest"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="com.minres.scviewer.database.test"/>
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="com.minres.scviewer.database.test">
<implementation class="com.minres.scviewer.database.test.DatabaseServicesTest"/>
<implementation class="com.minres.scviewer.database.test.DatabaseFactory"/>
<reference bind="setFactory" cardinality="1..1" interface="com.minres.scviewer.database.IWaveformDbFactory" name="IWaveformDbFactory" policy="static" unbind="unsetFactory"/>
</scr:component>

View File

@ -1,2 +1,3 @@
/.scviewer.*
/.my_db.txlog*
/.my_db.txlog*
/.simple_system.txlog_bdb.*

View File

@ -0,0 +1,24 @@
package com.minres.scviewer.database.test;
import com.minres.scviewer.database.IWaveformDb;
import com.minres.scviewer.database.IWaveformDbFactory;
public class DatabaseFactory {
private static IWaveformDbFactory waveformDbFactory;
public synchronized void setFactory(IWaveformDbFactory service) {
waveformDbFactory = service;
}
public synchronized void unsetFactory(IWaveformDbFactory service) {
if (waveformDbFactory == service) {
waveformDbFactory = null;
}
}
public IWaveformDb getDatabase() {
return waveformDbFactory.getDatabase();
}
}

View File

@ -0,0 +1,65 @@
/*******************************************************************************
* Copyright (c) 2015 MINRES Technologies GmbH and others.
* 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:
* MINRES Technologies GmbH - initial API and implementation
*******************************************************************************/
package com.minres.scviewer.database.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.minres.scviewer.database.IWaveformDb;
import com.minres.scviewer.database.IWaveformDbFactory;
public class DatabaseServicesPerformanceTest {
private DatabaseFactory databaseFactory;
private IWaveformDb waveformDb;
@Before
public void setUp() throws Exception {
databaseFactory = new DatabaseFactory();
waveformDb=databaseFactory.getDatabase();
}
@After
public void tearDown() throws Exception {
}
@Test
public void testVCD() throws Exception {
File f = new File("inputs/my_db.vcd").getAbsoluteFile();
assertTrue(f.exists());
waveformDb.load(f);
assertNotNull(waveformDb);
assertEquals(14, waveformDb.getAllWaves().size());
assertEquals(2, waveformDb.getChildNodes().size());
}
@Test
public void testTxText() throws Exception {
File f = new File("inputs/simple_system.txlog").getAbsoluteFile();
assertTrue(f.exists());
long timeBefore = System.currentTimeMillis();
waveformDb.load(f);
long timeAfter = System.currentTimeMillis();
long elapsed = timeAfter - timeBefore;
assertNotNull(waveformDb);
System.out.println("elapsed:" + elapsed);
}
}

View File

@ -26,23 +26,13 @@ import com.minres.scviewer.database.IWaveformDbFactory;
public class DatabaseServicesTest {
private static IWaveformDbFactory waveformDbFactory;
private DatabaseFactory databaseFactory;
private IWaveformDb waveformDb;
public synchronized void setFactory(IWaveformDbFactory service) {
waveformDbFactory = service;
}
public synchronized void unsetFactory(IWaveformDbFactory service) {
if (waveformDbFactory == service) {
waveformDbFactory = null;
}
}
@Before
public void setUp() throws Exception {
waveformDb=waveformDbFactory.getDatabase();
waveformDb=new DatabaseFactory().getDatabase();
// Wait for OSGi dependencies
// for (int i = 0; i < 10; i++) {
// if (waveformDb.size() == 3) // Dependencies fulfilled

View File

@ -1,2 +1,3 @@
eclipse.preferences.version=1
groovy.compiler.level=23
groovy.compiler.level=24
groovy.script.filters=**/*.dsld,y,**/*.gradle,n

View File

@ -26,17 +26,21 @@ import com.minres.scviewer.database.IWaveformDb
import com.minres.scviewer.database.IWaveformDbLoader
import com.minres.scviewer.database.RelationType
public class TextDbLoader implements IWaveformDbLoader{
public class TextDbLoader implements IWaveformDbLoader, Serializable{
private Long maxTime;
IWaveformDb db;
transient IWaveformDb db;
DB backingDb;
transient DB backingDb;
def streams = []
transient def streamsById = [:]
transient def generatorsById = [:]
transient def transactionsById = [:]
def relationTypes=[:]
transient def relationTypes=[:]
public TextDbLoader() {
}
@ -48,37 +52,39 @@ public class TextDbLoader implements IWaveformDbLoader{
@Override
public List<IWaveform> getAllWaves() {
return new LinkedList<IWaveform>(streams);
return new LinkedList<IWaveform>(streamsById.values());
}
public Map<Long, ITxGenerator> getGeneratorsById() {
TreeMap<Long, ITxGenerator> res = new TreeMap<Long, ITxGenerator>();
streams.each{TxStream stream -> stream.generators.each{res.put(it.id, id)} }
return res;
}
// public Map<Long, ITxGenerator> getGeneratorsById() {
// TreeMap<Long, ITxGenerator> res = new TreeMap<Long, ITxGenerator>();
// streamsById.values().each{TxStream stream ->
// stream.generators.each{res.put(it.id, id)} }
// return res;
// }
static final byte[] x = "scv_tr_stream".bytes
@Override
boolean load(IWaveformDb db, File file) throws Exception {
this.db=db
this.streams=[]
def gzipped = isGzipped(file)
if(isTxfile(gzipped?new GZIPInputStream(new FileInputStream(file)):new FileInputStream(file))){
if(true) {
def parentDir=file.absoluteFile.parent
def filename=file.name
new File(parentDir).eachFileRecurse (FileType.FILES) { f -> if(f.name=~/^\.${filename}/) f.delete() }
this.backingDb = DBMaker.openFile(parentDir+File.separator+"."+filename+"_bdb")
.deleteFilesAfterClose()
.useRandomAccessFile()
.setMRUCacheSize(4096)
//.disableTransactions()
.disableLocking()
.make();
} else {
this.backingDb = DBMaker.openMemory().disableLocking().make()
}
def parentDir=file.absoluteFile.parent
def filename=file.name
new File(parentDir).eachFileRecurse (FileType.FILES) { f -> if(f.name=~/^\.${filename}/) f.delete() }
this.backingDb = DBMaker.openFile(parentDir+File.separator+"."+filename+"_bdb")
.deleteFilesAfterClose()
.useRandomAccessFile()
//.enableHardCache()
.enableMRUCache()
.setMRUCacheSize(1024*4096)
.disableTransactions()
.disableLocking()
.make();
streamsById = backingDb.createHashMap("streamsById")
generatorsById = backingDb.createHashMap("generatorsById")
transactionsById = backingDb.createHashMap("transactionsById")
relationTypes=backingDb.createHashMap("relationTypes")
parseInput(gzipped?new GZIPInputStream(new FileInputStream(file)):new FileInputStream(file))
calculateConcurrencyIndicees()
return true
@ -122,9 +128,7 @@ public class TextDbLoader implements IWaveformDbLoader{
}
}
private def parseInput(InputStream inputStream){
def streamsById = [:]
def generatorsById = [:]
def transactionsById = [:]
//def transactionsById = backingDb.createHashMap("transactionsById")
TxGenerator generator
Tx transaction
boolean endTransaction=false
@ -139,15 +143,14 @@ public class TextDbLoader implements IWaveformDbLoader{
case "begin_attribute":
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], backingDb)
streams<<stream
def id = Long.parseLong(matcher[0][1])
def stream = new TxStream(this, id, matcher[0][2], matcher[0][3])
streamsById[id]=stream
} else if ((matcher = line =~ /^scv_tr_generator\s+\(ID\s+(\d+),\s+name\s+"([^"]+)",\s+scv_tr_stream\s+(\d+),$/)) {
def id = Integer.parseInt(matcher[0][1])
ITxStream stream=streamsById[Integer.parseInt(matcher[0][3])]
generator=new TxGenerator(id, stream, matcher[0][2])
stream.generators<<generator
def id = Long.parseLong(matcher[0][1])
ITxStream stream=streamsById[Long.parseLong(matcher[0][3])]
generator=new TxGenerator(this, id, stream.id, matcher[0][2])
stream.generators<<id
generatorsById[id]=generator
} else if ((matcher = line =~ /^begin_attribute \(ID (\d+), name "([^"]+)", type "([^"]+)"\)$/)) {
generator.begin_attrs << TxAttributeType.getAttrType(matcher[0][2], DataType.valueOf(matcher[0][3]), AssociationType.BEGIN)
@ -159,9 +162,9 @@ public class TextDbLoader implements IWaveformDbLoader{
generator=null
break
case "tx_begin"://matcher = line =~ /^tx_begin\s+(\d+)\s+(\d+)\s+(\d+)\s+([munpf]?s)/
def id = Integer.parseInt(tokens[1])
TxGenerator gen=generatorsById[Integer.parseInt(tokens[2])]
transaction = new Tx(id, gen.stream, gen, Long.parseLong(tokens[3])*stringToScale(tokens[4]))
def id = Long.parseLong(tokens[1])
TxGenerator gen=generatorsById[Long.parseLong(tokens[2])]
transaction = new Tx(this, id, gen.id, Long.parseLong(tokens[3])*stringToScale(tokens[4]))
gen.transactions << transaction
transactionsById[id]= transaction
gen.begin_attrs_idx=0;
@ -169,16 +172,16 @@ public class TextDbLoader implements IWaveformDbLoader{
endTransaction=false
break
case "tx_end"://matcher = line =~ /^tx_end\s+(\d+)\s+(\d+)\s+(\d+)\s+([munpf]?s)/
def id = Integer.parseInt(tokens[1])
def id = Long.parseLong(tokens[1])
transaction = transactionsById[id]
assert Integer.parseInt(tokens[2])==transaction.generator.id
assert Long.parseLong(tokens[2])==transaction.generator.id
transaction.endTime = Long.parseLong(tokens[3])*stringToScale(tokens[4])
transaction.generator.end_attrs_idx=0;
maxTime = maxTime>transaction.endTime?maxTime:transaction.endTime
endTransaction=true
break
case "tx_record_attribute"://matcher = line =~ /^tx_record_attribute\s+(\d+)\s+"([^"]+)"\s+(\S+)\s*=\s*(.+)$/
def id = Integer.parseInt(tokens[1])
def id = Long.parseLong(tokens[1])
transactionsById[id].attributes<<new TxAttribute(tokens[2][1..-2], DataType.valueOf(tokens[3]), AssociationType.RECORD, tokens[5..-1].join(' '))
break
case "a"://matcher = line =~ /^a\s+(.+)$/
@ -189,8 +192,8 @@ public class TextDbLoader implements IWaveformDbLoader{
}
break
case "tx_relation"://matcher = line =~ /^tx_relation\s+\"(\S+)\"\s+(\d+)\s+(\d+)$/
Tx tr2= transactionsById[Integer.parseInt(tokens[2])]
Tx tr1= transactionsById[Integer.parseInt(tokens[3])]
Tx tr2= transactionsById[Long.parseLong(tokens[2])]
Tx tr1= transactionsById[Long.parseLong(tokens[3])]
def relType=tokens[1][1..-2]
if(!relationTypes.containsKey(relType)) relationTypes[relType]=RelationType.create(relType)
def rel = new TxRelation(relationTypes[relType], tr1, tr2)
@ -202,14 +205,14 @@ public class TextDbLoader implements IWaveformDbLoader{
}
lineCnt++
if((lineCnt%1000) == 0) {
backingDb.commit()
}
}
backingDb.commit();
}
private def calculateConcurrencyIndicees(){
streams.each{ TxStream stream -> stream.getMaxConcurrency() }
streamsById.values().each{ TxStream stream ->
stream.getMaxConcurrency()
}
}

View File

@ -12,13 +12,13 @@ package com.minres.scviewer.database.text
import com.minres.scviewer.database.*
class Tx implements ITx {
class Tx implements ITx, Serializable {
TextDbLoader loader
Long id
TxGenerator generator
TxStream stream
Long generator_id
int concurrencyIndex
@ -32,10 +32,10 @@ class Tx implements ITx {
def outgoingRelations =[]
Tx(int id, TxStream stream, TxGenerator generator, Long begin){
Tx(TextDbLoader loader, Long id, Long generator_id, Long begin){
this.loader=loader
this.id=id
this.stream=stream
this.generator=generator
this.generator_id=generator_id
this.beginTime=begin
this.endTime=begin
}
@ -64,4 +64,14 @@ class Tx implements ITx {
return "tx#"+getId()+"["+getBeginTime()/1000000+"ns - "+getEndTime()/1000000+"ns]";
}
@Override
public ITxStream<ITxEvent> getStream() {
return generator.stream;
}
@Override
public ITxGenerator getGenerator() {
return loader.generatorsById[generator_id];
}
}

View File

@ -15,7 +15,7 @@ import com.minres.scviewer.database.DataType;
import com.minres.scviewer.database.ITxAttributeType;
import com.minres.scviewer.database.ITxAttribute
class TxAttribute implements ITxAttribute{
class TxAttribute implements ITxAttribute, Serializable {
TxAttributeType attributeType

View File

@ -14,7 +14,7 @@ import com.minres.scviewer.database.AssociationType;
import com.minres.scviewer.database.DataType;
import com.minres.scviewer.database.ITxAttributeType;
class TxAttributeType implements ITxAttributeType {
class TxAttributeType implements ITxAttributeType, Serializable {
String name
DataType dataType
AssociationType type

View File

@ -4,7 +4,7 @@ import com.minres.scviewer.database.ITx
import com.minres.scviewer.database.ITxEvent
import com.minres.scviewer.database.IWaveformEvent
class TxEvent implements ITxEvent {
class TxEvent implements ITxEvent, Serializable {
final ITxEvent.Type type;

View File

@ -12,7 +12,7 @@ package com.minres.scviewer.database.text
import java.util.ArrayList;
import java.util.List;
import org.apache.jdbm.DB
import com.minres.scviewer.database.ITxAttributeType
import com.minres.scviewer.database.ITxAttribute;
import com.minres.scviewer.database.ITxEvent;
@ -21,10 +21,11 @@ import com.minres.scviewer.database.ITxStream;
import com.minres.scviewer.database.ITx;
import com.minres.scviewer.database.IWaveformEvent;
class TxGenerator implements ITxGenerator{
class TxGenerator implements ITxGenerator, Serializable{
Long id
TxStream stream
Long stream_id
String name
TextDbLoader loader;
Boolean active = false
ArrayList<ITx> transactions=[]
@ -33,14 +34,15 @@ class TxGenerator implements ITxGenerator{
ArrayList<ITxAttributeType> end_attrs= []
int end_attrs_idx = 0
TxGenerator(int id, TxStream stream, name){
TxGenerator(TextDbLoader loader, Long id, Long stream_id, name){
this.id=id
this.stream=stream
this.stream_id=stream_id
this.name=name
this.loader=loader
}
ITxStream<? extends ITxEvent> getStream(){
return stream;
return loader.streamsById[stream_id];
}
List<ITx> getTransactions(){

View File

@ -4,7 +4,7 @@ import com.minres.scviewer.database.ITxRelation
import com.minres.scviewer.database.ITx;
import com.minres.scviewer.database.RelationType;
class TxRelation implements ITxRelation {
class TxRelation implements ITxRelation, Serializable {
Tx source
Tx target

View File

@ -27,11 +27,11 @@ import com.minres.scviewer.database.IHierNode
import com.minres.scviewer.database.ITxStream
import com.minres.scviewer.database.ITx
class TxStream extends HierNode implements ITxStream {
class TxStream extends HierNode implements ITxStream, Serializable {
Long id
IWaveformDb database
transient TextDbLoader loader
String fullName
@ -43,24 +43,24 @@ class TxStream extends HierNode implements ITxStream {
private TreeMap<Long, List<ITxEvent>> events
TxStream(IWaveformDb db, int id, String name, String kind, DB backingStore){
TxStream(TextDbLoader loader, Long id, String name, String kind){
super(name)
this.id=id
this.database=db
this.loader=loader
this.fullName=name
this.kind=kind
this.maxConcurrency=0
//events = new TreeMap<Long, List<ITxEvent>>()
events=backingStore.createTreeMap("stream-"+name)
events = new TreeMap<Long, List<ITxEvent>>()
//events=backingStore.createTreeMap("stream-"+name)
}
List<ITxGenerator> getGenerators(){
return generators as List<ITxGenerator>
return generators.collect { loader.generatorsById[it] } as List<ITxGenerator>
}
@Override
public IWaveformDb getDb() {
return database
return loader.db
}
@Override

View File

@ -12,18 +12,25 @@ package com.minres.scviewer.database;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.beans.Transient;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
public class HierNode implements IHierNode {
public class HierNode implements IHierNode, Serializable {
/**
*
*/
private static final long serialVersionUID = -2278641781226609616L;
protected String name;
protected String parentName;
protected ArrayList<IHierNode> childs;
protected transient ArrayList<IHierNode> childs;
protected PropertyChangeSupport pcs;
protected transient PropertyChangeSupport pcs;
public HierNode() {
childs = new ArrayList<IHierNode>();

View File

@ -10,10 +10,16 @@
*******************************************************************************/
package com.minres.scviewer.database;
import java.io.Serializable;
import java.util.HashMap;
public class RelationType {
public class RelationType implements Serializable {
/**
*
*/
private static final long serialVersionUID = -5598253591502850283L;
private static HashMap<String, RelationType> registry = new HashMap<>();
private String name;

View File

@ -11,6 +11,7 @@
package com.minres.scviewer.database.internal;
import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@ -31,7 +32,12 @@ import com.minres.scviewer.database.IWaveformEvent;
import com.minres.scviewer.database.InputFormatException;
import com.minres.scviewer.database.RelationType;
public class WaveformDb extends HierNode implements IWaveformDb {
public class WaveformDb extends HierNode implements IWaveformDb, Serializable {
/**
*
*/
private static final long serialVersionUID = 4917280760027131179L;
private static List<IWaveformDbLoader> loaders=new LinkedList<IWaveformDbLoader>();