![他のプログラムの実行中にプログラムの実際の実行時間を記録する方法は? [コピー]](https://linux33.com/image/52792/%E4%BB%96%E3%81%AE%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%A0%E3%81%AE%E5%AE%9F%E8%A1%8C%E4%B8%AD%E3%81%AB%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%A0%E3%81%AE%E5%AE%9F%E9%9A%9B%E3%81%AE%E5%AE%9F%E8%A1%8C%E6%99%82%E9%96%93%E3%82%92%E8%A8%98%E9%8C%B2%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95%E3%81%AF%EF%BC%9F%20%5B%E3%82%B3%E3%83%94%E3%83%BC%5D.png)
他のプログラムの実行中にLinuxでOpenMPプログラムの実際の実行時間を測定するときに実際の実行時間を取得するにはどうすればよいですか?
答え1
呼ぶtime myprogram
。
壁時計時間、ユーザー時間、およびシステム時間を報告します。ユーザー時間は、プロセスがコンピューティングに費やす時間です。プログラムがマルチスレッドであり、システムにマルチプロセッサがある場合、すべてのプロセッサに費やされた時間が合計されます(したがって、十分に並列プログラムの場合、ユーザー時間がウォールクロック時間より長くなる可能性があります)。システム時間は、カーネルで入力/出力を実行するのにかかる時間です。
これは、「実行中の他のプログラムの干渉を計算しない時間」に非常に近いです。同時プログラムがない場合、プログラムにかかる実際の時間を知る唯一の方法は、他の同時プログラムなしでプログラムを実行することです。
答え2
入手できるのか背景知識なのかによって、以下で見つけることができるのでpid
難しくありません。ps
/proc/self
$!
utime %lu (14) Amount of time that this process has been
scheduled in user mode, measured in clock ticks
(divide by sysconf(_SC_CLK_TCK)). This includes
guest time, guest_time (time spent running a
virtual CPU, see below), so that applications that
are not aware of the guest time field do not lose
that time from their calculations.
stime %lu (15) Amount of time that this process has been
scheduled in kernel mode, measured in clock ticks
(divide by sysconf(_SC_CLK_TCK)).
cutime %ld (16) Amount of time that this process's waited-for
children have been scheduled in user mode,
measured in clock ticks (divide by
sysconf(_SC_CLK_TCK)). (See also times(2).) This
includes guest time, cguest_time (time spent
running a virtual CPU, see below).
cstime %ld (17) Amount of time that this process's waited-for
children have been scheduled in kernel mode,
measured in clock ticks (divide by
sysconf(_SC_CLK_TCK)).
プロセスIDを取得するには、次のようにします。
prog ./and/args &
pid=$!
{ prog ./and/args & true ; } && ps -C prog
prog ./and/args
CTRL-Z
jobs -l ; fg %1
方法はさまざまです。