Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load test doesn't show more than 4GB for Working Set PerformanceCounter

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

enter image description here

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

enter image description here

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.

like image 912
Wahid Bitar Avatar asked Jun 07 '16 13:06

Wahid Bitar


1 Answers

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;
        }
    }
}
like image 67
Wahid Bitar Avatar answered Nov 20 '22 19:11

Wahid Bitar