Ejemplo n.º 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;
        }
Ejemplo n.º 2
0
        public void EmitSummary_Format_Normal()
        {
            PerformanceMonitor perfMonitor = new PerformanceMonitor();

            perfMonitor.Description = "Perf Mon is the SUT";

            DateTime baseTime = DateTime.Parse("2012-02-17 13:14");

            for (int i = 0; i < 10; i++)
            {
                var startTime          = baseTime.AddSeconds(i);
                var duration           = new TimeSpan(0, 0, 0, i, i * 20);
                PerformancePoint point = new PerformancePoint("PointName", baseTime.AddSeconds(i), duration);
                perfMonitor.LogPoint(point);
            }

            string summary = perfMonitor.GetSummary();

            Console.WriteLine(summary);

            // AssertBuilder.Generate(summary, "summary"); // The following assertions were generated on 17-Feb-2012
            #region Generated Assertions
            Assert.AreEqual(@"
--------------------------------------------------------------------------------
Performance Monitor Output: Perf Mon is the SUT
--------------------------------------------------------------------------------
  Name       Hits   Total (ms)  Average (ms)  Maximum (ms)                        Minimum (ms)                  
  ---------  -----  ----------  ------------  ----------------------------------  ------------------------------
  PointName     10   45,900.00      4,590.00  Duration=9,180.00ms, Time=13:14:09  Duration=0.00ms, Time=13:14:00
--------------------------------------------------------------------------------
".NormaliseCrlf(), summary.NormaliseCrlf());
            #endregion
        }
Ejemplo n.º 3
0
        public SubPoint AddPoint(string name, string description, double x, double y, DateTime dateCreate,
                                 bool isSpecial,
                                 string pointType, string[] performances)
        {
            var point = DataContext.Points
                        .FirstOrDefault(
                p => p.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase));

            if (point != null)
            {
                return(null);               //Точка {name} уже существует!
            }
            var type = DataContext.PointTypes
                       .FirstOrDefault(
                p => p.Name.Equals(pointType, StringComparison.CurrentCultureIgnoreCase));

            if (type == null)
            {
                return(null);              //Не найден тип {pointType} !
            }
            var listPerf = DataContext.Performances.Where(p => performances.Contains(p.Name)).ToList();

            if (listPerf.Count != performances.Length)
            {
                return(null);                                       //Не найдены характеристики для точки
            }
            point = new Point
            {
                Name        = name,
                PointType   = type,
                DateCreate  = dateCreate,
                IsSpecial   = isSpecial,
                X           = x,
                Y           = y,
                Description = description
            };
            DataContext.Points.Add(point);
            DataContext.SaveChanges();

            foreach (var performance in listPerf)
            {
                var perfPoint = new PerformancePoint
                {
                    Performance = performance,
                    Point       = point
                };
                DataContext.PerformancePoints.Add(perfPoint);
            }

            DataContext.SaveChanges();

            var subPoint = new SubPoint
            {
                Name             = point.Name,
                Description      = point.Description,
                Id               = point.Id,
                Y                = point.Y,
                X                = point.X,
                PointType        = type,
                PerformancePoint =
                    DataContext.PerformancePoints.Include(p => p.Point).First(p => p.Point.Id == point.Id)
            };

            return(subPoint);
        }