
このコマンドはどのストリームを使用しますかperf
? ?キャプチャしようとしました。
(perf stat -x, -ecache-misses ./a.out>/dev/null) 2> results
次のようなhttps://stackoverflow.com/q/13232889/50305、しかし役に立たない。なぜ入力をキャプチャできないのですか…魚が脱出するようにしておくようです!
答え1
以前のバージョンのパフォーマンス〜2.6.x
パフォーマンスバージョン:2.6.35.14-106を使用しています。。
すべての出力をキャプチャ
Fedora 14システムにスイッチがないため、-x
これが実際の問題であるかどうかはわかりません。後で最新のUbuntu 12.10システムを見てみましょうが、これは私にとって効果的でした。
$ (perf stat -ecache-misses ls ) > stat.log 2>&1
$
$ more stat.log
maccheck.txt
sample.txt
stat.log
Performance counter stats for 'ls':
13209 cache-misses
0.018231264 seconds time elapsed
私はperfの出力だけが欲しい。
これを試みると、出力がls
リダイレクトされます/dev/null
。出力形式perf
(STDERRとSTDOUT)はファイルに移動されますstat.log
。
$ (perf stat -ecache-misses ls > /dev/null ) > stat.log 2>&1
[saml@grinchy 89576]$ more stat.log
Performance counter stats for 'ls':
12949 cache-misses
0.022831281 seconds time elapsed
最新バージョンの perf 3.x+
私が使用するパフォーマンスバージョン:3.5.7
perfの出力のみをキャプチャ
最新バージョンには、perf
メッセージが送信される場所を制御するための専用オプションがあります。-o|--output
このオプションを使用してファイルに送信することを選択できます。出力をキャプチャするには、このスイッチにファイル名を指定するだけです。
-o file, --output file
Print the output into the designated file.
別のアプローチは、出力を代替ファイル記述子にリダイレクトすることです3
。ストリーミングする前に、この代替ファイルハンドルを指定するだけです。
--log-fd
Log output to fd, instead of stderr. Complementary to --output, and
mutually exclusive with it. --append may be used here. Examples:
3>results perf stat --log-fd 3 — $cmd
-or-
3>>results perf stat --log-fd 3 --append — $cmd
perf
したがって、コマンドの出力を収集するには、ls
次のコマンドを使用できます。
$ 3>results.log perf stat --log-fd 3 ls > /dev/null
$
$ more results.log
Performance counter stats for 'ls':
2.498964 task-clock # 0.806 CPUs utilized
0 context-switches # 0.000 K/sec
0 CPU-migrations # 0.000 K/sec
258 page-faults # 0.103 M/sec
880,752 cycles # 0.352 GHz
597,809 stalled-cycles-frontend # 67.87% frontend cycles idle
652,087 stalled-cycles-backend # 74.04% backend cycles idle
1,261,424 instructions # 1.43 insns per cycle
# 0.52 stalled cycles per insn [55.31%]
<not counted> branches
<not counted> branch-misses
0.003102139 seconds time elapsed
そのバージョンを使用している--append
場合は、複数のコマンドの内容が同じログファイルに追加されますresults.log
。
設置実績
インストールは非常に簡単です。
Fedoraの帽子
$ yum install perf
Ubuntu/Debian
$ apt-get install linux-tool-common linux-tools
引用する
答え2
これはついに私のために働いた。
3>results perf stat -x, -ecache-misses --log-fd 3 --append -- ./a.out
によるとman perf-stat
、log-fd
フラグ。