Esempio n. 1
0
        public void APISavesToStorage()
        {
            TimingDistributionMetricType metric = new TimingDistributionMetricType(
                disabled: false,
                category: "telemetry",
                lifetime: Lifetime.Ping,
                name: "timing_distribution",
                sendInPings: new string[] { "store1" },
                timeUnit: TimeUnit.Nanosecond
                );

            // Accumulate a few values
            for (ulong i = 1; i <= 3; i++)
            {
                HighPrecisionTimestamp.MockedValue = 0;
                GleanTimerId id = metric.Start();
                HighPrecisionTimestamp.MockedValue = i;
                metric.StopAndAccumulate(id);
            }

            // Check that data was properly recorded.
            Assert.True(metric.TestHasValue());
            var snapshot = metric.TestGetValue();

            // Check the sum
            Assert.Equal(6L, snapshot.Sum);
            // Check that the 1L fell into the first bucket (max 1)
            Assert.Equal(1L, snapshot.Values[1]);
            // Check that the 2L fell into the second bucket (max 2)
            Assert.Equal(1L, snapshot.Values[2]);
            // Check that the 3L fell into the third bucket (max 3)
            Assert.Equal(1L, snapshot.Values[3]);
        }
Esempio n. 2
0
        public void DisableTimingDistributionsMustNotRecordData()
        {
            TimingDistributionMetricType metric = new TimingDistributionMetricType(
                disabled: true,
                category: "telemetry",
                lifetime: Lifetime.Ping,
                name: "timing_distribution",
                sendInPings: new string[] { "store1" },
                timeUnit: TimeUnit.Nanosecond
                );

            // Attempt to store the timing distribution using set
            GleanTimerId id = metric.Start();

            metric.StopAndAccumulate(id);

            // Check that nothing was recorded.
            Assert.False(metric.TestHasValue(), "Disabled TimingDistributions should not record data.");
        }