Esempio n. 1
0
        /// <summary>
        /// Snapshot cache metrics
        /// </summary>
        /// <param name="pagesLoaded"></param>
        public static void RecordCacheMetric(int pagesLoaded)
        {
            SampledMetricDefinition pageMetricDefinition;

            //since sampled metrics have only one value per metric, we have to create multiple metrics (one for every value)
            if (SampledMetricDefinition.TryGetValue("GibraltarSample", "Database.Engine", "Cache Pages", out pageMetricDefinition) == false)
            {
                //doesn't exist yet - add it in all of its glory.  This call is MT safe - we get back the object in cache even if registered on another thread.
                pageMetricDefinition = SampledMetricDefinition.Register("GibraltarSample", "Database.Engine", "cachePages", SamplingType.RawCount, "Pages", "Cache Pages", "The number of pages in the cache");
            }

            //now that we know we have the definitions, make sure we've defined the metric instances.
            SampledMetric pageMetric = SampledMetric.Register(pageMetricDefinition, null);

            //now go ahead and write those samples....
            pageMetric.WriteSample(pagesLoaded);

            //Continue for our second metric.
            SampledMetricDefinition sizeMetricDefinition;

            if (SampledMetricDefinition.TryGetValue("GibraltarSample", "Database.Engine", "Cache Size", out sizeMetricDefinition) == false)
            {
                //doesn't exist yet - add it in all of its glory  This call is MT safe - we get back the object in cache even if registered on another thread.
                sizeMetricDefinition = SampledMetricDefinition.Register("GibraltarSample", "Database.Engine", "cacheSize", SamplingType.RawCount, "Bytes", "Cache Size", "The number of bytes used by pages in the cache");
            }

            SampledMetric sizeMetric = SampledMetric.Register(sizeMetricDefinition, null);

            sizeMetric.WriteSample(pagesLoaded * 8196);
        }
Esempio n. 2
0
        public void TestEventAttributeReflection()
        {
            SampledMetric.Register(typeof(UserSampledObject));

            UserSampledObject sampledObject = new UserSampledObject(25, 100);

            SampledMetricDefinition.Write(sampledObject);

            SampledMetricDefinition sampledMetricDefinition;

            Assert.IsTrue(SampledMetricDefinition.TryGetValue(typeof(UserSampledObject), "IncrementalCount", out sampledMetricDefinition));

            sampledObject.SetValue(35, 90);
            sampledMetricDefinition.WriteSample(sampledObject);
        }