致力于自动化测试技术,性能测试技术的研究,测试技术培训以及项目实施,做一个技术与实施的主导者。

[Linux系列] CPU Performance Statistics

上一篇 / 下一篇  2012-11-15 21:45:48 / 个人分类:Linux

--------------------------

CPU性能统计,英文原版,原滋原味!51Testing软件测试网%I XH n]\d(?

--------------------------

2.1. CPU Performance Statistics51Testing软件测试网 `7ODh#y)]L

Each system-wide Linux performance tool provides different ways to extract similar statistics. Although no tool displays all the statistics, some of the tools display the same statistics. Rather than describe the meaning of the statistics multiple times (once for each tool), we review them once before all the tools are described.

fH KkuwN/Q iH(^,V0

2.1.1. Run Queue Statistics

In Linux, a process can be either runnableor blocked waiting for an event to complete. A blocked process may be waiting for data from an I/O device or the results of a system call. If a process is runnable, that means that it is competing for the CPU time with the other processes that are also runnable. A runnable process is not necessarily using the CPU, but when the Linux scheduler is deciding which process to run next, it picks from the list of runnable processes. When these processes are runnable, but waiting to use the processor, they form. a line called the run queue. The longer the run queue, the more processes wait in line.51Testing软件测试网0?3@%e%d ?!N

The performance tools commonly show the number of processes that are runnable and the number of processes that are blocked waiting forI/O. Anothercommon system statistic is that of load average. The load on a system is the total amount of running and runnable process. For example, if two processes were running and three were available to run, the system's load would be five. The load average is the amount of load over a given amount of time. Typically, the load average is taken over 1 minute, 5 minutes, and 15 minutes. This enables you to see how the load changes overtime.51Testing软件测试网$RJ9W}#po3D2W lF

2.1.2. Context Switches

Most modern processors canrun only one process or thread at a time. Although some processors, such hyperthreaded processors, can actually run more than one process simultaneously, Linux treats them as multiple single-threaded processors. To create the illusion that a given single processor runs multiple tasks simultaneously, the Linux kernel constantly switches between different processes. The switch between different processes is called a context switch, because when it happens, the CPU saves all the context information from the old process and retrieves all the context information for the new process. The context contains a large amount of information that Linux tracks for each process, including, among others, which instruction the process is executing, which memory it has allocated, and which files the process has open. Switching these contexts can involve moving a large amount of information, and a context switch can be quite expensive. It is a good idea to minimize the number of context switches if possible.51Testing软件测试网.T"k9LZ Og4k6b

To avoid context switches, it is important to know how they can happen. First, context switches can result fromkernel scheduling. To guarantee that each process receives a fair share of processor time, the kernel periodically interrupts the running process and, if appropriate, the kernel scheduler decides to start another process rather than let the current process continue executing. It is possible that your system will context switch every time this periodic interrupt or timer occurs. The number of timer interrupts per second varies per architecture and kernel version. One easy way to check how often the interrupt fires is to use the/proc/interruptsfile to determine the number of interrupts that have occurred over a known amount of time. Thisis demonstrated inListing 2.1.

d1fD'N0B5trI0
Listing 2.1.
root@localhost asm-i386]# cat /proc/interrupts | grep timer

; sleep 10 ; cat /proc/interrupts | grep timer

  0:   24060043          XT-PIC  timer

  0:   24070093          XT-PIC  timer
51Testing软件测试网s#A8X%oyh"x

InListing 2.1, we ask the kernel to show us how many times the timer has fired, wait 10 seconds, and then ask again. That means that on this machine, the timer fires at a rate of (24,070,093 – 24,060,043) interrupts / (10 seconds) or ~1,000 interrupts/sec. If you have significantly more context switches than timer interrupts, the context switches are most likely caused by an I/O request or some other long-running system call (such as a sleep). When an application requests an operation that can not complete immediately, the kernel starts the operation, saves the requesting process, and tries to switch to another process if one is ready. This allows the processor to keep busy ifpossible.

-{Fw0E:L!~_t0

2.1.3. Interrupts

Inaddition, periodically, the processor receives an interrupt by hardware devices. These interrupts are usually triggered by a device that has an event that needs to be handled by the kernel. For example, if a disk controller has just finished retrieving a block from the drive and is ready for the kernel to use it, the disk controller may trigger an interrupt. For each interrupt the kernel receives, an interrupt handler is run if it has been registered for that interrupt; otherwise, the interrupt is ignored. These interrupt handlers run at a very high priority in the system and typically execute very quickly. Sometimes, the interrupt handler has work that needs to be done, but does not require the high priority, so it launches a "bottom half," which is also known as a soft-interrupt handler. If there are a high number of interrupts, the kernel can spend a large amount of time servicing these interrupts. The file/proc/interruptscan be examined to show which interrupts are firing on whichCPUs.51Testing软件测试网.b3Mk$?/X4UO

2.1.4. CPU Utilization

CPU utilizationis a straightforward concept. At any given time, the CPU can be doing one of seven things. First, it can be idle, which means that the processor is not actually doing any work and is waiting for something to do. Second, the CPU can be running user code, which is specified as "user" time. Third, the CPU can be executing code in the Linux kernel on behalf of the application code. This is "system" time. Fourth, the CPU can be executing user code that has been "nice"ed or set to run at a lower priority than normal processes. Fifth, the CPU can be iniowait, which mean the system is spending its time waiting for I/O (such as disk or network) to complete. Sixth, the CPU can be inirqstate, which means it is in high-priority kernel code handling a hardware interrupt. Finally, the CPU can be insoftirqmode, which means it is executing kernel code that was also triggered by an interrupt, but it is running at a lower priority (the bottom-half code). This can happen when a device interrupt occurs, but the kernel needs to do some work with it before it is ready to hand it over to user space (for example, with a network packet).51Testing软件测试网MT_ff h

Most performance tools specify these values as a percentage of the total CPU time. These times can range from 0 percent to 100 percent, but all three total 100 percent. A system with a high "system" percentage is spending most of its time in the kernel. Tools such asoprofilecan help determine where this time is being spent. A system that has a high "user" time spends most of its time running applications. The next chapter shows how to use performance tools to track down problems in these cases. If a system is spending most of its timeiowaitwhen it should be doing work, it is most likely waiting for I/O from a device. It may be a disk, network card, or something else causing theslowdown.51Testing软件测试网[iagU S&w


TAG:

 

评分:0

我来说两句

vprince

vprince

6年软件测试经验,TIB自动化测试工作室核心成员,ATF框架核心设计和开发人员,熟悉软件自动化测试、性能测试,多年从事软件项目的自动化测试和性能测试,对自动化测试的框架设计开发、框架搭建以及实施有较为丰富的实战经验。 目前关注开源自动化测试领域、 基于Selenium构建Web自动化测试框架,为多家企业进行自动化测试培训、实施自动化测试项目。

日历

« 2024-05-14  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 67549
  • 日志数: 49
  • 建立时间: 2009-09-09
  • 更新时间: 2012-12-14

RSS订阅

Open Toolbar