@atlaspack/profiler 2.14.15-typescript-d6e6d169c.0 → 2.14.15-typescript-6de04fbae.0

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.
@@ -26,7 +26,7 @@ type PositionTickInfo = {
26
26
  ticks: number;
27
27
  };
28
28
  export default class SamplingProfiler {
29
- session: Session;
29
+ session: Session | undefined;
30
30
  startProfiling(): Promise<unknown>;
31
31
  sendCommand(method: string, params?: any): Promise<{
32
32
  profile: Profile;
@@ -1,69 +1,111 @@
1
1
  "use strict";
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
3
+ value: true
5
4
  });
6
- exports.default = void 0;
7
- function _assert() {
8
- const data = _interopRequireDefault(require("assert"));
9
- _assert = function () {
10
- return data;
11
- };
12
- return data;
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return SamplingProfiler;
9
+ }
10
+ });
11
+ const _diagnostic = /*#__PURE__*/ _interop_require_default(require("@atlaspack/diagnostic"));
12
+ function _interop_require_default(obj) {
13
+ return obj && obj.__esModule ? obj : {
14
+ default: obj
15
+ };
13
16
  }
14
- function _diagnostic() {
15
- const data = _interopRequireDefault(require("@atlaspack/diagnostic"));
16
- _diagnostic = function () {
17
- return data;
18
- };
19
- return data;
17
+ function _getRequireWildcardCache(nodeInterop) {
18
+ if (typeof WeakMap !== "function") return null;
19
+ var cacheBabelInterop = new WeakMap();
20
+ var cacheNodeInterop = new WeakMap();
21
+ return (_getRequireWildcardCache = function(nodeInterop) {
22
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
23
+ })(nodeInterop);
24
+ }
25
+ function _interop_require_wildcard(obj, nodeInterop) {
26
+ if (!nodeInterop && obj && obj.__esModule) {
27
+ return obj;
28
+ }
29
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
30
+ return {
31
+ default: obj
32
+ };
33
+ }
34
+ var cache = _getRequireWildcardCache(nodeInterop);
35
+ if (cache && cache.has(obj)) {
36
+ return cache.get(obj);
37
+ }
38
+ var newObj = {
39
+ __proto__: null
40
+ };
41
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
42
+ for(var key in obj){
43
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
44
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
45
+ if (desc && (desc.get || desc.set)) {
46
+ Object.defineProperty(newObj, key, desc);
47
+ } else {
48
+ newObj[key] = obj[key];
49
+ }
50
+ }
51
+ }
52
+ newObj.default = obj;
53
+ if (cache) {
54
+ cache.set(obj, newObj);
55
+ }
56
+ return newObj;
20
57
  }
21
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
- // https://chromedevtools.github.io/devtools-protocol/tot/Profiler#type-Profile
23
- // https://chromedevtools.github.io/devtools-protocol/tot/Profiler#type-ProfileNode
24
- // https://chromedevtools.github.io/devtools-protocol/tot/Runtime#type-CallFrame
25
- // https://chromedevtools.github.io/devtools-protocol/tot/Profiler#type-PositionTickInfo
26
58
  class SamplingProfiler {
27
- startProfiling() {
28
- let inspector;
29
- try {
30
- inspector = require('inspector');
31
- } catch (err) {
32
- throw new (_diagnostic().default)({
33
- diagnostic: {
34
- message: `The inspector module isn't available`,
35
- origin: '@atlaspack/workers',
36
- hints: ['Disable build profiling']
59
+ session;
60
+ async startProfiling() {
61
+ let inspector;
62
+ try {
63
+ inspector = await Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard(require("inspector")));
64
+ } catch (err) {
65
+ throw new _diagnostic.default({
66
+ diagnostic: {
67
+ message: `The inspector module isn't available`,
68
+ origin: '@atlaspack/workers',
69
+ hints: [
70
+ 'Disable build profiling'
71
+ ]
72
+ }
73
+ });
74
+ }
75
+ if (!this.session) {
76
+ this.session = new inspector.Session();
37
77
  }
38
- });
78
+ this.session.connect();
79
+ return Promise.all([
80
+ this.sendCommand('Profiler.setSamplingInterval', {
81
+ interval: 100
82
+ }),
83
+ this.sendCommand('Profiler.enable'),
84
+ this.sendCommand('Profiler.start')
85
+ ]);
39
86
  }
40
- this.session = new inspector.Session();
41
- this.session.connect();
42
- return Promise.all([this.sendCommand('Profiler.setSamplingInterval', {
43
- interval: 100
44
- }), this.sendCommand('Profiler.enable'), this.sendCommand('Profiler.start')]);
45
- }
46
- sendCommand(method, params) {
47
- (0, _assert().default)(this.session != null);
48
- return new Promise((resolve, reject) => {
49
- this.session.post(method, params, (err, p) => {
50
- if (err == null) {
51
- resolve(p);
52
- } else {
53
- reject(err);
87
+ sendCommand(method, params) {
88
+ if (!this.session) {
89
+ throw new Error('No session set');
54
90
  }
55
- });
56
- });
57
- }
58
- destroy() {
59
- if (this.session != null) {
60
- this.session.disconnect();
91
+ return new Promise((resolve, reject)=>{
92
+ this.session.post(method, params, (err, p)=>{
93
+ if (err == null) {
94
+ resolve(p);
95
+ } else {
96
+ reject(err);
97
+ }
98
+ });
99
+ });
100
+ }
101
+ destroy() {
102
+ if (this.session != null) {
103
+ this.session.disconnect();
104
+ }
105
+ }
106
+ async stopProfiling() {
107
+ let res = await this.sendCommand('Profiler.stop');
108
+ this.destroy();
109
+ return res.profile;
61
110
  }
62
- }
63
- async stopProfiling() {
64
- let res = await this.sendCommand('Profiler.stop');
65
- this.destroy();
66
- return res.profile;
67
- }
68
111
  }
69
- exports.default = SamplingProfiler;
@@ -0,0 +1,47 @@
1
+ // @flow
2
+ import type {Session} from 'inspector';
3
+ import invariant from 'assert';
4
+ // @ts-expect-error TSMIGRATION
5
+ import ThrowableDiagnostic from '@atlaspack/diagnostic';
6
+
7
+ // https://chromedevtools.github.io/devtools-protocol/tot/Profiler#type-Profile
8
+ export type Profile = {|
9
+ nodes: Array<ProfileNode>,
10
+ startTime: number,
11
+ endTime: number,
12
+ samples?: Array<number>,
13
+ timeDeltas?: Array<number>,
14
+ |};
15
+
16
+ // https://chromedevtools.github.io/devtools-protocol/tot/Profiler#type-ProfileNode
17
+ type ProfileNode = {|
18
+ id: number,
19
+ callFrame: CallFrame,
20
+ hitCount?: number,
21
+ children?: Array<number>,
22
+ deoptReason?: string,
23
+ positionTicks?: PositionTickInfo,
24
+ |};
25
+
26
+ // https://chromedevtools.github.io/devtools-protocol/tot/Runtime#type-CallFrame
27
+ type CallFrame = {|
28
+ functionName: string,
29
+ scriptId: string,
30
+ url: string,
31
+ lineNumber: string,
32
+ columnNumber: string,
33
+ |};
34
+
35
+ // https://chromedevtools.github.io/devtools-protocol/tot/Profiler#type-PositionTickInfo
36
+ type PositionTickInfo = {|
37
+ line: number,
38
+ ticks: number,
39
+ |};
40
+
41
+ declare export default class SamplingProfiler {
42
+ session: Session;
43
+ startProfiling(): Promise<mixed>;
44
+ sendCommand(method: string, params?: any): Promise<{profile: Profile, ...}>;
45
+ destroy(): void;
46
+ stopProfiling(): Promise<Profile>;
47
+ }
@@ -0,0 +1,51 @@
1
+ import ThrowableDiagnostic from "@atlaspack/diagnostic";
2
+ export default class SamplingProfiler {
3
+ session;
4
+ async startProfiling() {
5
+ let inspector;
6
+ try {
7
+ inspector = await import('inspector');
8
+ }
9
+ catch (err) {
10
+ throw new ThrowableDiagnostic({
11
+ diagnostic: {
12
+ message: `The inspector module isn't available`,
13
+ origin: '@atlaspack/workers',
14
+ hints: ['Disable build profiling']
15
+ }
16
+ });
17
+ }
18
+ if (!this.session) {
19
+ this.session = new inspector.Session();
20
+ }
21
+ this.session.connect();
22
+ return Promise.all([this.sendCommand('Profiler.setSamplingInterval', {
23
+ interval: 100
24
+ }), this.sendCommand('Profiler.enable'), this.sendCommand('Profiler.start')]);
25
+ }
26
+ sendCommand(method, params) {
27
+ if (!this.session) {
28
+ throw new Error('No session set');
29
+ }
30
+ return new Promise((resolve, reject) => {
31
+ this.session.post(method, params, (err, p) => {
32
+ if (err == null) {
33
+ resolve(p);
34
+ }
35
+ else {
36
+ reject(err);
37
+ }
38
+ });
39
+ });
40
+ }
41
+ destroy() {
42
+ if (this.session != null) {
43
+ this.session.disconnect();
44
+ }
45
+ }
46
+ async stopProfiling() {
47
+ let res = await this.sendCommand('Profiler.stop');
48
+ this.destroy();
49
+ return res.profile;
50
+ }
51
+ }
@@ -1,6 +1,6 @@
1
- import type { Profile } from "./SamplingProfiler";
2
- import type { Writable } from "stream";
3
- import { Tracer } from "chrome-trace-event";
1
+ import type { Profile } from './SamplingProfiler.mts';
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;
package/lib/Trace.js CHANGED
@@ -1,119 +1,133 @@
1
1
  "use strict";
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
3
+ value: true
5
4
  });
6
- exports.default = void 0;
7
- function _chromeTraceEvent() {
8
- const data = require("chrome-trace-event");
9
- _chromeTraceEvent = function () {
10
- return data;
11
- };
12
- return data;
13
- }
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return Trace;
9
+ }
10
+ });
11
+ const _chrometraceevent = require("chrome-trace-event");
14
12
  class Trace {
15
- constructor() {
16
- this.tracer = new (_chromeTraceEvent().Tracer)();
17
- this.tid = 0;
18
- this.eventId = 0;
19
- }
20
- getEventId() {
21
- return this.eventId++;
22
- }
23
- init(ts) {
24
- this.tracer.instantEvent({
25
- name: 'TracingStartedInPage',
26
- id: this.getEventId(),
27
- ts,
28
- cat: ['disabled-by-default-devtools.timeline'],
29
- args: {
30
- data: {
31
- sessionId: '-1',
32
- page: '0xfff',
33
- frames: [{
34
- frame: '0xfff',
35
- url: 'parcel',
36
- name: ''
37
- }]
38
- }
39
- }
40
- });
41
- this.tracer.instantEvent({
42
- name: 'TracingStartedInBrowser',
43
- id: this.getEventId(),
44
- ts,
45
- cat: ['disabled-by-default-devtools.timeline'],
46
- args: {
47
- data: {
48
- sessionId: '-1'
49
- }
50
- }
51
- });
52
- }
53
- addCPUProfile(name, profile) {
54
- if (this.eventId === 0) {
55
- this.init(profile.startTime);
13
+ tracer;
14
+ tid;
15
+ eventId;
16
+ constructor(){
17
+ this.tracer = new _chrometraceevent.Tracer();
18
+ this.tid = 0;
19
+ this.eventId = 0;
56
20
  }
57
- const trace = this.tracer;
58
- const tid = this.tid;
59
- this.tid++;
60
- const cpuStartTime = profile.startTime;
61
- const cpuEndTime = profile.endTime;
62
- trace.instantEvent({
63
- tid,
64
- id: this.getEventId(),
65
- cat: ['toplevel'],
66
- name: 'TaskQueueManager::ProcessTaskFromWorkQueue',
67
- args: {
68
- src_file: '../../ipc/ipc_moji_bootstrap.cc',
69
- src_func: 'Accept'
70
- },
71
- ts: cpuStartTime
72
- });
73
- trace.completeEvent({
74
- tid,
75
- name: 'EvaluateScript',
76
- id: this.getEventId(),
77
- cat: ['devtools.timeline'],
78
- ts: cpuStartTime,
79
- dur: cpuEndTime - cpuStartTime,
80
- args: {
81
- data: {
82
- url: 'parcel',
83
- lineNumber: 1,
84
- columnNumber: 1,
85
- frame: '0xFFF'
86
- }
87
- }
88
- });
89
- trace.instantEvent({
90
- tid,
91
- ts: 0,
92
- ph: 'M',
93
- cat: ['__metadata'],
94
- name: 'thread_name',
95
- args: {
96
- name
97
- }
98
- });
99
- trace.instantEvent({
100
- tid,
101
- name: 'CpuProfile',
102
- id: this.getEventId(),
103
- cat: ['disabled-by-default-devtools.timeline'],
104
- ts: cpuEndTime,
105
- args: {
106
- data: {
107
- cpuProfile: profile
21
+ getEventId() {
22
+ return this.eventId++;
23
+ }
24
+ init(ts) {
25
+ this.tracer.instantEvent({
26
+ name: 'TracingStartedInPage',
27
+ id: this.getEventId(),
28
+ ts,
29
+ cat: [
30
+ 'disabled-by-default-devtools.timeline'
31
+ ],
32
+ args: {
33
+ data: {
34
+ sessionId: '-1',
35
+ page: '0xfff',
36
+ frames: [
37
+ {
38
+ frame: '0xfff',
39
+ url: 'parcel',
40
+ name: ''
41
+ }
42
+ ]
43
+ }
44
+ }
45
+ });
46
+ this.tracer.instantEvent({
47
+ name: 'TracingStartedInBrowser',
48
+ id: this.getEventId(),
49
+ ts,
50
+ cat: [
51
+ 'disabled-by-default-devtools.timeline'
52
+ ],
53
+ args: {
54
+ data: {
55
+ sessionId: '-1'
56
+ }
57
+ }
58
+ });
59
+ }
60
+ addCPUProfile(name, profile) {
61
+ if (this.eventId === 0) {
62
+ this.init(profile.startTime);
108
63
  }
109
- }
110
- });
111
- }
112
- pipe(writable) {
113
- return this.tracer.pipe(writable);
114
- }
115
- flush() {
116
- this.tracer.push(null);
117
- }
64
+ const trace = this.tracer;
65
+ const tid = this.tid;
66
+ this.tid++;
67
+ const cpuStartTime = profile.startTime;
68
+ const cpuEndTime = profile.endTime;
69
+ trace.instantEvent({
70
+ tid,
71
+ id: this.getEventId(),
72
+ cat: [
73
+ 'toplevel'
74
+ ],
75
+ name: 'TaskQueueManager::ProcessTaskFromWorkQueue',
76
+ args: {
77
+ src_file: '../../ipc/ipc_moji_bootstrap.cc',
78
+ src_func: 'Accept'
79
+ },
80
+ ts: cpuStartTime
81
+ });
82
+ trace.completeEvent({
83
+ tid,
84
+ name: 'EvaluateScript',
85
+ id: this.getEventId(),
86
+ cat: [
87
+ 'devtools.timeline'
88
+ ],
89
+ ts: cpuStartTime,
90
+ dur: cpuEndTime - cpuStartTime,
91
+ args: {
92
+ data: {
93
+ url: 'parcel',
94
+ lineNumber: 1,
95
+ columnNumber: 1,
96
+ frame: '0xFFF'
97
+ }
98
+ }
99
+ });
100
+ trace.instantEvent({
101
+ tid,
102
+ ts: 0,
103
+ ph: 'M',
104
+ cat: [
105
+ '__metadata'
106
+ ],
107
+ name: 'thread_name',
108
+ args: {
109
+ name
110
+ }
111
+ });
112
+ trace.instantEvent({
113
+ tid,
114
+ name: 'CpuProfile',
115
+ id: this.getEventId(),
116
+ cat: [
117
+ 'disabled-by-default-devtools.timeline'
118
+ ],
119
+ ts: cpuEndTime,
120
+ args: {
121
+ data: {
122
+ cpuProfile: profile
123
+ }
124
+ }
125
+ });
126
+ }
127
+ pipe(writable) {
128
+ return this.tracer.pipe(writable);
129
+ }
130
+ flush() {
131
+ this.tracer.push(null);
132
+ }
118
133
  }
119
- exports.default = Trace;
@@ -0,0 +1,15 @@
1
+ // @flow
2
+ import type {Profile} from './SamplingProfiler';
3
+ import type {Writable} from 'stream';
4
+ import {Tracer} from 'chrome-trace-event';
5
+
6
+ declare export default class Trace {
7
+ tracer: Tracer;
8
+ tid: number;
9
+ eventId: number;
10
+ getEventId(): number;
11
+ init(ts: number): void;
12
+ addCPUProfile(name: string, profile: Profile): void;
13
+ pipe(writable: Writable): Writable;
14
+ flush(): void;
15
+ }
package/lib/Trace.mjs ADDED
@@ -0,0 +1,111 @@
1
+ import { Tracer } from 'chrome-trace-event';
2
+ export default class Trace {
3
+ tracer;
4
+ tid;
5
+ eventId;
6
+ constructor() {
7
+ this.tracer = new Tracer();
8
+ this.tid = 0;
9
+ this.eventId = 0;
10
+ }
11
+ getEventId() {
12
+ return this.eventId++;
13
+ }
14
+ init(ts) {
15
+ this.tracer.instantEvent({
16
+ name: 'TracingStartedInPage',
17
+ id: this.getEventId(),
18
+ ts,
19
+ cat: ['disabled-by-default-devtools.timeline'],
20
+ args: {
21
+ data: {
22
+ sessionId: '-1',
23
+ page: '0xfff',
24
+ frames: [
25
+ {
26
+ frame: '0xfff',
27
+ url: 'parcel',
28
+ name: '',
29
+ },
30
+ ],
31
+ },
32
+ },
33
+ });
34
+ this.tracer.instantEvent({
35
+ name: 'TracingStartedInBrowser',
36
+ id: this.getEventId(),
37
+ ts,
38
+ cat: ['disabled-by-default-devtools.timeline'],
39
+ args: {
40
+ data: {
41
+ sessionId: '-1',
42
+ },
43
+ },
44
+ });
45
+ }
46
+ addCPUProfile(name, profile) {
47
+ if (this.eventId === 0) {
48
+ this.init(profile.startTime);
49
+ }
50
+ const trace = this.tracer;
51
+ const tid = this.tid;
52
+ this.tid++;
53
+ const cpuStartTime = profile.startTime;
54
+ const cpuEndTime = profile.endTime;
55
+ trace.instantEvent({
56
+ tid,
57
+ id: this.getEventId(),
58
+ cat: ['toplevel'],
59
+ name: 'TaskQueueManager::ProcessTaskFromWorkQueue',
60
+ args: {
61
+ src_file: '../../ipc/ipc_moji_bootstrap.cc',
62
+ src_func: 'Accept',
63
+ },
64
+ ts: cpuStartTime,
65
+ });
66
+ trace.completeEvent({
67
+ tid,
68
+ name: 'EvaluateScript',
69
+ id: this.getEventId(),
70
+ cat: ['devtools.timeline'],
71
+ ts: cpuStartTime,
72
+ dur: cpuEndTime - cpuStartTime,
73
+ args: {
74
+ data: {
75
+ url: 'parcel',
76
+ lineNumber: 1,
77
+ columnNumber: 1,
78
+ frame: '0xFFF',
79
+ },
80
+ },
81
+ });
82
+ trace.instantEvent({
83
+ tid,
84
+ ts: 0,
85
+ ph: 'M',
86
+ cat: ['__metadata'],
87
+ name: 'thread_name',
88
+ args: {
89
+ name,
90
+ },
91
+ });
92
+ trace.instantEvent({
93
+ tid,
94
+ name: 'CpuProfile',
95
+ id: this.getEventId(),
96
+ cat: ['disabled-by-default-devtools.timeline'],
97
+ ts: cpuEndTime,
98
+ args: {
99
+ data: {
100
+ cpuProfile: profile,
101
+ },
102
+ },
103
+ });
104
+ }
105
+ pipe(writable) {
106
+ return this.tracer.pipe(writable);
107
+ }
108
+ flush() {
109
+ this.tracer.push(null);
110
+ }
111
+ }
@@ -1,7 +1,7 @@
1
- import type { TraceEvent, IDisposable, PluginTracer as IPluginTracer } from "@atlaspack/types";
2
- import type { TraceMeasurement as ITraceMeasurement } from "./types";
1
+ import type { TraceEvent, IDisposable, PluginTracer as IPluginTracer } from '@atlaspack/types-internal';
2
+ import type { TraceMeasurement as ITraceMeasurement } from './types.mts';
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
7
  createMeasurement(name: string, category?: string, argumentName?: string, otherArgs?: Record<string, unknown>): ITraceMeasurement | null;