Exactly.  

REAL is the elapsed time according to the wall clock
USER is the actual time the CPU spent executing user code
SYS  is the actual time the CPU spent executing system code

In "modern" Operating Systems USER usually reflects CPU usage by your process 
while the CPU is in USER mode (non-protected, or executing at Ring-3 or below), 
while SYS reflects CPU usage by your process in SUPERVISOR mode (protected, or 
executing code at Ring-2 or above).

WAIT = REAL - (USER + SYS)

where WAIT is the amount of time that the program was not actually executing 
(ie, it was waiting for something to happen, whether that waiting occurred in 
user or system code).  Some I/O devices are co-processsed and interrupt driven 
or use third-party DMA, these will increase WAIT time.  Some I/O devices use 
I/O driven by the main CPU, and those devices will increase SYS time, even when 
they are waiting for something to happen.  Examples of CPU run devices (under 
Windows) are (almost) anything attached via USB, or non-interrupt driven 
printers.  Examples of co-processed devices are most (modern) SATA/SCSI type 
devices (especially if they use NCQ or Data Phase Disconnect).  Older IDE 
interfaces are usually CPU operated and not interrrupt driven or co-processed.

Some Ring-0 operations that occur in SUPERVISOR mode may be attributed to WAIT 
(ie, not show up in SYS) even though they are dependant on the CPU to carry 
them out, examples being "fiddling" with the Memory Mapper Page and Indirection 
tables (including SMM operations), and context switching, because although they 
may be triggered by your process, such fiddling cannot usually be attributed to 
a specific process.  

USER and SYS are the sum of all the CPU used in that mode by each core/thread, 
so it is possible for SYS+USER to exceed REAL even without explicit 
multithreading in your code (and even easier if you do have multiple threads).

The ratio between REAL and (USER + SYS) across all the processes running at the 
same time is called the Multiprogramming Ratio.

---
The fact that there's a Highway to Hell but only a Stairway to Heaven says a 
lot about anticipated traffic volume.


>-----Original Message-----
>From: sqlite-users [mailto:sqlite-users-
>boun...@mailinglists.sqlite.org] On Behalf Of Dan Kennedy
>Sent: Thursday, 14 June, 2018 09:13
>To: sqlite-users@mailinglists.sqlite.org
>Subject: Re: [sqlite] .timer
>
>On 06/14/2018 03:08 PM, Simon Slavin wrote:
>> On 14 Jun 2018, at 8:33am, x <tam118...@hotmail.com> wrote:
>>
>>> Could someone describe what the return values real, user and sys
>mean and why there’s sometimes a big difference between real and the
>sum of user & sys?.
>> [The following is simplified for clarity.]
>>
>> 'real' -- Elapsed time between the start and end of the command, as
>measured by the clock on your wall.  Sometimes called 'wall time'.
>>
>> The other two figures both concern just the process you're
>interested in, ignoring the many other things the computer is doing
>at the same time like seeing if you've clicked your mouse, updating
>your screen, checking to see if your laptop battery is going to run
>out, etc..
>>
>> 'user' -- Processor time taken by the command itself.  If you look
>at all the source code for that command, this is the time taken to
>run that source code.
>>
>> 'sys' -- Processor time taken to execute the system calls the
>command used.  If the command used system calls to find the current
>time, allocate memory, and write some bytes to a file, the amount of
>time each system call took contributes to 'sys', not 'user'.
>>
>> If 'sys' + 'user' > 'real', something weird happened.
>
>Multi-threaded apps often have (sys+user)>real. And you can
>build/configure SQLite to use multiple threads when sorting large
>amounts of data, so it is possible. Not terribly common though, I
>would
>think.
>
>> If 'sys' + 'user' < 'real', your computer is busy doing a lot of
>stuff in the background.  You probably have a printer plugged in, an
>ethernet or WiFi connection active, a keyboard and mouse pointer
>being monitored, etc..  This is normal on a modern computer,
>
>Another explanation is that your query had to load or sync data from
>or
>to the storage device, not just the OS cache. The "real" time
>increases
>while waiting on IO, but "user" and "sys" do not (since the CPU is
>idle).
>
>Dan.
>
>_______________________________________________
>sqlite-users mailing list
>sqlite-users@mailinglists.sqlite.org
>http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users



_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to