I'm trying to create load test to some application. And I want to get the memory usage for just the process of my application. To do so I added Process / Working Set
to my counter set
The problem is the Working Set
PerformanceCounter
read the values in bytes and didn't count values more than 4294967296
which equals to 4 GB
But my application "runs in 64-bit mode" uses more than 4 GB of the memory
It's clear from TaskManager I see that it takes about 6GB but this value doesn't appear in the load test Graph.
So how to create customized PerformanceCounter to act exactly like Process/Working Set
one but using Kilobytes instead of bytes I may get the real values. Or any other solution that enables me to calculate how much my application use memory in the load test.
I found a solution. Thanks for all your comments, all of them, were very helpful.
The first step is the normal installing new PerformanceCounterCategory
just the most important thing is to set it as PerformanceCounterCategoryType.MultiInstance
e.g.
var countersToCreate = new CounterCreationDataCollection();
var memoryCounterData = new CounterCreationData("Memory Usage", "Memory Usage", PerformanceCounterType.NumberOfItems64);
countersToCreate.Add(memoryCounterData);
PerformanceCounterCategory.Create("KB Memory Usage", "KB Memory Usage", PerformanceCounterCategoryType.MultiInstance, countersToCreate);
The next step is to have simple windows service or console application that should read the values for each process from process.WorkingSet64
and set them to your PerformanceCounter
. This application or Service should run while you're running your load test and of course in x64 mode.
e.g.
static void Main(string[] args)
{
while (true)
{
Thread.Sleep(500);
foreach (var process in Process.GetProcesses())
{
var memoryUsage = new PerformanceCounter("KB Memory Usage", "Memory Usage", process.ProcessName, false);
memoryUsage.RawValue = process.WorkingSet64/1024;
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With