Are my HW accelleration adjustments optimal?
Which function cause heavy system load?
Are there memory leaks in my application?
...
Attached class "CSystemLoad" may help you answer these questions.
![](https://forum.fs-net.de/wcf/images/avatars/d8/11-d85a4b41cd8e3a545a4ba1372821f32fb107fae7.png)
Simple class to measure system load
-
-
Can this class be used to see how many memory my application is using?
-
Is it possible to obtain the memory usage of my application in c#.net ?
-
Hello,
this thread refers the processors load.
For check RAM load use/search "GobalMemoryStatus". I think it is easy "dll-import" it to .NET, if not already an equivalent exists.
-
ok, i got this code:
[StructLayoutAttribute(LayoutKind.Sequential)]
public class MEMORYSTATUSEX
{
/// DWORD->unsigned int
public uint dwLength;/// DWORD->unsigned int
public uint dwMemoryLoad;/// DWORDLONG->ULONGLONG->unsigned __int64
public ulong ullTotalPhys;/// DWORDLONG->ULONGLONG->unsigned __int64
public ulong ullAvailPhys;/// DWORDLONG->ULONGLONG->unsigned __int64
public ulong ullTotalPageFile;/// DWORDLONG->ULONGLONG->unsigned __int64
public ulong ullAvailPageFile;/// DWORDLONG->ULONGLONG->unsigned __int64
public ulong ullTotalVirtual;/// DWORDLONG->ULONGLONG->unsigned __int64
public ulong ullAvailVirtual;/// DWORDLONG->ULONGLONG->unsigned __int64
public ulong ullAvailExtendedVirtual;
}[DllImport("coredll.dll", SetLastError = true)] public static extern bool GlobalMemoryStatus([In, Out] MEMORYSTATUSEX buffer);
public static MEMORYSTATUSEX GetMemoryStatusEx()
{
MEMORYSTATUSEX memStat = new MEMORYSTATUSEX();
memStat.dwLength = 64;
bool b = GlobalMemoryStatus(memStat);
return memStat;
}MEMORYSTATUSEX mem = new MEMORYSTATUSEX();
mem = GetMemoryStatusEx();
statusBar1.Text = mem.ullAvailPhys.ToString() + "/" + mem.ullTotalPhys.ToString() + " (" + mem.dwMemoryLoad.ToString() + ")";i get the following in my statusbar:
0/[number of 18 digits] (69)
only the last number seems to make sens....
the rest is not valid.What am i doing wrong?
-
Use "MEMORYSTATUS" and "GlobalMemoryStatus", the "EX" is not supported in WCE.
-
this code:
[StructLayout(LayoutKind.Sequential)]
public struct MEMORYSTATUS
{
internal uint dwLength;
internal uint dwMemoryLoad;
internal uint dwTotalPhys;
internal uint dwAvailPhys;
internal uint dwTotalPageFile;
internal uint dwAvailPageFile;
internal uint dwTotalVirtual;
internal uint dwAvailVirtual;
}[DllImport("coredll.dll", SetLastError = true)] public static extern bool GlobalMemoryStatus([In, Out] MEMORYSTATUS buffer);
public static MEMORYSTATUS GetMemoryStatus()
{
MEMORYSTATUS memStat = new MEMORYSTATUS();
//memStat.dwLength = 64;
bool b = GlobalMemoryStatus(memStat);
return memStat;
}MEMORYSTATUS mem = new MEMORYSTATUS();
mem = GetMemoryStatus();
statusBar1.Text = mem.dwAvailPhys.ToString() + "/" + mem.dwTotalPhys.ToString() + " (" + mem.dwMemoryLoad.ToString() + ")";makes my application crash....
-
Code
- [StructLayout(LayoutKind.Sequential)]
- public struct MEMORYSTATUS
- {
- internal UInt32 dwLength;
- internal UInt32 dwMemoryLoad;
- internal UInt32 dwTotalPhys;
- internal UInt32 dwAvailPhys;
- internal UInt32 dwTotalPageFile;
- internal UInt32 dwAvailPageFile;
- internal UInt32 dwTotalVirtual;
- internal UInt32 dwAvailVirtual;
- }
- [DllImport("coredll.dll", SetLastError = true)]
- public static extern void GlobalMemoryStatus
- (
- ref MEMORYSTATUS lpBuffer
- );
- static void Main(string[] args)
- {
- MEMORYSTATUS m = new MEMORYSTATUS();
- GlobalMemoryStatus(ref m);
- ....m.dwMemoryLoad;....
-
cool !! this works.
thanks -
Hi,
Is there a way to get the total cpu load?
thanks -
Hi,
QuoteIs there a way to get the total cpu load?
don't know exactly what is your intension? What is the lack of "CSystemLoad"?
-
i want to measure how busy the processor is.
our latencies in processing can messages gets sometimes too high... -
Ok, so you can use the first attachment in this post "SYSTEMLOAD.zip". This sample refers CPU load measurement.
-
Hello,
keep in mind - if you use a board with multiple cores you have to do the measurement above for each CPU!
You can use the SMP functions to do this, like:
CeGetTotalProcessors():
CeSetThreadAffinity();
Refer SMP Functions documentation on MS Windows Dev Center.