public void Stop()
        {
            if (_strategy == null)
            {
                return;
            }

            lock (SyncRoot)
            {
                if (_strategy == null)
                {
                    return;
                }

                // Stop strategy
                _strategy?.Stop();

                // Fill results
                _results.Clear();

                if (_strategy == null)
                {
                    return;
                }

                _results.AddRange(_strategy.GetResults());
                _strategy = null;
            }
        }
        public void Start(List <BenchmarkInstance> benchmarks)
        {
            if (benchmarks.Count == 0)
            {
                throw new ArgumentException("There are no benchmarks to execute");
            }

            if (_running)
            {
                Stop();
            }
            _running = true;

            _results.Clear();
            NotifyUpdated(ExecutionState.Running);

            // Create requested test strategy
            if (_configuration.ExecutionType == ExecutionType.Sequential)
            {
                _strategy = new SequencialExecutionStrategy(_configuration, _results, this, benchmarks);
            }
            else
            {
                _strategy = new ProportionalExecutionStrategy(_configuration, _results, this, benchmarks);
            }

            _strategy.Start();
        }
 public ExecutionContext(BenchmarkSuiteInstance suite,
                         ResultAggregator aggregator, ExecutionStrategy strategy)
 {
     _strategy   = strategy;
     _aggregator = aggregator;
     _suite      = suite;
 }
        public void Start(IEnumerable <BenchmarkSuiteInstance> suites)
        {
            if (_strategy != null)
            {
                Stop();
            }

            // Identify active tests
            _suites = new List <BenchmarkSuiteInstance>(suites);
            List <BenchmarkInstance> selectedBenchmarks = new List <BenchmarkInstance>();

            foreach (BenchmarkSuiteInstance suite in _suites)
            {
                foreach (BenchmarkInstance benchmark in suite.Benchmarks)
                {
                    if (benchmark.IsSelected)
                    {
                        selectedBenchmarks.Add(benchmark);
                    }
                }
            }

            // Check if there is at least one test defined
            if (selectedBenchmarks.Count == 0)
            {
                throw new BenchmarkException("There are no benchmarks to execute");
            }

            // Create requested test strategy
            if (_executionType == ExecutionType.Sequential)
            {
                _strategy = new SequencialExecutionStrategy(this, selectedBenchmarks);
            }
            else
            {
                _strategy = new ProportionalExecutionStrategy(this, selectedBenchmarks);
            }

            // Initialize parameters and start
            _results.Clear();

            try
            {
                _strategy.Start();
            }
            catch
            {
                Stop();
                throw;
            }
        }
        public void Stop()
        {
            if (_running)
            {
                lock (SyncRoot)
                {
                    if (_running)
                    {
                        _running = false;

                        // Null strategy to avoid double entry
                        if (_strategy != null)
                        {
                            _strategy.Stop();
                            _strategy = null;
                        }

                        NotifyUpdated(ExecutionState.Completed);
                    }
                }
            }
        }
 public ExecutionContext(ExecutionStrategy strategy, BenchmarkSuiteInstance suite)
 {
     _strategy = strategy;
     _suite    = suite;
 }