performance.getEntriesByName()
getEntriesByName()
メソッドは、指定された名前と種別の PerformanceEntry
オブジェクトのリストを返します。リストのメンバー(エントリー)は、明示的な時点でパフォーマンスマークまたはメジャーを作成することで(たとえば mark()
メソッドを呼び出すことで)作成できます。
注: この機能は Web Worker 内で利用可能です
構文
js
entries = window.performance.getEntriesByName(name, type);
引数
- name
-
取得するエントリーの名前
- type 省略可
-
"
mark
" など、取得するエントリーの種類。有効なエントリー種別の一覧はPerformanceEntry.entryType
にあります。
返値
- entries
-
指定された
name
とtype
を持つPerformanceEntry
オブジェクトのリスト。type
引数が指定されていない場合は、返されるエントリーを決定するために名前だけが使用されます。項目はエントリー 'startTime
に基づいて時系列に並んでいます。指定された基準を満たすオブジェクトがない場合は、空のリストが返されます。
例
js
function use_PerformanceEntry_methods() {
log("PerformanceEntry tests ...");
if (performance.mark === undefined) {
log("... performance.mark Not supported");
return;
}
// Create some performance entries via the mark() method
performance.mark("Begin");
do_work(50000);
performance.mark("End");
performance.mark("Begin");
do_work(100000);
performance.mark("End");
do_work(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 + "]");
check_PerformanceEntry(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 + "]");
check_PerformanceEntry(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);
}
}
仕様書
Specification |
---|
Performance Timeline # dom-performance-getentriesbyname |
ブラウザーの互換性
BCD tables only load in the browser