@atlaspack/profiler 2.14.1-canary.31 → 2.14.1-canary.311
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +233 -0
- package/dist/SamplingProfiler.js +57 -0
- package/dist/Trace.js +109 -0
- package/dist/Tracer.js +132 -0
- package/dist/index.js +13 -0
- package/dist/types.js +2 -0
- package/lib/SamplingProfiler.js +6 -0
- package/lib/Tracer.js +5 -2
- package/lib/{SamplingProfiler.d.ts → types/SamplingProfiler.d.ts} +2 -2
- package/lib/{Trace.d.ts → types/Trace.d.ts} +3 -3
- package/lib/{Tracer.d.ts → types/Tracer.d.ts} +9 -5
- package/lib/types/index.d.ts +4 -0
- package/lib/types/types.d.ts +7 -0
- package/package.json +10 -10
- package/src/{SamplingProfiler.js → SamplingProfiler.ts} +59 -40
- package/src/{Trace.js → Trace.ts} +0 -1
- package/src/{Tracer.js → Tracer.ts} +27 -15
- package/src/{index.js → index.ts} +0 -1
- package/src/types.ts +8 -0
- package/test/{Tracer.test.js → Tracer.test.ts} +2 -3
- package/tsconfig.json +18 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/lib/index.d.ts +0 -4
- package/lib/types.d.ts +0 -5
- package/src/types.js +0 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,238 @@
|
|
|
1
1
|
# @atlaspack/profiler
|
|
2
2
|
|
|
3
|
+
## 2.14.31
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies []:
|
|
8
|
+
- @atlaspack/types-internal@2.20.4
|
|
9
|
+
|
|
10
|
+
## 2.14.30
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies []:
|
|
15
|
+
- @atlaspack/types-internal@2.20.3
|
|
16
|
+
|
|
17
|
+
## 2.14.29
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- Updated dependencies []:
|
|
22
|
+
- @atlaspack/types-internal@2.20.2
|
|
23
|
+
|
|
24
|
+
## 2.14.28
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- [#785](https://github.com/atlassian-labs/atlaspack/pull/785) [`0e7dd5e`](https://github.com/atlassian-labs/atlaspack/commit/0e7dd5ec6fbe05aa9e0bb5775a9d0975f206a922) Thanks [@matt-koko](https://github.com/matt-koko)! - We need to re-publish every package in Atlaspack with the corrected types field.
|
|
29
|
+
|
|
30
|
+
- Updated dependencies [[`0e7dd5e`](https://github.com/atlassian-labs/atlaspack/commit/0e7dd5ec6fbe05aa9e0bb5775a9d0975f206a922)]:
|
|
31
|
+
- @atlaspack/diagnostic@2.14.4
|
|
32
|
+
- @atlaspack/types-internal@2.20.1
|
|
33
|
+
- @atlaspack/events@2.14.4
|
|
34
|
+
|
|
35
|
+
## 2.14.27
|
|
36
|
+
|
|
37
|
+
### Patch Changes
|
|
38
|
+
|
|
39
|
+
- Updated dependencies [[`eedcbc4`](https://github.com/atlassian-labs/atlaspack/commit/eedcbc408fc1e86a2a8e25f1a41c57146d8529e1), [`f6532d7`](https://github.com/atlassian-labs/atlaspack/commit/f6532d7a4f7f007bd4e5e36af04dd466f0b9f572)]:
|
|
40
|
+
- @atlaspack/types-internal@2.20.0
|
|
41
|
+
|
|
42
|
+
## 2.14.26
|
|
43
|
+
|
|
44
|
+
### Patch Changes
|
|
45
|
+
|
|
46
|
+
- Updated dependencies []:
|
|
47
|
+
- @atlaspack/types-internal@2.19.5
|
|
48
|
+
|
|
49
|
+
## 2.14.25
|
|
50
|
+
|
|
51
|
+
### Patch Changes
|
|
52
|
+
|
|
53
|
+
- Updated dependencies []:
|
|
54
|
+
- @atlaspack/types-internal@2.19.4
|
|
55
|
+
|
|
56
|
+
## 2.14.24
|
|
57
|
+
|
|
58
|
+
### Patch Changes
|
|
59
|
+
|
|
60
|
+
- Updated dependencies []:
|
|
61
|
+
- @atlaspack/types-internal@2.19.3
|
|
62
|
+
|
|
63
|
+
## 2.14.23
|
|
64
|
+
|
|
65
|
+
### Patch Changes
|
|
66
|
+
|
|
67
|
+
- [#742](https://github.com/atlassian-labs/atlaspack/pull/742) [`ee040bb`](https://github.com/atlassian-labs/atlaspack/commit/ee040bb6428f29b57d892ddd8107e29077d08ffd) Thanks [@yamadapc](https://github.com/yamadapc)! - Internal changes and bug fixes to environmentDeduplication flag
|
|
68
|
+
|
|
69
|
+
- Updated dependencies [[`ee040bb`](https://github.com/atlassian-labs/atlaspack/commit/ee040bb6428f29b57d892ddd8107e29077d08ffd)]:
|
|
70
|
+
- @atlaspack/types-internal@2.19.2
|
|
71
|
+
- @atlaspack/diagnostic@2.14.3
|
|
72
|
+
- @atlaspack/events@2.14.3
|
|
73
|
+
|
|
74
|
+
## 2.14.22
|
|
75
|
+
|
|
76
|
+
### Patch Changes
|
|
77
|
+
|
|
78
|
+
- Updated dependencies []:
|
|
79
|
+
- @atlaspack/types-internal@2.19.1
|
|
80
|
+
|
|
81
|
+
## 2.14.21
|
|
82
|
+
|
|
83
|
+
### Patch Changes
|
|
84
|
+
|
|
85
|
+
- Updated dependencies [[`7f5841c`](https://github.com/atlassian-labs/atlaspack/commit/7f5841c39df049f9546cccbeea2a7337e0337b45)]:
|
|
86
|
+
- @atlaspack/types-internal@2.19.0
|
|
87
|
+
|
|
88
|
+
## 2.14.20
|
|
89
|
+
|
|
90
|
+
### Patch Changes
|
|
91
|
+
|
|
92
|
+
- Updated dependencies [[`23d561e`](https://github.com/atlassian-labs/atlaspack/commit/23d561e51e68b0c38fd1ff4e4fb173e5e7b01cf2)]:
|
|
93
|
+
- @atlaspack/types-internal@2.18.0
|
|
94
|
+
|
|
95
|
+
## 2.14.19
|
|
96
|
+
|
|
97
|
+
### Patch Changes
|
|
98
|
+
|
|
99
|
+
- [#720](https://github.com/atlassian-labs/atlaspack/pull/720) [`d2fd849`](https://github.com/atlassian-labs/atlaspack/commit/d2fd849770fe6305e9c694bd97b1bd905abd9d94) Thanks [@alshdavid](https://github.com/alshdavid)! - Migrate to TypeScript
|
|
100
|
+
|
|
101
|
+
- Updated dependencies [[`d2fd849`](https://github.com/atlassian-labs/atlaspack/commit/d2fd849770fe6305e9c694bd97b1bd905abd9d94), [`43fdd22`](https://github.com/atlassian-labs/atlaspack/commit/43fdd223860fbc97af17d68c65419b97412cb888)]:
|
|
102
|
+
- @atlaspack/types-internal@2.17.0
|
|
103
|
+
- @atlaspack/diagnostic@2.14.2
|
|
104
|
+
- @atlaspack/events@2.14.2
|
|
105
|
+
|
|
106
|
+
## 2.14.18
|
|
107
|
+
|
|
108
|
+
### Patch Changes
|
|
109
|
+
|
|
110
|
+
- Updated dependencies [[`069de47`](https://github.com/atlassian-labs/atlaspack/commit/069de478e64fb5889f6f2ce023eb510782767fbd)]:
|
|
111
|
+
- @atlaspack/types-internal@2.16.0
|
|
112
|
+
|
|
113
|
+
## 2.14.17
|
|
114
|
+
|
|
115
|
+
### Patch Changes
|
|
116
|
+
|
|
117
|
+
- Updated dependencies []:
|
|
118
|
+
- @atlaspack/types-internal@2.15.2
|
|
119
|
+
|
|
120
|
+
## 2.14.16
|
|
121
|
+
|
|
122
|
+
### Patch Changes
|
|
123
|
+
|
|
124
|
+
- Updated dependencies []:
|
|
125
|
+
- @atlaspack/types-internal@2.15.1
|
|
126
|
+
|
|
127
|
+
## 2.14.15
|
|
128
|
+
|
|
129
|
+
### Patch Changes
|
|
130
|
+
|
|
131
|
+
- Updated dependencies [[`18a57cf`](https://github.com/atlassian-labs/atlaspack/commit/18a57cf8a4789b2de5ad8e2676f317a26cc91417)]:
|
|
132
|
+
- @atlaspack/types-internal@2.15.0
|
|
133
|
+
|
|
134
|
+
## 2.14.14
|
|
135
|
+
|
|
136
|
+
### Patch Changes
|
|
137
|
+
|
|
138
|
+
- Updated dependencies []:
|
|
139
|
+
- @atlaspack/types-internal@2.14.14
|
|
140
|
+
|
|
141
|
+
## 2.14.13
|
|
142
|
+
|
|
143
|
+
### Patch Changes
|
|
144
|
+
|
|
145
|
+
- Updated dependencies []:
|
|
146
|
+
- @atlaspack/types-internal@2.14.13
|
|
147
|
+
|
|
148
|
+
## 2.14.12
|
|
149
|
+
|
|
150
|
+
### Patch Changes
|
|
151
|
+
|
|
152
|
+
- Updated dependencies []:
|
|
153
|
+
- @atlaspack/types-internal@2.14.12
|
|
154
|
+
|
|
155
|
+
## 2.14.11
|
|
156
|
+
|
|
157
|
+
### Patch Changes
|
|
158
|
+
|
|
159
|
+
- Updated dependencies []:
|
|
160
|
+
- @atlaspack/types-internal@2.14.11
|
|
161
|
+
|
|
162
|
+
## 2.14.10
|
|
163
|
+
|
|
164
|
+
### Patch Changes
|
|
165
|
+
|
|
166
|
+
- Updated dependencies []:
|
|
167
|
+
- @atlaspack/types-internal@2.14.10
|
|
168
|
+
|
|
169
|
+
## 2.14.9
|
|
170
|
+
|
|
171
|
+
### Patch Changes
|
|
172
|
+
|
|
173
|
+
- Updated dependencies []:
|
|
174
|
+
- @atlaspack/types-internal@2.14.9
|
|
175
|
+
|
|
176
|
+
## 2.14.8
|
|
177
|
+
|
|
178
|
+
### Patch Changes
|
|
179
|
+
|
|
180
|
+
- Updated dependencies [[`51aba5f`](https://github.com/atlassian-labs/atlaspack/commit/51aba5fc0e49235ee06bbc3c376f48c3e7da5c4b)]:
|
|
181
|
+
- @atlaspack/types-internal@2.14.8
|
|
182
|
+
|
|
183
|
+
## 2.14.7
|
|
184
|
+
|
|
185
|
+
### Patch Changes
|
|
186
|
+
|
|
187
|
+
- Updated dependencies []:
|
|
188
|
+
- @atlaspack/types-internal@2.14.7
|
|
189
|
+
|
|
190
|
+
## 2.14.6
|
|
191
|
+
|
|
192
|
+
### Patch Changes
|
|
193
|
+
|
|
194
|
+
- Updated dependencies []:
|
|
195
|
+
- @atlaspack/types-internal@2.14.6
|
|
196
|
+
|
|
197
|
+
## 2.14.5
|
|
198
|
+
|
|
199
|
+
### Patch Changes
|
|
200
|
+
|
|
201
|
+
- Updated dependencies []:
|
|
202
|
+
- @atlaspack/types-internal@2.14.5
|
|
203
|
+
|
|
204
|
+
## 2.14.4
|
|
205
|
+
|
|
206
|
+
### Patch Changes
|
|
207
|
+
|
|
208
|
+
- Updated dependencies []:
|
|
209
|
+
- @atlaspack/types-internal@2.14.4
|
|
210
|
+
|
|
211
|
+
## 2.14.3
|
|
212
|
+
|
|
213
|
+
### Patch Changes
|
|
214
|
+
|
|
215
|
+
- Updated dependencies []:
|
|
216
|
+
- @atlaspack/types-internal@2.14.3
|
|
217
|
+
|
|
218
|
+
## 2.14.2
|
|
219
|
+
|
|
220
|
+
### Patch Changes
|
|
221
|
+
|
|
222
|
+
- Updated dependencies []:
|
|
223
|
+
- @atlaspack/types-internal@2.14.2
|
|
224
|
+
|
|
225
|
+
## 2.14.1
|
|
226
|
+
|
|
227
|
+
### Patch Changes
|
|
228
|
+
|
|
229
|
+
- [#478](https://github.com/atlassian-labs/atlaspack/pull/478) [`570493b`](https://github.com/atlassian-labs/atlaspack/commit/570493beaf754e7985aebc7daaaf6dfcfa8fe56b) Thanks [@yamadapc](https://github.com/yamadapc)! - The first attempt at Version Packages didn't include the built artifacts.
|
|
230
|
+
This has hopefully been fixed, so this change will force those packages to re-release.
|
|
231
|
+
- Updated dependencies [[`e1422ad`](https://github.com/atlassian-labs/atlaspack/commit/e1422ad0a801faaa4bc4f1023bed042ffe236e9b), [`570493b`](https://github.com/atlassian-labs/atlaspack/commit/570493beaf754e7985aebc7daaaf6dfcfa8fe56b)]:
|
|
232
|
+
- @atlaspack/types-internal@2.14.1
|
|
233
|
+
- @atlaspack/diagnostic@2.14.1
|
|
234
|
+
- @atlaspack/events@2.14.1
|
|
235
|
+
|
|
3
236
|
## 2.14.0
|
|
4
237
|
|
|
5
238
|
### Minor Changes
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const assert_1 = __importDefault(require("assert"));
|
|
7
|
+
const diagnostic_1 = __importDefault(require("@atlaspack/diagnostic"));
|
|
8
|
+
class SamplingProfiler {
|
|
9
|
+
startProfiling() {
|
|
10
|
+
let inspector;
|
|
11
|
+
try {
|
|
12
|
+
inspector = require('inspector');
|
|
13
|
+
}
|
|
14
|
+
catch (err) {
|
|
15
|
+
throw new diagnostic_1.default({
|
|
16
|
+
diagnostic: {
|
|
17
|
+
message: `The inspector module isn't available`,
|
|
18
|
+
origin: '@atlaspack/workers',
|
|
19
|
+
hints: ['Disable build profiling'],
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
this.session = new inspector.Session();
|
|
24
|
+
this.session.connect();
|
|
25
|
+
return Promise.all([
|
|
26
|
+
this.sendCommand('Profiler.setSamplingInterval', {
|
|
27
|
+
interval: 100,
|
|
28
|
+
}),
|
|
29
|
+
this.sendCommand('Profiler.enable'),
|
|
30
|
+
this.sendCommand('Profiler.start'),
|
|
31
|
+
]);
|
|
32
|
+
}
|
|
33
|
+
sendCommand(method, params) {
|
|
34
|
+
(0, assert_1.default)(this.session != null);
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
this.session.post(method, params, (err, p) => {
|
|
37
|
+
if (err == null) {
|
|
38
|
+
resolve(p);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
reject(err);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
destroy() {
|
|
47
|
+
if (this.session != null) {
|
|
48
|
+
this.session.disconnect();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async stopProfiling() {
|
|
52
|
+
let res = await this.sendCommand('Profiler.stop');
|
|
53
|
+
this.destroy();
|
|
54
|
+
return res.profile;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.default = SamplingProfiler;
|
package/dist/Trace.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const chrome_trace_event_1 = require("chrome-trace-event");
|
|
4
|
+
class Trace {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.tracer = new chrome_trace_event_1.Tracer();
|
|
7
|
+
this.tid = 0;
|
|
8
|
+
this.eventId = 0;
|
|
9
|
+
}
|
|
10
|
+
getEventId() {
|
|
11
|
+
return this.eventId++;
|
|
12
|
+
}
|
|
13
|
+
init(ts) {
|
|
14
|
+
this.tracer.instantEvent({
|
|
15
|
+
name: 'TracingStartedInPage',
|
|
16
|
+
id: this.getEventId(),
|
|
17
|
+
ts,
|
|
18
|
+
cat: ['disabled-by-default-devtools.timeline'],
|
|
19
|
+
args: {
|
|
20
|
+
data: {
|
|
21
|
+
sessionId: '-1',
|
|
22
|
+
page: '0xfff',
|
|
23
|
+
frames: [
|
|
24
|
+
{
|
|
25
|
+
frame: '0xfff',
|
|
26
|
+
url: 'parcel',
|
|
27
|
+
name: '',
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
this.tracer.instantEvent({
|
|
34
|
+
name: 'TracingStartedInBrowser',
|
|
35
|
+
id: this.getEventId(),
|
|
36
|
+
ts,
|
|
37
|
+
cat: ['disabled-by-default-devtools.timeline'],
|
|
38
|
+
args: {
|
|
39
|
+
data: {
|
|
40
|
+
sessionId: '-1',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
addCPUProfile(name, profile) {
|
|
46
|
+
if (this.eventId === 0) {
|
|
47
|
+
this.init(profile.startTime);
|
|
48
|
+
}
|
|
49
|
+
const trace = this.tracer;
|
|
50
|
+
const tid = this.tid;
|
|
51
|
+
this.tid++;
|
|
52
|
+
const cpuStartTime = profile.startTime;
|
|
53
|
+
const cpuEndTime = profile.endTime;
|
|
54
|
+
trace.instantEvent({
|
|
55
|
+
tid,
|
|
56
|
+
id: this.getEventId(),
|
|
57
|
+
cat: ['toplevel'],
|
|
58
|
+
name: 'TaskQueueManager::ProcessTaskFromWorkQueue',
|
|
59
|
+
args: {
|
|
60
|
+
src_file: '../../ipc/ipc_moji_bootstrap.cc',
|
|
61
|
+
src_func: 'Accept',
|
|
62
|
+
},
|
|
63
|
+
ts: cpuStartTime,
|
|
64
|
+
});
|
|
65
|
+
trace.completeEvent({
|
|
66
|
+
tid,
|
|
67
|
+
name: 'EvaluateScript',
|
|
68
|
+
id: this.getEventId(),
|
|
69
|
+
cat: ['devtools.timeline'],
|
|
70
|
+
ts: cpuStartTime,
|
|
71
|
+
dur: cpuEndTime - cpuStartTime,
|
|
72
|
+
args: {
|
|
73
|
+
data: {
|
|
74
|
+
url: 'parcel',
|
|
75
|
+
lineNumber: 1,
|
|
76
|
+
columnNumber: 1,
|
|
77
|
+
frame: '0xFFF',
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
trace.instantEvent({
|
|
82
|
+
tid,
|
|
83
|
+
ts: 0,
|
|
84
|
+
ph: 'M',
|
|
85
|
+
cat: ['__metadata'],
|
|
86
|
+
name: 'thread_name',
|
|
87
|
+
args: { name },
|
|
88
|
+
});
|
|
89
|
+
trace.instantEvent({
|
|
90
|
+
tid,
|
|
91
|
+
name: 'CpuProfile',
|
|
92
|
+
id: this.getEventId(),
|
|
93
|
+
cat: ['disabled-by-default-devtools.timeline'],
|
|
94
|
+
ts: cpuEndTime,
|
|
95
|
+
args: {
|
|
96
|
+
data: {
|
|
97
|
+
cpuProfile: profile,
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
pipe(writable) {
|
|
103
|
+
return this.tracer.pipe(writable);
|
|
104
|
+
}
|
|
105
|
+
flush() {
|
|
106
|
+
this.tracer.push(null);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.default = Trace;
|
package/dist/Tracer.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _TraceMeasurement_active, _TraceMeasurement_name, _TraceMeasurement_pid, _TraceMeasurement_tid, _TraceMeasurement_start, _TraceMeasurement_data, _Tracer_traceEmitter, _Tracer_enabled;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.PluginTracer = exports.tracer = void 0;
|
|
16
|
+
const events_1 = require("@atlaspack/events");
|
|
17
|
+
const perf_hooks_1 = require("perf_hooks");
|
|
18
|
+
// @ts-expect-error TS7034
|
|
19
|
+
let tid;
|
|
20
|
+
try {
|
|
21
|
+
tid = require('worker_threads').threadId;
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
tid = 0;
|
|
25
|
+
}
|
|
26
|
+
const pid = process.pid;
|
|
27
|
+
class TraceMeasurement {
|
|
28
|
+
constructor(tracer, name, pid, tid, data) {
|
|
29
|
+
_TraceMeasurement_active.set(this, true);
|
|
30
|
+
_TraceMeasurement_name.set(this, void 0);
|
|
31
|
+
_TraceMeasurement_pid.set(this, void 0);
|
|
32
|
+
_TraceMeasurement_tid.set(this, void 0);
|
|
33
|
+
_TraceMeasurement_start.set(this, void 0);
|
|
34
|
+
_TraceMeasurement_data.set(this, void 0);
|
|
35
|
+
__classPrivateFieldSet(this, _TraceMeasurement_name, name, "f");
|
|
36
|
+
__classPrivateFieldSet(this, _TraceMeasurement_pid, pid, "f");
|
|
37
|
+
__classPrivateFieldSet(this, _TraceMeasurement_tid, tid, "f");
|
|
38
|
+
__classPrivateFieldSet(this, _TraceMeasurement_start, perf_hooks_1.performance.now(), "f");
|
|
39
|
+
__classPrivateFieldSet(this, _TraceMeasurement_data, data, "f");
|
|
40
|
+
}
|
|
41
|
+
end() {
|
|
42
|
+
if (!__classPrivateFieldGet(this, _TraceMeasurement_active, "f"))
|
|
43
|
+
return;
|
|
44
|
+
const duration = perf_hooks_1.performance.now() - __classPrivateFieldGet(this, _TraceMeasurement_start, "f");
|
|
45
|
+
exports.tracer.trace({
|
|
46
|
+
type: 'trace',
|
|
47
|
+
name: __classPrivateFieldGet(this, _TraceMeasurement_name, "f"),
|
|
48
|
+
pid: __classPrivateFieldGet(this, _TraceMeasurement_pid, "f"),
|
|
49
|
+
tid: __classPrivateFieldGet(this, _TraceMeasurement_tid, "f"),
|
|
50
|
+
duration,
|
|
51
|
+
ts: __classPrivateFieldGet(this, _TraceMeasurement_start, "f"),
|
|
52
|
+
...__classPrivateFieldGet(this, _TraceMeasurement_data, "f"),
|
|
53
|
+
});
|
|
54
|
+
__classPrivateFieldSet(this, _TraceMeasurement_active, false, "f");
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
_TraceMeasurement_active = new WeakMap(), _TraceMeasurement_name = new WeakMap(), _TraceMeasurement_pid = new WeakMap(), _TraceMeasurement_tid = new WeakMap(), _TraceMeasurement_start = new WeakMap(), _TraceMeasurement_data = new WeakMap();
|
|
58
|
+
class Tracer {
|
|
59
|
+
constructor() {
|
|
60
|
+
_Tracer_traceEmitter.set(this, new events_1.ValueEmitter());
|
|
61
|
+
_Tracer_enabled.set(this, false);
|
|
62
|
+
}
|
|
63
|
+
onTrace(cb) {
|
|
64
|
+
return __classPrivateFieldGet(this, _Tracer_traceEmitter, "f").addListener(cb);
|
|
65
|
+
}
|
|
66
|
+
async wrap(name, fn) {
|
|
67
|
+
let measurement = this.createMeasurement(name);
|
|
68
|
+
try {
|
|
69
|
+
await fn();
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
measurement && measurement.end();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
createMeasurement(name, category = 'Core', argumentName, otherArgs) {
|
|
76
|
+
if (!this.enabled)
|
|
77
|
+
return null;
|
|
78
|
+
// We create `args` in a fairly verbose way to avoid object
|
|
79
|
+
// allocation where not required.
|
|
80
|
+
let args;
|
|
81
|
+
if (typeof argumentName === 'string') {
|
|
82
|
+
args = { name: argumentName };
|
|
83
|
+
}
|
|
84
|
+
if (typeof otherArgs === 'object') {
|
|
85
|
+
// @ts-expect-error TS2454
|
|
86
|
+
if (typeof args == 'undefined') {
|
|
87
|
+
args = {};
|
|
88
|
+
}
|
|
89
|
+
for (const [k, v] of Object.entries(otherArgs)) {
|
|
90
|
+
args[k] = v;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const data = {
|
|
94
|
+
categories: [category],
|
|
95
|
+
// @ts-expect-error TS2454
|
|
96
|
+
args,
|
|
97
|
+
};
|
|
98
|
+
// @ts-expect-error TS7005
|
|
99
|
+
return new TraceMeasurement(this, name, pid, tid, data);
|
|
100
|
+
}
|
|
101
|
+
get enabled() {
|
|
102
|
+
return __classPrivateFieldGet(this, _Tracer_enabled, "f");
|
|
103
|
+
}
|
|
104
|
+
enable() {
|
|
105
|
+
__classPrivateFieldSet(this, _Tracer_enabled, true, "f");
|
|
106
|
+
}
|
|
107
|
+
disable() {
|
|
108
|
+
__classPrivateFieldSet(this, _Tracer_enabled, false, "f");
|
|
109
|
+
}
|
|
110
|
+
trace(event) {
|
|
111
|
+
if (!__classPrivateFieldGet(this, _Tracer_enabled, "f"))
|
|
112
|
+
return;
|
|
113
|
+
__classPrivateFieldGet(this, _Tracer_traceEmitter, "f").emit(event);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
_Tracer_traceEmitter = new WeakMap(), _Tracer_enabled = new WeakMap();
|
|
117
|
+
exports.default = Tracer;
|
|
118
|
+
exports.tracer = new Tracer();
|
|
119
|
+
class PluginTracer {
|
|
120
|
+
/** @private */
|
|
121
|
+
constructor(opts) {
|
|
122
|
+
this.origin = opts.origin;
|
|
123
|
+
this.category = opts.category;
|
|
124
|
+
}
|
|
125
|
+
get enabled() {
|
|
126
|
+
return exports.tracer.enabled;
|
|
127
|
+
}
|
|
128
|
+
createMeasurement(name, category, argumentName, otherArgs) {
|
|
129
|
+
return exports.tracer.createMeasurement(name, `${this.category}:${this.origin}${typeof category === 'string' ? `:${category}` : ''}`, argumentName, otherArgs);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
exports.PluginTracer = PluginTracer;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PluginTracer = exports.tracer = exports.Trace = exports.SamplingProfiler = void 0;
|
|
7
|
+
var SamplingProfiler_1 = require("./SamplingProfiler");
|
|
8
|
+
Object.defineProperty(exports, "SamplingProfiler", { enumerable: true, get: function () { return __importDefault(SamplingProfiler_1).default; } });
|
|
9
|
+
var Trace_1 = require("./Trace");
|
|
10
|
+
Object.defineProperty(exports, "Trace", { enumerable: true, get: function () { return __importDefault(Trace_1).default; } });
|
|
11
|
+
var Tracer_1 = require("./Tracer");
|
|
12
|
+
Object.defineProperty(exports, "tracer", { enumerable: true, get: function () { return Tracer_1.tracer; } });
|
|
13
|
+
Object.defineProperty(exports, "PluginTracer", { enumerable: true, get: function () { return Tracer_1.PluginTracer; } });
|
package/dist/types.js
ADDED
package/lib/SamplingProfiler.js
CHANGED
|
@@ -20,10 +20,16 @@ function _diagnostic() {
|
|
|
20
20
|
}
|
|
21
21
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
22
|
// https://chromedevtools.github.io/devtools-protocol/tot/Profiler#type-Profile
|
|
23
|
+
|
|
23
24
|
// https://chromedevtools.github.io/devtools-protocol/tot/Profiler#type-ProfileNode
|
|
25
|
+
|
|
24
26
|
// https://chromedevtools.github.io/devtools-protocol/tot/Runtime#type-CallFrame
|
|
27
|
+
|
|
25
28
|
// https://chromedevtools.github.io/devtools-protocol/tot/Profiler#type-PositionTickInfo
|
|
29
|
+
|
|
26
30
|
class SamplingProfiler {
|
|
31
|
+
// @ts-expect-error not initialized
|
|
32
|
+
|
|
27
33
|
startProfiling() {
|
|
28
34
|
let inspector;
|
|
29
35
|
try {
|
package/lib/Tracer.js
CHANGED
|
@@ -18,7 +18,7 @@ function _perf_hooks() {
|
|
|
18
18
|
};
|
|
19
19
|
return data;
|
|
20
20
|
}
|
|
21
|
-
// @ts-
|
|
21
|
+
// @ts-expect-error TS7034
|
|
22
22
|
let tid;
|
|
23
23
|
try {
|
|
24
24
|
tid = require('worker_threads').threadId;
|
|
@@ -32,7 +32,6 @@ class TraceMeasurement {
|
|
|
32
32
|
#pid;
|
|
33
33
|
#tid;
|
|
34
34
|
#start;
|
|
35
|
-
// $FlowFixMe
|
|
36
35
|
#data;
|
|
37
36
|
constructor(tracer, name, pid, tid, data) {
|
|
38
37
|
this.#name = name;
|
|
@@ -82,6 +81,7 @@ class Tracer {
|
|
|
82
81
|
};
|
|
83
82
|
}
|
|
84
83
|
if (typeof otherArgs === 'object') {
|
|
84
|
+
// @ts-expect-error TS2454
|
|
85
85
|
if (typeof args == 'undefined') {
|
|
86
86
|
args = {};
|
|
87
87
|
}
|
|
@@ -91,8 +91,11 @@ class Tracer {
|
|
|
91
91
|
}
|
|
92
92
|
const data = {
|
|
93
93
|
categories: [category],
|
|
94
|
+
// @ts-expect-error TS2454
|
|
94
95
|
args
|
|
95
96
|
};
|
|
97
|
+
|
|
98
|
+
// @ts-expect-error TS7005
|
|
96
99
|
return new TraceMeasurement(this, name, pid, tid, data);
|
|
97
100
|
}
|
|
98
101
|
get enabled() {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Session } from
|
|
1
|
+
import type { Session } from 'inspector';
|
|
2
2
|
export type Profile = {
|
|
3
3
|
nodes: Array<ProfileNode>;
|
|
4
4
|
startTime: number;
|
|
@@ -28,7 +28,7 @@ type PositionTickInfo = {
|
|
|
28
28
|
export default class SamplingProfiler {
|
|
29
29
|
session: Session;
|
|
30
30
|
startProfiling(): Promise<unknown>;
|
|
31
|
-
sendCommand(method: string, params?:
|
|
31
|
+
sendCommand(method: string, params?: any): Promise<{
|
|
32
32
|
profile: Profile;
|
|
33
33
|
}>;
|
|
34
34
|
destroy(): void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Profile } from
|
|
2
|
-
import type { Writable } from
|
|
3
|
-
import { Tracer } from
|
|
1
|
+
import type { Profile } from './SamplingProfiler';
|
|
2
|
+
import type { Writable } from 'stream';
|
|
3
|
+
import { Tracer } from 'chrome-trace-event';
|
|
4
4
|
export default class Trace {
|
|
5
5
|
tracer: Tracer;
|
|
6
6
|
tid: number;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import type { TraceEvent, IDisposable, PluginTracer as IPluginTracer } from
|
|
2
|
-
import type { TraceMeasurement as ITraceMeasurement } from
|
|
1
|
+
import type { TraceEvent, IDisposable, PluginTracer as IPluginTracer } from '@atlaspack/types-internal';
|
|
2
|
+
import type { TraceMeasurement as ITraceMeasurement } from './types';
|
|
3
3
|
export default class Tracer {
|
|
4
|
-
|
|
4
|
+
#private;
|
|
5
5
|
onTrace(cb: (event: TraceEvent) => unknown): IDisposable;
|
|
6
6
|
wrap(name: string, fn: () => unknown): Promise<void>;
|
|
7
|
-
createMeasurement(name: string, category?: string, argumentName?: string, otherArgs?:
|
|
7
|
+
createMeasurement(name: string, category?: string, argumentName?: string, otherArgs?: {
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
}): ITraceMeasurement | null;
|
|
8
10
|
get enabled(): boolean;
|
|
9
11
|
enable(): void;
|
|
10
12
|
disable(): void;
|
|
@@ -23,6 +25,8 @@ export declare class PluginTracer implements IPluginTracer {
|
|
|
23
25
|
/** @private */
|
|
24
26
|
constructor(opts: TracerOpts);
|
|
25
27
|
get enabled(): boolean;
|
|
26
|
-
createMeasurement(name: string, category?: string, argumentName?: string, otherArgs?:
|
|
28
|
+
createMeasurement(name: string, category?: string, argumentName?: string, otherArgs?: {
|
|
29
|
+
[key: string]: unknown;
|
|
30
|
+
}): ITraceMeasurement | null;
|
|
27
31
|
}
|
|
28
32
|
export {};
|