1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531
|
\input texinfo @c -*-texinfo-*-
@c %**start of header
@setfilename time.info
@settitle Measuring Program Resource Use
@setchapternewpage odd
@c %**end of header
@include version.texi
@iftex
@finalout
@end iftex
@ifinfo
This file documents the the GNU @code{time} command for running programs
and summarizing the system resources they use.
Copyright @copyright{} 1991, 92, 93, 96 Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
are preserved on all copies.
@ignore
Permission is granted to process this file through TeX and print the
results, provided the printed document carries copying permission
notice identical to this one except for the removal of this paragraph
(this paragraph not being relevant to the printed manual).
@end ignore
Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided that the entire
resulting derived work is distributed under the terms of a permission
notice identical to this one.
Permission is granted to copy and distribute translations of this manual
into another language, under the above conditions for modified versions,
except that this permission notice may be stated in a translation approved
by the Foundation.
@end ifinfo
@titlepage
@title Measuring Program Resource Use
@subtitle The GNU @code{time} Command
@subtitle Edition @value{EDITION}, for version @value{VERSION}
@subtitle @value{UPDATED}
@author David MacKenzie
@page
@vskip 0pt plus 1filll
Copyright @copyright{} 1991, 92, 93, 96 Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
are preserved on all copies.
Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided that the entire
resulting derived work is distributed under the terms of a permission
notice identical to this one.
Permission is granted to copy and distribute translations of this manual
into another language, under the above conditions for modified versions,
except that this permission notice may be stated in a translation approved
by the Foundation.
@end titlepage
@node Top, , (dir), (dir)
@ifinfo
This file documents the the GNU @code{time} command for running programs
and summarizing the system resources they use.
This is edition @value{EDITION}, for version @value{VERSION}.
@end ifinfo
@menu
* Resource Measurement:: Measuring program resource use.
--- The Detailed Node Listing ---
Measuring Program Resource Use
* Setting Format:: Selecting the information reported by @code{time}.
* Format String:: The information @code{time} can report.
* Redirecting:: Writing the information to a file.
* Examples:: Examples of using @code{time}.
* Accuracy:: Limitations on the accuracy of @code{time} output.
* Invoking time:: Summary of the options to the @code{time} command.
The Format String
* Time Resources::
* Memory Resources::
* I/O Resources::
* Command Info::
@end menu
@node Resource Measurement, , , Top
@chapter Measuring Program Resource Use
@findex time
@kindex time
@pindex time
@pindex measurement
The @code{time} command runs another program, then displays information
about the resources used by that program, collected by the system while
the program was running. You can select which information is reported
and the format in which it is shown (@pxref{Setting Format}), or have
@code{time} save the information in a file instead of displaying it on the
screen (@pxref{Redirecting}).
The resources that @code{time} can report on fall into the general
categories of time, memory, and I/O and IPC calls. Some systems do not
provide much information about program resource use; @code{time}
reports unavailable information as zero values (@pxref{Accuracy}).
The format of the @code{time} command is:
@example
time @r{[}option@dots{}@r{]} @var{command} @r{[}@var{arg}@dots{}@r{]}
@end example
@kindex resources
@code{time} runs the program @var{command}, with any given arguments
@var{arg}@dots{}. When @var{command} finishes, @code{time} displays
information about resources used by @var{command}.
Here is an example of using @code{time} to measure the time and other
resources used by running the program @code{grep}:
@example
eg$ time grep nobody /etc/aliases
nobody:/dev/null
etc-files:nobody
misc-group:nobody
0.07user 0.50system 0:06.69elapsed 8%CPU (0avgtext+489avgdata 324maxresident)k
46inputs+7outputs (43major+251minor)pagefaults 0swaps
@end example
Mail suggestions and bug reports for GNU @code{time} to
@code{bug-gnu-utils@@prep.ai.mit.edu}. Please include the version of
@code{time}, which you can get by running @samp{time --version}, and the
operating system and C compiler you used.
@menu
* Setting Format:: Selecting the information reported by @code{time}.
* Format String:: The information @code{time} can report.
* Redirecting:: Writing the information to a file.
* Examples:: Examples of using @code{time}.
* Accuracy:: Limitations on the accuracy of @code{time} output.
* Invoking time:: Summary of the options to the @code{time} command.
@end menu
@node Setting Format
@section Setting the Output Format
@code{time} uses a @dfn{format string} to determine which information to
display about the resources used by the command it runs. @xref{Format
String}, for the interpretation of the format string contents.
You can specify a format string with the command line options listed
below. If no format is specified on the command line, but the
@code{TIME} environment variable is set, its value is used as the format
string. Otherwise, the default format built into @code{time} is used:
@example
%Uuser %Ssystem %Eelapsed %PCPU (%Xtext+%Ddata %Mmax)k
%Iinputs+%Ooutputs (%Fmajor+%Rminor)pagefaults %Wswaps
@end example
The command line options to set the format are:
@table @code
@item -f @var{format}
@itemx --format=@var{format}
Use @var{format} as the format string.
@item -p
@itemx --portability
Use the following format string, for conformance with POSIX standard
1003.2:
@example
real %e
user %U
sys %S
@end example
@item -q
@itemx --quiet
Suppress non-zero error code from the executed program.
@item -v
@itemx --verbose
@cindex format
Use the built-in verbose format, which displays each available piece of
information on the program's resource use on its own line, with an
English description of its meaning.
@end table
@node Format String
@section The Format String
@cindex format
@kindex resource
The @dfn{format string} controls the contents of the @code{time} output.
It consists of @dfn{resource specifiers} and @dfn{escapes}, interspersed
with plain text.
A backslash introduces an @dfn{escape}, which is translated
into a single printing character upon output. The valid escapes are
listed below. An invalid escape is output as a question mark followed
by a backslash.
@table @code
@item \t
a tab character
@item \n
a newline
@item \\
a literal backslash
@end table
@code{time} always prints a newline after printing the resource use
information, so normally format strings do not end with a newline
character (or @samp{\n}).
A resource specifier consists of a percent sign followed by another
character. An invalid resource specifier is output as a question mark
followed by the invalid character. Use @samp{%%} to output a literal
percent sign.
The resource specifiers, which are a superset of those recognized by the
@code{tcsh} builtin @code{time} command, are listed below. Not all
resources are measured by all versions of Unix, so some of the values
might be reported as zero (@pxref{Accuracy}).
@menu
* Time Resources::
* Memory Resources::
* I/O Resources::
* Command Info::
@end menu
@node Time Resources
@subsection Time Resources
@table @code
@item E
Elapsed real (wall clock) time used by the process, in
[hours:]minutes:seconds.
@item e
Elapsed real (wall clock) time used by the process, in
seconds.
@item S
Total number of CPU-seconds used by the system on behalf of the process
(in kernel mode), in seconds.
@item U
Total number of CPU-seconds that the process used directly (in user
mode), in seconds.
@item P
Percentage of the CPU that this job got. This is just user + system
times divied by the total running time.
@end table
@node Memory Resources
@subsection Memory Resources
@table @code
@item M
Maximum resident set size of the process during its lifetime, in
Kilobytes.
@item t
Average resident set size of the process, in Kilobytes.
@item K
Average total (data+stack+text) memory use of the process, in Kilobytes.
@item D
Average size of the process's unshared data area, in Kilobytes.
@item p
Average size of the process's unshared stack, in Kilobytes.
@item X
Average size of the process's shared text, in Kilobytes.
@item Z
System's page size, in bytes. This is a per-system constant, but
varies between systems.
@end table
@node I/O Resources
@subsection I/O Resources
@table @code
@item F
Number of major, or I/O-requiring, page faults that occurred while the
process was running. These are faults where the page has actually
migrated out of primary memory.
@item R
Number of minor, or recoverable, page faults. These are pages that are
not valid (so they fault) but which have not yet been claimed by other
virtual pages. Thus the data in the page is still valid but the system
tables must be updated.
@item W
Number of times the process was swapped out of main memory.
@item c
Number of times the process was context-switched involuntarily (because
the time slice expired).
@item w
Number of times that the program was context-switched voluntarily, for
instance while waiting for an I/O operation to complete.
@item I
Number of file system inputs by the process.
@item O
Number of file system outputs by the process.
@item r
Number of socket messages received by the process.
@item s
Number of socket messages sent by the process.
@item k
Number of signals delivered to the process.
@end table
@node Command Info
@subsection Command Info
@table @code
@item C
Name and command line arguments of the command being timed.
@item x
Exit status of the command.
@end table
@node Redirecting
@section Redirecting Output
By default, @code{time} writes the resource use statistics to the
standard error stream. The options below make it write the statistics
to a file instead. Doing this can be useful if the program you're
running writes to the standard error or you're running @code{time}
noninteractively or in the background.
@table @code
@item -o @var{file}
@itemx --output=@var{file}
Write the resource use statistics to @var{file}. By default, this
@emph{overwrites} the file, destroying the file's previous contents.
@item -a
@itemx --append
@emph{Append} the resource use information to the output file instead
of overwriting it. This option is only useful with the @samp{-o} or
@samp{--output} option.
@end table
@node Examples
@section Examples
@noindent
Run the command @samp{wc /etc/hosts} and show the default information:
@example
eg$ time wc /etc/hosts
35 111 1134 /etc/hosts
0.00user 0.01system 0:00.04elapsed 25%CPU (0avgtext+0avgdata 0maxresident)k
1inputs+1outputs (0major+0minor)pagefaults 0swaps
@end example
@noindent
Run the command @samp{ls -Fs} and show just the user, system, and
wall-clock time:
@example
eg$ time -f "\t%E real,\t%U user,\t%S sys" ls -Fs
total 16
1 account/ 1 db/ 1 mail/ 1 run/
1 backups/ 1 emacs/ 1 msgs/ 1 rwho/
1 crash/ 1 games/ 1 preserve/ 1 spool/
1 cron/ 1 log/ 1 quotas/ 1 tmp/
0:00.03 real, 0.00 user, 0.01 sys
@end example
@noindent
Edit the file @file{.bashrc} and have @code{time} append the elapsed time
and number of signals to the file @file{log}, reading the format string
from the environment variable @code{TIME}:
@example
eg$ export TIME="\t%E,\t%k" #@r{ If using bash or ksh}
eg$ setenv TIME "\t%E,\t%k" #@r{ If using csh or tcsh}
eg$ time -a -o log emacs .bashrc
eg$ cat log
0:16.55, 726
@end example
@noindent
Run the command @samp{sleep 4} and show all of the information about it
verbosely:
@example
eg$ time -v sleep 4
Command being timed: "sleep 4"
User time (seconds): 0.00
System time (seconds): 0.05
Percent of CPU this job got: 1%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:04.26
Average shared text size (kbytes): 36
Average unshared data size (kbytes): 24
Average stack size (kbytes): 0
Average total size (kbytes): 60
Maximum resident set size (kbytes): 32
Average resident set size (kbytes): 24
Major (requiring I/O) page faults: 3
Minor (reclaiming a frame) page faults: 0
Voluntary context switches: 11
Involuntary context switches: 0
Swaps: 0
File system inputs: 3
File system outputs: 1
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 1
Page size (bytes): 4096
Exit status: 0
@end example
@node Accuracy
@section Accuracy
@kindex error (in measurement)
The elapsed time is not collected atomically with the execution of the
program; as a result, in bizarre circumstances (if the @code{time}
command gets stopped or swapped out in between when the program being
timed exits and when @code{time} calculates how long it took to run), it
could be much larger than the actual execution time.
When the running time of a command is very nearly zero, some values
(e.g., the percentage of CPU used) may be reported as either zero (which
is wrong) or a question mark.
Most information shown by @code{time} is derived from the @code{wait3}
system call. The numbers are only as good as those returned by
@code{wait3}. Many systems do not measure all of the resources that
@code{time} can report on; those resources are reported as zero. The
systems that measure most or all of the resources are based on 4.2 or
4.3BSD. Later BSD releases use different memory management code that
measures fewer resources.
On systems that do not have a @code{wait3} call that returns status
information, the @code{times} system call is used instead. It provides
much less information than @code{wait3}, so on those systems @code{time}
reports most of the resources as zero.
The @samp{%I} and @samp{%O} values are allegedly only ``real'' input
and output and do not include those supplied by caching devices. The
meaning of ``real'' I/O reported by @samp{%I} and @samp{%O} may be
muddled for workstations, especially diskless ones.
@node Invoking time
@section Running the @code{time} Command
The format of the @code{time} command is:
@example
time @r{[}option@dots{}@r{]} @var{command} @r{[}@var{arg}@dots{}@r{]}
@end example
@kindex resources
@code{time} runs the program @var{command}, with any given arguments
@var{arg}@dots{}. When @var{command} finishes, @code{time} displays
information about resources used by @var{command} (on the standard error
output, by default). If @var{command} exits with non-zero status or is
terminated by a signal, @code{time} displays a warning message and the
exit status or signal number.
Options to @code{time} must appear on the command line before
@var{command}. Anything on the command line after @var{command} is
passed as arguments to @var{command}.
@table @code
@item -o @var{file}
@itemx --output=@var{file}
Write the resource use statistics to @var{file}.
@item -a
@itemx --append
@emph{Append} the resource use information to the output file instead
of overwriting it.
@item -f @var{format}
@itemx --format=@var{format}
Use @var{format} as the format string.
@item --help
Print a summary of the command line options to @code{time} and exit.
@item -p
@itemx --portability
Use the POSIX format.
@item -v
@itemx --verbose
@cindex format
Use the built-in verbose format.
@item -V
@itemx --version
@cindex version number
Print the version number of @code{time} and exit.
@end table
@contents
@bye
|