public PerformanceTest()
        {
            InitializeComponent();

            // To use RenderAsManyFramesAsPossible we need DirectXOverlay presentation type
            MainDXViewportView.PresentationType = DXView.PresentationTypes.DirectXOverlay;

            InfoTextBlock.Text = string.Format(InfoTextBlock.Text, HeadingIncreaseOnEachFrame);

            MainDXViewportView.DXSceneInitialized += delegate(object sender, EventArgs args)
            {
                if (MainDXViewportView.DXScene == null) // Probably WPF 3D rendering
                {
                    return;
                }

                string testName = string.Format("PerformanceTest with '{0}' ({1})",
                                                System.IO.Path.GetFileName(StartupFileName),
                                                OptimizeReadModel ? "optimized" : "not optimized");

                _performanceAnalyzer = new PerformanceAnalyzer(MainDXViewportView, testName, initialCapacity: 10000);
                _performanceAnalyzer.StartCollectingStatistics();
            };


            this.Loaded += OnLoaded;


            //this.Focusable = true; // by default Page is not focusable and therefore does not receive keyDown event
            //this.PreviewKeyDown += OnPreviewKeyDown;


            // FPS will be displayed in Window Title - save the title so we can restore it later
            _savedWindowTitle = Application.Current.MainWindow.Title;

            this.Unloaded += delegate(object sender, RoutedEventArgs args)
            {
                StopTest(showResults: false);

                MainDXViewportView.Dispose();

                if (_parentWindow != null)
                {
                    _parentWindow.PreviewKeyDown -= OnPreviewKeyDown;
                }
            };
        }
Example #2
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++;
        }
 private void RestartTestButton_OnClick(object sender, RoutedEventArgs e)
 {
     _performanceAnalyzer.StopCollectingStatistics();
     _performanceAnalyzer.StartCollectingStatistics();
 }