Exemplo n.º 1
0
        private void StartBenchmark()
        {
            StartStopTestButton.Content = "Abort benchmark";

            OptionsGrid.Visibility   = Visibility.Collapsed;
            InfoTextBlock.Visibility = Visibility.Visible;

            _mouseCameraController.IsEnabled = false;

            _totalRenderTimes.Clear();

            _performanceAnalyzer = new PerformanceAnalyzer(_mainDXViewportView);


            // get only system info
            string systemInfo = _performanceAnalyzer.GetResultsText(addSystemInfo: true, addDXEngineInfo: true, addGarbageCollectionsInfo: false, addTotals: false, addStateChangesStatistics: false, addFirstFrameStatisticsWhenAvailable: false, addRenderingStatistics: false, addMultiThreadingStatistics: false);

            InfoTextBlock.Text = $"Starting benchmark ({_mainDXViewportView.PresentationType} with {_objectsCount} objects)\r\nwith changing MaxBackgroundThreadsCount from 0 to {ThreadsCountSlider.Maximum:0}.\r\n\r\n{systemInfo}\r\n====================\r\n\r\nRendering with MaxBackgroundThreadsCount = 0\r\n\r\n";
            InfoTextBlock.UpdateLayout();
            InfoTextBlock.ScrollToEnd();


            SetLightingMode(LightingMode.DirectionalLight);
            ThreadsCountSlider.Value = 0;

            _benchmarkResults          = new StringBuilder();
            _benchmarkTotalRenderTimes = new List <double>();

            _benchmarkStepFramesCount          = 1;
            _mainDXViewportView.SceneRendered += OnBenchmarkSceneRendered;
        }
        private void StopTest(bool showResults)
        {
            Ab3d.DirectX.Controls.D3DHost.RenderAsManyFramesAsPossible = false;

            MainDXViewportView.SceneRendered -= OnSceneRendered;

            if (_stopwatch != null)
            {
                _stopwatch.Stop();
            }

            Application.Current.MainWindow.Title = _savedWindowTitle;

            if (_performanceAnalyzer == null)
            {
                return;
            }


            _performanceAnalyzer.StopCollectingStatistics();

            var resultsText = _performanceAnalyzer.GetResultsText();

            if (showResults)
            {
                ResultsTextBox.Text       = resultsText;
                ResultsTextBox.Visibility = Visibility.Visible;

                MainDXViewportView.Visibility = Visibility.Collapsed;
            }
        }
Exemplo n.º 3
0
        private void OnBenchmarkSceneRendered(object sender, EventArgs e)
        {
            var now = DateTime.Now;

            if (_benchmarkStepFramesCount == 1)
            {
                // Starting one benchmark step
                _performanceAnalyzer.StartCollectingStatistics();
                _benchmarkStepStartTime = now;
            }
            else if (_mainDXViewportView.DXScene.Statistics != null) // just in case check that Statistics is not null (this should not happen because we set DXDiagnostics.IsCollectingStatistics to true)
            {
                // else collect TotalRenderTimeMs
                _totalRenderTimes.Add(_mainDXViewportView.DXScene.Statistics.TotalRenderTimeMs);
            }


            // Complete one benchmark step after 5 seconds or after 200 frames
            if ((now - _benchmarkStepStartTime).TotalSeconds > 5 || _benchmarkStepFramesCount > 200)
            {
                _performanceAnalyzer.StopCollectingStatistics();

                double totalRenderTimes;

                if (_totalRenderTimes.Count > 0)
                {
                    totalRenderTimes = _totalRenderTimes.Average();
                    _totalRenderTimes.Clear();
                }
                else
                {
                    totalRenderTimes = 0;
                }

                _benchmarkTotalRenderTimes.Add(totalRenderTimes);

                int threadsCount = _mainDXViewportView.DXScene.MaxBackgroundThreadsCount;

                string resultsText = _performanceAnalyzer.GetResultsText(addSystemInfo: false,
                                                                         addDXEngineInfo: false,
                                                                         addGarbageCollectionsInfo: false,
                                                                         addTotals: true,
                                                                         addStateChangesStatistics: false,
                                                                         addFirstFrameStatisticsWhenAvailable: false,
                                                                         addRenderingStatistics: true,
                                                                         addMultiThreadingStatistics: true);

                AddInfoText(resultsText);


                if (ThreadsCountSlider.Value < ThreadsCountSlider.Maximum)
                {
                    ThreadsCountSlider.Value += 1; // Increase threads count
                    AddInfoText(string.Format("====================\r\n\r\nRendering with MaxBackgroundThreadsCount = {0}\r\n", threadsCount + 1));
                }
                else
                {
                    StopBenchmark();
                }

                _benchmarkStepFramesCount = 0;
            }

            _benchmarkStepFramesCount++;
        }