performance.getEntriesByType()

getEntriesByType() メソッドは、指定された型の PerformanceEntry オブジェクトのリストを返します。リストのメンバー(エントリー)は、明示的な時点でパフォーマンスマークまたはメジャーを作成することで(たとえば mark() メソッドを呼び出すことで)作成できます。

注: この機能は Web Worker 内で利用可能です

構文

js

entries = window.performance.getEntriesByType(type);

引数

type

"mark" など、取得するエントリーの種類。有効なエントリー種別の一覧は PerformanceEntry.entryType にあります。

返値

entries

指定された type を持つ PerformanceEntry オブジェクトのリスト。項目はエントリーの startTime に基づいて時系列に並んでいます。指定された type を持つオブジェクトがない場合、または引数が指定されていない場合は、空のリストが返されます。

js

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,
    );
  }
}

仕様書

Specification
Performance Timeline
# dom-performance-getentriesbytype

ブラウザーの互換性

BCD tables only load in the browser