예제 #1
0
        static async Task <int> Orchestrate(
            IConsole console,
            CancellationToken ct,
            FileInfo stressPath,
            int eventSize,
            int eventRate,
            BurstPattern burstPattern,
            ReaderType readerType,
            int slowReader,
            int duration,
            int cores,
            int threads,
            int eventCount,
            bool rundown,
            int bufferSize,
            int iterations,
            bool pause)
        {
            if (!stressPath.Exists)
            {
                Console.WriteLine($"");
                return(-1);
            }

            string readerTypeString = readerType switch
            {
                ReaderType.Stream => "Stream",
                ReaderType.EventPipeEventSource => "EventPipeEventSource",
                _ => "Stream"
            };

            var durationTimeSpan = TimeSpan.FromSeconds(duration);
            var testResults      = new TestResults(eventSize);

            Func <int, TestResult> threadProc = readerType switch
            {
                ReaderType.Stream => UseFS(rundown, bufferSize),
                ReaderType.EventPipeEventSource => UseEPES(rundown, bufferSize, slowReader),
                _ => throw new ArgumentException("Invalid reader type")
            };

            if (eventRate == -1 && burstPattern != BurstPattern.NONE)
            {
                throw new ArgumentException("Must have burst pattern of NONE if rate is -1");
            }

            Console.WriteLine($"Configuration: event_size={eventSize}, event_rate={eventRate}, cores={cores}, num_threads={threads}, reader={readerType}, event_rate={(eventRate == -1 ? -1 : eventRate * threads)}, burst_pattern={burstPattern.ToString()}, slow_reader={slowReader}, duration={duration}");

            for (int iteration = 0; iteration < iterations; iteration++)
            {
                Console.WriteLine("========================================================");
                Console.WriteLine($"Starting iteration {iteration + 1}");

                Process eventWritingProc = new Process();
                eventWritingProc.StartInfo.FileName                             = stressPath.FullName;
                eventWritingProc.StartInfo.Arguments                            = $"--threads {(threads == -1 ? cores.ToString() : threads.ToString())} --event-count {eventCount} --event-size {eventSize} --event-rate {eventRate} --burst-pattern {burstPattern} --duration {(int)durationTimeSpan.TotalSeconds}";
                eventWritingProc.StartInfo.UseShellExecute                      = false;
                eventWritingProc.StartInfo.RedirectStandardInput                = true;
                eventWritingProc.StartInfo.Environment["COMPlus_StressLog"]     = "1";
                eventWritingProc.StartInfo.Environment["COMPlus_LogFacility"]   = "2000";
                eventWritingProc.StartInfo.Environment["COMPlus_LogLevel"]      = "8";
                eventWritingProc.StartInfo.Environment["COMPlus_StressLogSize"] = "0x1000000";
                eventWritingProc.Start();

                Console.WriteLine($"Executing: {eventWritingProc.StartInfo.FileName} {eventWritingProc.StartInfo.Arguments}");

                if (IsWindowsOrLinux)
                {
                    // Set affinity and priority
                    ulong affinityMask = 0;
                    for (int j = 0; j < cores; j++)
                    {
                        affinityMask |= ((ulong)1 << j);
                    }
                    eventWritingProc.ProcessorAffinity = (IntPtr)((ulong)eventWritingProc.ProcessorAffinity & affinityMask);
                }

                // Start listening to the event.
                Task <TestResult> listenerTask = Task.Run(() => threadProc(eventWritingProc.Id), ct);

                if (pause)
                {
                    Console.WriteLine("Press <enter> to start test");
                    Console.ReadLine();
                }

                // start the target process
                StreamWriter writer = eventWritingProc.StandardInput;
                writer.WriteLine("\r\n");
                eventWritingProc.WaitForExit();

                var resultTuple = await listenerTask;
                testResults.Add(resultTuple);

                Console.WriteLine($"Done with iteration {iteration + 1}");
                Console.WriteLine("========================================================");
            }

            Console.WriteLine(testResults.GenerateSummary());
            Console.WriteLine(testResults.GenerateStatisticsTable());

            return(0);
        }
    }
}
예제 #2
0
        private static async Task <int> Run(IConsole console, CancellationToken ct, int eventSize, int eventRate, BurstPattern burstPattern, int threads, int duration, int eventCount)
        {
            TimeSpan durationTimeSpan = TimeSpan.FromSeconds(duration);

            MySource.s_Payload = new String('a', eventSize);

            threadProc = makeThreadProc(eventCount);

            Thread[] threadArray = new Thread[threads];
            TaskCompletionSource <bool>[] tcsArray = new TaskCompletionSource <bool> [threads];

            for (int i = 0; i < threads; i++)
            {
                var tcs = new TaskCompletionSource <bool>();
                threadArray[i] = new Thread(() => { threadProc(); tcs.TrySetResult(true); });
                tcsArray[i]    = tcs;
            }

            Console.WriteLine($"SUBPROCESSS :: Running - Threads: {threads}, EventSize: {eventSize * sizeof(char):N} bytes, EventCount: {(eventCount == -1 ? -1 : eventCount * threads)}, EventRate: {(eventRate == -1 ? -1 : eventRate * threads)} events/sec, duration: {durationTimeSpan.TotalSeconds}s");
            Console.ReadLine();

            for (int i = 0; i < threads; i++)
            {
                threadArray[i].Start();
            }

            if (eventCount != -1)
            {
                Console.WriteLine($"SUBPROCESSS :: Sleeping for {durationTimeSpan.TotalSeconds} seconds or until {eventCount} events have been sent on each thread, whichever happens first");
            }
            else
            {
                Console.WriteLine($"SUBPROCESSS :: Sleeping for {durationTimeSpan.TotalSeconds} seconds");
            }

            Task threadCompletionTask = Task.WhenAll(tcsArray.Select(tcs => tcs.Task));
            Task result = await Task.WhenAny(Task.Delay(durationTimeSpan), threadCompletionTask);

            finished = true;

            await threadCompletionTask;

            Console.WriteLine("SUBPROCESSS :: Done. Goodbye!");
            return(0);
        }