Directory
- 1. CPU user time and Kernel Time of the process
- 2. CPU usage statistics
- 3. Download source code
Returned directory
1. CPU user time and Kernel Time of the process
The userprocessortime and privilegedprocessortime attributes of the Process class can be used to return the CPU user and Kernel Time consumed by the current process. Process. totalprocessortime indicates the sum of the two. Both return the timespan struct object.
With these three attributes, you can make a simple program to monitor the CPU time of the process.
As follows: (of course, when the CPU is not very slow, a significant increase in CPU time will not be seen after an operation)
Returned directory
2. CPU usage statistics
The simplest way to count the usage of all CPUs is to use the Windows Task Manager program. By default, however, only the percentage of "non-idle" execution time is displayed. In the Windows 7 Task Manager view, the "display Kernel Time" option is displayed. In this way, the user time and Kernel Time are separated. The kernel time is in red, for example:
In programming, you can use performance counters for more detailed CPU time monitoring. For example, the following is a program that monitors CPU usage:
The performance counter used is in the processor class:
- % Idle time: idle
- % Interrupt time: Indicates hardware interruption.
- % USER time: Indicates processing user commands.
- % Privileged time: indicates the operating system kernel command
- % Processor time: indicates all non-idle time (also displayed by the task manager by default)
(Percentage of all the above performance counters returned !)
You can view this information in the Performance Monitor of the Control Panel (or type: perfmon during running)
The last thing to note is the transaction macecounter class (system. while the getnextvalue method in the namespace of diagnostics returns float, the percentage is normalized from 0.0 to 100.0, instead of 0.0 to 1.0.
Returned directory
3. Download source code
Download the current version of the program and source code
Download Page
Note: the link is the Microsoft SkyDrive page. When downloading, use a browser to download it directly. Some download tools may not be available for downloading.
Source code environment: Visual C # express 2010