performance.getEntriesByType()
getEntriesByType()
メソッドは、指定された型の PerformanceEntry
オブジェクトのリストを返します。リストのメンバ (エントリ) は、明示的な時点でパフォーマンスマークまたはメジャーを作成することで (たとえば mark()
メソッドを呼び出すことで) 作成できます。
注:
この機能は Web Worker 内で利用可能です。構文
entries = window.performance.getEntriesByType(type);
引数
- type
- "
mark
" など、取得するエントリの種類。有効なエントリタイプはPerformanceEntry.entryType
に一覧表示されています。
戻り値
- entries
- 指定された
type
を持つPerformanceEntry
オブジェクトのリスト。項目はエントリ 'startTime
に基づいて時系列に並んでいます。指定されたtype
を持つオブジェクトがない場合、または引数が指定されていない場合は、空のリストが返されます。
例
function usePerformanceEntryMethods() {
log("PerformanceEntry tests ...");
if (performance.mark === undefined) {
log("... performance.mark Not supported");
return;
}
// Create some performance entries via the mark() method
performance.mark("Begin");
doWork(50000);
performance.mark("End");
performance.mark("Begin");
doWork(100000);
performance.mark("End");
doWork(200000);
performance.mark("End");
// Use getEntries() to iterate through the each entry
var p = performance.getEntries();
for (var i=0; i < p.length; i++) {
log("Entry[" + i + "]");
checkPerformanceEntry(p[i]);
}
// Use getEntries(name, entryType) to get specific entries
p = performance.getEntries({name : "Begin", entryType: "mark"});
for (var i=0; i < p.length; i++) {
log("Begin[" + i + "]");
checkPerformanceEntry(p[i]);
}
// Use getEntriesByType() to get all "mark" entries
p = performance.getEntriesByType("mark");
for (var i=0; i < p.length; i++) {
log ("Mark only entry[" + i + "]: name = " + p[i].name +
"; startTime = " + p[i].startTime +
"; duration = " + p[i].duration);
}
// Use getEntriesByName() to get all "mark" entries named "Begin"
p = performance.getEntriesByName("Begin", "mark");
for (var i=0; i < p.length; i++) {
log ("Mark and Begin entry[" + i + "]: name = " + p[i].name +
"; startTime = " + p[i].startTime +
"; duration = " + p[i].duration);
}
}
仕様
仕様書 | ステータス | コメント |
---|---|---|
Performance Timeline Level 2 getEntriesByType() の定義 |
勧告候補 | |
Performance Timeline getEntriesByType() の定義 |
勧告 | 初期定義 |
ブラウザの互換性
BCD tables only load in the browser