示例#1
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);
                    }
                }
            }
        }
示例#2
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();
     }
 }