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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
---
title: Performance.mark()
slug: Web/API/Performance/mark
tags:
- 性能
- 性能追踪
translation_of: Web/API/Performance/mark
---
<p>{{APIRef("User Timing API")}}</p>
<p><strong><code>mark()</code></strong> 方法在浏览器的性能缓冲区中使用给定名称添加一个{{domxref("DOMHighResTimeStamp","timestamp(时间戳)")}} <em>。</em></p>
<p><em>应用</em>定义的时间戳可以通过 {{domxref("Performance")}} 接口的一个 <code>getEntries*()</code> 方法({{domxref("Performance.getEntries","getEntries()")}}, {{domxref("Performance.getEntriesByName","getEntriesByName()")}} 或者 {{domxref("Performance.getEntriesByType","getEntriesByType()")}})检索到。</p>
<p><code>标记</code> 的 {{domxref("PerformanceEntry","performance entry")}}将具有以下属性值:</p>
<ul>
<li>{{domxref("PerformanceEntry.entryType","entryType")}} - 设置为 "<code>mark</code>".</li>
<li>{{domxref("PerformanceEntry.name","name")}} - 设置为mark被创建时给出的 "<font face="consolas, Liberation Mono, courier, monospace"><span style="background-color: rgba(220, 220, 220, 0.5);">name</span></font>"。</li>
<li>{{domxref("PerformanceEntry.startTime","startTime")}} - 设置为 <code>mark()</code> 方法被调用时的 {{domxref("DOMHighResTimeStamp","timestamp")}} 。</li>
<li>{{domxref("PerformanceEntry.duration","duration")}} - 设置为 "<code>0</code>" (标记没有持续时间).</li>
</ul>
<p>如果这个方法被指定的 <code>name</code> 已经存在于{{domxref("PerformanceTiming")}} 接口, 会抛出一个{{jsxref("SyntaxError")}}错误。</p>
<h2 id="语法">语法</h2>
<pre class="syntaxbox"><em>performance</em>.mark(name);
</pre>
<h3 id="参数">参数</h3>
<dl>
<dt>name</dt>
<dd>一个表示标记名称的{{domxref("DOMString")}}。</dd>
</dl>
<h3 id="返回值">返回值</h3>
<dl>
<dt> 无</dt>
<dd> </dd>
</dl>
<h2 id="实例">实例</h2>
<p>下面的示例演示如何使用 <code>mark()</code> 来创建和检索{{domxref("PerformanceMark")}}条目。</p>
<p> </p>
<pre class="brush: js">// 创建一些标记。
performance.mark("squirrel");
performance.mark("squirrel");
performance.mark("monkey");
performance.mark("monkey");
performance.mark("dog");
performance.mark("dog");
// 获取所有的 PerformanceMark 条目。
const allEntries = performance.getEntriesByType("mark");
console.log(allEntries.length);
// 6
// 获取所有的 "monkey" PerformanceMark 条目。
const monkeyEntries = performance.getEntriesByName("monkey");
console.log(monkeyEntries.length);
// 2
// 删除所有标记。
performance.clearMarks();</pre>
<p> </p>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">规范</th>
<th scope="col">状态</th>
<th scope="col">注释</th>
</tr>
<tr>
<td>{{SpecName('User Timing Level 2', '#dom-performance-mark', 'mark()')}}</td>
<td>{{Spec2('User Timing Level 2')}}</td>
<td>阐明 <code>mark()</code> 处理模型。</td>
</tr>
<tr>
<td>{{SpecName('User Timing', '#dom-performance-mark', 'mark()')}}</td>
<td>{{Spec2('User Timing')}}</td>
<td>基础定义。</td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容">浏览器兼容</h2>
<div>{{CompatibilityTable}}</div>
<div id="compat-desktop">
<table class="compat-table">
<tbody>
<tr>
<th>Feature</th>
<th>Chrome</th>
<th>Edge</th>
<th>Firefox (Gecko)</th>
<th>Internet Explorer</th>
<th>Opera</th>
<th>Safari (WebKit)</th>
</tr>
<tr>
<td>Basic Support</td>
<td>{{CompatChrome(43.0)}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>41</td>
<td>10</td>
<td>33</td>
<td>{{CompatNo}}</td>
</tr>
</tbody>
</table>
</div>
<div id="compat-mobile">
<table class="compat-table">
<tbody>
<tr>
<th>Feature</th>
<th>Android</th>
<th>Android Webview</th>
<th>Edge</th>
<th>Firefox Mobile (Gecko)</th>
<th>Firefox OS</th>
<th>IE Phone</th>
<th>Opera Mobile</th>
<th>Safari Mobile</th>
<th>Chrome for Android</th>
</tr>
<tr>
<td>Basic Support</td>
<td>{{CompatNo}}</td>
<td>{{CompatChrome(46.0)}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>42</td>
<td>42</td>
<td>10</td>
<td>33</td>
<td>{{CompatNo}}</td>
<td>{{CompatChrome(46.0)}}</td>
</tr>
</tbody>
</table>
</div>
|