Example #1
0
        public void Test()
        {
            TestClass t = (TestClass)TypeAccessor.CreateInstance(typeof(TestClass));

            for (int i = 0; i < 10; i++)
            {
                t.Test();
            }

            MethodCallCounter counter = CounterAspect.GetCounter(typeof(TestClass).GetMethod("Test"));

            Assert.AreEqual(10, counter.TotalCount);

            Console.WriteLine(counter.TotalTime);

            new Thread(new ThreadStart(t.LongTest)).Start();
            Thread.Sleep(20);

            lock (CounterAspect.Counters.SyncRoot) foreach (MethodCallCounter c in CounterAspect.Counters)
                {
                    Console.WriteLine("{0}.{1,-10} | {2,2} | {3,2} | {4}",
                                      c.MethodInfo.DeclaringType.Name,
                                      c.MethodInfo.Name,
                                      c.TotalCount,
                                      c.CurrentCalls.Count,
                                      c.TotalTime);

                    lock (c.CurrentCalls.SyncRoot) for (int i = 0; i < c.CurrentCalls.Count; i++)
                        {
                            InterceptCallInfo ci = (InterceptCallInfo)c.CurrentCalls[i];
                            IPrincipal        pr = ci.CurrentPrincipal;

                            Console.WriteLine("{0,15} | {1}",
                                              pr == null? "***" : pr.Identity.Name,
                                              DateTime.Now - ci.BeginCallTime);
                        }
                }
        }
Example #2
0
        public void Test()
        {
            TestClass t = TypeAccessor <TestClass> .CreateInstance();

            for (int i = 0; i < 10; i++)
            {
                t.TestMethod();
            }

            MethodInfo        methodInfo = typeof(TestClass).GetMethod("TestMethod");
            MethodCallCounter counter    = CounterAspect.GetCounter(methodInfo);

            Assert.AreEqual(10, counter.TotalCount);

            Console.WriteLine(@"
Method         : {0}.{1}
TotalCount     : {2}
ExceptionCount : {3}
CachedCount    : {4}
CurrentCalls   : {5}
TotalTime      : {6}
MinTime        : {7}
MaxTime        : {8}
AverageTime    : {9}
",
                              counter.MethodInfo.DeclaringType.Name,
                              counter.MethodInfo.Name,
                              counter.TotalCount,                // total actual calls (no cached calls)
                              counter.ExceptionCount,            // calls with exceptions
                              counter.CachedCount,               // cached calls
                              counter.CurrentCalls.Count,        // current calls (make sense for multithreading)
                              counter.TotalTime,                 // total work time
                              counter.MinTime,                   // min call time
                              counter.MaxTime,                   // max call time
                              counter.AverageTime);              // average call time
        }