Example #1
0
        public async Task StartProgressWriter(Wrex wrexInstance, CancellationToken token)
        {
            const int DelayConstant = 500;
            var firstRun = true;
            while (!token.IsCancellationRequested)
            {
                if (firstRun)
                {
                    firstRun = false;
                }
                else
                {
                    await Task.Delay(DelayConstant);
                }
                WriteProgress(wrexInstance.ExecutedRequests, wrexInstance.Options.NumberOfRequests);
            }

            WriteProgress(wrexInstance.ExecutedRequests, wrexInstance.Options.NumberOfRequests);
            Console.WriteLine();
            Console.WriteLine();
        }
Example #2
0
        private static async Task RunWrexAsync(CmdOptions cmdOptions)
        {
            var validation = cmdOptions.Validate();

            if (!validation.IsValid)
            {
                var indent = new string(' ', 2);
                var errors = String.Join(Environment.NewLine, validation.ErrorMessages.Select(x => indent + x));
                throw new Exception(cmdOptions.CustomErrorWithUsage(errors));
            }

            Console.WriteLine(cmdOptions.GetHeader(new HelpText()));
            Console.WriteLine();

            try
            {
                var wrex = new Wrex(cmdOptions.GetWrexOptions());
                var consoleOut = new ConsoleOutput();

                if (cmdOptions.Verbose)
                {
                    const string OptionsText = "Options:";
                    Console.WriteLine(OptionsText);
                    Console.WriteLine(new string('-', OptionsText.Length));
                    Console.WriteLine();
                    consoleOut.PrintWrexOptions(wrex.Options);
                    Console.WriteLine();
                    const string ProgressText = "Progress:";
                    Console.WriteLine(ProgressText);
                    Console.WriteLine(new string('-', ProgressText.Length));
                    Console.WriteLine();
                }

                var cancelSource = new CancellationTokenSource();
                var progressDisplayTask = Task.Run(() => consoleOut.StartProgressWriter(wrex, cancelSource.Token));
                await wrex.RunAsync(
                    null,
                    ex =>
                        {
                            if (cmdOptions.Verbose)
                            {
                                consoleOut.HandleError(ex);
                            }
                            else
                            {
                                NoOp();
                            }
                        });

                cancelSource.Cancel();
                await progressDisplayTask;

                var analyzer = new WrexAnalyzer(wrex);
                var summary = analyzer.GetSummary();
                consoleOut.PrintSummary(summary, wrex);
                consoleOut.PrintStatusDistribution(analyzer.GetStatusDistribution(), wrex);
                consoleOut.PrintResponseTimeHistogram(analyzer.GetReponseTimeDistribution(summary), wrex);
                if (cmdOptions.Verbose)
                {
                    consoleOut.PrintSampleResponse(wrex);
                }
                Console.WriteLine();
            }
            catch (Exception ex)
            {
                lock (Console.Out)
                {
                    Console.WriteLine();
                    Console.WriteLine();
                    ExtendedConsole.WriteErrorLine("Error: " + ex.Message);
                    if (cmdOptions.Verbose)
                    {
                        Console.WriteLine();
                        Console.WriteLine("Details: ");
                        Console.WriteLine(ex.StackTrace);
                    }
                }
            }
        }
Example #3
0
 public void PrintSummary(WrexAnalyzer.Summary summary, Wrex wrexInstance)
 {
     const string Title = "Summary:";
     Console.WriteLine(Title);
     Console.WriteLine(new string('-', Title.Length));
     Console.WriteLine();
     Console.WriteLine("Total time taken: {0}", summary.TotalTimeTaken);
     Console.WriteLine();
     Console.WriteLine("Fastest: {0}", summary.FastestTime);
     Console.WriteLine("Slowest: {0}", summary.SlowestTime);
     Console.WriteLine("Average: {0}", summary.AverageTime);
     Console.WriteLine();
     Console.WriteLine("Requests/second: {0}", summary.RequestsPerSecond);
     Console.WriteLine();
     if (wrexInstance.SampleResponse != null)
     {
         Console.WriteLine("Total number of bytes received: " + wrexInstance.TotalTransferedBytes);
         Console.WriteLine(
             "Average bytes/request: "
             + (double)wrexInstance.TotalTransferedBytes / wrexInstance.Options.NumberOfRequests);
         Console.WriteLine();
     }
 }
Example #4
0
 public void PrintSampleResponse(Wrex wrexInstance)
 {
     if (wrexInstance.SampleResponse != null)
     {
         // Increase buffer height if possible.
         ExtendedConsole.SetBufferSize(-1, Console.BufferHeight + wrexInstance.SampleResponse.Length);
         const string Title = "Sample Response:";
         Console.WriteLine(Title);
         Console.WriteLine(new string('-', Title.Length));
         Console.WriteLine();
         Console.WriteLine(wrexInstance.SampleResponse);
         Console.WriteLine();
     }
 }
Example #5
0
        public void PrintResponseTimeHistogram(
            IEnumerable<WrexAnalyzer.ResponseTimeDistribution> responseTimeDistributions,
            Wrex wrexInstance)
        {
            const string Title = "Response-time histogram:";
            Console.WriteLine(Title);
            Console.WriteLine(new string('-', Title.Length));
            Console.WriteLine();

            var responsetimeDistributions = responseTimeDistributions.ToArray();

            var leftColumnLength = (responsetimeDistributions.Max(x => x.ResponseCount).ToString().Length
                                    + responsetimeDistributions.Max(x => x.TimeSpan).ToString().Length) + 10;

            foreach (var responseTimeDistribution in responsetimeDistributions)
            {
                var barWidth =
                    (int)
                    (((double)responseTimeDistribution.ResponseCount / wrexInstance.Options.NumberOfRequests)
                     * ((Console.WindowWidth * 2 / 3) - leftColumnLength));

                var leftColumn =
                    string.Format(
                        "{0} [{1}]",
                        responseTimeDistribution.TimeSpan,
                        responseTimeDistribution.ResponseCount).PadRight(leftColumnLength - 5);

                Console.Write("{0} |", leftColumn);
                ExtendedConsole.WriteInfoLine(new string('+', barWidth));
            }

            Console.WriteLine();
        }
Example #6
0
        public void PrintStatusDistribution(
            IEnumerable<WrexAnalyzer.StatusCodeDistribution> statusDistributions,
            Wrex wrexInstance)
        {
            const string Title = "Status code distribution:";
            Console.WriteLine(Title);
            Console.WriteLine(new string('-', Title.Length));
            Console.WriteLine();

            foreach (var distribution in statusDistributions)
            {
                var statusCode = (int)distribution.Status;
                string outputString;
                if (statusCode == 0)
                {
                    outputString = string.Format("Failed connections : {0}", distribution.ResponseCount);
                }
                else
                {
                    outputString = string.Format(
                        "{0} [{1}] : {2} response{3}",
                        statusCode,
                        distribution.Status.ToString(),
                        distribution.ResponseCount,
                        distribution.ResponseCount > 1 ? "s" : string.Empty);
                }

                if (statusCode < 200 || statusCode > 299)
                {
                    ExtendedConsole.WriteErrorLine(outputString);
                }
                else
                {
                    Console.WriteLine(outputString);
                }
            }
            Console.WriteLine();
        }