parcel-bundler
Version:
Blazing fast, zero configuration web application bundler
65 lines (52 loc) • 1.8 kB
JavaScript
;
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
// node.js builtin library
const inspector = require('inspector');
class Profiler {
constructor() {
this.session = undefined;
}
hasSession() {
return this.session != null;
}
startProfiling() {
var _this = this;
return _asyncToGenerator(function* () {
_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) {
var _this2 = this;
return _asyncToGenerator(function* () {
if (_this2.hasSession()) {
return new Promise(function (resolve, reject) {
_this2.session.post(method, params, function (err, params) {
if (err == null) {
resolve(params);
} else {
reject(err);
}
});
});
}
})();
}
destroy() {
if (this.hasSession()) {
this.session.disconnect();
}
}
stopProfiling() {
var _this3 = this;
return _asyncToGenerator(function* () {
const res = yield _this3.sendCommand('Profiler.stop');
_this3.destroy();
return res.profile;
})();
}
}
module.exports = Profiler;