contentTracing
Chromium からトレースデータを収集して、パフォーマンスのボトルネックや遅い操作を見つけます。
プロセス: メイン
このモジュールにはウェブインターフェイスが付属していません。 Traces are recorded in the Perfetto protobuf format; to view them, open them in the Perfetto UI.
[!NOTE] app モジュールの
readyイベントが発生するまではこのモジュールを使用してはいけません。
const { app, contentTracing } = require('electron')
app.whenReady().then(async () => {
await contentTracing.startRecording({
included_categories: ['*']
})
console.log('Tracing started')
await new Promise((resolve) => setTimeout(resolve, 5000))
const path = await contentTracing.stopRecording()
console.log('Tracing data recorded to ' + path)
})
メソッド
contentTracing モジュールには以下のメソッドがあります。
contentTracing.getCategories()
History
| Version(s) | Changes |
|---|---|
None | This method now returns a Promise instead of using a callback function. |
戻り値 Promise<string[]> - すべての子プロセスが getCategories リクエストを受諾したとき、そのカテゴリグループの配列で解決されます。
カテゴリグループの集合を取得します。新しいコードパスに到達したら、カテゴリグループは変更できます。組み込みのトレースカテゴリのリスト もご参照ください。
注意: Electron は
"electron"という非デフォルトのトレースカテゴリを追加します。このカテゴリは、Electron 固有のトレースイベントのキャプチャに使用できます。
contentTracing.startRecording(options)
History
| Version(s) | Changes |
|---|---|
None | The |
None | This function now returns a callback |
None | Added the |
戻り値 Promise<void> - すべての子プロセスが startRecording リクエストを受諾したときに解決されます。
すべてのプロセスで記録を開始します。
EnableRecordingリクエストを受信するとすぐにローカルでは即時、子プロセスでは非同期的に記録が開始されます。
記録を実行中の場合、promise はすぐに解決されます。一度に一つまでしかトレース操作は処理されません。 If options.nativeHeapProfiling is set while a recording is already running, the promise is rejected instead, since the already-running recording's options can't be changed to turn on heap profiling.
contentTracing.stopRecording([resultFilePath])
History
| Version(s) | Changes |
|---|---|
None | This method now returns a Promise instead of using a callback function. |
None | The |
None | Trace data is now written in the Perfetto protobuf format. The legacy JSON format is no longer supported. |
resultFilePathstring (任意)
戻り値 Promise<string> - すべての子プロセスが stopRecording リクエストを確認すると、トレースデータを格納したファイルへのパスで解決します
すべてのプロセスで記録を停止します。
子プロセスは、大抵、トレースデータをキャッシュし、滅多に書き出さず、メインプロセスにトレースデータを送り返すだけです。トレースデータをIPC越しに送信するのは高負荷な操作であるため、これはトレースのランタイムオーバーヘッドを最小化するのに役立ちます。そのため、トレースを終了するために、Chromium はすべての子プロセスに保留中のトレースデータをフラッシュするよう非同期に要求します。
トレースデータは resultFilePath へと書き込まれます。 resultFilePath が空であるか提供されていない場合、トレースデータは一時ファイルに書き込まれ、そのパスは promise で返されます。
Trace data is written in the Perfetto protobuf format.
Heap profiling samples record instruction addresses and module build IDs rather than function names. To symbolize them, use the symbols published for the matching Electron release with Chromium's symbolize_trace tool.
contentTracing.getTraceBufferUsage()
History
| Version(s) | Changes |
|---|---|
None | This method now returns a Promise instead of using a callback function. |
戻り値 Promise<Object> - トレースバッファの最大使用率の value と percentage を含むオブジェクトで実行されます。
valuenumberpercentagenumber
完全な形式のパーセンテージとして、トレースバッファのプロセス間の最大使用率を取得します。