Exemplo n.º 1
0
        public static int Main(string[] args)
        {
            Console.WriteLine("IoT Client Performance test");

            if (args.Length < 1)
            {
                Help();
                return(-1);
            }

            int    param_counter = 0;
            int    t             = 10;
            string o             = null;
            string p             = "mqtt";
            int    s             = 128;
            int    l             = 100;
            int    n             = 1;
            string a             = "sas";
            int    c             = -1;
            string i             = Guid.NewGuid().ToString();
            string f             = null;

            while (param_counter + 1 < args.Length)
            {
                switch (args[param_counter])
                {
                case "--":
                    break;

                case "-t":
                    t = int.Parse(args[++param_counter], CultureInfo.InvariantCulture);
                    break;

                case "-o":
                    o = args[++param_counter];
                    break;

                case "-p":
                    p = args[++param_counter];
                    break;

                case "-s":
                    s = int.Parse(args[++param_counter], CultureInfo.InvariantCulture);
                    break;

                case "-l":
                    l = int.Parse(args[++param_counter], CultureInfo.InvariantCulture);
                    break;

                case "-n":
                    n = int.Parse(args[++param_counter], CultureInfo.InvariantCulture);
                    break;

                case "-a":
                    a = args[++param_counter];
                    break;

                case "-c":
                    c = int.Parse(args[++param_counter], CultureInfo.InvariantCulture);
                    break;

                case "-i":
                    i = args[++param_counter];
                    break;

                case "-f":
                    f = args[++param_counter];
                    break;

                default:
                    Console.WriteLine($"Unknown parameter: {args[param_counter]}.");
                    return(-1);
                }

                param_counter++;
            }

            if (f == null)
            {
                Console.Error.WriteLine("Missing -f <scenario> parameter.");
                Help();
                return(-1);
            }

            Tuple <string, Func <PerfScenarioConfig, PerfScenario> > scenario;
            Func <PerfScenarioConfig, PerfScenario> scenarioFactory;

            if (!s_scenarios.TryGetValue(f, out scenario))
            {
                Console.Error.WriteLine($"Unknown scenario: {f}");
                return(-1);
            }

            scenarioFactory = scenario.Item2;

            Client.TransportType transportType;
            if (!s_transportDictionary.TryGetValue(p, out transportType))
            {
                Console.Error.WriteLine($"Unknown transport type: {p}");
                return(-1);
            }

            ResultWriter resultWriter;

            if (o == null)
            {
                resultWriter = new ResultWriterConsole();
            }
            else
            {
                resultWriter = new ResultWriterFile(o);
            }

            var runner = new PerfTestRunner(
                resultWriter,
                t,
                transportType,
                s,
                l,
                n,
                a,
                c,
                f,
                i,
                scenarioFactory);

            try
            {
                runner.RunTestAsync().GetAwaiter().GetResult();
            }
            finally
            {
                Console.Write("Writing output . . . ");
                resultWriter.FlushAsync().GetAwaiter().GetResult();
                Console.WriteLine("OK");
            }

            return(0);
        }
Exemplo n.º 2
0
        public static int Main(string[] args)
        {
            Console.WriteLine("IoT Client Performance test");

            if (args.Length < 1)
            {
                Help();
                return(-1);
            }

            int    param_counter = 0;
            int    t             = 10;
            string o             = null;
            string p             = "mqtt";
            int    s             = 128;
            int    l             = 100;
            int    n             = 1;
            string a             = "sas";
            int    c             = -1;
            string i             = null;
            string f             = null;

            while (param_counter + 1 < args.Length)
            {
                switch (args[param_counter])
                {
                case "--":
                    break;

                case "-t":
                    t = int.Parse(args[++param_counter], CultureInfo.InvariantCulture);
                    break;

                case "-o":
                    o = args[++param_counter];
                    break;

                case "-p":
                    p = args[++param_counter];
                    break;

                case "-s":
                    s = int.Parse(args[++param_counter], CultureInfo.InvariantCulture);
                    break;

                case "-l":
                    l = int.Parse(args[++param_counter], CultureInfo.InvariantCulture);
                    break;

                case "-n":
                    n = int.Parse(args[++param_counter], CultureInfo.InvariantCulture);
                    break;

                case "-a":
                    a = args[++param_counter];
                    break;

                case "-c":
                    c = int.Parse(args[++param_counter], CultureInfo.InvariantCulture);
                    break;

                case "-i":
                    i = args[++param_counter];
                    break;

                case "-f":
                    f = args[++param_counter];
                    break;

                default:
                    Console.WriteLine($"Unknown parameter: {args[param_counter]}.");
                    return(-1);
                }

                param_counter++;
            }

            if (f == null)
            {
                Console.Error.WriteLine("Missing -f <scenario> parameter.");
                Help();
                return(-1);
            }

            if (i == null)
            {
                i = $"{DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.ffZ")}_dotNet_{f}";
            }

            Tuple <string, Func <PerfScenarioConfig, PerfScenario> > scenario;
            Func <PerfScenarioConfig, PerfScenario> scenarioFactory;

            if (!s_scenarios.TryGetValue(f, out scenario))
            {
                Console.Error.WriteLine($"Unknown scenario: {f}");
                return(-1);
            }

            scenarioFactory = scenario.Item2;

            Client.TransportType transportType;
            if (!s_transportDictionary.TryGetValue(p, out transportType))
            {
                Console.Error.WriteLine($"Unknown transport type: {p}");
                return(-1);
            }

            ResultWriter resultWriter;

            if (o == null)
            {
                resultWriter = new ResultWriterConsole();
            }
            else
            {
                resultWriter = new ResultWriterFile(o, TelemetryMetrics.GetHeader());
            }

            Console.CancelKeyPress += delegate
            {
                // Make sure we flush the log before the process is terminated.
                Console.Write("Aborted. Writing output . . . ");
                resultWriter.FlushAsync().GetAwaiter().GetResult();
                Console.WriteLine("OK");
            };

            var runner = new PerfTestRunner(
                resultWriter,
                t,
                transportType,
                s,
                l,
                n,
                a,
                c,
                f,
                i,
                scenarioFactory);

            try
            {
                runner.RunTestAsync().GetAwaiter().GetResult();
            }
            finally
            {
                Console.Write("Writing output . . . ");
                resultWriter.FlushAsync().GetAwaiter().GetResult();
                Console.WriteLine("OK");
            }

            return(0);
        }