2021-01-02 16:15:27 +01:00
|
|
|
/*******************************************************************************
|
|
|
|
* 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;
|
2021-01-03 14:16:56 +01:00
|
|
|
import java.util.TreeMap;
|
2021-01-02 16:15:27 +01:00
|
|
|
|
|
|
|
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;
|
2021-01-08 20:31:24 +01:00
|
|
|
import com.minres.scviewer.database.tx.ITxEvent;
|
2021-01-02 16:15:27 +01:00
|
|
|
import com.minres.scviewer.database.tx.ITxGenerator;
|
|
|
|
|
2021-01-03 14:16:56 +01:00
|
|
|
class TxStream extends HierNode implements IWaveform {
|
2021-01-02 16:15:27 +01:00
|
|
|
|
|
|
|
private Long id;
|
2021-01-02 17:02:05 +01:00
|
|
|
|
2021-01-03 14:16:56 +01:00
|
|
|
private TextDbLoader loader;
|
2021-01-02 16:15:27 +01:00
|
|
|
|
2021-01-02 18:04:48 +01:00
|
|
|
private int maxConcurrency = 0;
|
2021-01-02 16:15:27 +01:00
|
|
|
|
2021-01-02 18:04:48 +01:00
|
|
|
private int concurrency = 0;
|
2021-01-03 14:16:56 +01:00
|
|
|
|
|
|
|
boolean concurrencyCalculated = false;
|
|
|
|
|
2021-01-02 18:04:48 +01:00
|
|
|
void setConcurrency(int concurrency) {
|
|
|
|
this.concurrency = concurrency;
|
|
|
|
if(concurrency>maxConcurrency)
|
|
|
|
maxConcurrency = concurrency;
|
|
|
|
}
|
|
|
|
|
|
|
|
int getConcurrency() {
|
|
|
|
return this.concurrency;
|
|
|
|
}
|
|
|
|
|
2021-01-03 14:16:56 +01:00
|
|
|
TreeMap<Long, IEvent[]> events = new TreeMap<>();
|
2021-01-02 16:15:27 +01:00
|
|
|
|
|
|
|
TxStream(TextDbLoader loader, Long id, String name, String kind){
|
|
|
|
super(name);
|
|
|
|
this.id=id;
|
2021-01-03 14:16:56 +01:00
|
|
|
this.loader=loader;
|
2021-01-02 16:15:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
List<ITxGenerator> getGenerators(){
|
2021-01-03 14:16:56 +01:00
|
|
|
return new ArrayList<>(loader.txGenerators.values());
|
2021-01-02 16:15:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getWidth() {
|
|
|
|
return maxConcurrency;
|
|
|
|
}
|
|
|
|
|
2021-01-08 20:31:24 +01:00
|
|
|
public void addEvent(ITxEvent evt) {
|
|
|
|
if(!events.containsKey(evt.getTime()))
|
|
|
|
events.put(evt.getTime(), new IEvent[] {evt});
|
2021-01-03 14:16:56 +01:00
|
|
|
else {
|
2021-01-08 20:31:24 +01:00
|
|
|
IEvent[] evts = events.get(evt.getTime());
|
2021-01-03 14:16:56 +01:00
|
|
|
IEvent[] newEvts = Arrays.copyOf(evts, evts.length+1);
|
|
|
|
newEvts[evts.length]=evt;
|
2021-01-08 20:31:24 +01:00
|
|
|
events.put(evt.getTime(), newEvts);
|
2021-01-03 14:16:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-02 16:15:27 +01:00
|
|
|
@Override
|
|
|
|
public NavigableMap<Long, IEvent[]> getEvents() {
|
2021-01-03 14:16:56 +01:00
|
|
|
if(!concurrencyCalculated) calculateConcurrency();
|
2021-01-02 16:15:27 +01:00
|
|
|
return (NavigableMap<Long, IEvent[]>)events;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IEvent[] getEventsAtTime(Long time) {
|
2021-01-03 14:16:56 +01:00
|
|
|
if(!concurrencyCalculated) calculateConcurrency();
|
2021-01-02 16:15:27 +01:00
|
|
|
return events.get(time);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isSame(IWaveform other) {
|
|
|
|
return(other instanceof TxStream && this.getId()==other.getId());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IEvent[] getEventsBeforeTime(Long time) {
|
2021-01-03 14:16:56 +01:00
|
|
|
if(!concurrencyCalculated) calculateConcurrency();
|
2021-01-02 16:15:27 +01:00
|
|
|
Entry<Long, IEvent[]> e = events.floorEntry(time);
|
|
|
|
if(e==null)
|
|
|
|
return null;
|
|
|
|
else
|
|
|
|
return events.floorEntry(time).getValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public WaveformType getType() {
|
|
|
|
return WaveformType.TRANSACTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Long getId() {
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2021-01-08 15:04:30 +01:00
|
|
|
synchronized void calculateConcurrency() {
|
|
|
|
if(concurrencyCalculated) return;
|
2021-01-03 14:16:56 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-01-02 16:15:27 +01:00
|
|
|
}
|