示例#1
0
        public static void Main(string[] args)
        {
            Console.WriteLine("######## Starting at " + DateTime.UtcNow);
            // supported scenarios:
            // --------------------
            // 0: all
            // 1: start threads with specific callstacks in another appdomain
            // 2: start threads with generic type and method having long parameters list in callstack
            // 3: start threads that sleep/task.delay for 10s, 20s, 30s, 40s every minute
            // 4: start a thread to compute pi at a certain precision (high CPU usage)
            // 5: start n threads computing fibonacci
            // 6: start n threads sleeping
            // 7: start n threads doing async calls with CPU consumption along the way
            Console.WriteLine($"{Environment.NewLine}Usage:{Environment.NewLine} > {Process.GetCurrentProcess().ProcessName} [--service] [--iterations <number of iterations to execute>] [--scenario <0=all 1=computer 2=generics 3=wall time 4=pi computation>] [--timeout <duration in seconds> | --run-infinitely]");
            Console.WriteLine();

            EnvironmentInfo.PrintDescriptionToConsole();

            ParseCommandLine(args, out TimeSpan timeout, out bool runAsService, out Scenario scenario, out int iterations, out int nbThreads);

            // This application is used for several purposes:
            //  - execute a processing for a given duration (for smoke test)
            //  - execute a processing several times (for runtime test)
            //  - never stop (for reliability environment)
            //  - as a service
            //  - interactively for debugging
            var computerService = new ComputerService();

            if (runAsService)
            {
                computerService.RunAsService(timeout, scenario);
            }
            else
            {
                // collect CLR metrics that will be saved into a json file
                // if SIGNALFX_PROFILING_METRICS_FILEPATH is set
                using (var collector = new MetricsCollector())
                {
                    if (iterations > 0)
                    {
                        Console.WriteLine($" ########### The application will run scenario {scenario} {iterations} times with {nbThreads} thread(s).");

                        computerService.Run(scenario, iterations, nbThreads);
                    }
                    else
                    if (timeout == TimeSpan.MinValue)
                    {
                        Console.WriteLine($" ########### The application will run interactively because no timeout was specified or could be parsed. Number of Threads: {nbThreads}.");

                        computerService.StartService(scenario, nbThreads);

                        Console.WriteLine($"{Environment.NewLine} ########### Press enter to finish.");
                        Console.ReadLine();

                        computerService.StopService();

                        Console.WriteLine($"{Environment.NewLine} ########### Press enter to terminate.");
                        Console.ReadLine();
                    }
                    else
                    {
                        Console.WriteLine($" ########### The application will run non-interactively for {timeout} and will stop after that time. Number of Threads: {nbThreads}.");

                        computerService.StartService(scenario, nbThreads);

                        Thread.Sleep(timeout);

                        computerService.StopService();
                    }
                }

                Console.WriteLine($"{Environment.NewLine} ########### Finishing run at {DateTime.UtcNow}");
            }
        }
 protected override void OnStop()
 {
     _computerService.StopService();
     base.OnStop();
 }