Search in sources :

Example 6 with AbstractStage

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"));
}
Also used : StateChange(teetime.framework.performancelogging.StateChange) AbstractStage(teetime.framework.AbstractStage)

Example 7 with AbstractStage

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);
}
Also used : CollectorSink(teetime.stage.CollectorSink) AbstractStage(teetime.framework.AbstractStage)

Example 8 with AbstractStage

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);
}
Also used : InitialElementProducer(teetime.stage.InitialElementProducer) AbstractStage(teetime.framework.AbstractStage)

Example 9 with AbstractStage

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));
}
Also used : AbstractStage(teetime.framework.AbstractStage) Test(org.junit.Test)

Example 10 with AbstractStage

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));
}
Also used : AbstractStage(teetime.framework.AbstractStage) Test(org.junit.Test)

Aggregations

AbstractStage (teetime.framework.AbstractStage)23 Test (org.junit.Test)9 Traverser (teetime.framework.Traverser)3 StateChange (teetime.framework.performancelogging.StateChange)3 ObjectIntHashMap (com.carrotsearch.hppc.ObjectIntHashMap)1 Logger (org.slf4j.Logger)1 InstantiationPipe (teetime.framework.InstantiationPipe)1 TestConfiguration (teetime.framework.TestConfiguration)1 StageActivationState (teetime.framework.performancelogging.StateChange.StageActivationState)1 CollectorSink (teetime.stage.CollectorSink)1 InitialElementProducer (teetime.stage.InitialElementProducer)1 CreatePortActionDistributor (teetime.stage.basic.distributor.dynamic.CreatePortActionDistributor)1 CreatePortActionMerger (teetime.stage.basic.merger.dynamic.CreatePortActionMerger)1