Simple class to measure system load

  • 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.

    Files

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • 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.

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • 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.

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • 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....

  • F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • Hi,

    Quote

    Is there a way to get the total cpu load?

    don't know exactly what is your intension? What is the lack of "CSystemLoad"?

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • Ok, so you can use the first attachment in this post "SYSTEMLOAD.zip". This sample refers CPU load measurement.

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • 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.

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.