public void RecordEventMetricReflection()
        {
            UserEventObject myDataObject = new UserEventObject(null);

            EventMetric.Register(myDataObject);

            EventMetricDefinition metricDefinition;

            Assert.IsTrue(EventMetricDefinition.TryGetValue(typeof(UserEventObject), out metricDefinition));

            EventMetricDefinition.Write(myDataObject);

            // Now try it with inheritance and interfaces in the mix.

            UserMultipleEventObject bigDataObject = new UserMultipleEventObject(null);

            EventMetric.Register(bigDataObject);
            // There's no event at the top level, so this lookup should fail.
            Assert.IsFalse(EventMetricDefinition.TryGetValue(typeof(UserMultipleEventObject), out metricDefinition));
            // Now check for interfaces...
            Assert.IsTrue(EventMetricDefinition.TryGetValue(typeof(IEventMetricOne), out metricDefinition));
            Assert.IsTrue(EventMetricDefinition.TryGetValue(typeof(IEventMetricTwo), out metricDefinition));
            Assert.IsTrue(EventMetricDefinition.TryGetValue(typeof(IEventMetricThree), out metricDefinition));
            Assert.IsTrue(EventMetricDefinition.TryGetValue(typeof(IEventMetricFour), out metricDefinition));

            // And sample all of them on the big object with a single call...

            EventMetric.Write(bigDataObject);
        }
예제 #2
0
        public void EventMetricsByAttributesPerformanceTest()
        {
            EventMetric.Register(typeof(UserPerformanceObject));
            Trace.TraceInformation("Event metrics registered by attributes.");

            UserPerformanceObject eventObject    = new UserPerformanceObject("AttributesPerformanceTest");
            DateTimeOffset        operationStart = DateTimeOffset.UtcNow;
            DateTimeOffset        operationEnd   = operationStart.AddMilliseconds(1234);

            eventObject.SetEventData(@"C:\Dummy\File\Name.txt", UserFileOperation.Write, operationStart, operationEnd);

            //first, lets get everything to flush so we have our best initial state.
            Log.Information(LogWriteMode.WaitForCommit, "Test.Agent.Metrics.Performance", "Preparing for Test", "Flushing queue");

            //now that we know it's flushed everything, lets do our timed loop.
            DateTimeOffset startTime = DateTimeOffset.UtcNow;

            for (int curMessage = 0; curMessage < LoopsPerEventTest; curMessage++)
            {
                EventMetricDefinition.Write(eventObject);
            }
            DateTimeOffset messageEndTime = DateTimeOffset.UtcNow;

            //one wait for commit message to force the buffer to flush.
            Log.Information(LogWriteMode.WaitForCommit, "Test.Agent.Metrics.Performance", "Waiting for Samples to Commit", null);

            //and store off our time
            DateTimeOffset endTime = DateTimeOffset.UtcNow;

            TimeSpan  testDuration    = endTime - startTime;
            TimeSpan  loopDuration    = messageEndTime - startTime;
            const int messagesPerTest = LoopsPerEventTest * MessagesPerEventLoop;

            Trace.TraceInformation("Event Metrics by Attributes Test committed {0:N0} events in {1:F3} ms (average {2:F4} ms per message).  Average loop time {3:F4} ms ({4} values per message) and final flush time {5:F3} ms.",
                                   messagesPerTest, testDuration.TotalMilliseconds, (testDuration.TotalMilliseconds / messagesPerTest),
                                   (loopDuration.TotalMilliseconds / LoopsPerEventTest), ValuesPerEventMessage,
                                   (endTime - messageEndTime).TotalMilliseconds);
        }
예제 #3
0
 /// <summary>
 /// Write event metric samples for all event metrics defined on the provided data object by attributes.
 /// </summary>
 /// <remarks>The provided user data object must be assignable to the bound type which defined this event metric
 /// via attributes.</remarks>
 /// <param name="metricData">The object to retrieve both metric values and definition from</param>
 /// <example>
 /// See the <see cref="EventMetric">EventMetric Class Overview</see> for an example.
 /// </example>
 public static void Write(object metricData)
 {
     // The real logic is in EventMetricDefinition.
     EventMetricDefinition.Write(metricData, null);
 }
예제 #4
0
 /// <summary>
 /// Write event metric samples for all event metrics defined on the provided data object by attributes.
 /// </summary>
 /// <remarks>The provided user data object must be assignable to the bound type which defined this event metric
 /// via attributes.</remarks>
 /// <param name="metricData">The object to retrieve both metric values and definition from</param>
 /// <param name="fallbackInstanceName">The instance name to fall back on if a definition does not specify an instance name binding (may be null).</param>
 /// <example>
 /// See the <see cref="EventMetric">EventMetric Class Overview</see> for an example.
 /// </example>
 public static void Write(object metricData, string fallbackInstanceName)
 {
     // The real logic is in EventMetricDefinition.
     EventMetricDefinition.Write(metricData, fallbackInstanceName);
 }