Ejemplo n.º 1
0
        public void StartEvent(string name)
        {
            Stop();

            _current = new PerformanceEntry(name);
            _entries.Add(_current);
            _stopwatch.Start();
        }
        /// <summary>
        /// Gets the value of a property from the performance entry.
        /// </summary>
        /// <param name="tokenTemplate">Dictionary key name.</param>
        /// <param name="performance">Log entry containing with extended properties dictionary values.</param>
        /// <returns>The value of the key from the extended properties dictionary, or <see langword="null"/>
        /// (Nothing in Visual Basic) if there is no entry with that key.</returns>
        public override string FormatToken(string tokenTemplate, PerformanceEntry performance)
        {
            string propertyString = string.Empty;
            object propertyObject;

            if (performance.ExtendedProperties.TryGetValue(tokenTemplate, out propertyObject))
            {
                propertyString = propertyObject.ToString();
            }

            return(propertyString);
        }
        private void AppendToPerformanceEntries(TQuery command, TimeSpan elapsed)
        {
            PerformanceEntry entry = new PerformanceEntry()
            {
                TimeOfExecution = this.timeProvider.UtcNow,
                Operation       = command.GetType().Name,
                OperationData   = JsonConvert.SerializeObject(command),
                Duration        = elapsed
            };

            this.performanceRepository.Add(entry);
            this.contextSaveChanges.SaveChanges();
        }
Ejemplo n.º 4
0
        public static List <TestResult> CallBatch(Func <IRpcService, TestRequest> requestFactory, int batchSize, PerformanceCollectorOptions options, TestResultCollector testResultCollector = null)
        {
            string requestMethodName = null;
            var    testResults       = new List <TestResult>();

            foreach (var service in TestExecutor.Services)
            {
                var request = requestFactory(service);
                if (requestMethodName == null)
                {
                    requestMethodName = request.MethodName;
                }

                if (options.Enabled)
                {
                    options?.Writer?
                    .WriteLine()
                    .WriteLine($"Calling batch of {batchSize} {requestMethodName}".Center(80, '~'))
                    .WriteLine(request.ToString())
                    .DrawLine('~');
                }

                using (PerformanceCollector performanceCollector = new PerformanceCollector(service.GetServiceDescription(), options))
                {
                    PerformanceEntry performance = performanceCollector.Measure(() => service.CallBatch(Enumerable.Range(0, batchSize).Select(n => request).ToList()));
                    testResults.Add(new TestResult(service, batchSize, performance));
                    AddBatchCallResult(service, requestMethodName, batchSize, performance.Elapsed);
                }
            }

            if (testResultCollector != null)
            {
                testResultCollector.Collect(batchSize.ToString(), testResults);
            }
            else
            {
                using (testResultCollector = new TestResultCollector($"{requestMethodName} BATCH calls"))
                {
                    testResultCollector.Collect(batchSize.ToString(), testResults);
                }
            }

            return(testResults);
        }
Ejemplo n.º 5
0
 public TestResult(IRpcService service, int count, PerformanceEntry performanceEntry)
 {
     Service          = service;
     Count            = count;
     PerformanceEntry = performanceEntry;
 }
Ejemplo n.º 6
0
        public void CanLoadPerformanceSnapshot()
        {
            var ps = PerformanceEntry.Load();

            Assert.Greater(ps.Count, 0);
        }
Ejemplo n.º 7
0
        public static void CallNTimes(Func <IRpcService, TestRequest> requestFactory, int count, PerformanceCollectorOptions options, TestResultCollector testResultCollector = null)
        {
            string requestMethodName = null;

            List <TestResult>[] testResults = Enumerable.Range(0, count).Select((i) => new List <TestResult>()).ToArray();

            foreach (var service in TestExecutor.Services)
            {
                var request = requestFactory(service);
                if (requestMethodName == null)
                {
                    requestMethodName = request.MethodName;
                }

                if (options.Enabled)
                {
                    options?.Writer?
                    .WriteLine()
                    .WriteLine($"Calling {requestMethodName} {count} times".Center(80, '~'))
                    .WriteLine(request.ToString())
                    .DrawLine('~');
                }

                using (PerformanceCollector performanceCollector = new PerformanceCollector(service.GetServiceDescription(), options))
                {
                    for (int i = 0; i < count; i++)
                    {
                        int retries = 0;
                        while (retries < MAX_RETRY)
                        {
                            try
                            {
                                PerformanceEntry performance = performanceCollector.Measure(() => service.CallSingle(request));
                                testResults[i].Add(new TestResult(service, count, performance));
                                AddSingleCallResult(service, requestMethodName, performance.Elapsed);
                                break;
                            }
                            catch (System.Exception ex)
                            {
                                Thread.Sleep(200); //introduces a wait between calls because of intermittent problem with "The server returned an invalid or unrecognized response" error
                                retries++;
                            }
                        }
                    }
                }
            }

            if (testResultCollector != null)
            {
                for (int i = 0; i < testResults.Length; i++)
                {
                    testResultCollector.Collect($"t-{i + 1}", testResults[i]);
                }
            }
            else
            {
                using (testResultCollector = new TestResultCollector($"{requestMethodName} repeated calls ({count})."))
                {
                    for (int i = 0; i < testResults.Length; i++)
                    {
                        testResultCollector.Collect($"t-{i + 1}", testResults[i]);
                    }
                }
            }
        }
 /// <summary>
 /// Formats a performance entry and return a string to be outputted.
 /// </summary>
 /// <param name="performance">Log entry to format.</param>
 /// <returns>A string representing the performance entry.</returns>
 public abstract string Format(PerformanceEntry performance);