HOME

TheInfoList



OR:

CPU time (or process time) is the amount of
time Time is the continued sequence of existence and events that occurs in an apparently irreversible succession from the past, through the present, into the future. It is a component quantity of various measurements used to sequence events, t ...
for which a
central processing unit A central processing unit (CPU), also called a central processor, main processor or just processor, is the electronic circuitry that executes instructions comprising a computer program. The CPU performs basic arithmetic, logic, controlling, a ...
(CPU) was used for processing instructions of a computer program or
operating system An operating system (OS) is system software that manages computer hardware, software resources, and provides common daemon (computing), services for computer programs. Time-sharing operating systems scheduler (computing), schedule tasks for ef ...
, as opposed to elapsed time, which includes for example, waiting for
input/output In computing, input/output (I/O, or informally io or IO) is the communication between an information processing system, such as a computer, and the outside world, possibly a human or another information processing system. Inputs are the signals ...
(I/O) operations or entering low-power (idle) mode. The CPU time is measured in clock ticks or seconds. Often, it is useful to measure CPU time as a percentage of the CPU's capacity, which is called the CPU usage. CPU time and CPU usage have two main uses. The CPU time is used to quantify the overall empirical efficiency of two functionally identical algorithms. For example any
sorting algorithm In computer science, a sorting algorithm is an algorithm that puts elements of a list into an order. The most frequently used orders are numerical order and lexicographical order, and either ascending or descending. Efficient sorting is importa ...
takes an unsorted list and returns a sorted list, and will do so in a
deterministic Determinism is a philosophical view, where all events are determined completely by previously existing causes. Deterministic theories throughout the history of philosophy have developed from diverse and sometimes overlapping motives and consi ...
number of steps based for a given input list. However a
bubble sort Bubble sort, sometimes referred to as sinking sort, is a simple sorting algorithm that repeatedly steps through the input list element by element, comparing the current element with the one after it, swapping their values if needed. These passes ...
and a
merge sort In computer science, merge sort (also commonly spelled as mergesort) is an efficient, general-purpose, and comparison-based sorting algorithm. Most implementations produce a stable sort, which means that the order of equal elements is the same ...
have different running time complexity such that merge sort tends to complete in fewer steps. Without any knowledge of the workings of either algorithm a greater CPU time of bubble sort shows it is less efficient for particular input data than merge sort. This type of measurement is especially useful when comparing like algorithms that are not trivial in complexity. In this case the wall time (actual duration elapsed) is irrelevant, the computer may execute the program slower or faster depending on real world variables such as the CPU's temperature, as well as other operating system variables, such as the process's priority. The CPU usage is used to quantify how the processor is shared between computer programs. High CPU usage by a single program may indicate that it is highly demanding of processing power or that it may malfunction; for example, it has entered an
infinite loop In computer programming, an infinite loop (or endless loop) is a sequence of instructions that, as written, will continue endlessly, unless an external intervention occurs ("pull the plug"). It may be intentional. Overview This differs from: ...
. CPU time allows measurement of the processing power a single program requires, eliminating interference, such as time executed waiting for input or being suspended to allow other programs to run. In contrast,
elapsed real time Elapsed real time, real time, wall-clock time, wall time, or walltime is the actual time taken from the start of a computer program to the end. In other words, it is the difference between the time at which a task finishes and the time at which the ...
(or simply real time, or
wall-clock time Elapsed real time, real time, wall-clock time, wall time, or walltime is the actual time taken from the start of a computer program to the end. In other words, it is the difference between the time at which a task finishes and the time at which the ...
) is the time taken from the start of a computer program until the end as measured by an ordinary clock. Elapsed real time includes I/O time, any multitasking delays, and all other types of waits incurred by the program.


Subdivision

CPU time or CPU usage can be reported either for each thread, for each
process A process is a series or set of activities that interact to produce a result; it may occur once-only or be recurrent or periodic. Things called a process include: Business and management *Business process, activities that produce a specific se ...
or for the entire system. Moreover, depending on what exactly the CPU was doing, the reported values can be subdivided in: * User time is the amount of time the CPU was busy executing code in
user space A modern computer operating system usually segregates virtual memory into user space and kernel space. Primarily, this separation serves to provide memory protection and hardware protection from malicious or errant software behaviour. Kernel ...
. * System time is the amount of time the CPU was busy executing code in
kernel space A modern computer operating system usually segregates virtual memory into user space and kernel space. Primarily, this separation serves to provide memory protection and hardware protection from malicious or errant software behaviour. Kernel ...
. If this value is reported for a thread or process, then it represents the amount of time the kernel was doing work on behalf of the executing context, for example, after a thread issued a
system call In computing, a system call (commonly abbreviated to syscall) is the programmatic way in which a computer program requests a service from the operating system on which it is executed. This may include hardware-related services (for example, ac ...
. * Idle time (for the whole system only) is the amount of time the CPU was not busy, or, otherwise, the amount of time it executed the
System Idle process In Windows NT operating systems, the System Idle Process contains one or more kernel threads which run when no other runnable thread can be scheduled on a CPU. In a multiprocessor system, there is one idle thread associated with each CPU core. ...
. Idle time actually measures unused CPU capacity. * Steal time (for the whole system only), on
virtualized In computing, virtualization or virtualisation (sometimes abbreviated v12n, a numeronym) is the act of creating a virtual (rather than actual) version of something at the same abstraction level, including virtual computer hardware platforms, stor ...
hardware, is the amount of time the
operating system An operating system (OS) is system software that manages computer hardware, software resources, and provides common daemon (computing), services for computer programs. Time-sharing operating systems scheduler (computing), schedule tasks for ef ...
wanted to execute, but was not allowed to by the
hypervisor A hypervisor (also known as a virtual machine monitor, VMM, or virtualizer) is a type of computer software, firmware or hardware that creates and runs virtual machines. A computer on which a hypervisor runs one or more virtual machines is called ...
. This can happen if the physical hardware runs multiple guest operating system and the hypervisor chose to allocate a CPU time slot to another one.


Unix commands for CPU time


Unix command ''top''

The
Unix Unix (; trademarked as UNIX) is a family of multitasking, multiuser computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, and ot ...
command
top A spinning top, or simply a top, is a toy with a squat body and a sharp point at the bottom, designed to be spun on its vertical axis, balancing on the tip due to the gyroscopic effect. Once set in motion, a top will usually wobble for a few ...
provides CPU time, priority,
elapsed real time Elapsed real time, real time, wall-clock time, wall time, or walltime is the actual time taken from the start of a computer program to the end. In other words, it is the difference between the time at which a task finishes and the time at which the ...
, and other information for all processes and updates it in real time.


Unix command ''time''

The
Unix Unix (; trademarked as UNIX) is a family of multitasking, multiuser computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, and ot ...
command
time Time is the continued sequence of existence and events that occurs in an apparently irreversible succession from the past, through the present, into the future. It is a component quantity of various measurements used to sequence events, t ...
prints CPU time and elapsed real time for a Unix process. % gcc nextPrimeNumber.c -o nextPrimeNumber % time ./nextPrimeNumber 30000007 Prime number greater than 30000007 is 30000023 0.327u 0.010s 0:01.15 28.6% 0+0k 0+0io 0pf+0w This process took a total of 0.337 seconds of CPU time, out of which 0.327 seconds was spent in user space, and the final 0.010 seconds in kernel mode on behalf of the process.
Elapsed real time Elapsed real time, real time, wall-clock time, wall time, or walltime is the actual time taken from the start of a computer program to the end. In other words, it is the difference between the time at which a task finishes and the time at which the ...
was 1.15 seconds. The following is the source code of the application nextPrimeNumber which was used in the above example. // nextPrimeNumber.c #include #include int isPrimeNumber(unsigned long int n) int main(int argc, char *argv[])


POSIX functions clock() and getrusage()

C POSIX library, POSIX functions clock() and getrusage() can be used to get CPU time consumed by any process in a POSIX environment. If the process is multithreaded, the CPU time is the sum for all threads. With Linux starting from kernel 2.6.26 there is a parameter RUSAGE_THREAD which leads to resource usage statistics for the calling thread only.


Total CPU time

On
multi-processor Multiprocessing is the use of two or more central processing units (CPUs) within a single computer system. The term also refers to the ability of a system to support more than one processor or the ability to allocate tasks between them. There ar ...
machines, a computer program can use two or more
CPU A central processing unit (CPU), also called a central processor, main processor or just processor, is the electronic circuitry that executes instructions comprising a computer program. The CPU performs basic arithmetic, logic, controlling, and ...
s for processing using parallel processing scheduling. In such situations, the notion of ''total CPU time'' is used, which is the sum of CPU time consumed by all of the CPUs utilized by the computer program.


CPU time and elapsed real time

Elapsed real time is always greater than or equal to the CPU time for computer programs which use only one CPU for processing. If no wait is involved for I/O or other resources, elapsed real time and CPU time are very similar.


CPU time and elapsed real time for parallel processing technology

If a program uses parallel processing, total CPU time for that program would be more than its elapsed real time. (Total CPU time)/(Number of CPUs) would be same as elapsed real time if the work load is evenly distributed on each CPU and no wait is involved for I/O or other resources. Example: A software application executed on a hexa-core processor creates three Unix processes for fulfilling the user requirement. Each of these three processes creates two threads, enumerating a total of 6 working threads. Computation is distributed evenly on the 6 independent threads. If no wait for resources is involved, total CPU time is expected to be six times the elapsed real time.


See also

*
Elapsed real time Elapsed real time, real time, wall-clock time, wall time, or walltime is the actual time taken from the start of a computer program to the end. In other words, it is the difference between the time at which a task finishes and the time at which the ...
*
CPU A central processing unit (CPU), also called a central processor, main processor or just processor, is the electronic circuitry that executes instructions comprising a computer program. The CPU performs basic arithmetic, logic, controlling, and ...
*
Process (computing) In computing, a process is the instance of a computer program that is being executed by one or many threads. There are many different process models, some of which are light weight, but almost all processes (even entire virtual machines) are ...
*
System time In computer science and computer programming, system time represents a computer system's notion of the passage of time. In this sense, ''time'' also includes the passing of days on the calendar. System time is measured by a ''system clock'', ...
*
top A spinning top, or simply a top, is a toy with a squat body and a sharp point at the bottom, designed to be spun on its vertical axis, balancing on the tip due to the gyroscopic effect. Once set in motion, a top will usually wobble for a few ...
* mpstat *
Load (computing) In UNIX computing, the system load is a measure of the amount of computational work that a computer system performs. The load average represents the average system load over a period of time. It conventionally appears in the form of three numb ...


References


External links

* * * * {{cite web , url=http://www.opengroup.org/onlinepubs/000095399/functions/getrusage.html , title=getrusage - get information about resource utilization , work=The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition , accessdate=2014-08-05 Computer performance