use of teetime.framework.AbstractStage in project TeeTime by teetime-framework.
the class PercentageOfActiveTime method formatData.
@Override
public String formatData() {
String result = "\n Formating of the data to get percentage of active time:\n\n";
result += "name;% active time\n";
for (AbstractStage stage : stages) {
result += formateName(stage);
boolean lastActive = false;
long lastActiveTimestamp = Long.MAX_VALUE;
long cumulativeActiveTime = 0;
long firstTimestamp = Long.MAX_VALUE;
long lastTimestamp = Long.MIN_VALUE;
for (StateChange state : StateStatisticsUtils.getStates(stage)) {
if (state.getTimeStamp() < firstTimestamp) {
firstTimestamp = state.getTimeStamp();
}
if (state.getTimeStamp() > lastTimestamp) {
lastTimestamp = state.getTimeStamp();
}
if (!lastActive && state.getStageActivationState() == StageActivationState.ACTIVE) {
lastActive = true;
lastActiveTimestamp = state.getTimeStamp();
}
if (lastActive && state.getStageActivationState() != StageActivationState.ACTIVE && lastActiveTimestamp != Long.MAX_VALUE) {
lastActive = false;
cumulativeActiveTime += (state.getTimeStamp() - lastActiveTimestamp);
}
}
result += ((double) cumulativeActiveTime / (double) (lastTimestamp - firstTimestamp)) * 100 + "\n";
}
return result.replace("\n", String.format("%n"));
}
use of teetime.framework.AbstractStage in project TeeTime by teetime-framework.
the class StageFactory method getSinkFromOutputPort.
@SuppressWarnings("unchecked")
static <T> CollectorSink<T> getSinkFromOutputPort(final OutputPort<T> outputPort) {
InputPort<?> targetPort = outputPort.getPipe().getTargetPort();
AbstractStage owningStage = targetPort.getOwningStage();
if (owningStage instanceof CollectorSink) {
return (CollectorSink<T>) owningStage;
}
String message = String.format("%s", owningStage);
throw new IllegalArgumentException(message);
}
use of teetime.framework.AbstractStage in project TeeTime by teetime-framework.
the class StageFactory method getProducerFromInputPort.
@SuppressWarnings("unchecked")
static <T> InitialElementProducer<T> getProducerFromInputPort(final InputPort<T> inputPort) {
OutputPort<?> sourcePort = inputPort.getPipe().getSourcePort();
AbstractStage owningStage = sourcePort.getOwningStage();
if (owningStage instanceof InitialElementProducer) {
return (InitialElementProducer<T>) owningStage;
}
String message = String.format("%s", owningStage);
throw new IllegalArgumentException(message);
}
use of teetime.framework.AbstractStage in project TeeTime by teetime-framework.
the class PrioritizedTaskPoolTest method nextStageIsDeepStageLevelExplicit.
@Test
public void nextStageIsDeepStageLevelExplicit() throws Exception {
threadPool.scheduleStage(producer);
threadPool.scheduleStage(counter4);
AbstractStage nextStage = threadPool.removeNextStage(4);
assertThat(nextStage, is(counter4));
}
use of teetime.framework.AbstractStage in project TeeTime by teetime-framework.
the class PrioritizedTaskPoolTest method removeInCorrectOrder.
@Test
public void removeInCorrectOrder() throws Exception {
// add to pool in an arbitrary order
threadPool.scheduleStage(counter3);
threadPool.scheduleStage(producer);
threadPool.scheduleStage(counter2);
threadPool.scheduleStage(counter4);
threadPool.scheduleStage(counter1);
// remove from the pool in a sorted order
AbstractStage nextStage = threadPool.removeNextStage();
assertThat(nextStage, is(counter4));
nextStage = threadPool.removeNextStage();
assertThat(nextStage, is(counter3));
nextStage = threadPool.removeNextStage();
assertThat(nextStage, is(counter2));
nextStage = threadPool.removeNextStage();
assertThat(nextStage, is(counter1));
nextStage = threadPool.removeNextStage();
assertThat(nextStage, is(producer));
}
Aggregations