EzPerformanceMonitor

EzPerformanceMonitor provides a series of properties representing various memory metrics of the application under test. Additionally it provides methods that allow the user to watch the application's memory to make sure that the various memory metrics are within a proper range. Be sure to check out the Samples and Usage section at the bottom.

Syntax

        public class EzLogMonitor

Constructors

Name Input Description
EzPerformanceMonitor(EzProcess process) EzProcess Creates a new instance of EzPerformanceMonitor based on an instance of EzProcess

Properties

Name Type Description
NonPagedSystemMemorySize long See documentation for NonPagedSystemMemorySize64 here
PagedMemorySize long See documentation for PagedMemorySize64 here
PagedSystemMemorySize long See documentation for PagedSystemMemorySize64 here
PeakPagedMemorySize long See documentation for PeakPagedMemorySize64 here
PeakVirtualMemorySize long See documentation for PeakVirtualMemorySize64 here
PeakWorkingSet long See documentation for PeakWorkingSet64 here
PrivateMemorySize long See documentation for PrivateMemorySize64 here
VirtualMemorySize long See documentation for VirtualMemorySize64 here
WorkingSet long See documentation for WorkingSet64 here

Methods

Name Return Type Description
StartSyncWatch(MemoryType type, long amount, int timeInSeconds, IfFail ifFail, SingularSuccess ifSuccess) void Performs a sync watch on a specific memory type. If that memory type exceeds the threshold at any point during the monitoring period, the ifFail delegate will be called. Otherwise, the ifSuccess delegate will be called
StartSyncWatch(IEnumerable<MemoryWatch> watches, int timeInSeconds, IfFail ifFail, MultiSuccess ifSuccess) void Performs a sync watch on a series of memory types. If that any of the memory types exceed the threshold at any point during the monitoring period, the ifFail delegate will be called. Otherwise, the ifSuccess delegate will be called

Samples and Usage

EzPerformanceMonitor is designed to watch various memory metrics via two methods, both called StartSyncWatch (one takes a single memory metric and one takes multiple). They will both monitor the application for the duration of the time passed in and will call an ifSuccess delegate if the memory metric(s) never exceed the passed in threshold. If any of the memory metrics exceed their threshold, the ifFail delegate will be called

        const string calculatorPath = "C:\\Windows\\System32\\calculator.exe";
        using (EzProcess process = new EzProcess(calculatorPath, "Calculator"))
        {
            process.StartProcess();

            EzPerformanceMonitor performanceMonitor = new EzPerformanceMonitor(process);

            //Create a list of watches.  These are the memory metrics we will be watching for to make sure they don't
            //exceed the amount given for each
            List<MemoryWatch> watches = new List<MemoryWatch>
            {
                new MemoryWatch(MemoryType.PagedMemorySize, 100000000),
                new MemoryWatch(MemoryType.PeakVirtualMemorySize, 200000000),
                new MemoryWatch(MemoryType.VirtualMemorySize, 203040506060)
            };

            //Call the StartSyncWatch method.  We will watch based on the list above for 60 seconds
            performanceMonitor.StartSyncWatch(watches, 60, (type, original, actual, failure) =>
            {
                //Method to be run if a failure occurs
                Console.WriteLine($"Memory type {type} exceeded the threshhold of {original}.  " +
                    "Value: {actual}.  Time at failure: {failure}.");
            }, (memWatches, time) =>
            {
                //Method to run if no failure occurs
                string watchesString = memWatches.Select(x => x.Type.ToString()).Aggregate((a, b) => a + ", ");
                Console.WriteLine($"After {time} seconds of profiling, no memory types exceeded their limits." + 
                $"Memory types: {watchesString}.");
            });
        }