@atlaspack/profiler 2.14.1-canary.3710 → 2.14.1-canary.373

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,288 @@
1
1
  # @atlaspack/profiler
2
2
 
3
+ ## 2.15.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies []:
8
+ - @atlaspack/logger@2.14.32
9
+ - @atlaspack/utils@3.2.1
10
+ - @atlaspack/types-internal@2.21.1
11
+
12
+ ## 2.15.0
13
+
14
+ ### Minor Changes
15
+
16
+ - [#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.
17
+
18
+ ### Patch Changes
19
+
20
+ - 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)]:
21
+ - @atlaspack/types-internal@2.21.0
22
+ - @atlaspack/utils@3.2.0
23
+ - @atlaspack/logger@2.14.31
24
+
25
+ ## 2.14.35
26
+
27
+ ### Patch Changes
28
+
29
+ - Updated dependencies []:
30
+ - @atlaspack/types-internal@2.20.8
31
+
32
+ ## 2.14.34
33
+
34
+ ### Patch Changes
35
+
36
+ - Updated dependencies []:
37
+ - @atlaspack/types-internal@2.20.7
38
+
39
+ ## 2.14.33
40
+
41
+ ### Patch Changes
42
+
43
+ - Updated dependencies []:
44
+ - @atlaspack/types-internal@2.20.6
45
+
46
+ ## 2.14.32
47
+
48
+ ### Patch Changes
49
+
50
+ - Updated dependencies [[`c372f3f`](https://github.com/atlassian-labs/atlaspack/commit/c372f3fd6fce8200d5cf47f41bc7895c6cbb5558)]:
51
+ - @atlaspack/types-internal@2.20.5
52
+
53
+ ## 2.14.31
54
+
55
+ ### Patch Changes
56
+
57
+ - Updated dependencies []:
58
+ - @atlaspack/types-internal@2.20.4
59
+
60
+ ## 2.14.30
61
+
62
+ ### Patch Changes
63
+
64
+ - Updated dependencies []:
65
+ - @atlaspack/types-internal@2.20.3
66
+
67
+ ## 2.14.29
68
+
69
+ ### Patch Changes
70
+
71
+ - Updated dependencies []:
72
+ - @atlaspack/types-internal@2.20.2
73
+
74
+ ## 2.14.28
75
+
76
+ ### Patch Changes
77
+
78
+ - [#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.
79
+
80
+ - Updated dependencies [[`0e7dd5e`](https://github.com/atlassian-labs/atlaspack/commit/0e7dd5ec6fbe05aa9e0bb5775a9d0975f206a922)]:
81
+ - @atlaspack/diagnostic@2.14.4
82
+ - @atlaspack/types-internal@2.20.1
83
+ - @atlaspack/events@2.14.4
84
+
85
+ ## 2.14.27
86
+
87
+ ### Patch Changes
88
+
89
+ - Updated dependencies [[`eedcbc4`](https://github.com/atlassian-labs/atlaspack/commit/eedcbc408fc1e86a2a8e25f1a41c57146d8529e1), [`f6532d7`](https://github.com/atlassian-labs/atlaspack/commit/f6532d7a4f7f007bd4e5e36af04dd466f0b9f572)]:
90
+ - @atlaspack/types-internal@2.20.0
91
+
92
+ ## 2.14.26
93
+
94
+ ### Patch Changes
95
+
96
+ - Updated dependencies []:
97
+ - @atlaspack/types-internal@2.19.5
98
+
99
+ ## 2.14.25
100
+
101
+ ### Patch Changes
102
+
103
+ - Updated dependencies []:
104
+ - @atlaspack/types-internal@2.19.4
105
+
106
+ ## 2.14.24
107
+
108
+ ### Patch Changes
109
+
110
+ - Updated dependencies []:
111
+ - @atlaspack/types-internal@2.19.3
112
+
113
+ ## 2.14.23
114
+
115
+ ### Patch Changes
116
+
117
+ - [#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
118
+
119
+ - Updated dependencies [[`ee040bb`](https://github.com/atlassian-labs/atlaspack/commit/ee040bb6428f29b57d892ddd8107e29077d08ffd)]:
120
+ - @atlaspack/types-internal@2.19.2
121
+ - @atlaspack/diagnostic@2.14.3
122
+ - @atlaspack/events@2.14.3
123
+
124
+ ## 2.14.22
125
+
126
+ ### Patch Changes
127
+
128
+ - Updated dependencies []:
129
+ - @atlaspack/types-internal@2.19.1
130
+
131
+ ## 2.14.21
132
+
133
+ ### Patch Changes
134
+
135
+ - Updated dependencies [[`7f5841c`](https://github.com/atlassian-labs/atlaspack/commit/7f5841c39df049f9546cccbeea2a7337e0337b45)]:
136
+ - @atlaspack/types-internal@2.19.0
137
+
138
+ ## 2.14.20
139
+
140
+ ### Patch Changes
141
+
142
+ - Updated dependencies [[`23d561e`](https://github.com/atlassian-labs/atlaspack/commit/23d561e51e68b0c38fd1ff4e4fb173e5e7b01cf2)]:
143
+ - @atlaspack/types-internal@2.18.0
144
+
145
+ ## 2.14.19
146
+
147
+ ### Patch Changes
148
+
149
+ - [#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
150
+
151
+ - Updated dependencies [[`d2fd849`](https://github.com/atlassian-labs/atlaspack/commit/d2fd849770fe6305e9c694bd97b1bd905abd9d94), [`43fdd22`](https://github.com/atlassian-labs/atlaspack/commit/43fdd223860fbc97af17d68c65419b97412cb888)]:
152
+ - @atlaspack/types-internal@2.17.0
153
+ - @atlaspack/diagnostic@2.14.2
154
+ - @atlaspack/events@2.14.2
155
+
156
+ ## 2.14.18
157
+
158
+ ### Patch Changes
159
+
160
+ - Updated dependencies [[`069de47`](https://github.com/atlassian-labs/atlaspack/commit/069de478e64fb5889f6f2ce023eb510782767fbd)]:
161
+ - @atlaspack/types-internal@2.16.0
162
+
163
+ ## 2.14.17
164
+
165
+ ### Patch Changes
166
+
167
+ - Updated dependencies []:
168
+ - @atlaspack/types-internal@2.15.2
169
+
170
+ ## 2.14.16
171
+
172
+ ### Patch Changes
173
+
174
+ - Updated dependencies []:
175
+ - @atlaspack/types-internal@2.15.1
176
+
177
+ ## 2.14.15
178
+
179
+ ### Patch Changes
180
+
181
+ - Updated dependencies [[`18a57cf`](https://github.com/atlassian-labs/atlaspack/commit/18a57cf8a4789b2de5ad8e2676f317a26cc91417)]:
182
+ - @atlaspack/types-internal@2.15.0
183
+
184
+ ## 2.14.14
185
+
186
+ ### Patch Changes
187
+
188
+ - Updated dependencies []:
189
+ - @atlaspack/types-internal@2.14.14
190
+
191
+ ## 2.14.13
192
+
193
+ ### Patch Changes
194
+
195
+ - Updated dependencies []:
196
+ - @atlaspack/types-internal@2.14.13
197
+
198
+ ## 2.14.12
199
+
200
+ ### Patch Changes
201
+
202
+ - Updated dependencies []:
203
+ - @atlaspack/types-internal@2.14.12
204
+
205
+ ## 2.14.11
206
+
207
+ ### Patch Changes
208
+
209
+ - Updated dependencies []:
210
+ - @atlaspack/types-internal@2.14.11
211
+
212
+ ## 2.14.10
213
+
214
+ ### Patch Changes
215
+
216
+ - Updated dependencies []:
217
+ - @atlaspack/types-internal@2.14.10
218
+
219
+ ## 2.14.9
220
+
221
+ ### Patch Changes
222
+
223
+ - Updated dependencies []:
224
+ - @atlaspack/types-internal@2.14.9
225
+
226
+ ## 2.14.8
227
+
228
+ ### Patch Changes
229
+
230
+ - Updated dependencies [[`51aba5f`](https://github.com/atlassian-labs/atlaspack/commit/51aba5fc0e49235ee06bbc3c376f48c3e7da5c4b)]:
231
+ - @atlaspack/types-internal@2.14.8
232
+
233
+ ## 2.14.7
234
+
235
+ ### Patch Changes
236
+
237
+ - Updated dependencies []:
238
+ - @atlaspack/types-internal@2.14.7
239
+
240
+ ## 2.14.6
241
+
242
+ ### Patch Changes
243
+
244
+ - Updated dependencies []:
245
+ - @atlaspack/types-internal@2.14.6
246
+
247
+ ## 2.14.5
248
+
249
+ ### Patch Changes
250
+
251
+ - Updated dependencies []:
252
+ - @atlaspack/types-internal@2.14.5
253
+
254
+ ## 2.14.4
255
+
256
+ ### Patch Changes
257
+
258
+ - Updated dependencies []:
259
+ - @atlaspack/types-internal@2.14.4
260
+
261
+ ## 2.14.3
262
+
263
+ ### Patch Changes
264
+
265
+ - Updated dependencies []:
266
+ - @atlaspack/types-internal@2.14.3
267
+
268
+ ## 2.14.2
269
+
270
+ ### Patch Changes
271
+
272
+ - Updated dependencies []:
273
+ - @atlaspack/types-internal@2.14.2
274
+
275
+ ## 2.14.1
276
+
277
+ ### Patch Changes
278
+
279
+ - [#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.
280
+ This has hopefully been fixed, so this change will force those packages to re-release.
281
+ - Updated dependencies [[`e1422ad`](https://github.com/atlassian-labs/atlaspack/commit/e1422ad0a801faaa4bc4f1023bed042ffe236e9b), [`570493b`](https://github.com/atlassian-labs/atlaspack/commit/570493beaf754e7985aebc7daaaf6dfcfa8fe56b)]:
282
+ - @atlaspack/types-internal@2.14.1
283
+ - @atlaspack/diagnostic@2.14.1
284
+ - @atlaspack/events@2.14.1
285
+
3
286
  ## 2.14.0
4
287
 
5
288
  ### Minor 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;