@atlaspack/profiler 2.14.1-canary.40 → 2.14.1-canary.401

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 CHANGED
@@ -1,5 +1,322 @@
1
1
  # @atlaspack/profiler
2
2
 
3
+ ## 2.15.6
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies []:
8
+ - @atlaspack/types-internal@2.22.2
9
+ - @atlaspack/utils@3.2.6
10
+ - @atlaspack/logger@2.14.37
11
+
12
+ ## 2.15.5
13
+
14
+ ### Patch Changes
15
+
16
+ - Updated dependencies []:
17
+ - @atlaspack/logger@2.14.36
18
+ - @atlaspack/utils@3.2.5
19
+ - @atlaspack/types-internal@2.22.1
20
+
21
+ ## 2.15.4
22
+
23
+ ### Patch Changes
24
+
25
+ - Updated dependencies [[`00fa643`](https://github.com/atlassian-labs/atlaspack/commit/00fa6433202bfd3311479f6314c9ec878a789f2c)]:
26
+ - @atlaspack/types-internal@2.22.0
27
+ - @atlaspack/logger@2.14.35
28
+ - @atlaspack/utils@3.2.4
29
+
30
+ ## 2.15.3
31
+
32
+ ### Patch Changes
33
+
34
+ - Updated dependencies []:
35
+ - @atlaspack/logger@2.14.34
36
+ - @atlaspack/utils@3.2.3
37
+ - @atlaspack/types-internal@2.21.3
38
+
39
+ ## 2.15.2
40
+
41
+ ### Patch Changes
42
+
43
+ - Updated dependencies []:
44
+ - @atlaspack/logger@2.14.33
45
+ - @atlaspack/utils@3.2.2
46
+ - @atlaspack/types-internal@2.21.2
47
+
48
+ ## 2.15.1
49
+
50
+ ### Patch Changes
51
+
52
+ - Updated dependencies []:
53
+ - @atlaspack/logger@2.14.32
54
+ - @atlaspack/utils@3.2.1
55
+ - @atlaspack/types-internal@2.21.1
56
+
57
+ ## 2.15.0
58
+
59
+ ### Minor Changes
60
+
61
+ - [#892](https://github.com/atlassian-labs/atlaspack/pull/892) [`617a318`](https://github.com/atlassian-labs/atlaspack/commit/617a318ddc9419b38360257353fec50b9051ee13) Thanks [@marcins](https://github.com/marcins)! - Added a new `shouldProfileNative` option that provides a way to pause and connect a native profiler to Atlaspack.
62
+
63
+ ### Patch Changes
64
+
65
+ - Updated dependencies [[`8eb84ee`](https://github.com/atlassian-labs/atlaspack/commit/8eb84ee61a42bfe87c58079b610802b07a6a13e4), [`73168c2`](https://github.com/atlassian-labs/atlaspack/commit/73168c275a5d9abff9907bcf536b340bca1ed5f0), [`617a318`](https://github.com/atlassian-labs/atlaspack/commit/617a318ddc9419b38360257353fec50b9051ee13)]:
66
+ - @atlaspack/types-internal@2.21.0
67
+ - @atlaspack/utils@3.2.0
68
+ - @atlaspack/logger@2.14.31
69
+
70
+ ## 2.14.35
71
+
72
+ ### Patch Changes
73
+
74
+ - Updated dependencies []:
75
+ - @atlaspack/types-internal@2.20.8
76
+
77
+ ## 2.14.34
78
+
79
+ ### Patch Changes
80
+
81
+ - Updated dependencies []:
82
+ - @atlaspack/types-internal@2.20.7
83
+
84
+ ## 2.14.33
85
+
86
+ ### Patch Changes
87
+
88
+ - Updated dependencies []:
89
+ - @atlaspack/types-internal@2.20.6
90
+
91
+ ## 2.14.32
92
+
93
+ ### Patch Changes
94
+
95
+ - Updated dependencies [[`c372f3f`](https://github.com/atlassian-labs/atlaspack/commit/c372f3fd6fce8200d5cf47f41bc7895c6cbb5558)]:
96
+ - @atlaspack/types-internal@2.20.5
97
+
98
+ ## 2.14.31
99
+
100
+ ### Patch Changes
101
+
102
+ - Updated dependencies []:
103
+ - @atlaspack/types-internal@2.20.4
104
+
105
+ ## 2.14.30
106
+
107
+ ### Patch Changes
108
+
109
+ - Updated dependencies []:
110
+ - @atlaspack/types-internal@2.20.3
111
+
112
+ ## 2.14.29
113
+
114
+ ### Patch Changes
115
+
116
+ - Updated dependencies []:
117
+ - @atlaspack/types-internal@2.20.2
118
+
119
+ ## 2.14.28
120
+
121
+ ### Patch Changes
122
+
123
+ - [#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.
124
+
125
+ - Updated dependencies [[`0e7dd5e`](https://github.com/atlassian-labs/atlaspack/commit/0e7dd5ec6fbe05aa9e0bb5775a9d0975f206a922)]:
126
+ - @atlaspack/diagnostic@2.14.4
127
+ - @atlaspack/types-internal@2.20.1
128
+ - @atlaspack/events@2.14.4
129
+
130
+ ## 2.14.27
131
+
132
+ ### Patch Changes
133
+
134
+ - Updated dependencies [[`eedcbc4`](https://github.com/atlassian-labs/atlaspack/commit/eedcbc408fc1e86a2a8e25f1a41c57146d8529e1), [`f6532d7`](https://github.com/atlassian-labs/atlaspack/commit/f6532d7a4f7f007bd4e5e36af04dd466f0b9f572)]:
135
+ - @atlaspack/types-internal@2.20.0
136
+
137
+ ## 2.14.26
138
+
139
+ ### Patch Changes
140
+
141
+ - Updated dependencies []:
142
+ - @atlaspack/types-internal@2.19.5
143
+
144
+ ## 2.14.25
145
+
146
+ ### Patch Changes
147
+
148
+ - Updated dependencies []:
149
+ - @atlaspack/types-internal@2.19.4
150
+
151
+ ## 2.14.24
152
+
153
+ ### Patch Changes
154
+
155
+ - Updated dependencies []:
156
+ - @atlaspack/types-internal@2.19.3
157
+
158
+ ## 2.14.23
159
+
160
+ ### Patch Changes
161
+
162
+ - [#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
163
+
164
+ - Updated dependencies [[`ee040bb`](https://github.com/atlassian-labs/atlaspack/commit/ee040bb6428f29b57d892ddd8107e29077d08ffd)]:
165
+ - @atlaspack/types-internal@2.19.2
166
+ - @atlaspack/diagnostic@2.14.3
167
+ - @atlaspack/events@2.14.3
168
+
169
+ ## 2.14.22
170
+
171
+ ### Patch Changes
172
+
173
+ - Updated dependencies []:
174
+ - @atlaspack/types-internal@2.19.1
175
+
176
+ ## 2.14.21
177
+
178
+ ### Patch Changes
179
+
180
+ - Updated dependencies [[`7f5841c`](https://github.com/atlassian-labs/atlaspack/commit/7f5841c39df049f9546cccbeea2a7337e0337b45)]:
181
+ - @atlaspack/types-internal@2.19.0
182
+
183
+ ## 2.14.20
184
+
185
+ ### Patch Changes
186
+
187
+ - Updated dependencies [[`23d561e`](https://github.com/atlassian-labs/atlaspack/commit/23d561e51e68b0c38fd1ff4e4fb173e5e7b01cf2)]:
188
+ - @atlaspack/types-internal@2.18.0
189
+
190
+ ## 2.14.19
191
+
192
+ ### Patch Changes
193
+
194
+ - [#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
195
+
196
+ - Updated dependencies [[`d2fd849`](https://github.com/atlassian-labs/atlaspack/commit/d2fd849770fe6305e9c694bd97b1bd905abd9d94), [`43fdd22`](https://github.com/atlassian-labs/atlaspack/commit/43fdd223860fbc97af17d68c65419b97412cb888)]:
197
+ - @atlaspack/types-internal@2.17.0
198
+ - @atlaspack/diagnostic@2.14.2
199
+ - @atlaspack/events@2.14.2
200
+
201
+ ## 2.14.18
202
+
203
+ ### Patch Changes
204
+
205
+ - Updated dependencies [[`069de47`](https://github.com/atlassian-labs/atlaspack/commit/069de478e64fb5889f6f2ce023eb510782767fbd)]:
206
+ - @atlaspack/types-internal@2.16.0
207
+
208
+ ## 2.14.17
209
+
210
+ ### Patch Changes
211
+
212
+ - Updated dependencies []:
213
+ - @atlaspack/types-internal@2.15.2
214
+
215
+ ## 2.14.16
216
+
217
+ ### Patch Changes
218
+
219
+ - Updated dependencies []:
220
+ - @atlaspack/types-internal@2.15.1
221
+
222
+ ## 2.14.15
223
+
224
+ ### Patch Changes
225
+
226
+ - Updated dependencies [[`18a57cf`](https://github.com/atlassian-labs/atlaspack/commit/18a57cf8a4789b2de5ad8e2676f317a26cc91417)]:
227
+ - @atlaspack/types-internal@2.15.0
228
+
229
+ ## 2.14.14
230
+
231
+ ### Patch Changes
232
+
233
+ - Updated dependencies []:
234
+ - @atlaspack/types-internal@2.14.14
235
+
236
+ ## 2.14.13
237
+
238
+ ### Patch Changes
239
+
240
+ - Updated dependencies []:
241
+ - @atlaspack/types-internal@2.14.13
242
+
243
+ ## 2.14.12
244
+
245
+ ### Patch Changes
246
+
247
+ - Updated dependencies []:
248
+ - @atlaspack/types-internal@2.14.12
249
+
250
+ ## 2.14.11
251
+
252
+ ### Patch Changes
253
+
254
+ - Updated dependencies []:
255
+ - @atlaspack/types-internal@2.14.11
256
+
257
+ ## 2.14.10
258
+
259
+ ### Patch Changes
260
+
261
+ - Updated dependencies []:
262
+ - @atlaspack/types-internal@2.14.10
263
+
264
+ ## 2.14.9
265
+
266
+ ### Patch Changes
267
+
268
+ - Updated dependencies []:
269
+ - @atlaspack/types-internal@2.14.9
270
+
271
+ ## 2.14.8
272
+
273
+ ### Patch Changes
274
+
275
+ - Updated dependencies [[`51aba5f`](https://github.com/atlassian-labs/atlaspack/commit/51aba5fc0e49235ee06bbc3c376f48c3e7da5c4b)]:
276
+ - @atlaspack/types-internal@2.14.8
277
+
278
+ ## 2.14.7
279
+
280
+ ### Patch Changes
281
+
282
+ - Updated dependencies []:
283
+ - @atlaspack/types-internal@2.14.7
284
+
285
+ ## 2.14.6
286
+
287
+ ### Patch Changes
288
+
289
+ - Updated dependencies []:
290
+ - @atlaspack/types-internal@2.14.6
291
+
292
+ ## 2.14.5
293
+
294
+ ### Patch Changes
295
+
296
+ - Updated dependencies []:
297
+ - @atlaspack/types-internal@2.14.5
298
+
299
+ ## 2.14.4
300
+
301
+ ### Patch Changes
302
+
303
+ - Updated dependencies []:
304
+ - @atlaspack/types-internal@2.14.4
305
+
306
+ ## 2.14.3
307
+
308
+ ### Patch Changes
309
+
310
+ - Updated dependencies []:
311
+ - @atlaspack/types-internal@2.14.3
312
+
313
+ ## 2.14.2
314
+
315
+ ### Patch Changes
316
+
317
+ - Updated dependencies []:
318
+ - @atlaspack/types-internal@2.14.2
319
+
3
320
  ## 2.14.1
4
321
 
5
322
  ### Patch Changes
@@ -0,0 +1,205 @@
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 utils_1 = require("@atlaspack/utils");
7
+ const logger_1 = __importDefault(require("@atlaspack/logger"));
8
+ const readline_1 = __importDefault(require("readline"));
9
+ const chalk_1 = __importDefault(require("chalk"));
10
+ const child_process_1 = require("child_process");
11
+ const util_1 = require("util");
12
+ const execAsync = (0, util_1.promisify)(child_process_1.exec);
13
+ class NativeProfiler {
14
+ startProfiling(profilerType) {
15
+ const pid = process.pid;
16
+ const timeId = (0, utils_1.getTimeId)();
17
+ let filename;
18
+ let command;
19
+ logger_1.default.info({
20
+ origin: '@atlaspack/profiler',
21
+ message: 'Starting native profiling...',
22
+ });
23
+ if (profilerType === 'instruments') {
24
+ filename = `native-profile-${timeId}.trace`;
25
+ command = `xcrun xctrace record --template "CPU Profiler" --output ${filename} --attach ${pid}`;
26
+ }
27
+ else {
28
+ filename = `native-profile-${timeId}.json`;
29
+ command = `samply record --save-only --output ${filename} --pid ${pid}`;
30
+ }
31
+ // Display banner with PID and command
32
+ // Strip ANSI codes for length calculation
33
+ // eslint-disable-next-line no-control-regex
34
+ const stripAnsi = (str) => str.replace(/\u001b\[[0-9;]*m/g, '');
35
+ const boxWidth = Math.max(60, stripAnsi(command).length + 6);
36
+ const title = 'Native Profiling';
37
+ const titlePadding = Math.floor((boxWidth - title.length - 2) / 2);
38
+ const isTTY = process.stdin.isTTY;
39
+ const maxWaitTime = 30; // seconds
40
+ const padLine = (content) => {
41
+ const contentLength = stripAnsi(content).length;
42
+ const padding = Math.max(0, boxWidth - contentLength - 2);
43
+ return (chalk_1.default.blue('│') +
44
+ ' ' +
45
+ content +
46
+ ' '.repeat(padding) +
47
+ ' ' +
48
+ chalk_1.default.blue('│'));
49
+ };
50
+ // Make the command visually distinct and easy to copy
51
+ // Note: Hyperlinks can cause issues with commands (words become separate links)
52
+ // So we just make it visually prominent with colors
53
+ const makeCommandDisplay = (cmd) => {
54
+ return chalk_1.default.cyan.bold(cmd);
55
+ };
56
+ // Contextual message based on TTY
57
+ const continueMessage = isTTY
58
+ ? 'Press Enter or start the profiler to continue'
59
+ : `Build will continue when profiler has started, or after ${maxWaitTime}s`;
60
+ const banner = [
61
+ '',
62
+ chalk_1.default.blue('┌' + '─'.repeat(boxWidth) + '┐'),
63
+ chalk_1.default.blue('│') +
64
+ ' '.repeat(titlePadding) +
65
+ chalk_1.default.blue.bold(title) +
66
+ ' '.repeat(boxWidth - title.length - titlePadding) +
67
+ chalk_1.default.blue('│'),
68
+ chalk_1.default.blue('├' + '─'.repeat(boxWidth) + '┤'),
69
+ padLine(`${chalk_1.default.gray('PID:')} ${chalk_1.default.white.bold(String(pid))}`),
70
+ padLine(''),
71
+ padLine(chalk_1.default.gray('Command:')),
72
+ padLine(makeCommandDisplay(command)),
73
+ padLine(''),
74
+ padLine(chalk_1.default.gray('Run the command above to start profiling.')),
75
+ padLine(chalk_1.default.gray(continueMessage)),
76
+ chalk_1.default.blue('└' + '─'.repeat(boxWidth) + '┘'),
77
+ '',
78
+ ].join('\n');
79
+ // eslint-disable-next-line no-console
80
+ console.log(banner);
81
+ // In both interactive and non-interactive mode, detect when profiler is running
82
+ // In interactive mode, also allow user to press Enter to continue
83
+ if (!process.stdin.isTTY) {
84
+ return this.waitForProfiler(profilerType, pid);
85
+ }
86
+ // Interactive mode: wait for either user to press Enter OR profiler to be detected
87
+ return new Promise((resolve) => {
88
+ let resolved = false;
89
+ const doResolve = () => {
90
+ if (resolved)
91
+ return;
92
+ resolved = true;
93
+ logger_1.default.info({
94
+ origin: '@atlaspack/profiler',
95
+ message: 'Native profiling setup complete',
96
+ });
97
+ resolve();
98
+ };
99
+ const rl = readline_1.default.createInterface({
100
+ input: process.stdin,
101
+ output: process.stdout,
102
+ });
103
+ // User presses Enter
104
+ rl.on('line', () => {
105
+ rl.close();
106
+ doResolve();
107
+ });
108
+ // Also poll for profiler in the background
109
+ this.pollForProfiler(profilerType, pid, doResolve);
110
+ });
111
+ }
112
+ waitForProfiler(profilerType, pid) {
113
+ logger_1.default.info({
114
+ origin: '@atlaspack/profiler',
115
+ message: 'Non-interactive mode: waiting for profiler to attach...',
116
+ });
117
+ return new Promise((resolve) => {
118
+ this.pollForProfiler(profilerType, pid, () => {
119
+ logger_1.default.info({
120
+ origin: '@atlaspack/profiler',
121
+ message: 'Native profiling setup complete',
122
+ });
123
+ resolve();
124
+ });
125
+ });
126
+ }
127
+ async pollForProfiler(profilerType, pid, onDetected) {
128
+ const maxAttempts = 60; // 60 attempts * 500ms = 30 seconds max
129
+ const pollInterval = 500; // 500ms between checks
130
+ for (let attempt = 0; attempt < maxAttempts; attempt++) {
131
+ const isRunning = await this.checkProfilerRunning(profilerType, pid);
132
+ if (isRunning) {
133
+ // Instruments takes longer to start up (~5s), samply needs ~1s
134
+ const waitTime = profilerType === 'instruments' ? 5000 : 1000;
135
+ logger_1.default.info({
136
+ origin: '@atlaspack/profiler',
137
+ message: `Profiler detected, waiting ${waitTime}ms before continuing...`,
138
+ });
139
+ await new Promise((resolve) => setTimeout(resolve, waitTime));
140
+ onDetected();
141
+ return;
142
+ }
143
+ await new Promise((resolve) => setTimeout(resolve, pollInterval));
144
+ }
145
+ // If we couldn't detect the profiler after 30 seconds, log a warning and continue anyway
146
+ logger_1.default.warn({
147
+ origin: '@atlaspack/profiler',
148
+ message: 'Could not detect profiler after 30 seconds, continuing anyway...',
149
+ });
150
+ onDetected();
151
+ }
152
+ async checkProfilerRunning(profilerType, pid) {
153
+ try {
154
+ // Get all processes and filter in JavaScript
155
+ const { stdout } = await execAsync('ps aux');
156
+ const lines = stdout.split('\n').filter((line) => line.trim().length > 0);
157
+ // Use word boundaries to match the PID as a complete number
158
+ const pidRegex = new RegExp(`\\b${pid}\\b`);
159
+ // Determine the profiler process name to look for
160
+ const profilerName = profilerType === 'instruments' ? 'xctrace' : 'samply';
161
+ for (const line of lines) {
162
+ const lowerLine = line.toLowerCase();
163
+ // Skip lines that are part of our own process checking (avoid false positives)
164
+ // Skip lines containing "ps aux" or "grep" to avoid matching our own commands
165
+ if (lowerLine.includes('ps aux') || lowerLine.includes(' grep ')) {
166
+ continue;
167
+ }
168
+ // Skip our own process (the Atlaspack process itself)
169
+ // The PID column is the second field in ps aux output
170
+ const fields = line.trim().split(/\s+/);
171
+ if (fields.length >= 2 && fields[1] === String(pid)) {
172
+ continue;
173
+ }
174
+ // Check if this line contains the profiler name as a command
175
+ const profilerRegex = new RegExp(`\\b${profilerName}\\b`);
176
+ if (!profilerRegex.test(lowerLine)) {
177
+ continue;
178
+ }
179
+ // Now check if our PID appears in the command arguments (not in the PID column)
180
+ // The PID should appear after the profiler command, typically as --pid <pid> or --attach <pid>
181
+ // We need to check the command portion, which starts around column 11 in ps aux
182
+ // For safety, check if PID appears after the profiler name in the line
183
+ const profilerIndex = lowerLine.indexOf(profilerName);
184
+ if (profilerIndex === -1) {
185
+ continue;
186
+ }
187
+ // Check if PID appears in the command portion (after the profiler name)
188
+ const commandPortion = line.substring(profilerIndex);
189
+ if (pidRegex.test(commandPortion)) {
190
+ return true;
191
+ }
192
+ }
193
+ return false;
194
+ }
195
+ catch (error) {
196
+ // If the command fails, log and return false
197
+ logger_1.default.warn({
198
+ origin: '@atlaspack/profiler',
199
+ message: `Error checking profiler status: ${error.message}`,
200
+ });
201
+ return false;
202
+ }
203
+ }
204
+ }
205
+ exports.default = NativeProfiler;
@@ -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;