Exemplo n.º 1
0
        public void StartTest()
        {
            VmLocator.OnlineDb.SendPageHit("stressStart");
            ScreenOn.Enable();
            TestNotStarted = false;
            UpdateCounter  = 0;

            stressTest = new Saplin.xOPS.StressTest(samplingMs, smoothing, warmUpSample, Environment.ProcessorCount, true, true);

            Gflops = stressTest.GflopsResults?.SmoothResults;
            Ginops = stressTest.GinopsResults?.SmoothResults;
            Temp   = null;

            di = DependencyService.Get <IDeviceInfo>();

            try
            {
                di.GetCpuTemp();
                Temp = new List <double>();
                RaisePropertyChanged(nameof(Temp));
            }
            catch { }

            var tempText = string.Empty;

            if (Temp == null)
            {
                tempText = TempLabel = VmLocator.L11n.TempNotAvailable +
                                       (Device.RuntimePlatform == Device.WPF && !di.IsAdmin ?  " - " + VmLocator.L11n.TryAdmin : "")
                                       + "\n";
            }

            RaisePropertyChanged(nameof(Gflops));
            RaisePropertyChanged(nameof(Ginops));

            var label1 = VmLocator.L11n.Start + ": {1:0.00} {0}\n" + VmLocator.L11n.Now + ": {2:0.00} {0}";
            var label2 = "{1:0.00} {0}\n{2:0.00}%";

            var prevCount = 0;

            stressTest.ResultsUpdated += (e) =>
            {
                if (stressTest.WarmpingUp)
                {
                    GflopsLabel = GinopsLabel = Environment.ProcessorCount + " " + VmLocator.L11n.threads + " \n" + VmLocator.L11n.WarmingUp + "...";
                    TempLabel   = VmLocator.L11n.WarmingUp + "...";
                }
                else
                {
                    var count = Gflops != null ? Gflops.Count
                        : Ginops != null ? Ginops.Count : 0;

                    if (prevCount != count)
                    {
                        prevCount = count;

                        if (stressTest.GflopsResults != null)
                        {
                            GflopsLabel = UpdateCounter < 10 ?
                                          string.Format(label1,
                                                        "GFLOPS",
                                                        stressTest.GflopsResults.StartSmooth,
                                                        stressTest.GflopsResults.CurrentSmooth) :
                                          string.Format(label2,
                                                        "GFLOPS",
                                                        stressTest.GflopsResults.CurrentSmooth,
                                                        ((stressTest.GflopsResults.CurrentSmooth - stressTest.GflopsResults.StartSmooth) / stressTest.GflopsResults.StartSmooth * 100));
                        }

                        if (stressTest.GinopsResults != null)
                        {
                            GinopsLabel = UpdateCounter < 14 ?
                                          string.Format(label1,
                                                        "GINOPS",
                                                        stressTest.GinopsResults.StartSmooth,
                                                        stressTest.GinopsResults.CurrentSmooth) :
                                          string.Format(label2,
                                                        "GINOPS",
                                                        stressTest.GinopsResults.CurrentSmooth,
                                                        ((stressTest.GinopsResults.CurrentSmooth - stressTest.GinopsResults.StartSmooth) / stressTest.GinopsResults.StartSmooth * 100));
                        }

                        if (Temp != null)
                        {
                            try
                            {
                                var temp = di.GetCpuTemp();
                                Temp.Add(temp);
                                tempText = "CPU " + temp.ToString("0.0") + "°C "
                                           + (temp > Temp[0] ? "↑" : "↓")
                                           + (temp - Temp[0]).ToString("0.0") + "°C";
                            }
                            catch { };
                        }

                        Update();
                    }

                    TempLabel = tempText + "\n" + sw.Elapsed.Minutes + (UpdateCounter % 2 == 0 ? ":" : ".") + sw.Elapsed.Seconds.ToString("00");;
                }

                RaisePropertyChanged(nameof(GflopsLabel));
                RaisePropertyChanged(nameof(GinopsLabel));
                RaisePropertyChanged(nameof(TempLabel));
            };

            stressTest.Start();
            sw.Restart();
        }