@atlaspack/profiler 2.14.15-typescript-e769947a5.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.
- package/lib/{SamplingProfiler.d.ts → SamplingProfiler.d.mts} +1 -1
- package/lib/SamplingProfiler.js +100 -58
- package/lib/SamplingProfiler.js.flow +47 -0
- package/lib/SamplingProfiler.mjs +51 -0
- package/lib/{Trace.d.ts → Trace.d.mts} +3 -3
- package/lib/Trace.js +126 -112
- package/lib/Trace.js.flow +15 -0
- package/lib/Trace.mjs +111 -0
- package/lib/{Tracer.d.ts → Tracer.d.mts} +3 -3
- package/lib/Tracer.js +112 -114
- package/lib/Tracer.js.flow +46 -0
- package/lib/Tracer.mjs +114 -0
- package/lib/index.d.mts +4 -0
- package/lib/index.js +22 -22
- package/lib/index.mjs +3 -0
- package/lib/types.js +4 -1
- package/lib/types.mjs +1 -0
- package/package.json +21 -9
- package/src/SamplingProfiler.mts +94 -0
- package/src/{Trace.js → Trace.mts} +5 -9
- package/src/{Tracer.js → Tracer.mts} +28 -23
- package/src/index.mts +4 -0
- package/src/types.mts +6 -0
- package/test/{Tracer.test.js → Tracer.test.mts} +9 -4
- package/tsconfig.json +4 -0
- package/build-ts.js +0 -8
- package/lib/index.d.ts +0 -4
- package/src/SamplingProfiler.js +0 -93
- /package/{src/index.js → lib/index.js.flow} +0 -0
- /package/lib/{types.d.ts → types.d.mts} +0 -0
- /package/{src/types.js → lib/types.js.flow} +0 -0
|
@@ -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;
|
package/lib/SamplingProfiler.js
CHANGED
|
@@ -1,69 +1,111 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
|
2
|
-
import type { Writable } from
|
|
3
|
-
import { Tracer } from
|
|
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
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
|
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.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;
|