示例#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]);
        }
示例#2
0
        public void StartingAndStoppingATimerBeforeInitializationDoesNotCrash()
        {
            GleanInstance.TestDestroyGleanHandle();
            Dispatchers.QueueInitialTasks = true;

            TimingDistributionMetricType metric = new TimingDistributionMetricType(
                disabled: false,
                category: "telemetry",
                lifetime: Lifetime.Ping,
                name: "timing_distribution",
                sendInPings: new string[] { "store1" },
                timeUnit: TimeUnit.Second
                );

            GleanTimerId timerId = metric.Start();

            metric.StopAndAccumulate(timerId);

            // Start Glean again.
            string tempDataDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            GleanInstance.Initialize(
                applicationId: "org.mozilla.csharp.tests",
                applicationVersion: "1.0-test",
                uploadEnabled: true,
                configuration: new Configuration(),
                dataDir: tempDataDir
                );
            Assert.True(metric.TestGetValue().Sum >= 0);
        }
示例#3
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.");
        }