CPU usage calculation for Linux platforms

Source: Internet
Author: User

Ref:http://www.blogjava.net/fjzag/articles/317773.html

Proc File system

The/proc file system is a pseudo-file system that only exists in memory and does not occupy external memory space. It provides the interface for the kernel to communicate with the process in a file system manner. Users and applications can get system information through/PROC, and can change certain parameters of the kernel. Because the information of the system, such as the process, is dynamically changed, so when a user or application reads a file from the/proc directory, the proc file system dynamically reads the required information from the system kernel and submits it.

There are some directory names in the/proc directory, which are the process directories. Each process currently running in the system corresponds to a directory/proc/pid that is the directory name of the process number under/proc, which is the interface that reads the process information. In addition, there is a task directory in the/proc/pid directory in the version above Linux 2.6.0-test6, and there are some directory/proc/pid/task/tid named for the thread number of threads owned by the process/proc/pid/task directory. They are interfaces that read thread information.

/proc/stat file

The file contains information about all CPU activity, and all values in the file are accumulated from the start of the system to the current moment. The format of the file may be inconsistent in different kernel versions, and the following examples illustrate the meaning of each field in the data file.

Instance data: 2.6. On version 24-24

[Email protected]:~$ cat/proc/stat

CPU 38082 627 27594 893908 12256 581 895 0 0

Cpu0 22880 472 16855 430287 10617 576 661 0 0

CPU1 15202 154 10739 463620 1639 4 234 0 0

Intr 120053 222 2686 0 1 1 0 5 0 3 0 0 0 47302 0 0 34194 29775 0 5019 845 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Ctxt 1434984

Btime 1252028243

Processes 8113

Procs_running 1

procs_blocked 0

The number on the first line represents the total CPU usage, so we just use the first line of numbers to calculate it. The following table resolves the meanings of the first row of values:

Parameter Resolution (unit: Jiffies)

(Jiffies is a global variable in the kernel, used to record the number of Beats generated from the start of the system, in Linux, a beat is roughly understood as the minimum time slice of the operating system process scheduling, different Linux cores may have different values, usually between 1ms to 10ms)

User (38082) accumulated from the start of the system to the current time, in the user state of the run time, does not include the nice value is a negative process.

Nice (627) Accumulated from the start of the system to the current time, the nice value is negative the CPU time occupied by the process

system (27594) from the start of the system to accumulate to the current moment, in the nuclear mentality of the running time

Idle (893908) from the start of the system to accumulate to the current moment, in addition to the IO wait time other than the wait time iowait (12256) from the start of the system to accumulate to the current moment, IO wait time (since 2.5.41)

IRQ (581) accumulated from the start of the system to the current time, hard interrupt time (since 2.6.0-TEST4)

SOFTIRQ (895) from the start of the system to accumulate to the current moment, soft interrupt time (since 2.6.0-test4)Stealstolen(0) which is the times spent in Oth ER operating systems when running in a virtualized environment (since 2.6.11)

Guest (0) which is the time spent running a virtual CPU for guest operating systems under the C Ontrol of the Linux kernel (since 2.6.24)

Conclusion 2: Total CPU Time Totalcputime = user + nice + system + Idle + iowait + IRQ + SOFTIRQ + Stealstolen + Guest

CPU usage calculation for Linux platforms

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.