このセクションでは、Linux perf を最初に認識するためのくさびとして、主に Linux perf について、それが何であるか、何に使用できるか、および使用する観点から簡単に紹介します。
@作者: Mercury_Lc
Linux perf (パフォーマンス プロファイラー) は、開発者がLinux システムやアプリケーションのパフォーマンスの問題を診断、調整、監視するのに役立つ強力なパフォーマンス分析ツールです。システム内のさまざまな現象を分析するために、ハードウェア パフォーマンス カウンター (ハードウェア パフォーマンス カウンター)、トレース ポイント、およびソフトウェア測定に基づくさまざまなデータ収集方法を実装します。perf ツールは、主に perf_event サブシステムを通じて Linux カーネルに統合されています。
パフォーマンス カウンターは、実行された命令、キャッシュ ミス、予測ミスなどのハードウェア イベントをカウントする CPU ハードウェア レジスタです。これらは、アプリケーションを分析して動的な制御フローを追跡し、ホット スポットを特定するための基礎を形成します。perf は、ハードウェア固有の機能に対する豊富な汎用抽象化を提供します。
一般に、perf は、CPU、メモリ、I/O、ロックなどのリソースを含む、さまざまなレベルでシステム パフォーマンスを分析できます。perf は、アプリケーションのプロファイリング、ハードウェア イベント (キャッシュ ミス、分岐予測ミスなど) とシステム コールの表示、カーネル イベントとユーザー空間イベントのトレース、パフォーマンス レポートの生成など、さまざまなタスクに使用できます。
perf は、さまざまなパフォーマンス分析のニーズを満たすために、次のようなさまざまなサブコマンドを提供します。
● perf stat: 実行中にパフォーマンス カウンタ統計を収集して表示します。
● perf レコード: イベント サンプル情報を記録します。
● perf レポート: perf レコードに記録されたデータに基づいてパフォーマンス レポートを生成します。
● perf annotate: バイナリ ファイルに注釈を付けて分析します。
● perf top: システム アクティビティとそのパフォーマンス カウンター データのリアルタイム表示。
● perf トレース: カーネルおよびユーザー空間のトレース パフォーマンス データを収集、解析、表示、または処理します。
● perf bench: さまざまな組み込みベンチマークを実行します。
上記は、perf をインストールした後、perf -h によって取得できます。
[root ~]# perf -h
usage: perf [--version] [--help] [OPTIONS] COMMAND [ARGS]
The most commonly used perf commands are:
annotate Read perf.data (created by perf record) and display annotated code
archive Create archive with object files with build-ids found in perf.data file
bench General framework for benchmark suites
buildid-cache Manage build-id cache.
buildid-list List the buildids in a perf.data file
c2c Shared Data C2C/HITM Analyzer.
config Get and set variables in a configuration file.
data Data file related processing
diff Read perf.data files and display the differential profile
evlist List the event names in a perf.data file
ftrace simple wrapper for kernel's ftrace functionality
inject Filter to augment the events stream with additional information
kallsyms Searches running kernel for symbols
kmem Tool to trace/measure kernel memory properties
kvm Tool to trace/measure kvm guest os
list List all symbolic event types
lock Analyze lock events
mem Profile memory accesses
record Run a command and record its profile into perf.data
report Read perf.data (created by perf record) and display the profile
sched Tool to trace/measure scheduler properties (latencies)
script Read perf.data (created by perf record) and display trace output
stat Run a command and gather performance counter statistics
test Runs sanity tests.
timechart Tool to visualize total system behavior during a workload
top System profiling tool.
version display the version of perf binary
probe Define new dynamic tracepoints
trace strace inspired tool
See 'perf help COMMAND' for more information on a specific command.
perf を使用する前に、システム カーネルが perf_event サブシステムをサポートしていることを確認する必要があることに注意してください。perf コマンドを使用する場合は、通常、root 権限を持っているか、特定のユーザー グループ (perf-users など) に属している必要があります。
つまり、Linux perf は、開発者がパフォーマンスの問題を特定し、システム パフォーマンスを最適化し、システムとアプリケーションの動作効率を向上させるのに役立つ強力なパフォーマンス分析ツールです。
参照
https://perf.wiki.kernel.org/index.php/Main_Page