private void StopTest(bool showResults) { Ab3d.DirectX.Controls.D3DHost.RenderAsManyFramesAsPossible = false; MainDXViewportView.SceneRendered -= OnSceneRendered; if (_stopwatch != null) { _stopwatch.Stop(); } if (Application.Current.MainWindow != null) { 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; } }
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++; }