Simple class to measure system load

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

        (5.35 kB, downloaded 328 times, last: )
      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....

      Source Code

      1. [StructLayout(LayoutKind.Sequential)]
      2. public struct MEMORYSTATUS
      3. {
      4. internal UInt32 dwLength;
      5. internal UInt32 dwMemoryLoad;
      6. internal UInt32 dwTotalPhys;
      7. internal UInt32 dwAvailPhys;
      8. internal UInt32 dwTotalPageFile;
      9. internal UInt32 dwAvailPageFile;
      10. internal UInt32 dwTotalVirtual;
      11. internal UInt32 dwAvailVirtual;
      12. }
      13. [DllImport("coredll.dll", SetLastError = true)]
      14. public static extern void GlobalMemoryStatus
      15. (
      16. ref MEMORYSTATUS lpBuffer
      17. );
      18. static void Main(string[] args)
      19. {
      20. MEMORYSTATUS m = new MEMORYSTATUS();
      21. GlobalMemoryStatus(ref m);
      22. ....m.dwMemoryLoad;....

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