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
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);
List<MemoryWatch> watches = new List<MemoryWatch>
{
new MemoryWatch(MemoryType.PagedMemorySize, 100000000),
new MemoryWatch(MemoryType.PeakVirtualMemorySize, 200000000),
new MemoryWatch(MemoryType.VirtualMemorySize, 203040506060)
};
performanceMonitor.StartSyncWatch(watches, 60, (type, original, actual, failure) =>
{
Console.WriteLine($"Memory type {type} exceeded the threshhold of {original}. " +
"Value: {actual}. Time at failure: {failure}.");
}, (memWatches, time) =>
{
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}.");
});
}