animate/webGl/my-threejs-test/node_modules/@parcel/profiler/lib/SamplingProfiler.js

69 lines
2.0 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
function _assert() {
const data = _interopRequireDefault(require("assert"));
_assert = function () {
return data;
};
return data;
}
function _diagnostic() {
const data = _interopRequireDefault(require("@parcel/diagnostic"));
_diagnostic = function () {
return data;
};
return data;
}
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// https://chromedevtools.github.io/devtools-protocol/tot/Profiler#type-Profile
// https://chromedevtools.github.io/devtools-protocol/tot/Profiler#type-ProfileNode
// https://chromedevtools.github.io/devtools-protocol/tot/Runtime#type-CallFrame
// https://chromedevtools.github.io/devtools-protocol/tot/Profiler#type-PositionTickInfo
class SamplingProfiler {
startProfiling() {
let inspector;
try {
inspector = require('inspector');
} catch (err) {
throw new (_diagnostic().default)({
diagnostic: {
message: `The inspector module isn't available`,
origin: '@parcel/workers',
hints: ['Disable build profiling']
}
});
}
this.session = new inspector.Session();
this.session.connect();
return Promise.all([this.sendCommand('Profiler.setSamplingInterval', {
interval: 100
}), this.sendCommand('Profiler.enable'), this.sendCommand('Profiler.start')]);
}
sendCommand(method, params) {
(0, _assert().default)(this.session != null);
return new Promise((resolve, reject) => {
this.session.post(method, params, (err, p) => {
if (err == null) {
resolve(p);
} else {
reject(err);
}
});
});
}
destroy() {
if (this.session != null) {
this.session.disconnect();
}
}
async stopProfiling() {
let res = await this.sendCommand('Profiler.stop');
this.destroy();
return res.profile;
}
}
exports.default = SamplingProfiler;