add TX attribute value caching
This commit is contained in:
parent
8700e2fdde
commit
af388b2462
|
@ -10,12 +10,8 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package com.minres.scviewer.database.sqlite;
|
package com.minres.scviewer.database.sqlite;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.minres.scviewer.database.IWaveform;
|
import com.minres.scviewer.database.IWaveform;
|
||||||
import com.minres.scviewer.database.sqlite.tables.ScvGenerator;
|
import com.minres.scviewer.database.sqlite.tables.ScvGenerator;
|
||||||
import com.minres.scviewer.database.tx.ITx;
|
|
||||||
import com.minres.scviewer.database.tx.ITxGenerator;
|
import com.minres.scviewer.database.tx.ITxGenerator;
|
||||||
|
|
||||||
public class TxGenerator implements ITxGenerator {
|
public class TxGenerator implements ITxGenerator {
|
||||||
|
@ -44,9 +40,4 @@ public class TxGenerator implements ITxGenerator {
|
||||||
return scvGenerator.getName();
|
return scvGenerator.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<ITx> getTransactions() {
|
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
|
import org.eclipse.collections.impl.map.mutable.UnifiedMap;
|
||||||
import org.mapdb.DB;
|
import org.mapdb.DB;
|
||||||
import org.mapdb.DB.TreeMapSink;
|
import org.mapdb.DB.TreeMapSink;
|
||||||
import org.mapdb.DBMaker;
|
import org.mapdb.DBMaker;
|
||||||
|
@ -49,15 +50,17 @@ public class TextDbLoader implements IWaveformDbLoader{
|
||||||
|
|
||||||
DB mapDb=null;
|
DB mapDb=null;
|
||||||
|
|
||||||
final Map<String, RelationType> relationTypes=new HashMap<>();
|
final List<String> attrValues = new ArrayList<>();
|
||||||
|
|
||||||
final Map<Long, TxStream> txStreams = new HashMap<>();
|
final Map<String, RelationType> relationTypes = UnifiedMap.newMap();
|
||||||
|
|
||||||
final Map<Long, TxGenerator> txGenerators = new HashMap<>();
|
final Map<Long, TxStream> txStreams = UnifiedMap.newMap();
|
||||||
|
|
||||||
|
final Map<Long, TxGenerator> txGenerators = UnifiedMap.newMap();
|
||||||
|
|
||||||
Map<Long, ScvTx> transactions = null;
|
Map<Long, ScvTx> transactions = null;
|
||||||
|
|
||||||
final Map<String, TxAttributeType> attributeTypes = new HashMap<>();
|
final Map<String, TxAttributeType> attributeTypes = UnifiedMap.newMap();
|
||||||
|
|
||||||
final HashMultimap<Long, ScvRelation> relationsIn = HashMultimap.create();
|
final HashMultimap<Long, ScvRelation> relationsIn = HashMultimap.create();
|
||||||
|
|
||||||
|
@ -144,6 +147,7 @@ public class TextDbLoader implements IWaveformDbLoader{
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
|
attrValues.clear();
|
||||||
relationTypes.clear();
|
relationTypes.clear();
|
||||||
txStreams.clear();
|
txStreams.clear();
|
||||||
txGenerators.clear();
|
txGenerators.clear();
|
||||||
|
@ -202,6 +206,8 @@ public class TextDbLoader implements IWaveformDbLoader{
|
||||||
|
|
||||||
TxGenerator generator=null;
|
TxGenerator generator=null;
|
||||||
|
|
||||||
|
Map<String, Integer> attrValueLut = new HashMap<>();
|
||||||
|
|
||||||
public TextDbParser(TextDbLoader loader) {
|
public TextDbParser(TextDbLoader loader) {
|
||||||
super();
|
super();
|
||||||
this.loader = loader;
|
this.loader = loader;
|
||||||
|
@ -238,13 +244,12 @@ public class TextDbLoader implements IWaveformDbLoader{
|
||||||
DataType type = DataType.valueOf(tokens[3]);
|
DataType type = DataType.valueOf(tokens[3]);
|
||||||
String remaining = tokens.length>5?String.join(" ", Arrays.copyOfRange(tokens, 5, tokens.length)):"";
|
String remaining = tokens.length>5?String.join(" ", Arrays.copyOfRange(tokens, 5, tokens.length)):"";
|
||||||
TxAttributeType attrType = getAttrType(name, type, AssociationType.RECORD);
|
TxAttributeType attrType = getAttrType(name, type, AssociationType.RECORD);
|
||||||
transactionById.get(id).attributes.add(new TxAttribute(attrType, remaining));
|
transactionById.get(id).attributes.add(new TxAttribute(attrType, getAttrString(attrType, remaining)));
|
||||||
} else if("tx_begin".equals(tokens[0])){
|
} else if("tx_begin".equals(tokens[0])){
|
||||||
Long id = Long.parseLong(tokens[1]);
|
Long id = Long.parseLong(tokens[1]);
|
||||||
Long genId = Long.parseLong(tokens[2]);
|
Long genId = Long.parseLong(tokens[2]);
|
||||||
TxGenerator gen=loader.txGenerators.get(genId);
|
TxGenerator gen=loader.txGenerators.get(genId);
|
||||||
ScvTx scvTx = new ScvTx(id, gen.stream.getId(), genId, Long.parseLong(tokens[3])*stringToScale(tokens[4]));
|
ScvTx scvTx = new ScvTx(id, gen.stream.getId(), genId, Long.parseLong(tokens[3])*stringToScale(tokens[4]));
|
||||||
Tx tx = new Tx(loader, scvTx);
|
|
||||||
loader.maxTime = loader.maxTime>scvTx.beginTime?loader.maxTime:scvTx.beginTime;
|
loader.maxTime = loader.maxTime>scvTx.beginTime?loader.maxTime:scvTx.beginTime;
|
||||||
TxStream stream = loader.txStreams.get(gen.stream.getId());
|
TxStream stream = loader.txStreams.get(gen.stream.getId());
|
||||||
stream.setConcurrency(stream.getConcurrency()+1);
|
stream.setConcurrency(stream.getConcurrency()+1);
|
||||||
|
@ -252,7 +257,8 @@ public class TextDbLoader implements IWaveformDbLoader{
|
||||||
int idx=0;
|
int idx=0;
|
||||||
while(nextLine!=null && nextLine.charAt(0)=='a') {
|
while(nextLine!=null && nextLine.charAt(0)=='a') {
|
||||||
String[] attrTokens=nextLine.split("\\s+");
|
String[] attrTokens=nextLine.split("\\s+");
|
||||||
TxAttribute attr = new TxAttribute(gen.beginAttrs.get(idx), attrTokens[1]);
|
TxAttributeType attrType = gen.beginAttrs.get(idx);
|
||||||
|
TxAttribute attr = new TxAttribute(attrType, getAttrString(attrType, attrTokens[1]));
|
||||||
scvTx.attributes.add(attr);
|
scvTx.attributes.add(attr);
|
||||||
idx++;
|
idx++;
|
||||||
nextLine=reader.readLine();
|
nextLine=reader.readLine();
|
||||||
|
@ -260,10 +266,8 @@ public class TextDbLoader implements IWaveformDbLoader{
|
||||||
}
|
}
|
||||||
txSink.put(id, scvTx);
|
txSink.put(id, scvTx);
|
||||||
transactionById.put(id, scvTx);
|
transactionById.put(id, scvTx);
|
||||||
gen.getTransactions().add(tx);
|
|
||||||
} else if("tx_end".equals(tokens[0])){
|
} else if("tx_end".equals(tokens[0])){
|
||||||
Long id = Long.parseLong(tokens[1]);
|
Long id = Long.parseLong(tokens[1]);
|
||||||
//ScvTx tx = loader.transactions.get(id);
|
|
||||||
ScvTx scvTx = transactionById.get(id);
|
ScvTx scvTx = transactionById.get(id);
|
||||||
assert Long.parseLong(tokens[2])==scvTx.generatorId;
|
assert Long.parseLong(tokens[2])==scvTx.generatorId;
|
||||||
scvTx.endTime=Long.parseLong(tokens[3])*stringToScale(tokens[4]);
|
scvTx.endTime=Long.parseLong(tokens[3])*stringToScale(tokens[4]);
|
||||||
|
@ -281,7 +285,8 @@ public class TextDbLoader implements IWaveformDbLoader{
|
||||||
int idx=0;
|
int idx=0;
|
||||||
while(nextLine!=null && nextLine.charAt(0)=='a') {
|
while(nextLine!=null && nextLine.charAt(0)=='a') {
|
||||||
String[] attrTokens=nextLine.split("\\s+");
|
String[] attrTokens=nextLine.split("\\s+");
|
||||||
TxAttribute attr = new TxAttribute(gen.endAttrs.get(idx), attrTokens[1]);
|
TxAttributeType attrType = gen.endAttrs.get(idx);
|
||||||
|
TxAttribute attr = new TxAttribute(attrType, getAttrString(attrType, attrTokens[1]));
|
||||||
scvTx.attributes.add(attr);
|
scvTx.attributes.add(attr);
|
||||||
idx++;
|
idx++;
|
||||||
nextLine=reader.readLine();
|
nextLine=reader.readLine();
|
||||||
|
@ -332,6 +337,25 @@ public class TextDbLoader implements IWaveformDbLoader{
|
||||||
return nextLine;
|
return nextLine;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getAttrString(TxAttributeType attrType, String string) {
|
||||||
|
String value;
|
||||||
|
switch(attrType.getDataType()){
|
||||||
|
case STRING:
|
||||||
|
case ENUMERATION:
|
||||||
|
value=string.substring(1, string.length()-1);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
value=string;
|
||||||
|
}
|
||||||
|
if(attrValueLut.containsKey(value)){
|
||||||
|
return loader.attrValues.get(attrValueLut.get(value));
|
||||||
|
} else {
|
||||||
|
attrValueLut.put(value, loader.attrValues.size());
|
||||||
|
loader.attrValues.add(value);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private long stringToScale(String scale){
|
private long stringToScale(String scale){
|
||||||
String cmp = scale.trim();
|
String cmp = scale.trim();
|
||||||
if("fs".equals(cmp)) return 1L;
|
if("fs".equals(cmp)) return 1L;
|
||||||
|
|
|
@ -23,25 +23,14 @@ public class TxAttribute implements ITxAttribute, Serializable {
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 4767726016651807152L;
|
private static final long serialVersionUID = 4767726016651807152L;
|
||||||
|
|
||||||
private TxAttributeType attributeType;
|
private final TxAttributeType attributeType;
|
||||||
|
|
||||||
private String value=null;
|
private final String value;
|
||||||
|
|
||||||
TxAttribute(TxAttributeType attributeType){
|
|
||||||
this.attributeType=attributeType;
|
|
||||||
}
|
|
||||||
|
|
||||||
TxAttribute(TxAttributeType type, String value){
|
TxAttribute(TxAttributeType type, String value){
|
||||||
attributeType=type;
|
this.attributeType=type;
|
||||||
switch(type.getDataType()){
|
|
||||||
case STRING:
|
|
||||||
case ENUMERATION:
|
|
||||||
this.value=value.substring(1, value.length()-1);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
this.value=value;
|
this.value=value;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
|
|
@ -13,30 +13,26 @@ package com.minres.scviewer.database.text;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.minres.scviewer.database.HierNode;
|
||||||
import com.minres.scviewer.database.IWaveform;
|
import com.minres.scviewer.database.IWaveform;
|
||||||
import com.minres.scviewer.database.tx.ITx;
|
|
||||||
import com.minres.scviewer.database.tx.ITxGenerator;
|
import com.minres.scviewer.database.tx.ITxGenerator;
|
||||||
|
|
||||||
class TxGenerator implements ITxGenerator {
|
class TxGenerator extends HierNode implements ITxGenerator {
|
||||||
|
|
||||||
Long id;
|
Long id;
|
||||||
|
|
||||||
IWaveform stream;
|
IWaveform stream;
|
||||||
|
|
||||||
String name;
|
|
||||||
|
|
||||||
Boolean active = false;
|
Boolean active = false;
|
||||||
|
|
||||||
List<ITx> transactions=new ArrayList<>();
|
|
||||||
|
|
||||||
List<TxAttributeType> beginAttrs = new ArrayList<>();
|
List<TxAttributeType> beginAttrs = new ArrayList<>();
|
||||||
|
|
||||||
List<TxAttributeType> endAttrs= new ArrayList<>();
|
List<TxAttributeType> endAttrs= new ArrayList<>();
|
||||||
|
|
||||||
TxGenerator(Long id, TxStream stream, String name){
|
TxGenerator(Long id, TxStream stream, String name){
|
||||||
|
super(name, stream);
|
||||||
this.id=id;
|
this.id=id;
|
||||||
this.stream=stream;
|
this.stream=stream;
|
||||||
this.name=name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -54,11 +50,6 @@ class TxGenerator implements ITxGenerator {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<ITx> getTransactions(){
|
|
||||||
return transactions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<TxAttributeType> getBeginAttrs() {
|
public List<TxAttributeType> getBeginAttrs() {
|
||||||
return beginAttrs;
|
return beginAttrs;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ import com.minres.scviewer.database.HierNode;
|
||||||
import com.minres.scviewer.database.IEvent;
|
import com.minres.scviewer.database.IEvent;
|
||||||
import com.minres.scviewer.database.IWaveform;
|
import com.minres.scviewer.database.IWaveform;
|
||||||
import com.minres.scviewer.database.WaveformType;
|
import com.minres.scviewer.database.WaveformType;
|
||||||
|
import com.minres.scviewer.database.tx.ITxEvent;
|
||||||
import com.minres.scviewer.database.tx.ITxGenerator;
|
import com.minres.scviewer.database.tx.ITxGenerator;
|
||||||
|
|
||||||
class TxStream extends HierNode implements IWaveform {
|
class TxStream extends HierNode implements IWaveform {
|
||||||
|
@ -63,14 +64,14 @@ class TxStream extends HierNode implements IWaveform {
|
||||||
return maxConcurrency;
|
return maxConcurrency;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addEvent(TxEvent evt) {
|
public void addEvent(ITxEvent evt) {
|
||||||
if(!events.containsKey(evt.time))
|
if(!events.containsKey(evt.getTime()))
|
||||||
events.put(evt.time, new IEvent[] {evt});
|
events.put(evt.getTime(), new IEvent[] {evt});
|
||||||
else {
|
else {
|
||||||
IEvent[] evts = events.get(evt.time);
|
IEvent[] evts = events.get(evt.getTime());
|
||||||
IEvent[] newEvts = Arrays.copyOf(evts, evts.length+1);
|
IEvent[] newEvts = Arrays.copyOf(evts, evts.length+1);
|
||||||
newEvts[evts.length]=evt;
|
newEvts[evts.length]=evt;
|
||||||
events.put(evt.time, newEvts);
|
events.put(evt.getTime(), newEvts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,13 +10,10 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package com.minres.scviewer.database.tx;
|
package com.minres.scviewer.database.tx;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.minres.scviewer.database.IWaveform;
|
import com.minres.scviewer.database.IWaveform;
|
||||||
|
|
||||||
public interface ITxGenerator {
|
public interface ITxGenerator {
|
||||||
public Long getId();
|
public Long getId();
|
||||||
public IWaveform getStream();
|
public IWaveform getStream();
|
||||||
public String getName();
|
public String getName();
|
||||||
public List<ITx> getTransactions();
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue