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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
---
title: performance.getEntriesByName()
slug: Web/API/Performance/getEntriesByName
tags:
- web性能
translation_of: Web/API/Performance/getEntriesByName
---
<div><strong><code>getEntriesByName()</code></strong>方法返回一个给定名称和name和type属性的{{domxref("PerformanceEntry")}}对象数组。在创建performance标记或在明确的时间点测量(比如手动调用{{domxref("Performance.mark","mark()")}}方法)也可以创建这样的对象数组。</div>
<p>在Workers中可以使用该方法。</p>
<h2 id="语法">语法</h2>
<pre class="syntaxbox"><em>entries</em> = window.performance.getEntriesByName(name, type);
</pre>
<h3 id="参数">参数</h3>
<dl>
<dt>name</dt>
<dd>The name of the entry to retrieve.</dd>
<dt>type {{optional_inline}}</dt>
<dd>The type of entry to retrieve such as "<code>mark</code>". The valid entry types are listed in {{domxref("PerformanceEntry.entryType")}}.</dd>
</dl>
<h3 id="Return_Value" name="Return_Value">Return value</h3>
<dl>
<dt>entries</dt>
<dd>A list of {{domxref("PerformanceEntry")}} objects that have the specified <code>name</code> and <code>type</code>. If the <code>type</code> argument is not specified, only the <code>name</code> will be used to determine the entries to return. The items will be in chronological order based on the entries' {{domxref("PerformanceEntry.startTime","startTime")}}. If no objects meet the specified criteria, an empty list is returned.</dd>
</dl>
<h2 id="Example">Example</h2>
<pre class="brush: 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);
}
}
</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-performance-getentriesbyname', 'getEntriesByName()')}}</td>
<td>{{Spec2('Performance Timeline Level 2')}}</td>
<td></td>
</tr>
<tr>
<td>{{SpecName('Performance Timeline', '#dom-performance-getentriesbyname', 'getEntriesByName()')}}</td>
<td>{{Spec2('Performance Timeline')}}</td>
<td>Initial definition.</td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<div>
<p>{{Compat("api.Performance.getEntriesByName")}}</p>
</div>
|