TIME(1) Linux User’s Manual TIME(1) 名前 time - コマンドの時間計測やリソース使用量を表示する 書式 time [options] command [arguments...] 説明 time コマンドは、指定されたプログラム command を渡された引き数で実行す る。 command が終了すると、 time はこのプログラムの実行時間の統計情報に つ いてのメッセージを標準エラー出力に出力する。表示される統計情報は以下 の三つから構成される: (i) 起動から終了までに経過した実時間 (real time) 、 (ii) ユ ーザ CPU 時間 (times(2) が返す struct tms の tms_utime と tms_cutime の値の合計)、 (iii) システム CPU 時 間 (times(2) が 返 す struct tms の tms_stime と tms_cstime の値の合計)。 (bash(1) などの) いくつかのシェルには、ここで説明するコマンドよりも機能 が少ない、組み込みの time コマンドが存在する。組み込みではない実際の コ マ ンドを使用するためには、 (/usr/bin/time のような) コマンドのパス名を 指定する必要があるかもしれない。 オプション -p POSIX ロケールの場合、伝統的なフォーマットである "real %f\nuser %f\nsys %f\n" が使用される (各数字は秒単位)。 %f の出力での小数点以下の桁数 は 規定されていないが、クロック・ティック (clock tick) の精度を表す のに十分な桁数となり、少なくとも一桁は存在する。 終了ステータス command が起動された場合は、 command の終了ステータスが終了ステータスと な る 。 command が見つからなかった場合は終了ステータスは 127 で、 com- mand が見つかったが起動できなかった場合は 126 となる。これ以外で何か エ ラ ーがあった場合は、終了ステータスは 0 以外の前記以外の値 (1-125) の何 かになる。 環境変数 環境変数 LANG, LC_ALL, LC_CTYPE, LC_MESSAGES, LC_NUMERIC, NLSPATH, PATH が使用される。 PATH は command を探すのに使われる。それ以外は出力文字や 書式に使用される。 GNU バージョン 以下は GNU 1.7 バージョンの time の説明である。コマンド名と は 裏 腹 に 、GNU バージョンでは有益な情報がたくさん出力される。使用時間だけでなく 、 (取得できる場合には) メモリや I/O、IPC 呼び出しなどの他のリソース に 関 する情報も出力される。出力はフォーマット文字列を使って整形され、フォ ーマット文字列は -f オプションか環境変数 TIME で指定できる。 デフォルトのフォーマット文字列は以下の通り。 %Uuser %Ssystem %Eelapsed %PCPU (%Xtext+%Ddata %Mmax)k %Iinputs+%Ooutputs (%Fmajor+%Rminor)pagefaults %Wswaps -p オプションが指定された場合には、(他と互換性のある) 出力フォーマッ ト が使用される。 real %e user %U sys %S フォーマット文字列 フ ォーマットはよくある printf 形式で解釈される。通常の文字はそのままコ ピーされ、タブ、改行 (newline)、バックスラッシュはそれぞれ \t, \n, \\ でエスケープされる。パーセント記号は %% で表現され、それ以外の % は変換 を示す。末尾には必ず改行文字 (newline) が追加される。変換は以下の通りで ある。 tcsh(1) で使用される変換は全てサポートされている。 Time %E 経過した実時間 ([hours:]minutes:seconds の形式)。 %e (tcsh にはない) 経過した実時間 (秒単位)。 %S そのプロセスがカーネルモードで消費した CPU 時間の合計 (秒単位)。 %U そのプロセスがユーザモードで消費した CPU 時間の合計 (秒単位)。 %P このジョブが獲得した CPU の割り合い (パーセンテージ)。 (%U + %S) / %E で計算される。 Memory %M プロセス生存中のそのプロセスの resident set size の最大値。キロ バイト単位。 %t (tcsh にはない) そのプロセスの resident set size の平均値。キ ロ バイト単位。 %K そのプロセスのメモリ使用量の合計 (データ+スタック+テキスト) の平 均値。キロバイト単位。 %D そのプロセスの非共有データ領域の平均サイズ。キロバイト単位。 %p (tcsh にはない) そのプロセスの非共有スタック空間の平均サイズ。キ ロバイト単位。 %X そのプロセスの共有テキスト空間の平均サイズ。キロバイト単位。 %Z (tcsh にはない) システムのページサイズ (バイト単位)。この値はシ ステム毎に決まる定数だが、システムにより異なる。 %F プロセスの動作中に発生したメジャーページフォルトの回数。これは、 ディスクからページを読み込む必要があったページフォルトに関するも のである。 %R マイナーページフォールト、つまり回復可能なページフォルトの回数。 これは、そのページは有効でないが、まだ他の仮想ページに奪われてい なかったページに対するページフォルトに関するものである。 %W そのプロセスが主記憶からスワップアウトされた回数。 %c そのプロセスが (タイムスライスの経過により) 強制的にコンテキスト スイッチされた回数。 %w wait の回数、つまりそのプログラムが自発的にコンテキストスイッチ された回数。例えば、I/O 操作の完了を待っている間などが該当する。 I/O %I そのプロセスによるファイルシステムからの入力の回数。 %O そのプロセスによるファイルシステムへの出力の回数。 %r そのプロセスが受信したソケットメッセージ数。 %s そのプロセスが送信したソケットメッセージ数。 %k そのプロセスに配送されたシグナル数。 %C (tcsh にはない) time の対象となったコマンド名とコマンドライン引 き数。 %x (tcsh にはない) コマンドの終了ステータス。 GNU オプション -f FORMAT, --format=FORMAT 出力フォーマットを指定する。環境変数 TIME で指定されたフォーマッ トよりも優先される。 -p, --portability 他の time と互換性のある出力フォーマットを使用する。 -o FILE, --output=FILE 結果を stderr に送らず、指定されたファイルに書き込む。ファイルは 上書きされる。 -a, --append (-o と一緒に使用する。) ファイルを上書きせずに、結果をファイル末 尾に追加する。 -v, --verbose 非常に詳しい出力で、入手できる全ての情報を出力する。 GNU 標準オプション --help 使用方法に関するメッセージを標準出力に表示し、正常終了する。 -V, --version バージョン情報を標準出力に表示し、正常終了する。 -- オプションリストの末尾を示す。 バグ 全 てのリソースが Unix の全てのバージョンで計測されているわけではないの で、いくつかの値が 0 と報告される可能性がある。現在の出力項目のほとんど は 4.2BSD や 4.3BSD で取得可能なデータに基づいて選択されている。 GNU time バージョン 1.7 はまだローカライズされていない。そのため、POSIX の要件を実装していないことになる。 TIME という環境変数は名前の選択がまずい。 autoconf(1) や make(1) のよう な システムでは、使用するコマンドを上書きするのにそのコマンドの名前の環 境変数を使うのが珍しくない。 MORE や TIME のような名前を (プログラム の パ ス名の指定ではなく) プログラムへのオプションを指定するのに使うと、面 倒なことを引き起こす可能性が高い。 -o が追記ではなく上書きになっているのは残念なことだ (つまり -a オプショ ンがデフォルトになっているべきだろうということだ)。 GNU time に対する提案やバグレポートは bug-utils@prep.ai.mit.edu ま でメールを送ってほしい。その場合には time や OS、使用している C コン パイラのバージョンを記載してほしい。 time のバージョンは以下のコマン ド で取得できる。 time --version 関連項目 tcsh(1), times(2), wait3(2) 2008-11-14 TIME(1)
TIME(1) Linux User’s Manual TIME(1) NAME time - time a simple command or give resource usage SYNOPSIS time [options] command [arguments...] DESCRIPTION The time command runs the specified program command with the given arguments. When command finishes, time writes a message to standard error giving timing statistics about this program run. These statis- tics consist of (i) the elapsed real time between invocation and termi- nation, (ii) the user CPU time (the sum of the tms_utime and tms_cutime values in a struct tms as returned by times(2)), and (iii) the system CPU time (the sum of the tms_stime and tms_cstime values in a struct tms as returned by times(2)). Note: some shells (e.g., bash(1)) have a built-in time command that provides less functionality than the command described here. To access the real command, you may need to specify its pathname (something like /usr/bin/time). OPTIONS -p When in the POSIX locale, use the precise traditional format "real %f\nuser %f\nsys %f\n" (with numbers in seconds) where the number of decimals in the output for %f is unspecified but is sufficient to express the clock tick accuracy, and at least one. EXIT STATUS If command was invoked, the exit status is that of command. Otherwise it is 127 if command could not be found, 126 if it could be found but could not be invoked, and some other non-zero value (1-125) if some- thing else went wrong. ENVIRONMENT The variables LANG, LC_ALL, LC_CTYPE, LC_MESSAGES, LC_NUMERIC, NLSPATH, and PATH are used. The last one to search for command. The remaining ones for the text and formatting of the output. GNU VERSION Below a description of the GNU 1.7 version of time. Disregarding the name of the utility, GNU makes it output lots of useful information, not only about time used, but also on other resources like memory, I/O and IPC calls (where available). The output is formatted using a for- mat string that can be specified using the -f option or the TIME envi- ronment variable. The default format string is: %Uuser %Ssystem %Eelapsed %PCPU (%Xtext+%Ddata %Mmax)k %Iinputs+%Ooutputs (%Fmajor+%Rminor)pagefaults %Wswaps When the -p option is given the (portable) output format real %e user %U sys %S is used. The format string The format is interpreted in the usual printf-like way. Ordinary char- acters are directly copied, tab, newline and backslash are escaped using \t, \n and \\, a percent sign is represented by %%, and otherwise % indicates a conversion. The program time will always add a trailing newline itself. The conversions follow. All of those used by tcsh(1) are supported. Time %E Elapsed real time (in [hours:]minutes:seconds). %e (Not in tcsh.) Elapsed real time (in seconds). %S Total number of CPU-seconds that the process spent in kernel mode. %U Total number of CPU-seconds that the process spent in user mode. %P Percentage of the CPU that this job got, computed as (%U + %S) / %E. Memory %M Maximum resident set size of the process during its lifetime, in Kbytes. %t (Not in tcsh.) Average resident set size of the process, in Kbytes. %K Average total (data+stack+text) memory use of the process, in Kbytes. %D Average size of the process’s unshared data area, in Kbytes. %p (Not in tcsh.) Average size of the process’s unshared stack space, in Kbytes. %X Average size of the process’s shared text space, in Kbytes. %Z (Not in tcsh.) System’s page size, in bytes. This is a per-sys- tem constant, but varies between systems. %F Number of major page faults that occurred while the process was running. These are faults where the page has to be read in from disk. %R Number of minor, or recoverable, page faults. These are faults for pages that are not valid 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. %W Number of times the process was swapped out of main memory. %c Number of times the process was context-switched involuntarily (because the time slice expired). %w Number of waits: times that the program was context-switched voluntarily, for instance while waiting for an I/O operation to complete. I/O %I Number of file system inputs by the process. %O Number of file system outputs by the process. %r Number of socket messages received by the process. %s Number of socket messages sent by the process. %k Number of signals delivered to the process. %C (Not in tcsh.) Name and command-line arguments of the command being timed. %x (Not in tcsh.) Exit status of the command. GNU Options -f FORMAT, --format=FORMAT Specify output format, possibly overriding the format specified in the environment variable TIME. -p, --portability Use the portable output format. -o FILE, --output=FILE Do not send the results to stderr, but overwrite the specified file. -a, --append (Used together with -o.) Do not overwrite but append. -v, --verbose Give very verbose output about all the program knows about. GNU Standard Options --help Print a usage message on standard output and exit successfully. -V, --version Print version information on standard output, then exit success- fully. -- Terminate option list. BUGS Not all resources are measured by all versions of Unix, so some of the values might be reported as zero. The present selection was mostly inspired by the data provided by 4.2 or 4.3BSD. GNU time version 1.7 is not yet localized. Thus, it does not implement the POSIX requirements. The environment variable TIME was badly chosen. It is not unusual for systems like autoconf(1) or make(1) to use environment variables with the name of a utility to override the utility to be used. Uses like MORE or TIME for options to programs (instead of program pathnames) tend to lead to difficulties. It seems unfortunate that -o overwrites instead of appends. (That is, the -a option should be the default.) Mail suggestions and bug reports for GNU time to bug-utils@prep.ai.mit.edu Please include the version of time, which you can get by running time --version and the operating system and C compiler you used. SEE ALSO tcsh(1), times(2), wait3(2) COLOPHON This page is part of release 3.22 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. 2008-11-14 TIME(1)
Copyright(C) linux-cmd.com All Rights Reserved. Author Takayuki Yukawa