Example #1
0
        static int Main(string[] args)
        {
            LogManager.ThrowExceptions = true;
            if (args.Length > 0 && args[0] == "/child")
            {
                Console.Error.WriteLine("AAA");
                int    repetitions = Convert.ToInt32(args[1]);
                int    threads     = Convert.ToInt32(args[2]);
                string targetName  = args[3];

                Console.Error.WriteLine("Child #{0} running {1} threads, {2} repetitions on {3}", AppDomain.GetCurrentThreadId(), threads, repetitions, targetName);
                Target t = LogManager.Configuration.FindTargetByName(targetName);

                double minTime, maxTime, avgTime, timeToFlush;
                bool   gotException;

                // warmup
                Console.Error.WriteLine("Warming up...");
                TimeTarget(t, 1, 1, out minTime, out maxTime, out avgTime, out timeToFlush, out gotException);

                // wait on mutex and release immediately
                // the processes are started with mutex held
                // so they all wait here.

                Console.Error.WriteLine("Ready and waiting...");
                _syncStartMutex.WaitOne();
                _syncStartMutex.ReleaseMutex();
                Console.Error.WriteLine("Go!");

                TimeTarget(t, threads, repetitions, out minTime, out maxTime, out avgTime, out timeToFlush, out gotException);
                Console.WriteLine("{0} {1} {2} {3} {4}", minTime, maxTime, avgTime, timeToFlush, gotException ? "1" : "0");
                Console.Error.WriteLine("Child #{0} finished.", AppDomain.GetCurrentThreadId());
                return(0);
            }

            Internal.InternalLogger.LogLevel          = LogLevel.Warn;
            Internal.InternalLogger.LogToConsoleError = true;

            foreach (string s in Directory.GetFiles(".", "*.log"))
            {
                File.Delete(s);
            }

            NLog.Config.LoggingConfiguration defaultConfig = LogManager.Configuration;

            TextWriter output    = new StreamWriter("results.csv", false, System.Text.Encoding.ASCII);
            string     separator = Thread.CurrentThread.CurrentCulture.TextInfo.ListSeparator;

            output.Write("targetName");
            output.Write(separator);
            output.Write("processCount");
            output.Write(separator);
            output.Write("threadCount");
            output.Write(separator);
            output.Write("repetitions");
            output.Write(separator);
            output.Write("avgTime");
            output.Write(separator);
            output.Write("ttf");
            output.Write(separator);
            output.Write("gotException");
            output.WriteLine();
            output.Flush();
            foreach (Target t in defaultConfig.GetConfiguredNamedTargets())
            {
                TimeTarget(output, t);
            }
            output.Close();
            return(0);
        }