Implemented painter concept
This commit is contained in:
@ -10,31 +10,18 @@
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.database.text;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import com.minres.scviewer.database.AssociationType;
|
||||
import com.minres.scviewer.database.DataType;
|
||||
import com.minres.scviewer.database.HierNode;
|
||||
import com.minres.scviewer.database.ITxAttributeType;
|
||||
import com.minres.scviewer.database.ITxAttribute;
|
||||
import com.minres.scviewer.database.AssociationType
|
||||
import com.minres.scviewer.database.DataType
|
||||
import com.minres.scviewer.database.ITxGenerator
|
||||
import com.minres.scviewer.database.ITxStream
|
||||
import com.minres.scviewer.database.IWaveform
|
||||
import com.minres.scviewer.database.IWaveformDb;
|
||||
import com.minres.scviewer.database.ITxGenerator;
|
||||
import com.minres.scviewer.database.IHierNode;
|
||||
import com.minres.scviewer.database.ITxStream;
|
||||
import com.minres.scviewer.database.IWaveformDbLoader;
|
||||
import com.minres.scviewer.database.InputFormatException;
|
||||
import com.minres.scviewer.database.EventTime
|
||||
import com.minres.scviewer.database.IWaveformDb
|
||||
import com.minres.scviewer.database.IWaveformDbLoader
|
||||
import com.minres.scviewer.database.RelationType
|
||||
|
||||
public class TextDbLoader implements IWaveformDbLoader{
|
||||
|
||||
private EventTime maxTime;
|
||||
private Long maxTime;
|
||||
|
||||
IWaveformDb db;
|
||||
|
||||
@ -46,7 +33,7 @@ public class TextDbLoader implements IWaveformDbLoader{
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventTime getMaxTime() {
|
||||
public Long getMaxTime() {
|
||||
return maxTime;
|
||||
}
|
||||
|
||||
@ -74,9 +61,20 @@ public class TextDbLoader implements IWaveformDbLoader{
|
||||
for(int i=0; i<x.size(); i++)
|
||||
if(buffer[i]!=x[i]) return false
|
||||
parseInput(file)
|
||||
calculateConcurrencyIndicees()
|
||||
return true
|
||||
}
|
||||
|
||||
private stringToScale(String scale){
|
||||
switch(scale.trim()){
|
||||
case "fs":return 1L
|
||||
case "ps":return 1000L
|
||||
case "ns":return 1000000L
|
||||
case "us":return 1000000000L
|
||||
case "ms":return 1000000000000L
|
||||
case "s": return 1000000000000000L
|
||||
}
|
||||
}
|
||||
private def parseInput(File input){
|
||||
def streamsById = [:]
|
||||
def generatorsById = [:]
|
||||
@ -115,7 +113,7 @@ public class TextDbLoader implements IWaveformDbLoader{
|
||||
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, new EventTime(Integer.parseInt(tokens[3]), EventTime.Unit.fromString(tokens[4])))
|
||||
transaction = new Tx(id, gen.stream, gen, Long.parseLong(tokens[3])*stringToScale(tokens[4]))
|
||||
gen.transactions << transaction
|
||||
transactionsById[id]= transaction
|
||||
gen.begin_attrs_idx=0;
|
||||
@ -126,7 +124,7 @@ public class TextDbLoader implements IWaveformDbLoader{
|
||||
def id = Integer.parseInt(tokens[1])
|
||||
transaction = transactionsById[id]
|
||||
assert Integer.parseInt(tokens[2])==transaction.generator.id
|
||||
transaction.endTime = new EventTime(Integer.parseInt(tokens[3]), EventTime.Unit.fromString(tokens[4]))
|
||||
transaction.endTime = Long.parseLong(tokens[3])*stringToScale(tokens[4])
|
||||
transaction.generator.end_attrs_idx=0;
|
||||
maxTime = maxTime>transaction.endTime?maxTime:transaction.endTime
|
||||
endTransaction=true
|
||||
@ -158,4 +156,7 @@ public class TextDbLoader implements IWaveformDbLoader{
|
||||
}
|
||||
}
|
||||
|
||||
private def calculateConcurrencyIndicees(){
|
||||
streams.each{ TxStream stream -> stream.getMaxConcurrency() }
|
||||
}
|
||||
}
|
||||
|
@ -10,9 +10,6 @@
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.database.text
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set
|
||||
|
||||
import com.minres.scviewer.database.*
|
||||
|
||||
class Tx implements ITx {
|
||||
@ -23,9 +20,11 @@ class Tx implements ITx {
|
||||
|
||||
TxStream stream
|
||||
|
||||
EventTime beginTime
|
||||
int concurrencyIndex
|
||||
|
||||
EventTime endTime
|
||||
Long beginTime
|
||||
|
||||
Long endTime
|
||||
|
||||
ArrayList<ITxAttribute> attributes = new ArrayList<ITxAttribute>()
|
||||
|
||||
@ -33,7 +32,7 @@ class Tx implements ITx {
|
||||
|
||||
def outgoingRelations =[]
|
||||
|
||||
Tx(int id, TxStream stream, TxGenerator generator, EventTime begin){
|
||||
Tx(int id, TxStream stream, TxGenerator generator, Long begin){
|
||||
this.id=id
|
||||
this.stream=stream
|
||||
this.generator=generator
|
||||
|
@ -0,0 +1,32 @@
|
||||
package com.minres.scviewer.database.text;
|
||||
|
||||
import com.minres.scviewer.database.ITx;
|
||||
import com.minres.scviewer.database.ITxEvent;
|
||||
import com.minres.scviewer.database.IWaveformEvent;
|
||||
|
||||
class TxEvent implements ITxEvent {
|
||||
|
||||
final ITxEvent.Type type;
|
||||
|
||||
Tx transaction;
|
||||
|
||||
TxEvent(ITxEvent.Type type, ITx transaction) {
|
||||
super();
|
||||
this.type = type;
|
||||
this.transaction = transaction;
|
||||
}
|
||||
|
||||
@Override
|
||||
IWaveformEvent duplicate() throws CloneNotSupportedException {
|
||||
new TxEvent(type, transaction, time)
|
||||
}
|
||||
|
||||
@Override
|
||||
int compareTo(IWaveformEvent o) {
|
||||
time.compareTo(o.getTime())
|
||||
}
|
||||
|
||||
Long getTime(){
|
||||
return type==ITxEvent.Type.BEGIN?transaction.beginTime:transaction.endTime
|
||||
}
|
||||
}
|
@ -11,10 +11,15 @@
|
||||
package com.minres.scviewer.database.text
|
||||
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.NavigableMap;
|
||||
|
||||
import com.google.common.collect.TreeMultimap;
|
||||
import com.minres.scviewer.database.HierNode;
|
||||
import com.minres.scviewer.database.ITxEvent;
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.IWaveformDb
|
||||
import com.minres.scviewer.database.ITxGenerator
|
||||
@ -24,24 +29,28 @@ import com.minres.scviewer.database.ITx
|
||||
|
||||
class TxStream extends HierNode implements ITxStream {
|
||||
|
||||
Long id;
|
||||
Long id
|
||||
|
||||
IWaveformDb database
|
||||
|
||||
String fullName;
|
||||
String fullName
|
||||
|
||||
String kind;
|
||||
String kind
|
||||
|
||||
def generators = [];
|
||||
def generators = []
|
||||
|
||||
int maxConcurrency
|
||||
|
||||
private TreeMap<Long, List<ITxEvent>> events
|
||||
|
||||
private TreeSet<Tx> allTransactions;
|
||||
|
||||
TxStream(IWaveformDb db, int id, String name, String kind){
|
||||
super(name)
|
||||
this.id=id
|
||||
this.database=db
|
||||
this.fullName=name
|
||||
this.kind=kind
|
||||
this.maxConcurrency=0
|
||||
events = new TreeMap<Long, List<ITxEvent>>()
|
||||
}
|
||||
|
||||
List<ITxGenerator> getGenerators(){
|
||||
@ -50,37 +59,50 @@ class TxStream extends HierNode implements ITxStream {
|
||||
|
||||
@Override
|
||||
public IWaveformDb getDb() {
|
||||
return database;
|
||||
return database
|
||||
}
|
||||
|
||||
// FIXME: maybe need to be somewhere else
|
||||
public int getMaxConcurrrentTx() {
|
||||
def rowendtime = [0]
|
||||
getTransactions().each{Tx tx ->
|
||||
def rowIdx = 0
|
||||
for(rowIdx=0; rowendtime.size()<rowIdx || rowendtime[rowIdx]>tx.beginTime.value; rowIdx++);
|
||||
if(rowendtime.size<=rowIdx){
|
||||
rowendtime<<tx.endTime?.value?:tx.beginTime.value+1
|
||||
} else {
|
||||
rowendtime[rowIdx]=tx.endTime?.value?:tx.beginTime.value+1
|
||||
@Override
|
||||
public int getMaxConcurrency() {
|
||||
if(!maxConcurrency){
|
||||
generators.each {TxGenerator generator ->
|
||||
generator.transactions.each{ Tx tx ->
|
||||
putEvent(new TxEvent(ITxEvent.Type.BEGIN, tx))
|
||||
putEvent(new TxEvent(ITxEvent.Type.END, tx))
|
||||
}
|
||||
}
|
||||
def rowendtime = [0]
|
||||
events.keySet().each{long time ->
|
||||
def value=events.get(time)
|
||||
def starts=value.findAll{ITxEvent event ->event.type==ITxEvent.Type.BEGIN}
|
||||
starts.each {ITxEvent event ->
|
||||
Tx tx = event.transaction
|
||||
def rowIdx = 0
|
||||
for(rowIdx=0; rowIdx<rowendtime.size() && rowendtime[rowIdx]>tx.beginTime; rowIdx++);
|
||||
if(rowendtime.size<=rowIdx)
|
||||
rowendtime<<tx.endTime
|
||||
else
|
||||
rowendtime[rowIdx]=tx.endTime
|
||||
tx.concurrencyIndex=rowIdx
|
||||
}
|
||||
}
|
||||
maxConcurrency=rowendtime.size()
|
||||
}
|
||||
return rowendtime.size()
|
||||
return maxConcurrency
|
||||
}
|
||||
|
||||
private putEvent(ITxEvent event){
|
||||
if(!events.containsKey(event.time)) events.put(event.time, [])
|
||||
events[event.time]<<event
|
||||
}
|
||||
|
||||
@Override
|
||||
public NavigableMap getEvents() {
|
||||
return events;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NavigableSet<ITx> getTransactions() {
|
||||
if(!allTransactions){
|
||||
allTransactions=new TreeSet<Tx>()
|
||||
allTransactions.addAll(generators.transactions.flatten())
|
||||
}
|
||||
return allTransactions
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITx getTransactionById(long id) {
|
||||
if(!allTransactions)
|
||||
allTransactions=generators.transactions.flatten().sort{it.beginTime.value}
|
||||
allTransactions.find{it.id==id}
|
||||
public Collection getWaveformEventsAtTime(Long time) {
|
||||
return events.get(time);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user