
コマンドtime -v
出力% CPU 使用率Linuxで与えられたコマンドについて。 OS Xでこれを行う方法は? Linux/OS X の違いを図に示します。ここ。短期実行プログラムの全実行期間中にマルチコア使用率を測定したいと思います。top
特定の時点で測定/平均を計算するため、機能しない可能性があります。
答え1
sysstat パッケージをインストールし、sar コマンドを使用できます。 (https://tipstricks.itmatrix.eu/installing-sar-monitoring-tools/)
すべてのCPUのCPU使用量(sar -u)
これは、すべてのCPUの累積リアルタイムCPU使用率を提供します。 「1 3」は1秒ごとに3回報告されます。 CPU負荷を確認するには、最後のフィールド「%idle」に集中する可能性が高くなります。
$ sar -u 1 3
Linux 2.6.18-194.el5PAE (dev-db) 03/26/2011 _i686_ (8 CPU)
01:27:32 PM CPU %user %nice %system %iowait %steal %idle
01:27:33 PM all 0.00 0.00 0.00 0.00 0.00 100.00
01:27:34 PM all 0.25 0.00 0.25 0.00 0.00 99.50
01:27:35 PM all 0.75 0.00 0.25 0.00 0.00 99.00
Average: all 0.33 0.00 0.17 0.00 0.00 99.50
以下はいくつかの変更です。
sar -u Displays CPU usage for the current day that was collected until that point.
sar -u 1 3 Displays real time CPU usage every 1 second for 3 times.
sar -u ALL Same as “sar -u” but displays additional fields.
sar -u ALL 1 3 Same as “sar -u 1 3″ but displays additional fields.
sar -u -f /var/log/sa/sa10 Displays CPU usage for the 10day of the month from the sa10 file.
シングル CPU またはコアの CPU 使用量 (sar -P)
コンピュータに4つのコアがあり、各コアが何をしているのかを確認するには、次の手順を実行します。
「-P ALL」は、すべての個々のコアの統計を表示する必要があることを意味します。
以下の例では、「CPU」列の下の0、1、2、3は対応するCPUコア番号を示しています。
$ sar -P ALL 1 1
Linux 2.6.18-194.el5PAE (dev-db) 03/26/2011 _i686_ (8 CPU)
01:34:12 PM CPU %user %nice %system %iowait %steal %idle
01:34:13 PM all 11.69 0.00 4.71 0.69 0.00 82.90
01:34:13 PM 0 35.00 0.00 6.00 0.00 0.00 59.00
01:34:13 PM 1 22.00 0.00 5.00 0.00 0.00 73.00
01:34:13 PM 2 3.00 0.00 1.00 0.00 0.00 96.00
01:34:13 PM 3 0.00 0.00 0.00 0.00 0.00 100.00
「-P 1」は、2番目のコアの統計のみを表示することを意味します。 (コア番号は0から始まります。)
$ sar -P 1 1 1
Linux 2.6.18-194.el5PAE (dev-db) 03/26/2011 _i686_ (8 CPU)
01:36:25 PM CPU %user %nice %system %iowait %steal %idle
01:36:26 PM 1 8.08 0.00 2.02 1.01 0.00 88.89
以下はいくつかの変更です。
sar -P ALL Displays CPU usage broken down by all cores for the current day.
sar -P ALL 1 3 Displays real time CPU usage for ALL cores every 1 second for 3 times (broken down by all cores).
sar -P 1 Displays CPU usage for core number 1 for the current day.
sar -P 1 1 3 Displays real time CPU usage for core number 1, every 1 second for 3 times.
sar -P ALL -f /var/log/sa/sa10 Displays CPU usage broken down by all cores for the 10day day of the month from sa10 file.
答え2
gnuコマンドを実際に置き換えることができるコマンドはないようですtime
。それで結局これを設置することになりました。 OS Xでは、homebrew:を使用してgnu-timeをインストールできますbrew install gnu-time
。その後、特定の命令のCPU使用率を測定するために使用できますgtime <command>
。テストの結果、私のプログラムは実際に同時に実行されることがわかりました1.73user 0.13system 0:01.61elapsed 115%CPU
。