Commit 841679d1 authored by Christian Wulf's avatar Christian Wulf

lastState is set now

parent 25a007a1
......@@ -30,7 +30,8 @@ import org.slf4j.LoggerFactory;
import teetime.framework.exceptionHandling.AbstractExceptionListener;
import teetime.framework.exceptionHandling.AbstractExceptionListener.FurtherExecution;
import teetime.framework.exceptionHandling.TerminateException;
import teetime.framework.performancelogging.ActivationState;
import teetime.framework.performancelogging.StateChange;
import teetime.framework.performancelogging.StateChange.ExecutionState;
import teetime.framework.performancelogging.StateLoggable;
import teetime.framework.signal.ISignal;
import teetime.framework.signal.StartingSignal;
......@@ -110,15 +111,18 @@ public abstract class AbstractStage implements StateLoggable {
// If the stage get null-element it can't be active. If it's the first time
// after being active the according time stamp is saved so that one can gather
// information about the time the stage was in one state uninterrupted.
if (newStateRequired(ActivationState.BLOCKED)) {
ActivationState newState = new ActivationState(ActivationState.BLOCKED, this.getActualTimeStamp(), ActivationState.PULLING_FAILED);
if (newStateRequired(ExecutionState.BLOCKED)) {
StateChange newState = new StateChange(ExecutionState.BLOCKED, this.getActualTimeStamp(), StateChange.PULLING_FAILED);
this.addState(newState);
}
throw NOT_ENOUGH_INPUT_EXCEPTION;
}
protected final void executeStage() {
// this.setActualTimeStamp(System.nanoTime());
if (performanceLoggingEnabled) {
this.setActualTimeStamp(System.nanoTime());
}
try {
this.execute();
} catch (NotEnoughInputException e) {
......@@ -320,7 +324,7 @@ public abstract class AbstractStage implements StateLoggable {
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
public void onTerminating() throws Exception {
this.addState(ActivationState.TERMINATED);
this.addState(ExecutionState.TERMINATED);
changeState(StageState.TERMINATED);
calledOnTerminating = true;
}
......@@ -534,9 +538,9 @@ public abstract class AbstractStage implements StateLoggable {
* A list which save a timestamp and an associated state (active or inactive). This Information can be used for Bottleneck analysis.
*
*/
private final List<ActivationState> states = new ArrayList<ActivationState>();
private final List<StateChange> states = new ArrayList<StateChange>();
private ActivationState lastState;
private StateChange lastState = new StateChange(ExecutionState.INITIALIZED);
private long actualTimeStamp;
......@@ -546,44 +550,45 @@ public abstract class AbstractStage implements StateLoggable {
private final boolean performanceLoggingEnabled = false;
@Override
public List<ActivationState> getStates() {
public List<StateChange> getStates() {
return states;
}
protected void addState(final int stateCode) {
ActivationState state = new ActivationState(stateCode);
this.states.add(state);
protected void addState(final ExecutionState stateCode) {
StateChange state = new StateChange(stateCode);
addState(state);
}
protected void addState(final ActivationState state) {
protected void addState(final StateChange state) {
this.states.add(state);
this.lastState = state;
}
protected boolean newStateRequired(final int state) {
protected boolean newStateRequired(final ExecutionState state) {
if (!performanceLoggingEnabled) {
return false;
}
return ((this.lastState == null) || (this.lastState.getState() != state));
return (this.lastState.getExecutionState() != state);
}
@Override
public void sendingFailed() {
if (newStateRequired(ActivationState.BLOCKED)) {
this.addState(new ActivationState(ActivationState.BLOCKED, ActivationState.SENDING_FAILED));
if (newStateRequired(ExecutionState.BLOCKED)) {
this.addState(new StateChange(ExecutionState.BLOCKED, StateChange.SENDING_FAILED));
}
}
@Override
public void sendingSucceeded() {
if (newStateRequired(ActivationState.ACTIV_WAITING)) {
this.addState(ActivationState.ACTIV_WAITING);
if (newStateRequired(ExecutionState.ACTIVE_WAITING)) {
this.addState(ExecutionState.ACTIVE_WAITING);
}
}
@Override
public void sendingReturned() {
if (newStateRequired(ActivationState.ACTIV)) {
this.addState(ActivationState.ACTIV);
if (newStateRequired(ExecutionState.ACTIVE)) {
this.addState(ExecutionState.ACTIVE);
}
}
......
......@@ -33,7 +33,7 @@ class CumulativeActivePassivTime implements ActivationStateLogger.IFormatingStra
long cumulativeBlockedTime = 0;
// go through all states of this stage and sum up the active times while counting the number of active times
for (ActivationState state : stage.getStates()) {
for (StateChange state : stage.getStates()) {
long actualTimeStamp = state.getTimeStamp();
if (actualTimeStamp < earliestTimeStamp) {
......@@ -45,14 +45,14 @@ class CumulativeActivePassivTime implements ActivationStateLogger.IFormatingStra
long elapsedTime = actualTimeStamp - lastTimeStamp;
switch (state.getState()) {
case ActivationState.ACTIV:
switch (state.getExecutionState()) {
case ACTIVE:
cumulativeActiveTime += elapsedTime;
break;
case ActivationState.ACTIV_WAITING:
case ACTIVE_WAITING:
cumulativeActiveWaitingTime += elapsedTime;
break;
case ActivationState.BLOCKED:
case BLOCKED:
cumulativeBlockedTime += elapsedTime;
break;
default:
......
......@@ -27,9 +27,9 @@ class PercentageOfActiveTime implements ActivationStateLogger.IFormatingStrategy
long lastActiveTimeStamp = 0;
boolean lastActive = false;
for (ActivationState state : stage.getStates()) {
for (StateChange state : stage.getStates()) {
long currentTimeStamp = state.getTimeStamp();
if (state.getCause() == ActivationState.NOTHING_FAILED) {
if (state.getCause() == StateChange.NOTHING_FAILED) {
if (!lastActive) {
lastActiveTimeStamp = currentTimeStamp;
}
......
......@@ -37,8 +37,8 @@ class RNTFormating implements IFormatingStrategy {
boolean lastActive = false;
// go through all states of this stage and sum up the active times while counting the number of active times
for (ActivationState state : stage.getStates()) {
if (state.getCause() == ActivationState.NOTHING_FAILED) {
for (StateChange state : stage.getStates()) {
if (state.getCause() == StateChange.NOTHING_FAILED) {
if (!lastActive) {
lastActiveTimeStamp = state.getTimeStamp();
}
......
......@@ -6,31 +6,45 @@ package teetime.framework.performancelogging;
* @author Adrian
*
*/
public class ActivationState {
public class StateChange {
public enum ExecutionState {
/**
* Represents the state where the stage has been initialized, but not yet been executed.
* This state is used to implement the null object pattern.
* It avoids to check for <code>this.lastState == null</code>.
*/
INITIALIZED,
/** Represents the state where the stage is being executed. */
ACTIVE,
/** Represents the state where the stage is waiting for its passive successor stage to return. */
ACTIVE_WAITING,
/** Represents the state where the stage is waiting for its active successor stage to consume the elements within the interconnected pipe. */
BLOCKED,
/** Represents the stage where the stage has been terminated. */
TERMINATED,
}
// TODO vielleicht überflüssig
public final static int SENDING_FAILED = -1;
public final static int PULLING_FAILED = -2;
public final static int GENERAL_EXCEPTION = -3;
public final static int NOTHING_FAILED = 0;
public final static int ACTIV = 1;
public final static int ACTIV_WAITING = 0;
public final static int BLOCKED = -1;
public final static int TERMINATED = -2;
private final int state;
private final ExecutionState executionState;
private final long timeStamp;
private final int cause;
public ActivationState(final int state) {
public StateChange(final ExecutionState state) {
this(state, System.nanoTime(), 0);
}
public ActivationState(final int state, final int cause) {
public StateChange(final ExecutionState state, final int cause) {
this(state, System.nanoTime(), cause);
}
public ActivationState(final int state, final long timeStamp, final int cause) {
this.state = state;
public StateChange(final ExecutionState state, final long timeStamp, final int cause) {
this.executionState = state;
this.timeStamp = timeStamp;
this.cause = cause;
}
......@@ -43,8 +57,8 @@ public class ActivationState {
return cause;
}
public int getState() {
return state;
public ExecutionState getExecutionState() {
return executionState;
}
}
......@@ -9,7 +9,7 @@ public interface StateLoggable {
*
* @return List of states this stage saved during its run.
*/
public List<ActivationState> getStates();
public List<StateChange> getStates();
/**
* This method is called by Pipes if the sending of the next element needs to be delayed because of full Queue.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment