예제 #1
0
        //private async Task IfApexTestDelayAsync()
        //{
        //    if (stressUtilOptions.IsTestApexTest())
        //    {
        //        var ApexLeaseDelay = System.Runtime.Remoting.Lifetime.LifetimeServices.LeaseTime + TimeSpan.FromSeconds(10 * stressUtilOptions.DelayMultiplier); // a little more than the lease lifetime
        //        logger.LogMessage($"Apex test: waiting {ApexLeaseDelay.TotalSeconds:n0} seconds for leaselifetime to expire");
        //        await Task.Delay(ApexLeaseDelay);
        //    }
        //    else
        //    {
        //        if (PerfCounterData.ProcToMonitor.Id != Process.GetCurrentProcess().Id)
        //        {
        //            await Task.Delay(TimeSpan.FromSeconds(2 * stressUtilOptions.DelayMultiplier));
        //        }
        //    }
        //}

        /// <summary>
        /// get the counter for graphing
        /// </summary>
        /// <returns></returns>
        public Dictionary <PerfCounterType, uint> GetLastMeasurements()
        {
            var res = new Dictionary <PerfCounterType, uint>();

            foreach (var ctr in LstPerfCounterData.Where(pctr => pctr.IsEnabledForGraph))
            {
                var entry = measurements[ctr.perfCounterType];
                res[ctr.perfCounterType] = entry[entry.Count - 1];
            }
            return(res);
        }
예제 #2
0
 public void TakeRawMeasurement(StringBuilder sBuilderMeasurementResult = null, bool IsForInteractiveGraph = false)
 {
     foreach (var ctr in LstPerfCounterData.Where(pctr => IsForInteractiveGraph ? pctr.IsEnabledForGraph : pctr.IsEnabledForMeasurement))
     {
         if (!measurements.TryGetValue(ctr.perfCounterType, out var lst))
         {
             lst = new List <uint>();
             measurements[ctr.perfCounterType] = lst;
         }
         var pcValueAsFloat = 0f;
         try
         {
             pcValueAsFloat = ctr.ReadNextValue();
         }
         catch (InvalidOperationException ex) //From Eventlog:The Open procedure for service ".NETFramework" in DLL "C:\Windows\system32\mscoree.dll" failed with error code 5. Performance data for this service will not be available.
         {
             string clrFilePath    = string.Empty;
             string clrFileVersion = string.Empty;
             foreach (ProcessModule module in Process.GetCurrentProcess().Modules)
             {
                 if (module.ModuleName.Equals("clr.dll", StringComparison.OrdinalIgnoreCase))
                 {
                     clrFilePath    = module.FileName;
                     clrFileVersion = module.FileVersionInfo.FileVersion;
                     break;
                 }
             }
             Logger.LogMessage($"***EXCEPTION PerfCounter '{ex.Message}' {ctr} ProcId{ctr.ProcToMonitor.Id} StartTime= {ctr.ProcToMonitor.StartTime} HasExited={ctr.ProcToMonitor.HasExited} ClrPath={clrFilePath} ClrVersion={clrFileVersion}");
         }
         uint priorValue = 0;
         if (lst.Count > 0)
         {
             priorValue = lst[lst.Count - 1];
             if (this.sampleType != SampleType.SampleTypeIteration)
             {
                 lst.RemoveAt(0); // we're not iterating, don't accumulate more than 1 (1 for previous)
             }
         }
         uint pcValue = (uint)pcValueAsFloat;
         int  delta   = (int)pcValue - (int)priorValue;
         sBuilderMeasurementResult?.Append($"{ctr.PerfCounterName}={pcValue,13:n0}  Δ = {delta,13:n0} ");
         lst.Add(pcValue);
     }
     if (this.sampleType == SampleType.SampleTypeIteration)
     {
         nSamplesTaken++;
     }
 }
예제 #3
0
        public string DumpOutMeasurementsToTxtFile()
        {
            var sb  = new StringBuilder();
            var lst = new List <string>();

            foreach (var ctr in LstPerfCounterData.Where(pctr => pctr.IsEnabledForMeasurement))
            {
                lst.Add(ctr.PerfCounterName);
            }
            sb.AppendLine(string.Join(",", lst.ToArray()));

            for (int i = 0; i < nSamplesTaken; i++)
            {
                lst.Clear();
                foreach (var ctr in LstPerfCounterData.Where(pctr => pctr.IsEnabledForMeasurement))
                {
                    if (i < measurements[ctr.perfCounterType].Count)
                    {
                        lst.Add($"{measurements[ctr.perfCounterType][i]}");
                    }
                    else
                    {
                        Logger.LogMessage($"Index out of range {ctr.PerfCounterName}  {i}  {measurements[ctr.perfCounterType].Count}");
                    }
                }
                sb.AppendLine(string.Join(",", lst.ToArray()));
            }
            var filename = Path.Combine(ResultsFolder, $"Measurements.txt");

            File.WriteAllText(filename, sb.ToString());
            lstFileResults.Add(new FileResultsData()
            {
                filename = filename, description = "Raw Measuremensts as Txt File to open/graph in Excel"
            });
            return(filename);
        }
예제 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="showGraph">show a graph interactively</param>
        /// <param name="GraphsAsFilePrefix">Create graphs as files and test attachments. Null means none</param>
        /// <returns></returns>
        public async Task <List <LeakAnalysisResult> > CalculateLeaksAsync(bool showGraph, string GraphsAsFilePrefix)
        {
            var lstResults = new List <LeakAnalysisResult>();

            this.stressUtilOptions.SetPerfCounterOverrideSettings();
            foreach (var ctr in LstPerfCounterData.Where(pctr => pctr.IsEnabledForMeasurement))
            {
                var leakAnalysis = new LeakAnalysisResult(measurements[ctr.perfCounterType])
                {
                    perfCounterData     = ctr,
                    sensitivity         = stressUtilOptions.Sensitivity,
                    pctOutliersToIgnore = stressUtilOptions.pctOutliersToIgnore,
                    RSquaredThreshold   = stressUtilOptions.RSquaredThreshold
                };
                leakAnalysis.FindLinearLeastSquaresFit();

                lstResults.Add(leakAnalysis);
            }
            if (showGraph)
            {
                var tcs = new TaskCompletionSource <int>();
                // if we're running in testhost process, then we want a timeout
                var timeoutEnabled = this.testContext != null;
                var timeout        = TimeSpan.FromSeconds(60);
                Logger.LogMessage($"Showing graph  timeoutenabled ={timeoutEnabled} {timeout.TotalSeconds:n0} secs");
                var thr = new Thread((oparam) =>
                {
                    try
                    {
                        var graphWin = new GraphWin(this);
                        if (timeoutEnabled)
                        {
                            var timer = new DispatcherTimer()
                            {
                                Interval = timeout
                            };
                            timer.Tick += (o, e) =>
                            {
                                Logger.LogMessage($"Timedout showing graph");
                                timer.Stop();
                                graphWin.Close();
                            };
                            timer.Start();
                        }
                        graphWin.AddGraph(lstResults);
                        if (timeoutEnabled)
                        {
                            graphWin.Title += $" timeout {timeout.TotalSeconds:n0}";
                        }
                        graphWin.ShowDialog();
                        Logger.LogMessage($"finished showing graph");
                    }
                    catch (Exception ex)
                    {
                        Logger.LogMessage($"graph {ex}");
                    }
                    tcs.SetResult(0);
                });
                thr.SetApartmentState(ApartmentState.STA);
                thr.Start();
                await tcs.Task;
                //if (await Task.WhenAny(tcs.Task, Task.Delay(timeout)) != tcs.Task)
                //{
                //    Logger.LogMessage($"Timedout showing graph");
                //}
            }
            // Create graphs as files. do this after showgraph else hang
            if (!string.IsNullOrEmpty(GraphsAsFilePrefix))
            {
                foreach (var item in lstResults)
                {
                    using (var chart = new Chart())
                    {
                        chart.Titles.Add($"{TestName} {item}");
                        chart.Size = new System.Drawing.Size(1200, 800);
                        chart.Series.Clear();
                        chart.ChartAreas.Clear();
                        ChartArea chartArea = new ChartArea("ChartArea");
                        chartArea.AxisY.LabelStyle.Format = "{0:n0}";
                        chartArea.AxisY.Title             = item.perfCounterData.PerfCounterName;
                        chartArea.AxisX.Title             = "Iteration";
                        chartArea.AxisY.LabelStyle.Font   = new System.Drawing.Font("Consolas", 12);
                        chart.ChartAreas.Add(chartArea);
                        chartArea.AxisY.IsStartedFromZero = false;
                        var series = new Series
                        {
                            ChartType = SeriesChartType.Line,
                            Name      = item.perfCounterData.PerfCounterName
                        };
                        series.MarkerSize  = 10;
                        series.MarkerStyle = MarkerStyle.Circle;
                        chart.Series.Add(series);
                        for (int i = 0; i < item.NumSamplesToUse; i++)
                        {
                            var dp = new DataPoint(i + 1, item.lstData[i].point.Y); // measurements taken at end of iteration
                            if (item.lstData[i].IsOutlier)
                            {
                                dp.MarkerColor = System.Drawing.Color.Red;
                                dp.MarkerStyle = MarkerStyle.Cross;
                            }
                            series.Points.Add(dp);
                        }
                        // now show trend line
                        var seriesTrendLine = new Series()
                        {
                            ChartType = SeriesChartType.Line,
                            Name      = "Trend Line"
                        };
                        chart.Series.Add(seriesTrendLine);
                        var dp0 = new DataPoint(1, item.yintercept + item.slope);
                        seriesTrendLine.Points.Add(dp0);
                        var dp1 = new DataPoint(item.NumSamplesToUse, item.NumSamplesToUse * item.slope + item.yintercept);
                        seriesTrendLine.Points.Add(dp1);

                        chart.Legends.Add(new Legend());
                        chart.Legends[0].CustomItems.Add(new LegendItem()
                        {
                            Name              = "IsOutlier",
                            ImageStyle        = LegendImageStyle.Marker,
                            MarkerColor       = System.Drawing.Color.Red,
                            MarkerStyle       = MarkerStyle.Cross,
                            MarkerBorderWidth = 0,
                            MarkerSize        = 10
                        });

                        var fname = Path.Combine(ResultsFolder, $"{GraphsAsFilePrefix} {item.perfCounterData.PerfCounterName}.png");
                        chart.SaveImage(fname, ChartImageFormat.Png);
                        lstFileResults.Add(new FileResultsData()
                        {
                            filename = fname, description = $"{GraphsAsFilePrefix} {item.perfCounterData}"
                        });
                    }
                }
            }
            return(lstResults);
        }