Exemple #1
0
        // =========================


        /// <summary>
        /// Допустим ли переход между состояниями
        /// </summary>
        /// <param name="curState">Исходное состояние</param>
        /// <param name="newState">Новое состояние</param>
        /// <returns>Допустимость</returns>
        private bool CanChangeState(ExecutionThroughoutTrackerUpDownCorrectionState curState, ExecutionThroughoutTrackerUpDownCorrectionState newState)
        {
            if (curState == newState)
            {
                return(true);
            }

            switch (curState)
            {
            case ExecutionThroughoutTrackerUpDownCorrectionState.InOptimalState:
                return(newState == ExecutionThroughoutTrackerUpDownCorrectionState.FindBestDirection);

            case ExecutionThroughoutTrackerUpDownCorrectionState.FindBestDirection:
                return(newState == ExecutionThroughoutTrackerUpDownCorrectionState.InOptimalState || newState == ExecutionThroughoutTrackerUpDownCorrectionState.Increasing || newState == ExecutionThroughoutTrackerUpDownCorrectionState.Decreasing);

            case ExecutionThroughoutTrackerUpDownCorrectionState.Increasing:
                return(newState == ExecutionThroughoutTrackerUpDownCorrectionState.InOptimalState || newState == ExecutionThroughoutTrackerUpDownCorrectionState.FindBestDirection);

            case ExecutionThroughoutTrackerUpDownCorrectionState.Decreasing:
                return(newState == ExecutionThroughoutTrackerUpDownCorrectionState.InOptimalState || newState == ExecutionThroughoutTrackerUpDownCorrectionState.FindBestDirection);

            default:
                throw new InvalidOperationException("Unknown state: " + curState.ToString());
            }
        }
Exemple #2
0
        /// <summary>
        /// Конструктор ExecutionThroughoutTrackerUpDownCorrection
        /// </summary>
        /// <param name="maxThreadCount">Максимальное число потоков</param>
        /// <param name="reasonableThreadCount">Базовое число потоков</param>
        public ExecutionThroughoutTrackerUpDownCorrection(int maxThreadCount, int reasonableThreadCount)
        {
            Contract.Requires(maxThreadCount > 0);
            Contract.Requires(reasonableThreadCount > 0);
            Contract.Requires(maxThreadCount >= reasonableThreadCount);

            _maxThreadCount        = maxThreadCount;
            _reasonableThreadCount = reasonableThreadCount;

            _executedTasks = 0;
            _lastTimeStamp = GetTimestamp();

            _data          = new ThroughoutData[EstimationDataLength];
            _nextDataIndex = 0;

            _state = ExecutionThroughoutTrackerUpDownCorrectionState.FindBestDirection;
            _enterStateTimeStamp      = GetTimestamp();
            _enterStateThroughoutData = new ThroughoutData();
            _stateMeasureCount        = 0;

            _findBestDirectionBlinkCount       = 0;
            _optimalStateAverageThroughout     = -1;
            _decresingAverageThoughoutBaseline = -1;

            _isPerfMeasureThreadWork = false;
        }
Exemple #3
0
        /// <summary>
        /// Выполнить переход в состояние
        /// </summary>
        /// <param name="description">Описание причин перехода</param>
        /// <param name="state">Новое состояние</param>
        private void GoToState(string description, ExecutionThroughoutTrackerUpDownCorrectionState state)
        {
            if (!CanChangeState(_state, state))
            {
                throw new InvalidOperationException("Invalid state change from " + _state.ToString() + " to " + state.ToString());
            }

            //Console.WriteLine(description + ". State = " + _state.ToString() + ", NewState = " + state.ToString());

            if (_state != state)
            {
                _state = state;

                _enterStateTimeStamp      = GetTimestamp();
                _enterStateThroughoutData = this.GetCurrentMeasure();
                _stateMeasureCount        = 0;

                _findBestDirectionBlinkCount       = 0;
                _optimalStateAverageThroughout     = -1;
                _decresingAverageThoughoutBaseline = -1;

                Debug.Assert(_isPerfMeasureThreadWork == false);
            }
        }