aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/performanceentry/index.html
blob: c0fde6ee9de96ef2d970ca2f45b4e305f8cc8d8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
---
title: PerformanceEntry
slug: Web/API/PerformanceEntry
tags:
  - API
  - Interface
  - NeedsTranslation
  - Reference
  - TopicStub
  - Web Performance
translation_of: Web/API/PerformanceEntry
---
<div>{{APIRef("Performance Timeline API")}}</div>

<p><strong><code>PerformanceEntry</code></strong> 对象代表了 performance 时间列表中的单个 metric 数据. 每一个 <em>performance entry 都可以在应用运行过程中通过手动构建 </em><em>{{domxref("PerformanceMark","mark")}}</em> 或者 <em>{{domxref("PerformanceMeasure","measure")}}</em> (例如调用 {{domxref("Performance.mark","mark()")}} 方法) 生成. 此外, Performance entries 在资源加载的时候,也会被动生成(例如图片、script、css等资源加载)</p>

<p class="note">Note: Performance 对象暴露给了 {{domxref("Window")}}{{domxref("Worker")}}. 同时该对象扩展了几个其他对象的属性,包括 {{domxref("PerformanceMark")}}, {{domxref("PerformanceMeasure")}}, {{domxref("PerformanceFrameTiming")}}, {{domxref("PerformanceNavigationTiming")}} 以及 {{domxref("PerformanceResourceTiming")}}.</p>

<h2 id="Properties">Properties</h2>

<dl>
 <dt>{{domxref("PerformanceEntry.name")}} {{readonlyInline}}</dt>
 <dd>{{domxref("DOMString")}} 该 performance entry 的名字</dd>
 <dt>{{domxref("PerformanceEntry.entryType")}} {{readonlyInline}}</dt>
 <dd>{{domxref("DOMString")}} 代表所上报的 performance metric 的 entryType 类型,例如 "mark". 可以通过 {{domxref("PerformanceEntry.entryType","entryType")}} 查阅完整的 entryType type 类型.</dd>
 <dt>{{domxref("PerformanceEntry.startTime")}} {{readonlyInline}}</dt>
 <dd> {{domxref("DOMHighResTimeStamp")}}  此为 metric 上报时的时间</dd>
 <dt>{{domxref("PerformanceEntry.duration")}} {{readonlyInline}}</dt>
 <dd>{{domxref("DOMHighResTimeStamp")}} 该事件的耗时</dd>
</dl>

<h2 id="Methods">Methods</h2>

<dl>
 <dt>{{domxref("PerformanceEntry.toJSON","PerformanceEntry.toJSON()")}}</dt>
 <dd>返回 <code>PerformanceEntry</code> 对象的 JSON 格式数据</dd>
 <dd> </dd>
</dl>

<h2 id="Example">Example</h2>

<p>以下例子检查了当前浏览器所支持的所有 <code>PerformanceEntry</code> 属性,每个属性的检查结果都会通过 console 打印出来</p>

<pre class="brush: js">function print_PerformanceEntries() {
  // Use getEntries() to get a list of all performance entries
  var p = performance.getEntries();
  for (var i=0; i &lt; p.length; i++) {
    console.log("PerformanceEntry[" + i + "]");
    print_PerformanceEntry(p[i]);
  }
}
function print_PerformanceEntry(perfEntry) {
  var properties = ["name",
    "entryType",
    "startTime",
    "duration"];

  for (var i=0; i &lt; properties.length; i++) {
    // check each property
    var supported = properties[i] in perfEntry;
    if (supported) {
      var value = perfEntry[properties[i]];
      console.log("... " + properties[i] + " = " + value);
    } else {
      console.log("... " + properties[i] + " = NOT supported");
    }
  }
}
</pre>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('Performance Timeline Level 2', '#dom-performanceentry', 'PerformanceEntry')}}</td>
   <td>{{Spec2('Performance Timeline Level 2')}}</td>
   <td>Added <code>toJSON()</code> serializer method.</td>
  </tr>
  <tr>
   <td>{{SpecName('Performance Timeline', '#dom-performanceentry', 'PerformanceEntry')}}</td>
   <td>{{Spec2('Performance Timeline')}}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<div>
<div>


<p>{{Compat("api.PerformanceEntry")}}</p>
</div>
</div>