Windows System CPU Memory network performance statistics first memory

Source: Internet
Author: User

Recently turned out the Windows System performance statistics program, which can be used to count the CPU usage, memory usage and network traffic in the system. Now to organize it (a total of three), I hope to be helpful to everyone.

The directory is as follows:

1. "Windows System CPU memory network performance statistics first Memory"

2. "Windows System CPU memory network performance statistics second CPU"

3. "Windows System CPU Memory network performance statistics" Third network traffic

This article describes the statistical system memory usage, including memory usage, total physical memory size, available physical memory size, total virtual memory size, available virtual memory size, and more. Statistical system memory usage is very simple, directly using the GlobalMemoryStatus function to query on it. Its function prototype is as follows:

void Winapiglobalmemorystatus (

__out Lpmemorystatus lpbuffer

);

This function will pass out the structure of the Memorystatus type, which describes the use of memory in the system. Details can be found in the code:

[CPP]View PlainCopy
  1. Windows System CPU Memory network performance statistics first memory GlobalMemoryStatus
  2. by morewindows-(http://blog.csdn.net/MoreWindows)
  3. #include <stdio.h>
  4. #include <windows.h>
  5. const INT kb_div = 1024;
  6. const INT mb_div = 1024 * 1024;
  7. int main ()
  8. {
  9. printf ("Windows System CPU memory network performance statistics first memory globalmemorystatus\n");
  10. printf ("-by Morewindows (http://blog.csdn.net/MoreWindows)--\n\n");
  11. Memorystatus Memstatus;
  12. GlobalMemoryStatus (&memstatus);
  13. printf ("Current Memory utilization:%d%%\n", memstatus.dwmemoryload);
  14. printf ("Total system physical Memory:%DKB (%dMB) \ n", Memstatus.dwtotalphys/kb_div, Memstatus.dwtotalphys/mb_div);
  15. printf ("Currently available physical Memory:%dkb (%dMB) \ n", Memstatus.dwavailphys/kb_div, Memstatus.dwavailphys/mb_div);
  16. printf ("Total system virtual Memory:%DKB (%dMB) \ n", Memstatus.dwtotalvirtual/kb_div, Memstatus.dwtotalvirtual/mb_div);
  17. printf ("Currently idle virtual Memory:%DKB (%dMB) \ n", Memstatus.dwavailvirtual/kb_div, Memstatus.dwavailvirtual/mb_div);
  18. printf ("Total system Paging File:%dkb (%dMB) \ n", Memstatus.dwtotalpagefile/kb_div, Memstatus.dwtotalpagefile/mb_div);
  19. printf ("Current free paging file:%dkb (%dMB) \ n", Memstatus.dwavailpagefile/kb_div, Memstatus.dwavailpagefile/mb_div);
  20. return 0;
  21. }

The result of running on this machine is as follows, hehe, 2G memory is enough for XP system. Switching to Win7 certainly won't have so much memory available.

Since the MEMORYSTATUS structure is stored in DWORD for the memory size, the DWORD is only 4 bytes and the maximum is 4G. Therefore, when the memory of the system is greater than 4GB, there are certain problems. So the Windows system provides another function,--globalmemorystatusex, whose function is prototyped as follows:

Boolwinapiglobalmemorystatusex (

__in_out Lpmemorystatusexlpbuffer

);

This function is an enhanced version of the previous GlobalMemoryStatus function. It will pass out the structure of the Memorystatusex type, which uses variables of type Dwordlong to describe the size of the memory, dwordlong similar to __int64, accounting for 8 bytes. The following also gives the source code that uses the GlobalMemoryStatusEx function to count memory information:

[CPP]View PlainCopy
  1. Windows System CPU Memory network performance statistics first memory GlobalMemoryStatusEx
  2. by morewindows-(http://blog.csdn.net/MoreWindows)
  3. #include <stdio.h>
  4. #include <windows.h>
  5. const INT kb_div = 1024;
  6. const INT mb_div = 1024 * 1024;
  7. int main ()
  8. {
  9. printf ("Windows System CPU memory network performance statistics first memory globalmemorystatusex\n");
  10. printf ("-by Morewindows (http://blog.csdn.net/MoreWindows)--\n\n");
  11. Memorystatusex Memstatusex;
  12. Memstatusex.dwlength = sizeof (memstatusex);
  13. if (GlobalMemoryStatusEx (&memstatusex))
  14. {
  15. printf ("Current Memory utilization:%d%%\n", memstatusex.dwmemoryload);
  16. printf ("Total system physical Memory: \T%I64DKB (%I64DMB) \ n", Memstatusex.ulltotalphys/kb_div, Memstatusex.ulltotalphys/mb_div);
  17. printf ("Currently available physical Memory: \t%i64dkb (%I64DMB) \ n", Memstatusex.ullavailphys/kb_div, Memstatusex.ullavailphys/mb_div);
  18. printf ("Total system virtual Memory: \T%I64DKB (%I64DMB) \ n", Memstatusex.ulltotalvirtual/kb_div, Memstatusex.ulltotalvirtual/mb_  DIV);
  19. printf ("Currently idle virtual Memory: \T%I64DKB (%I64DMB) \ n", Memstatusex.ullavailvirtual/kb_div, Memstatusex.ullavailvirtual/mb_  DIV);
  20. printf ("Total system Paging File: \t%i64dkb (%I64DMB) \ n", Memstatusex.ulltotalpagefile/kb_div, MEMSTATUSEX.ULLTOTALPAGEFILE/MB  _DIV);
  21. printf ("Current free paging file: \t%i64dkb (%I64DMB) \ n", Memstatusex.ullavailpagefile/kb_div, MEMSTATUSEX.ULLAVAILPAGEFILE/MB  _DIV);
  22. }
  23. return 0;
  24. }

The results of the operation are as follows:

This article describes and demonstrates the GlobalMemoryStatus and GlobalMemoryStatusEx functions to query memory usage. The following two article "Windows System CPU memory network performance statistics second CPU" and "Windows System CPU memory network performance statistics Third" network traffic will explain the query CPU usage and network traffic statistics respectively, welcome to continue browsing.

http://blog.csdn.net/morewindows/article/details/8459219

Windows system CPU memory network performance statistics first memory

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.