Ejemplo n.º 1
0
        async Task AddDataPointsAsync(MeasurementHolder measurementHolder)
        {
            var dictPerfCtrCurrentMeasurements = measurementHolder.GetLastMeasurements();

            if (_dataPoints.Count == 0) // nothing yet
            {
                for (int i = 0; i < NumDataPoints; i++)
                {
                    _dataPoints[i] = new List <uint>(dictPerfCtrCurrentMeasurements.Values); // let all init points be equal, so y axis scales IsStartedFromZero
                }
            }
            else
            {
                _dataPoints[_bufferIndex++] = new List <uint>(dictPerfCtrCurrentMeasurements.Values);
                if (_bufferIndex == _dataPoints.Count) // wraparound?
                {
                    _bufferIndex = 0;
                }
            }
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            if (DoFullGCPerSample)
            {
                DoGC();// do a GC.Collect on main thread for every sample (the graphing uses memory)
            }
            // this needs to be done on UI thread
            _chart.Series.Clear();
            _chart.ChartAreas.Clear();
            ChartArea chartArea = new ChartArea("ChartArea");

            chartArea.AxisY.LabelStyle.Format = "{0:n0}";
            chartArea.AxisY.LabelStyle.Font   = new System.Drawing.Font("Consolas", 12);
            _chart.ChartAreas.Add(chartArea);
            int ndxSeries = 0;

            chartArea.AxisY.IsStartedFromZero = false;
            if (SetMaxGraphTo100)
            {
                _chart.ChartAreas[0].AxisY.Maximum = 100;
            }
            foreach (var entry in dictPerfCtrCurrentMeasurements)
            {
                var series = new Series
                {
                    ChartType = SeriesChartType.Line,
                    Name      = entry.Key.ToString()
                };
                _chart.Series.Add(series);
                if (UpdateInterval == 0) // if we're not doing auto update on timer, we're iterating or doing manual measurement
                {
                    series.MarkerSize  = 10;
                    series.MarkerStyle = MarkerStyle.Circle;
                }
                for (int i = 0; i < _dataPoints.Count; i++)
                {
                    var ndx = _bufferIndex + i;
                    if (ndx >= _dataPoints.Count)
                    {
                        ndx -= _dataPoints.Count;
                    }
                    var dp = new DataPoint(i + 1, _dataPoints[ndx][ndxSeries]);
                    series.Points.Add(dp);
                }
                ndxSeries++;
            }
            _chart.Legends.Clear();
            _chart.Legends.Add(new Legend());
            _chart.DataBind();

            if (_editorTracker != null)
            {
                var(openedViews, lstLeakedViews) = _editorTracker.GetCounts();
                OpenedViews.Clear();
                LeakedViews.Clear();
                foreach (var dictEntry in openedViews)
                {
                    var sp = new StackPanel()
                    {
                        Orientation = Orientation.Horizontal
                    };
                    sp.Children.Add(new TextBlock()
                    {
                        Text = $"{ dictEntry.Key,-15} {dictEntry.Value,3}", FontFamily = FontFamilyMono
                    });
                    OpenedViews.Add(sp);
                }

                foreach (var entry in lstLeakedViews)
                {
                    var sp = new StackPanel()
                    {
                        Orientation = Orientation.Horizontal
                    };
                    sp.Children.Add(new TextBlock()
                    {
                        Text = $"{ entry._contentType,-15} Ser#={entry._serialNo,3} {entry._dtCreated:hh:mm:ss} {entry._filename}", FontFamily = FontFamilyMono
                    });
Ejemplo n.º 2
0
        public async Task DoSampleAsync(MeasurementHolder measurementHolder, bool DoForceGC, string descriptionOverride = "")
        {
            var res = string.Empty;

            if (measurementHolder == null)
            {
                measurementHolder = measurementHolderInteractiveUser;
            }
            try
            {
                await TaskScheduler.Default;
                try
                {
                    res = await measurementHolder.TakeMeasurementAsync(descriptionOverride, DoForceGC, IsForInteractiveGraph : UpdateInterval != 0);

                    await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
                    await AddDataPointsAsync(measurementHolder);

                    if (AutoDumpIsEnabled)
                    {
                        var lastmeasurements = measurementHolder.GetLastMeasurements();
                        if (lastmeasurements.Count == 1)
                        {
                            var val = lastmeasurements.Values.First();
                            if (val >= AutoDumpThresh)
                            {
                                await AddStatusMsgAsync($"Autodump Threshold triggered: {lastmeasurements.Keys.First()}  {val} > {AutoDumpThresh}");

                                AutoDumpIsEnabled = false;
                                var pathDump = await CreateDumpFileAsync(MemoryAnalysisType.JustCreateDump, "AutoDump", tspanDelayAfterGC : TimeSpan.FromSeconds(0.2));
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    res = ex.ToString();
                }
                AddStatusMsgAsync($"{res}").Forget();
            }
            catch (InvalidOperationException ex)
            {
                if (ex.Message.Contains("Instance 'devenv#")) // user changed # of instance of devenv runnning
                {
                    await AddStatusMsgAsync($"Resetting perf counters due to devenv instances change");

                    lock (measurementHolder.LstPerfCounterData)
                    {
                        foreach (var ctr in measurementHolder.LstPerfCounterData)
                        {
                            ctr.ResetCounter();
                        }
                        _dataPoints.Clear();
                        _bufferIndex = 0;
                    }
                }
            }
            catch (Exception ex)
            {
                await AddStatusMsgAsync($"Exception in {nameof(DoSampleAsync)}" + ex.ToString());

                _dataPoints.Clear();
                _bufferIndex = 0;
            }
        }