public void MultipleGCStatsEvents_StatsValuesAreLatestValues()
        {
            var expectedValues = new Dictionary <GCSampleType, float>()
            {
                { GCSampleType.Gen0Size, 1 },
                { GCSampleType.Gen0Promoted, 2 },
                { GCSampleType.Gen1Size, 3 },
                { GCSampleType.Gen1Promoted, 4 },
                { GCSampleType.Gen2Size, 5 },
                { GCSampleType.Gen2Survived, 6 },
                { GCSampleType.LOHSize, 7 },
                { GCSampleType.LOHSurvived, 8 },
                { GCSampleType.HandlesCount, 9 },
                { GCSampleType.InducedCount, 0 },
                { GCSampleType.Gen0CollectionCount, 0 },
                { GCSampleType.Gen1CollectionCount, 0 },
                { GCSampleType.Gen2CollectionCount, 0 },
            };

            var expectedValues2 = expectedValues.ToDictionary(x => x.Key, x => x.Value * x.Value);

            using (var listener = new GCEventsListener())
                using (var src = new TestGCEventSource())
                {
                    src.GCHeapStats_V1(
                        (ulong)expectedValues[GCSampleType.Gen0Size],
                        (ulong)expectedValues[GCSampleType.Gen0Promoted],
                        (ulong)expectedValues[GCSampleType.Gen1Size],
                        (ulong)expectedValues[GCSampleType.Gen1Promoted],
                        (ulong)expectedValues[GCSampleType.Gen2Size],
                        (ulong)expectedValues[GCSampleType.Gen2Survived],
                        (ulong)expectedValues[GCSampleType.LOHSize],
                        (ulong)expectedValues[GCSampleType.LOHSurvived], 100, 200, 300, 400,
                        (uint)expectedValues[GCSampleType.HandlesCount], 1);

                    src.GCHeapStats_V1(
                        (ulong)expectedValues2[GCSampleType.Gen0Size],
                        (ulong)expectedValues2[GCSampleType.Gen0Promoted],
                        (ulong)expectedValues2[GCSampleType.Gen1Size],
                        (ulong)expectedValues2[GCSampleType.Gen1Promoted],
                        (ulong)expectedValues2[GCSampleType.Gen2Size],
                        (ulong)expectedValues2[GCSampleType.Gen2Survived],
                        (ulong)expectedValues2[GCSampleType.LOHSize],
                        (ulong)expectedValues2[GCSampleType.LOHSurvived], 100, 200, 300, 400,
                        (uint)expectedValues2[GCSampleType.HandlesCount], 1);

                    var sampleValues = listener.Sample();

                    Assert.AreEqual(expectedValues2.Count, sampleValues.Count);

                    //Validate that each SampleType generated the expected MetricType
                    foreach (var q in expectedValues2)
                    {
                        Assert.IsTrue(sampleValues.ContainsKey(q.Key), $"Missing value for {q.Key}");
                        Assert.AreEqual(q.Value, sampleValues[q.Key], $"Mismatch on {q.Key}, expected {q.Value}, actual {q.Key}");
                    }
                }
        }
        public void GCStartEventUpdatesInducedCountOnlyForSpecificReasons()
        {
            using (var listener = new GCEventsListener())
                using (var src = new TestGCEventSource())
                {
                    //Send GCStartEvent for every reason.
                    //Only two of the reasons should increment the counter
                    for (uint i = 0; i <= 7; i++)
                    {
                        src.GCStart_V1(1, 1, i, 1, 1);
                    }

                    var sampleValues = listener.Sample();

                    Assert.AreEqual(2, sampleValues[GCSampleType.InducedCount]);
                }
        }
        public void GCStartEventUpdatesProperGenCollectionCount()
        {
            using (var listener = new GCEventsListener())
                using (var src = new TestGCEventSource())
                {
                    //  Running Count
                    //	G0	G1	G2
                    //--------------
                    src.GCStart_V1(1, 0, 1, 1, 1);  //	1	0	0

                    src.GCStart_V1(1, 1, 1, 1, 1);  //	2	1	0
                    src.GCStart_V1(1, 1, 1, 1, 1);  //	3	2	0

                    src.GCStart_V1(1, 2, 1, 1, 1);  //	4	3	1
                    src.GCStart_V1(1, 2, 1, 1, 1);  //	5	4	2
                    src.GCStart_V1(1, 2, 1, 1, 1);  //	6	5	3

                    var sampleValues = listener.Sample();

                    Assert.AreEqual(6, sampleValues[GCSampleType.Gen0CollectionCount]);
                    Assert.AreEqual(5, sampleValues[GCSampleType.Gen1CollectionCount]);
                    Assert.AreEqual(3, sampleValues[GCSampleType.Gen2CollectionCount]);
                }
        }
        public void MultipleGCStartEvents_StatsValuesAreCumulative()
        {
            const uint reasonCDInduced1 = 1;
            const uint reasonCDInduced2 = 7;

            using (var listener = new GCEventsListener())
                using (var src = new TestGCEventSource())
                {
                    src.GCStart_V1(1, 1, reasonCDInduced1, 1, 1);

                    var sampleValues = listener.Sample();

                    Assert.AreEqual(1, sampleValues[GCSampleType.InducedCount]);

                    src.GCStart_V1(1, 1, reasonCDInduced1, 1, 1);
                    src.GCStart_V1(1, 1, reasonCDInduced2, 1, 1);
                    src.GCStart_V1(1, 1, reasonCDInduced1, 1, 1);
                    src.GCStart_V1(1, 1, reasonCDInduced2, 1, 1);

                    sampleValues = listener.Sample();

                    Assert.AreEqual(4, sampleValues[GCSampleType.InducedCount]);
                }
        }