. Net (C #): gets the private working set of the process's memory

Source: Internet
Author: User

Currently, the process of. NET Framework (. NET 4.0) only provides the acquisition of the memory working set of the process (through the workingset64 attribute), but does not provide the acquisition of the private working set. Note that after Windows Vista, the process memory in Windows Task Manager displays the private working set of the process by default. Therefore, this performance data is very important.

 

You can use workingset-Private of the process class of the performance counter to obtain the private working set of the process. Of course, the workset can also be obtained through the workingset attribute. In addition, both the process class and the performance counter have the peak workingset to obtain the peak value of the working set.

 

For example, you can use process. workingset64 and workingset private of the performance counter to monitor the memory working set of a program (taking the Task Manager taskmgr as an example.

VaR processname = "taskmgr ";

Using (VAR process = process. getprocessesbyname (processname) [0])

Using (VAR p1 = new performancecounter ("process", "Working Set-private", processname ))

Using (VAR P2 = new performancecounter ("process", "Working Set", processname ))

{

While (true)

{

// Note divided by the number of CPUs

Console. writeline ("{0} {1: n} kb", "Working Set (process type)", process. workingset64/1024 );

Console. writeline ("{0} {1: n} kb", "Working Set", process. workingset64/1024 );

Console. writeline ("{0} {1: n} kb", "private working set", p1.nextvalue ()/1024 );

Thread. Sleep (1000 );

}

}

 

Output:

Working Set (process class) 9,024.00 KB

Working Set 9,024.00 KB

Private workset 2,028.00 KB

Working Set (process class) 9,024.00 KB

Working Set 9,024.00 KB

Private workset 2,028.00 KB

......

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.