コード例 #1
0
        public void DbCommandLogger_PerformanceMonitorNotify_Demo()
        {
            // Normally this would be a singleton across all scope
            PerformanceMonitor perfMonitor = new PerformanceMonitor();
            perfMonitor.Description = "Demonstration of Cyclops PerfMon";

            // Wire up the notification to perf monitor
            DbCommandLogger.PerformanceMonitorNotify += (sender, p) =>
                                                           {
                                                               // Convert Cyclops point to consuming solutions perf capture tool..in this case a Kraken library
                                                               var perfPoint = new PerformancePoint(p.CommandText, p.Start, p.End - p.Start);

                                                               perfMonitor.LogPoint(perfPoint);
                                                           };

            // Do some work
            var customerRepo = CustomerRepositoryTest.GetCustomerRepository();
            for (int i = 0; i < 10; i++)
            {
                var customer = CustomerRepositoryTests.GetUnpersistedCustomer();
                customer.FirstName = i.ToString();
                customerRepo.Save(customer);
            }

            // Emit to logs from in perf mon so we can direct to a specific log file via namespace
            perfMonitor.EmitSummary();

            // Tear down
            DbCommandLogger.PerformanceMonitorNotify = null;
        }