Skip to content

Commit b3d57c3

Browse files
committed
clean up
1 parent c9fb93a commit b3d57c3

File tree

12 files changed

+201
-448
lines changed

12 files changed

+201
-448
lines changed

README.md

+9-168
Original file line numberDiff line numberDiff line change
@@ -1,176 +1,17 @@
1-
# javascript_performance_measurement
1+
# JavaScript Performance Measurement Toolkit
22

3-
## 1. 用拓扑图的方式展现 CPU Profile 结果
3+
## OneProfile
44

5-
Chrome Dev Tools 自带的 Profile 功能非常好用。用它可以方便的生成 JavaScript `Flame Chart`
5+
> OneProfile 是一个网页版的小工具,可以用全新的方式展示 JavaScript 性能分析的结果,帮助开发者洞悉函数调用关系,优化应用性能
66
7-
![Flame Chart](./cpuprofile_topology/screenshot_chrome.png)
7+
[点击打开 OneProfile](http://wyvernnot.github.io/javascript_performance_measurement/cpuprofile_topology/)
88

9-
更棒的是你可以把 `Flame Chart` 导出,留着下次或者拷贝到其它机器上看。但是网上关于它的文件格式以及如何生成 `Flame Chart` 的文档非常稀有,所以我自己摸索了一下它的文件格式,并尝试着用另一种方式展示 Profile 的结果。
9+
[原理和使用帮助](./cpuprofile_topology/README.md)
1010

11-
**如何生成 CPU Profile 文件**
11+
## OneSnapshot
1212

13-
使用最新版的 Chrome 打开任意一个 [测试网站](http://oneapm.com),按 F12 打开 `Devtools`, 切换到 `Profiles` 页,点击 `Start` 开始
14-
收集 Profile 信息,在当前页面任意滑动鼠标等待大约5秒后, 点击 `Stop` 停止 Profile。在生成的 CPU Profile 名字上单击右键可以导出,
15-
比如这个 [sample.cpuprofile](https://raw.githubusercontent.com/wyvernnot/javascript_performance_measurement/gh-pages/cpuprofile_topology/sample.cpuprofile)
13+
> {placehodler}
1614
17-
**原理**
15+
## OneGC
1816

19-
0\. `sample.cpuprofile` 其实就是一个 JSON 格式的文件,有 `head`, `timestamps`, `samples` 等几个重要的属性
20-
21-
1\. 如果对 `head` 结点及其子节点 `children` 做一次深度优先的遍历,每个可能路径都会有一个编号
22-
23-
2\. `timestamps` 是一个数组,记录着 Profiling 过程中每个采样点的时间戳
24-
25-
3\. 对应 `timestamps` 下的每个时间点,`samples` 数组相同的位置都会有一个数字,研究表明这个数字 _就是步骤1中的编号_
26-
27-
4\. 对于任意一个时间点,都会有一个 active 的路径,用蓝色表示。
28-
29-
**DEMO**
30-
31-
使用 Chrome 打开: [DEMO](http://wyvernnot.github.io/javascript_performance_measurement/cpuprofile_topology/)
32-
33-
**操作**
34-
35-
1\. 等待加载完成
36-
37-
2\. 鼠标滚轮可以缩放图片
38-
39-
3\. 拖过滑块可以查看每个时间点的详细情况
40-
41-
42-
## 2. snapshot 数据结构解读
43-
44-
运行代码 `index.html`,创建 Snapshot。
45-
46-
![heapsnapshot](./devtools_heapsnapshot_screenshot.png)
47-
48-
随便找一个数字例如 `206751`,在 `nodes.json` 中查找 `206751` ,定位到这行
49-
50-
nodes.json#L3630
51-
52-
```
53-
,3,1726,206751,40,4,0
54-
```
55-
56-
每一列的含义可在 sample.heapsnapshot.json#L4 中找到
57-
58-
```
59-
"node_fields": [
60-
"type",
61-
"name",
62-
"id",
63-
"self_size",
64-
"edge_count",
65-
"trace_node_id"
66-
],
67-
```
68-
69-
type 是一个数字,对应类型存在这个对象里
70-
71-
```
72-
"node_types": [
73-
[
74-
"hidden",
75-
"array",
76-
"string",
77-
"object",
78-
"code",
79-
"closure",
80-
"regexp",
81-
"number",
82-
"native",
83-
"synthetic",
84-
"concatenated string",
85-
"sliced string"
86-
],
87-
```
88-
89-
关联起来解读:
90-
91-
- 3 type node_types[3]="object" 表示这是一个 object 对象
92-
93-
- 1726 name string[1726]="People" 这个对象的名字是 People
94-
95-
- 206751 id 对象示例的 id
96-
97-
- 40 self_size 对象的 shallow size
98-
99-
- 4 edge_count
100-
101-
- 0 trace_node_id
102-
103-
string[1726]="People"
104-
@206751
105-
40 shallow size
106-
107-
108-
```
109-
{ '0':
110-
{ count: 27627,
111-
size: 1144320,
112-
name: 'hidden',
113-
hsize: '1117.5 k' },
114-
'1':
115-
{ count: 8748,
116-
size: 1972224,
117-
name: 'array',
118-
hsize: '1926.0 k' },
119-
'2':
120-
{ count: 6107,
121-
size: 367736,
122-
name: 'string',
123-
hsize: '359.1 k' },
124-
'3':
125-
{ count: 7178,
126-
size: 304504,
127-
name: 'object',
128-
hsize: '297.4 k' },
129-
'4':
130-
{ count: 7024,
131-
size: 1622640,
132-
name: 'code',
133-
hsize: '1584.6 k' },
134-
'5':
135-
{ count: 9732,
136-
size: 700704,
137-
name: 'closure',
138-
hsize: '684.3 k' },
139-
'6':
140-
{ count: 6,
141-
size: 384,
142-
name: 'regexp',
143-
hsize: '0.4 k' },
144-
'7':
145-
{ count: 26,
146-
size: 416,
147-
name: 'number',
148-
hsize: '0.4 k' },
149-
'8':
150-
{ count: 16,
151-
size: 672,
152-
name: 'native',
153-
hsize: '0.7 k' },
154-
'9':
155-
{ count: 20,
156-
size: 0,
157-
name: 'synthetic',
158-
hsize: '0.0 k' },
159-
'10':
160-
{ count: 302,
161-
size: 12080,
162-
name: 'concatenated string',
163-
hsize: '11.8 k' },
164-
'12':
165-
{ count: 45,
166-
size: 1440,
167-
name: undefined,
168-
hsize: '1.4 k' } }
169-
```
170-
171-
** 计算结果 实际/DevTools **
172-
173-
总计 5984KB / 5984KB
174-
Code 1585KB / 1425KB
175-
Strings 360KB / 303KB
176-
JS Arrays 1926KB / 53KB
17+
> {placeholder}

click/click.cpuprofile

-171
This file was deleted.

click/index.html

-28
This file was deleted.

click/reveal.js

-3
This file was deleted.

0 commit comments

Comments
 (0)