Search in sources :

Example 1 with StageActivationState

use of teetime.framework.performancelogging.StateChange.StageActivationState in project TeeTime by teetime-framework.

the class CumulativeActivePassivTime method formatData.

@Override
public String formatData() {
    String result = "\n Formating to analyse differences in runtime:\n\n";
    result += "name;total time;cumulative blocked time;cumulative active waiting time time;active time\n";
    // go through all the stages
    for (AbstractStage stage : stages) {
        // first add a formated version of their names to the line.
        result += formateName(stage);
        long earliestTimeStamp = Long.MAX_VALUE;
        long latestTimeStamp = Long.MIN_VALUE;
        long lastTimeStamp = 0;
        StageActivationState lastState = StageActivationState.INITIALIZED;
        long cumulativeActiveTime = 0;
        long cumulativeActiveWaitingTime = StateStatistics.getActiveWaitingTime(stage);
        long cumulativeBlockedTime = 0;
        // go through all states of this stage and sum up the active times while counting the number of active timestamp
        for (StateChange state : StateStatistics.getStates(stage)) {
            long actualTimeStamp = state.getTimeStamp();
            // update earliest and latest timeStamp if necessary
            if (actualTimeStamp < earliestTimeStamp) {
                earliestTimeStamp = actualTimeStamp;
            } else if (actualTimeStamp > latestTimeStamp) {
                latestTimeStamp = actualTimeStamp;
            }
            // In the first loop neither lastTimeStamp nor lastState are set. So the next part wouldn't calculate correct.
            if (lastState != StageActivationState.INITIALIZED) {
                long elapsedTime = actualTimeStamp - lastTimeStamp;
                switch(lastState) {
                    case ACTIVE:
                        cumulativeActiveTime += elapsedTime;
                        break;
                    case BLOCKED:
                        cumulativeBlockedTime += elapsedTime;
                        break;
                    case TERMINATED:
                        break;
                    default:
                        break;
                }
            }
            lastTimeStamp = actualTimeStamp;
            lastState = state.getStageActivationState();
        }
        // The ActiveWaiting time was counted into active time till now. So it it subtracted now.
        cumulativeActiveTime -= cumulativeActiveWaitingTime;
        result += (latestTimeStamp - earliestTimeStamp) + ";" + cumulativeBlockedTime + ";" + cumulativeActiveWaitingTime + ";" + cumulativeActiveTime;
        result += "\n";
    }
    return result.replace("\n", String.format("%n"));
}
Also used : StateChange(teetime.framework.performancelogging.StateChange) StageActivationState(teetime.framework.performancelogging.StateChange.StageActivationState) AbstractStage(teetime.framework.AbstractStage)

Aggregations

AbstractStage (teetime.framework.AbstractStage)1 StateChange (teetime.framework.performancelogging.StateChange)1 StageActivationState (teetime.framework.performancelogging.StateChange.StageActivationState)1