SCViewer/plugins/com.minres.scviewer.databas.../src/com/minres/scviewer/database/text/AbstractTxStream.java

194 lines
4.4 KiB
Java
Raw Normal View History

2021-01-09 10:34:22 +01:00
/*******************************************************************************
* Copyright (c) 2012 IT Just working
* Copyright (c) 2020 MINRES Technologies GmbH
2021-01-09 10:34:22 +01:00
* 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;
2021-01-14 23:13:11 +01:00
import java.util.HashMap;
2021-01-09 10:34:22 +01:00
2021-02-27 13:26:07 +01:00
import com.minres.scviewer.database.EventEntry;
2021-02-26 12:57:54 +01:00
import com.minres.scviewer.database.EventList;
2021-01-09 10:34:22 +01:00
import com.minres.scviewer.database.HierNode;
import com.minres.scviewer.database.IEvent;
2021-02-26 12:57:54 +01:00
import com.minres.scviewer.database.IEventList;
2021-01-09 10:34:22 +01:00
import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.WaveformType;
2021-01-14 23:13:11 +01:00
import com.minres.scviewer.database.tx.ITx;
2021-01-09 10:34:22 +01:00
import com.minres.scviewer.database.tx.ITxEvent;
/**
* The Class AbstractTxStream.
*/
2021-01-09 10:34:22 +01:00
abstract class AbstractTxStream extends HierNode implements IWaveform {
2021-02-24 07:56:28 +01:00
private final String fullName;
/** The id. */
2021-01-09 10:34:22 +01:00
private Long id;
/** The loader. */
2021-01-09 10:34:22 +01:00
protected TextDbLoader loader;
/** The events. */
2021-02-27 13:26:07 +01:00
IEventList events = new EventList();
2021-01-09 10:34:22 +01:00
2021-01-14 23:13:11 +01:00
/** The max concurrency. */
2021-01-15 08:53:06 +01:00
private int rowCount = -1;
/**
* Instantiates a new abstract tx stream.
*
* @param loader the loader
* @param id the id
* @param name the name
*/
2021-01-14 23:13:11 +01:00
protected AbstractTxStream(TextDbLoader loader, Long id, String name) {
2021-01-09 10:34:22 +01:00
super(name);
2021-02-24 07:56:28 +01:00
fullName=name;
this.loader = loader;
this.id = id;
2021-01-09 10:34:22 +01:00
}
2021-02-24 07:56:28 +01:00
/**
* Gets the full hierarchical name.
*
* @return the full name
*/
@Override
public String getFullName() {
return fullName;
}
/**
* Adds the event.
*
* @param evt the evt
*/
2021-01-09 10:34:22 +01:00
public void addEvent(ITxEvent evt) {
2021-02-27 14:47:37 +01:00
events.put(evt.getTime(), evt);
2021-01-09 10:34:22 +01:00
}
/**
* Gets the events.
*
* @return the events
*/
2021-01-09 10:34:22 +01:00
@Override
2021-02-27 13:26:07 +01:00
public IEventList getEvents() {
2021-01-09 10:34:22 +01:00
return events;
}
/**
* Gets the events at time.
*
* @param time the time
* @return the events at time
*/
2021-01-09 10:34:22 +01:00
@Override
2021-02-27 14:59:00 +01:00
public IEvent[] getEventsAtTime(long time) {
2021-01-09 10:34:22 +01:00
return events.get(time);
}
/**
* Gets the events before time.
*
* @param time the time
* @return the events before time
*/
2021-01-09 10:34:22 +01:00
@Override
2021-02-27 14:59:00 +01:00
public IEvent[] getEventsBeforeTime(long time) {
2021-02-27 13:26:07 +01:00
EventEntry e = events.floorEntry(time);
if (e == null)
return new IEvent[] {};
else
2021-02-27 13:26:07 +01:00
return events.floorEntry(time).events;
2021-01-09 10:34:22 +01:00
}
/**
* Gets the type.
*
* @return the type
*/
2021-01-09 10:34:22 +01:00
@Override
public WaveformType getType() {
return WaveformType.TRANSACTION;
}
/**
* Gets the id.
*
* @return the id
*/
2021-01-09 10:34:22 +01:00
@Override
2021-02-27 14:59:00 +01:00
public long getId() {
2021-01-09 10:34:22 +01:00
return id;
}
2021-01-14 23:13:11 +01:00
/**
* Gets the width.
*
* @return the width
*/
@Override
public int getRowCount() {
2021-01-15 08:53:06 +01:00
if (rowCount<0)
2021-01-14 23:13:11 +01:00
calculateConcurrency();
2021-01-15 08:53:06 +01:00
return rowCount;
2021-01-14 23:13:11 +01:00
}
2023-02-27 13:07:10 +01:00
@Override
public int getWidth() {
return 0;
}
/**
* Calculate concurrency.
*/
2021-01-15 08:53:06 +01:00
void calculateConcurrency() {
if (rowCount>=0)
return;
2021-01-14 23:13:11 +01:00
ArrayList<Long> rowEndTime = new ArrayList<>();
HashMap<Long, Integer> rowByTxId = new HashMap<>();
2021-02-27 13:26:07 +01:00
for(EventEntry entry: events) {
for(IEvent evt:entry.events) {
2021-01-14 23:13:11 +01:00
TxEvent txEvt = (TxEvent) evt;
ITx tx = txEvt.getTransaction();
2021-01-09 10:34:22 +01:00
int rowIdx = 0;
2021-01-14 23:13:11 +01:00
switch(evt.getKind()) {
case END:
Long txId = txEvt.getTransaction().getId();
txEvt.setConcurrencyIndex(rowByTxId.get(txId));
rowByTxId.remove(txId);
break;
case SINGLE:
2021-01-15 08:53:06 +01:00
for (; rowIdx < rowEndTime.size() && rowEndTime.get(rowIdx)>tx.getBeginTime(); rowIdx++);
2021-01-14 23:13:11 +01:00
if (rowEndTime.size() <= rowIdx)
rowEndTime.add(tx.getEndTime());
else
rowEndTime.set(rowIdx, tx.getEndTime());
((TxEvent) evt).setConcurrencyIndex(rowIdx);
break;
case BEGIN:
2021-01-15 08:53:06 +01:00
for (; rowIdx < rowEndTime.size() && rowEndTime.get(rowIdx)>tx.getBeginTime(); rowIdx++);
2021-01-14 23:13:11 +01:00
if (rowEndTime.size() <= rowIdx)
rowEndTime.add(tx.getEndTime());
else
rowEndTime.set(rowIdx, tx.getEndTime());
((TxEvent) evt).setConcurrencyIndex(rowIdx);
rowByTxId.put(tx.getId(), rowIdx);
break;
}
2021-01-15 08:53:06 +01:00
}
}
rowCount=rowEndTime.size()>0?rowEndTime.size():1;
2023-02-21 09:10:35 +01:00
//getChildNodes().parallelStream().forEach(c -> ((TxGenerator)c).calculateConcurrency());
getChildNodes().stream().forEach(c -> ((TxGenerator)c).calculateConcurrency());
2021-01-09 10:34:22 +01:00
}
}