Exemplo n.º 1
0
        public string ParseResultsToString(RequestWriter writer, int totalTimeSecs, int threads)
        {
            var result = ParseResults(writer, totalTimeSecs, threads);

            StringBuilder sb = new StringBuilder();

            sb.AppendLine("Total Requests: " + result.TotalRequests.ToString("n0"));

            if (threads > 0)
            {
                sb.AppendLine("       Threads: " + result.ThreadCount);
            }

            sb.AppendLine("        Failed: " + result.FailedRequests);

            if (result.TimeTakenSecs > 0)
            {
                sb.AppendLine("    Total Time: " + result.TimeTakenSecs.ToString("n2") + " secs");
                if (result.TotalRequests > 0)
                {
                    sb.AppendLine("       Req/Sec: " +
                                  ((decimal)result.TotalRequests / (decimal)result.TimeTakenSecs).ToString("n2") +
                                  "\r\n");
                }
            }
            if (result.TotalRequests > 0)
            {
                sb.AppendLine(string.Format("      Avg Time: {0:n2} ms", result.AvgRequestTimeMs));
                sb.AppendLine(string.Format("      Min Time: {0:n2} ms", result.MinRequestTimeMs));
                sb.AppendLine(string.Format("      Max Time: {0:n2} ms", result.MaxRequestTimeMs));
            }

            return(sb.ToString());
        }
Exemplo n.º 2
0
        public string GetResultReportHtml(RequestWriter writer,
                                          int totalTimeTakenMs,
                                          int threadCount)
        {
            var model = GetResultReport(writer, totalTimeTakenMs, threadCount);

            return(TemplateRenderer.RenderTemplate("TestResult.cshtml", model));
        }
Exemplo n.º 3
0
        public ChartFormZed(RequestWriter requestWriter, string url = null, ChartTypes chartType = ChartTypes.TimeTakenPerRequest, Form parentForm = null)
        {
            InitializeComponent();

            Url           = url;
            Results       = requestWriter.GetResults();
            RequestWriter = requestWriter;
            ChartType     = chartType;
            ParentForm    = null;

            Text = "WebSurge - Request Times Taken";
        }
Exemplo n.º 4
0
        public IEnumerable <UrlSummary> UrlSummary(RequestWriter requestWriter, int totalTimeTakenSecs)
        {
            // avoid divide by 0 error - assume at least 1 second
            if (totalTimeTakenSecs == 0)
            {
                totalTimeTakenSecs = 1;
            }

            IEnumerable <HttpRequestData> resultData = requestWriter.GetResults();
            var urls = resultData
                       .GroupBy(res => res.HttpVerb + " " + res.Url + (string.IsNullOrEmpty(res.Name) ? "" : " • " + res.Name),
                                rs => rs, (key, uls) =>
            {
                // Prevent multiple enumerations
                var results = uls as IList <HttpRequestData> ?? uls.ToList();

                return(new UrlSummary()
                {
                    Url = key,
                    Results = new TestResult()
                    {
                        TimeTakenSecs = totalTimeTakenSecs,
                        TotalRequests = results.Count(),
                        FailedRequests = results.Count(u => u.IsError),
                        SuccessRequests = results.Count(u => !u.IsError),
                        RequestsPerSecond = ((decimal)results.Count() / (decimal)totalTimeTakenSecs),
                        MinRequestTimeMs = results.Min(u => u.TimeTakenMs),
                        MaxRequestTimeMs = results.Max(u => u.TimeTakenMs),
                        AvgRequestTimeMs = (decimal)results.Average(u => u.TimeTakenMs),
                        TotalBytesSent = results.Sum(req => req.ResponseLength),
                        TotalBytesPosted = results.Sum(req => string.IsNullOrEmpty(req.RequestContent) ? 0 : req.RequestContent.Length),

                        ErrorMessages = results
                                        .GroupBy(x => x.ErrorMessage)
                                        .Where(g => g.Key != null)
                                        .Select(g => new ErrorMessage()
                        {
                            Message = g.Key,
                            Count = g.Count()
                        })
                    }
                });
            });

            return(urls.ToList());
        }
Exemplo n.º 5
0
        public string ParseResultsToString(RequestWriter writer, int totalTimeSecs, int threads)
        {
            var result = ParseResults(writer, totalTimeSecs, threads);

            StringBuilder sb = new StringBuilder();

            sb.AppendLine("Total Requests: " + result.TotalRequests.ToString("n0"));

            if (threads > 0)
            {
                sb.AppendLine("       Threads: " + result.ThreadCount);
            }

            sb.AppendLine("        Failed: " + result.FailedRequests);

            if (result.TimeTakenSecs > 0)
            {
                sb.AppendLine("    Total Time: " + result.TimeTakenSecs.ToString("n2") + " secs");
                if (result.TotalRequests > 0)
                {
                    sb.AppendLine("       Req/Sec: " +
                                  ((decimal)result.TotalRequests / (decimal)result.TimeTakenSecs).ToString("n2") +
                                  "\r\n");
                }
            }

            string totalBytesSent = "0 bytes";

            if (result.TotalBytesSent > 0)
            {
            }



            if (result.TotalRequests > 0)
            {
                sb.AppendLine($"      Avg Time: {result.AvgRequestTimeMs:n2} ms");
                sb.AppendLine($"      Min Time: {result.MinRequestTimeMs:n2} ms");
                sb.AppendLine($"      Max Time: {result.MaxRequestTimeMs:n2} ms");
                sb.AppendLine($" data returned: {result.ByteSizeString(result.TotalBytesSent)}");
                sb.AppendLine($" data   posted: {result.ByteSizeString(result.TotalBytesPosted)}");
            }

            return(sb.ToString());
        }
Exemplo n.º 6
0
        public TestResult ParseResults(RequestWriter requestWriter, int totalTimeSecs, int threads)
        {
            // avoid divide by zero errors
            if (totalTimeSecs < 1)
            {
                totalTimeSecs = 1;
            }

            var results = requestWriter.GetResults();
            var count   = results.Count;

            TestResult res;

            if (count == 0)
            {
                return(res = new TestResult());
            }

            res = new TestResult()
            {
                TotalRequests     = results.Count,
                ThreadCount       = threads,
                TimeTakenSecs     = totalTimeSecs,
                FailedRequests    = results.Count(req => req.IsError),
                SuccessRequests   = results.Count(req => !req.IsError),
                RequestsPerSecond = ((decimal)results.Count / (decimal)totalTimeSecs),
                AvgRequestTimeMs  = (decimal)results.Average(req => req.TimeTakenMs),
                MinRequestTimeMs  = results.Min(req => req.TimeTakenMs),
                MaxRequestTimeMs  = results.Max(req => req.TimeTakenMs),
                TotalBytesSent    = results.Sum(req => req.ResponseLength),
                TotalBytesPosted  = results.Sum(req => string.IsNullOrEmpty(req.RequestContent) ? 0 : req.RequestContent.Length),

                ErrorMessages = results
                                .GroupBy(x => x.ErrorMessage)
                                .Where(g => g.Key != null)
                                .Select(g => new ErrorMessage()
                {
                    Message = g.Key,
                    Count   = g.Count()
                })
            };

            return(res);
        }
Exemplo n.º 7
0
        public TestResultView GetResultReport(RequestWriter requestWriter,
                                              int totalTimeTakenMs,
                                              int threadCount)
        {
            // Convert milliseconds to seconds
            var totalTimeTaken = totalTimeTakenMs / 1000;

            var urlSummary = UrlSummary(requestWriter, totalTimeTaken);
            var testResult = ParseResults(requestWriter, totalTimeTaken, threadCount);

            var model = new TestResultView()
            {
                Timestamp  = DateTime.UtcNow,
                TestResult = testResult,
                UrlSummary = urlSummary
            };

            return(model);
        }
Exemplo n.º 8
0
        public IEnumerable <RequestsPerSecondResult> RequestsPerSecond(RequestWriter requestWriter,
                                                                       string url = null)
        {
            IEnumerable <HttpRequestData> resultData = requestWriter.GetResults();

            if (!string.IsNullOrEmpty(url))
            {
                resultData = resultData.Where(rd => rd.Url.ToLower() == url.ToLower());
            }

            DateTime startTime = resultData.First().Timestamp;
            var      res       = resultData.OrderBy(rd => rd.Timestamp)
                                 .GroupBy(rd => (int)rd.Timestamp.Subtract(startTime).TotalSeconds,
                                          rd => rd,
                                          (second, rd) => new RequestsPerSecondResult()
            {
                Second = second, Requests = rd.Count()
            });

            return(res.ToList());
        }