make ITxGenerator as stream
This commit is contained in:
parent
90f45c698f
commit
d970d07048
|
@ -0,0 +1,129 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* 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.sqlite;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.NavigableMap;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
|
||||||
|
import com.minres.scviewer.database.EventKind;
|
||||||
|
import com.minres.scviewer.database.HierNode;
|
||||||
|
import com.minres.scviewer.database.IEvent;
|
||||||
|
import com.minres.scviewer.database.IWaveform;
|
||||||
|
import com.minres.scviewer.database.RelationType;
|
||||||
|
import com.minres.scviewer.database.RelationTypeFactory;
|
||||||
|
import com.minres.scviewer.database.WaveformType;
|
||||||
|
import com.minres.scviewer.database.sqlite.db.IDatabase;
|
||||||
|
import com.minres.scviewer.database.tx.ITx;
|
||||||
|
|
||||||
|
abstract class AbstractTxStream extends HierNode implements IWaveform {
|
||||||
|
|
||||||
|
protected IDatabase database;
|
||||||
|
|
||||||
|
private long streamId;
|
||||||
|
|
||||||
|
private Integer maxConcurrency;
|
||||||
|
|
||||||
|
private TreeMap<Long, IEvent[]> events;
|
||||||
|
|
||||||
|
private List<RelationType> usedRelationsList;
|
||||||
|
|
||||||
|
public AbstractTxStream(IDatabase database, String name, long streamId) {
|
||||||
|
super(name);
|
||||||
|
this.database=database;
|
||||||
|
this.streamId=streamId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getWidth() {
|
||||||
|
if(maxConcurrency==null){
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append("SELECT MAX(concurrencyLevel) as concurrencyLevel FROM ScvTx where stream=");
|
||||||
|
sb.append(streamId);
|
||||||
|
try(
|
||||||
|
java.sql.Connection connection = database.createConnection();
|
||||||
|
java.sql.Statement statement = connection.createStatement();
|
||||||
|
java.sql.ResultSet resultSet = statement.executeQuery(sb.toString());
|
||||||
|
) {
|
||||||
|
while (resultSet.next()) {
|
||||||
|
if(maxConcurrency==null) maxConcurrency=0;
|
||||||
|
Object value = resultSet.getObject("concurrencyLevel");
|
||||||
|
if(value!=null)
|
||||||
|
maxConcurrency=(Integer) value;
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
if(maxConcurrency==null) maxConcurrency=0;
|
||||||
|
}
|
||||||
|
maxConcurrency+=1;
|
||||||
|
}
|
||||||
|
return maxConcurrency;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NavigableMap<Long, IEvent[]> getEvents(){
|
||||||
|
if(events==null){
|
||||||
|
events=new TreeMap<>();
|
||||||
|
for(Entry<Integer, ITx> entry:getTransactions().entrySet()){
|
||||||
|
putEvent(new TxEvent(EventKind.BEGIN, entry.getValue()));
|
||||||
|
putEvent(new TxEvent(EventKind.END, entry.getValue()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return events;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void putEvent(TxEvent ev){
|
||||||
|
Long time = ev.getTime();
|
||||||
|
if(events.containsKey(time)) {
|
||||||
|
IEvent[] oldV = events.get(time);
|
||||||
|
IEvent[] newV = new IEvent[oldV.length+1];
|
||||||
|
System.arraycopy(oldV, 0, newV, 0, oldV.length);
|
||||||
|
newV[oldV.length]=ev;
|
||||||
|
events.put(time, newV);
|
||||||
|
} else {
|
||||||
|
events.put(time, new IEvent[] {ev});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract Map<Integer, ITx> getTransactions();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IEvent[] getEventsAtTime(Long time) {
|
||||||
|
return getEvents().get(time);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRelationTypeList(List<RelationType> usedRelationsList){
|
||||||
|
this.usedRelationsList=usedRelationsList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RelationType getRelationType(String name) {
|
||||||
|
RelationType relType=RelationTypeFactory.create(name);
|
||||||
|
if(!usedRelationsList.contains(relType)) usedRelationsList.add(relType);
|
||||||
|
return relType;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IEvent[] getEventsBeforeTime(Long time) {
|
||||||
|
Entry<Long, IEvent[]> e = events.floorEntry(time);
|
||||||
|
if(e==null)
|
||||||
|
return new IEvent[]{};
|
||||||
|
else
|
||||||
|
return events.floorEntry(time).getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WaveformType getType() {
|
||||||
|
return WaveformType.TRANSACTION;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -10,17 +10,30 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package com.minres.scviewer.database.sqlite;
|
package com.minres.scviewer.database.sqlite;
|
||||||
|
|
||||||
|
import java.beans.IntrospectionException;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
|
||||||
import com.minres.scviewer.database.IWaveform;
|
import com.minres.scviewer.database.IWaveform;
|
||||||
|
import com.minres.scviewer.database.sqlite.db.IDatabase;
|
||||||
|
import com.minres.scviewer.database.sqlite.db.SQLiteDatabaseSelectHandler;
|
||||||
import com.minres.scviewer.database.sqlite.tables.ScvGenerator;
|
import com.minres.scviewer.database.sqlite.tables.ScvGenerator;
|
||||||
|
import com.minres.scviewer.database.sqlite.tables.ScvTx;
|
||||||
|
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 extends AbstractTxStream implements ITxGenerator {
|
||||||
|
|
||||||
private IWaveform stream;
|
private TxStream stream;
|
||||||
|
|
||||||
private ScvGenerator scvGenerator;
|
private ScvGenerator scvGenerator;
|
||||||
|
|
||||||
public TxGenerator(IWaveform stream, ScvGenerator scvGenerator) {
|
private TreeMap<Integer, ITx> transactions;
|
||||||
|
|
||||||
|
public TxGenerator(IDatabase database, TxStream stream, ScvGenerator scvGenerator) {
|
||||||
|
super(database, scvGenerator.getName(), stream.getId());
|
||||||
this.stream=stream;
|
this.stream=stream;
|
||||||
this.scvGenerator=scvGenerator;
|
this.scvGenerator=scvGenerator;
|
||||||
}
|
}
|
||||||
|
@ -40,4 +53,32 @@ public class TxGenerator implements ITxGenerator {
|
||||||
return scvGenerator.getName();
|
return scvGenerator.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSame(IWaveform other) {
|
||||||
|
return(other instanceof TxGenerator && this.getId().equals(other.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getKind() {
|
||||||
|
return stream.getKind();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Map<Integer, ITx> getTransactions() {
|
||||||
|
if(transactions==null){
|
||||||
|
transactions = new TreeMap<>();
|
||||||
|
SQLiteDatabaseSelectHandler<ScvTx> handler = new SQLiteDatabaseSelectHandler<>(ScvTx.class, database,
|
||||||
|
"stream="+stream.getId()+" and generator="+scvGenerator.getId());
|
||||||
|
try {
|
||||||
|
for(ScvTx scvTx:handler.selectObjects()){
|
||||||
|
transactions.put(scvTx.getId(), new Tx(database, (TxStream) stream, this, scvTx));
|
||||||
|
}
|
||||||
|
} catch (SecurityException | IllegalArgumentException | InstantiationException | IllegalAccessException
|
||||||
|
| InvocationTargetException | SQLException | IntrospectionException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return transactions;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,9 +35,7 @@ import com.minres.scviewer.database.sqlite.tables.ScvTx;
|
||||||
import com.minres.scviewer.database.tx.ITx;
|
import com.minres.scviewer.database.tx.ITx;
|
||||||
import com.minres.scviewer.database.tx.ITxGenerator;
|
import com.minres.scviewer.database.tx.ITxGenerator;
|
||||||
|
|
||||||
public class TxStream extends HierNode implements IWaveform {
|
public class TxStream extends AbstractTxStream {
|
||||||
|
|
||||||
private IDatabase database;
|
|
||||||
|
|
||||||
private String fullName;
|
private String fullName;
|
||||||
|
|
||||||
|
@ -47,15 +45,8 @@ public class TxStream extends HierNode implements IWaveform {
|
||||||
|
|
||||||
private TreeMap<Integer, ITx> transactions;
|
private TreeMap<Integer, ITx> transactions;
|
||||||
|
|
||||||
private Integer maxConcurrency;
|
|
||||||
|
|
||||||
private TreeMap<Long, IEvent[]> events;
|
|
||||||
|
|
||||||
private List<RelationType> usedRelationsList;
|
|
||||||
|
|
||||||
public TxStream(IDatabase database, ScvStream scvStream) {
|
public TxStream(IDatabase database, ScvStream scvStream) {
|
||||||
super(scvStream.getName());
|
super(database, scvStream.getName(), scvStream.getId());
|
||||||
this.database=database;
|
|
||||||
fullName=scvStream.getName();
|
fullName=scvStream.getName();
|
||||||
this.scvStream=scvStream;
|
this.scvStream=scvStream;
|
||||||
}
|
}
|
||||||
|
@ -77,7 +68,7 @@ public class TxStream extends HierNode implements IWaveform {
|
||||||
generators=new TreeMap<>();
|
generators=new TreeMap<>();
|
||||||
try {
|
try {
|
||||||
for(ScvGenerator scvGenerator:handler.selectObjects()){
|
for(ScvGenerator scvGenerator:handler.selectObjects()){
|
||||||
generators.put(scvGenerator.getId(), new TxGenerator(this, scvGenerator));
|
generators.put(scvGenerator.getId(), new TxGenerator(database, this, scvGenerator));
|
||||||
}
|
}
|
||||||
} catch (SecurityException | IllegalArgumentException | InstantiationException | IllegalAccessException
|
} catch (SecurityException | IllegalArgumentException | InstantiationException | IllegalAccessException
|
||||||
| InvocationTargetException | SQLException | IntrospectionException e) {
|
| InvocationTargetException | SQLException | IntrospectionException e) {
|
||||||
|
@ -87,56 +78,6 @@ public class TxStream extends HierNode implements IWaveform {
|
||||||
return new ArrayList<>(generators.values());
|
return new ArrayList<>(generators.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getWidth() {
|
|
||||||
if(maxConcurrency==null){
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
sb.append("SELECT MAX(concurrencyLevel) as concurrencyLevel FROM ScvTx where stream=");
|
|
||||||
sb.append(scvStream.getId());
|
|
||||||
try(
|
|
||||||
java.sql.Connection connection = database.createConnection();
|
|
||||||
java.sql.Statement statement = connection.createStatement();
|
|
||||||
java.sql.ResultSet resultSet = statement.executeQuery(sb.toString());
|
|
||||||
) {
|
|
||||||
while (resultSet.next()) {
|
|
||||||
if(maxConcurrency==null) maxConcurrency=0;
|
|
||||||
Object value = resultSet.getObject("concurrencyLevel");
|
|
||||||
if(value!=null)
|
|
||||||
maxConcurrency=(Integer) value;
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
if(maxConcurrency==null) maxConcurrency=0;
|
|
||||||
}
|
|
||||||
maxConcurrency+=1;
|
|
||||||
}
|
|
||||||
return maxConcurrency;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public NavigableMap<Long, IEvent[]> getEvents(){
|
|
||||||
if(events==null){
|
|
||||||
events=new TreeMap<>();
|
|
||||||
for(Entry<Integer, ITx> entry:getTransactions().entrySet()){
|
|
||||||
putEvent(new TxEvent(EventKind.BEGIN, entry.getValue()));
|
|
||||||
putEvent(new TxEvent(EventKind.END, entry.getValue()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return events;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void putEvent(TxEvent ev){
|
|
||||||
Long time = ev.getTime();
|
|
||||||
if(events.containsKey(time)) {
|
|
||||||
IEvent[] oldV = events.get(time);
|
|
||||||
IEvent[] newV = new IEvent[oldV.length+1];
|
|
||||||
System.arraycopy(oldV, 0, newV, 0, oldV.length);
|
|
||||||
newV[oldV.length]=ev;
|
|
||||||
events.put(time, newV);
|
|
||||||
} else {
|
|
||||||
events.put(time, new IEvent[] {ev});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Map<Integer, ITx> getTransactions() {
|
protected Map<Integer, ITx> getTransactions() {
|
||||||
if(transactions==null){
|
if(transactions==null){
|
||||||
if(generators==null) getGenerators();
|
if(generators==null) getGenerators();
|
||||||
|
@ -160,33 +101,13 @@ public class TxStream extends HierNode implements IWaveform {
|
||||||
return getEvents().get(time);
|
return getEvents().get(time);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRelationTypeList(List<RelationType> usedRelationsList){
|
|
||||||
this.usedRelationsList=usedRelationsList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public RelationType getRelationType(String name) {
|
|
||||||
RelationType relType=RelationTypeFactory.create(name);
|
|
||||||
if(!usedRelationsList.contains(relType)) usedRelationsList.add(relType);
|
|
||||||
return relType;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSame(IWaveform other) {
|
public boolean isSame(IWaveform other) {
|
||||||
return(other instanceof TxStream && this.getId().equals(other.getId()));
|
return(other instanceof TxStream && this.getId().equals(other.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IEvent[] getEventsBeforeTime(Long time) {
|
public String getKind() {
|
||||||
Entry<Long, IEvent[]> e = events.floorEntry(time);
|
return scvStream.getKind();
|
||||||
if(e==null)
|
|
||||||
return new IEvent[]{};
|
|
||||||
else
|
|
||||||
return events.floorEntry(time).getValue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public WaveformType getType() {
|
|
||||||
return WaveformType.TRANSACTION;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,127 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2012 IT Just working.
|
||||||
|
* 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:
|
||||||
|
* IT Just working - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
package com.minres.scviewer.database.text;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.NavigableMap;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
|
||||||
|
import com.minres.scviewer.database.EventKind;
|
||||||
|
import com.minres.scviewer.database.HierNode;
|
||||||
|
import com.minres.scviewer.database.IEvent;
|
||||||
|
import com.minres.scviewer.database.IWaveform;
|
||||||
|
import com.minres.scviewer.database.WaveformType;
|
||||||
|
import com.minres.scviewer.database.tx.ITxEvent;
|
||||||
|
import com.minres.scviewer.database.tx.ITxGenerator;
|
||||||
|
|
||||||
|
abstract class AbstractTxStream extends HierNode implements IWaveform {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
protected TextDbLoader loader;
|
||||||
|
|
||||||
|
TreeMap<Long, IEvent[]> events = new TreeMap<>();
|
||||||
|
|
||||||
|
private int maxConcurrency = 0;
|
||||||
|
|
||||||
|
private int concurrency = 0;
|
||||||
|
|
||||||
|
boolean concurrencyCalculated = false;
|
||||||
|
|
||||||
|
public AbstractTxStream(TextDbLoader loader, Long id, String name) {
|
||||||
|
super(name);
|
||||||
|
this.loader=loader;
|
||||||
|
this.id=id;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setConcurrency(int concurrency) {
|
||||||
|
this.concurrency = concurrency;
|
||||||
|
if(concurrency>maxConcurrency)
|
||||||
|
maxConcurrency = concurrency;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getConcurrency() {
|
||||||
|
return this.concurrency;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getWidth() {
|
||||||
|
return maxConcurrency;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addEvent(ITxEvent evt) {
|
||||||
|
if(!events.containsKey(evt.getTime()))
|
||||||
|
events.put(evt.getTime(), new IEvent[] {evt});
|
||||||
|
else {
|
||||||
|
IEvent[] evts = events.get(evt.getTime());
|
||||||
|
IEvent[] newEvts = Arrays.copyOf(evts, evts.length+1);
|
||||||
|
newEvts[evts.length]=evt;
|
||||||
|
events.put(evt.getTime(), newEvts);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NavigableMap<Long, IEvent[]> getEvents() {
|
||||||
|
if(!concurrencyCalculated) calculateConcurrency();
|
||||||
|
return events;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IEvent[] getEventsAtTime(Long time) {
|
||||||
|
if(!concurrencyCalculated) calculateConcurrency();
|
||||||
|
return events.get(time);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IEvent[] getEventsBeforeTime(Long time) {
|
||||||
|
if(!concurrencyCalculated)
|
||||||
|
calculateConcurrency();
|
||||||
|
Entry<Long, IEvent[]> e = events.floorEntry(time);
|
||||||
|
if(e==null)
|
||||||
|
return new IEvent[] {};
|
||||||
|
else
|
||||||
|
return events.floorEntry(time).getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WaveformType getType() {
|
||||||
|
return WaveformType.TRANSACTION;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized void calculateConcurrency() {
|
||||||
|
if(concurrencyCalculated) return;
|
||||||
|
ArrayList<Long> rowendtime = new ArrayList<>();
|
||||||
|
events.entrySet().stream().forEach( entry -> {
|
||||||
|
IEvent[] values = entry.getValue();
|
||||||
|
Arrays.asList(values).stream().filter(e->e.getKind()==EventKind.BEGIN).forEach(evt -> {
|
||||||
|
Tx tx = (Tx) ((TxEvent)evt).getTransaction();
|
||||||
|
int rowIdx = 0;
|
||||||
|
for(; rowIdx<rowendtime.size() && rowendtime.get(rowIdx)>tx.getBeginTime(); rowIdx++);
|
||||||
|
if(rowendtime.size()<=rowIdx)
|
||||||
|
rowendtime.add(tx.getEndTime());
|
||||||
|
else
|
||||||
|
rowendtime.set(rowIdx, tx.getEndTime());
|
||||||
|
tx.setConcurrencyIndex(rowIdx);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
concurrencyCalculated=true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -318,7 +318,7 @@ public class TextDbLoader implements IWaveformDbLoader{
|
||||||
if ((matcher.matches())) {
|
if ((matcher.matches())) {
|
||||||
Long id = Long.parseLong(matcher.group(1));
|
Long id = Long.parseLong(matcher.group(1));
|
||||||
TxStream stream=loader.txStreams.get(Long.parseLong(matcher.group(3)));
|
TxStream stream=loader.txStreams.get(Long.parseLong(matcher.group(3)));
|
||||||
generator=new TxGenerator(id, stream, matcher.group(2));
|
generator=new TxGenerator(loader, id, matcher.group(2), stream);
|
||||||
loader.txGenerators.put(id, generator);
|
loader.txGenerators.put(id, generator);
|
||||||
}
|
}
|
||||||
} else if("begin_attribute".equals(tokens[0])){
|
} else if("begin_attribute".equals(tokens[0])){
|
||||||
|
|
|
@ -11,9 +11,9 @@ class TxEvent implements ITxEvent {
|
||||||
|
|
||||||
final EventKind kind;
|
final EventKind kind;
|
||||||
|
|
||||||
final Long transaction;
|
final long transaction;
|
||||||
|
|
||||||
final Long time;
|
final long time;
|
||||||
|
|
||||||
TxEvent(TextDbLoader loader, EventKind kind, Long transaction, Long time) {
|
TxEvent(TextDbLoader loader, EventKind kind, Long transaction, Long time) {
|
||||||
this.loader=loader;
|
this.loader=loader;
|
||||||
|
|
|
@ -13,43 +13,32 @@ 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.ITxGenerator;
|
import com.minres.scviewer.database.tx.ITxGenerator;
|
||||||
|
|
||||||
class TxGenerator extends HierNode implements ITxGenerator {
|
class TxGenerator extends AbstractTxStream implements ITxGenerator {
|
||||||
|
|
||||||
Long id;
|
TxStream stream;
|
||||||
|
|
||||||
IWaveform stream;
|
|
||||||
|
|
||||||
Boolean active = false;
|
|
||||||
|
|
||||||
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(TextDbLoader loader, Long id, String name, TxStream stream){
|
||||||
super(name, stream);
|
super(loader, id, name);
|
||||||
this.id=id;
|
|
||||||
this.stream=stream;
|
this.stream=stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IWaveform getStream(){
|
public IWaveform getStream(){
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public boolean isSame(IWaveform other) {
|
||||||
return name;
|
return(other instanceof TxGenerator && this.getId().equals(other.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TxAttributeType> getBeginAttrs() {
|
public List<TxAttributeType> getBeginAttrs() {
|
||||||
return beginAttrs;
|
return beginAttrs;
|
||||||
}
|
}
|
||||||
|
@ -57,7 +46,9 @@ class TxGenerator extends HierNode implements ITxGenerator {
|
||||||
public List<TxAttributeType> getEndAttrs() {
|
public List<TxAttributeType> getEndAttrs() {
|
||||||
return endAttrs;
|
return endAttrs;
|
||||||
}
|
}
|
||||||
|
|
||||||
Boolean isActive() {return active;}
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getKind() {
|
||||||
|
return stream.getKind();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,85 +10,16 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package com.minres.scviewer.database.text;
|
package com.minres.scviewer.database.text;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.NavigableMap;
|
|
||||||
import java.util.TreeMap;
|
|
||||||
|
|
||||||
import com.minres.scviewer.database.EventKind;
|
|
||||||
import com.minres.scviewer.database.HierNode;
|
|
||||||
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.tx.ITxEvent;
|
|
||||||
import com.minres.scviewer.database.tx.ITxGenerator;
|
|
||||||
|
|
||||||
class TxStream extends HierNode implements IWaveform {
|
class TxStream extends AbstractTxStream {
|
||||||
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
private TextDbLoader loader;
|
|
||||||
|
|
||||||
final String kind;
|
final String kind;
|
||||||
|
|
||||||
private int maxConcurrency = 0;
|
|
||||||
|
|
||||||
private int concurrency = 0;
|
|
||||||
|
|
||||||
boolean concurrencyCalculated = false;
|
|
||||||
|
|
||||||
void setConcurrency(int concurrency) {
|
|
||||||
this.concurrency = concurrency;
|
|
||||||
if(concurrency>maxConcurrency)
|
|
||||||
maxConcurrency = concurrency;
|
|
||||||
}
|
|
||||||
|
|
||||||
int getConcurrency() {
|
|
||||||
return this.concurrency;
|
|
||||||
}
|
|
||||||
|
|
||||||
TreeMap<Long, IEvent[]> events = new TreeMap<>();
|
|
||||||
|
|
||||||
TxStream(TextDbLoader loader, Long id, String name, String kind){
|
TxStream(TextDbLoader loader, Long id, String name, String kind){
|
||||||
super(name);
|
super(loader, id, name);
|
||||||
this.id=id;
|
|
||||||
this.loader=loader;
|
|
||||||
this.kind=kind;
|
this.kind=kind;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ITxGenerator> getGenerators(){
|
|
||||||
return new ArrayList<>(loader.txGenerators.values());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getWidth() {
|
|
||||||
return maxConcurrency;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addEvent(ITxEvent evt) {
|
|
||||||
if(!events.containsKey(evt.getTime()))
|
|
||||||
events.put(evt.getTime(), new IEvent[] {evt});
|
|
||||||
else {
|
|
||||||
IEvent[] evts = events.get(evt.getTime());
|
|
||||||
IEvent[] newEvts = Arrays.copyOf(evts, evts.length+1);
|
|
||||||
newEvts[evts.length]=evt;
|
|
||||||
events.put(evt.getTime(), newEvts);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public NavigableMap<Long, IEvent[]> getEvents() {
|
|
||||||
if(!concurrencyCalculated) calculateConcurrency();
|
|
||||||
return events;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IEvent[] getEventsAtTime(Long time) {
|
|
||||||
if(!concurrencyCalculated) calculateConcurrency();
|
|
||||||
return events.get(time);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSame(IWaveform other) {
|
public boolean isSame(IWaveform other) {
|
||||||
|
@ -96,43 +27,8 @@ class TxStream extends HierNode implements IWaveform {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IEvent[] getEventsBeforeTime(Long time) {
|
public String getKind() {
|
||||||
if(!concurrencyCalculated)
|
return kind;
|
||||||
calculateConcurrency();
|
|
||||||
Entry<Long, IEvent[]> e = events.floorEntry(time);
|
|
||||||
if(e==null)
|
|
||||||
return new IEvent[] {};
|
|
||||||
else
|
|
||||||
return events.floorEntry(time).getValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public WaveformType getType() {
|
|
||||||
return WaveformType.TRANSACTION;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized void calculateConcurrency() {
|
|
||||||
if(concurrencyCalculated) return;
|
|
||||||
ArrayList<Long> rowendtime = new ArrayList<>();
|
|
||||||
events.entrySet().stream().forEach( entry -> {
|
|
||||||
IEvent[] values = entry.getValue();
|
|
||||||
Arrays.asList(values).stream().filter(e->e.getKind()==EventKind.BEGIN).forEach(evt -> {
|
|
||||||
Tx tx = (Tx) ((TxEvent)evt).getTransaction();
|
|
||||||
int rowIdx = 0;
|
|
||||||
for(; rowIdx<rowendtime.size() && rowendtime.get(rowIdx)>tx.getBeginTime(); rowIdx++);
|
|
||||||
if(rowendtime.size()<=rowIdx)
|
|
||||||
rowendtime.add(tx.getEndTime());
|
|
||||||
else
|
|
||||||
rowendtime.set(rowIdx, tx.getEndTime());
|
|
||||||
tx.setConcurrencyIndex(rowIdx);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
concurrencyCalculated=true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,4 +113,9 @@ public class VCDSignal<T extends IEvent> extends HierNode implements IWaveform {
|
||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getKind() {
|
||||||
|
return "signal";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,8 @@ public interface IWaveform extends IHierNode {
|
||||||
|
|
||||||
public WaveformType getType();
|
public WaveformType getType();
|
||||||
|
|
||||||
|
public String getKind();
|
||||||
|
|
||||||
public int getWidth();
|
public int getWidth();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,8 +12,8 @@ package com.minres.scviewer.database.tx;
|
||||||
|
|
||||||
import com.minres.scviewer.database.IWaveform;
|
import com.minres.scviewer.database.IWaveform;
|
||||||
|
|
||||||
public interface ITxGenerator {
|
public interface ITxGenerator extends IWaveform {
|
||||||
public Long getId();
|
|
||||||
public IWaveform getStream();
|
public IWaveform getStream();
|
||||||
public String getName();
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue