| | |
| | | JSON_MODULE_TYPE, |
| | | WEBASSEMBLY_MODULES |
| | | } = require("../ModuleTypeConstants"); |
| | | const createSchemaValidation = require("../util/create-schema-validation"); |
| | | const { dirname, mkdirpSync } = require("../util/fs"); |
| | | |
| | | /** @typedef {import("inspector").Session} Session */ |
| | |
| | | /** @typedef {import("../util/fs").IntermediateFileSystem} IntermediateFileSystem */ |
| | | |
| | | /** |
| | | * Defines the hook type used by this module. |
| | | * @template T, R |
| | | * @typedef {import("tapable").Hook<T, R>} Hook |
| | | */ |
| | | |
| | | /** |
| | | * Defines the fake hook type used by this module. |
| | | * @template T |
| | | * @typedef {import("../util/deprecation").FakeHook<T>} FakeHook |
| | | */ |
| | | |
| | | /** |
| | | * Defines the hook map type used by this module. |
| | | * @template T |
| | | * @typedef {import("tapable").HookMap<T>} HookMap |
| | | */ |
| | | |
| | | /** |
| | | * Defines the hook interceptor type used by this module. |
| | | * @template T, R |
| | | * @typedef {import("tapable").HookInterceptor<T, R>} HookInterceptor |
| | | */ |
| | | |
| | | const validate = createSchemaValidation( |
| | | require("../../schemas/plugins/debug/ProfilingPlugin.check"), |
| | | () => require("../../schemas/plugins/debug/ProfilingPlugin.json"), |
| | | { |
| | | name: "Profiling Plugin", |
| | | baseDataPath: "options" |
| | | } |
| | | ); |
| | | |
| | | /** @typedef {{ Session: typeof import("inspector").Session }} Inspector */ |
| | | |
| | |
| | | |
| | | class Profiler { |
| | | /** |
| | | * Creates an instance of Profiler. |
| | | * @param {Inspector} inspector inspector |
| | | */ |
| | | constructor(inspector) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns promise for the result. |
| | | * @param {string} method method name |
| | | * @param {EXPECTED_OBJECT=} params params |
| | | * @returns {Promise<EXPECTED_ANY | void>} Promise for the result |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns }>} profile result. |
| | | * @returns {Promise<{ profile: { startTime: number, endTime: number } }>} profile result |
| | | */ |
| | | stopProfiling() { |
| | |
| | | */ |
| | | |
| | | /** |
| | | * Creates a trace from the provided f. |
| | | * @param {IntermediateFileSystem} fs filesystem used for output |
| | | * @param {string} outputPath The location where to write the log. |
| | | * @returns {Trace} The trace object |
| | |
| | | |
| | | class ProfilingPlugin { |
| | | /** |
| | | * Creates an instance of ProfilingPlugin. |
| | | * @param {ProfilingPluginOptions=} options options object |
| | | */ |
| | | constructor(options = {}) { |
| | | validate(options); |
| | | this.outputPath = options.outputPath || "events.json"; |
| | | /** @type {ProfilingPluginOptions} */ |
| | | this.options = options; |
| | | } |
| | | |
| | | /** |
| | | * Apply the plugin |
| | | * Applies the plugin by registering its hooks on the compiler. |
| | | * @param {Compiler} compiler the compiler instance |
| | | * @returns {void} |
| | | */ |
| | | apply(compiler) { |
| | | compiler.hooks.validate.tap(PLUGIN_NAME, () => { |
| | | compiler.validate( |
| | | () => require("../../schemas/plugins/debug/ProfilingPlugin.json"), |
| | | this.options, |
| | | { |
| | | name: "Profiling Plugin", |
| | | baseDataPath: "options" |
| | | }, |
| | | (options) => |
| | | require("../../schemas/plugins/debug/ProfilingPlugin.check")(options) |
| | | ); |
| | | }); |
| | | |
| | | const tracer = createTrace( |
| | | /** @type {IntermediateFileSystem} */ |
| | | (compiler.intermediateFileSystem), |
| | | this.outputPath |
| | | this.options.outputPath || "events.json" |
| | | ); |
| | | tracer.profiler.startProfiling(); |
| | | |
| | |
| | | /** @typedef {Record<string, Hook<EXPECTED_ANY, EXPECTED_ANY> | FakeHook<EXPECTED_ANY> | HookMap<EXPECTED_ANY>>} Hooks */ |
| | | |
| | | /** |
| | | * Intercept all hooks for. |
| | | * @param {EXPECTED_OBJECT & { hooks?: Hooks }} instance instance |
| | | * @param {Trace} tracer tracer |
| | | * @param {string} logLabel log label |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Intercept all parser hooks. |
| | | * @param {NormalModuleFactory} moduleFactory normal module factory |
| | | * @param {Trace} tracer tracer |
| | | */ |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Intercept all generator hooks. |
| | | * @param {NormalModuleFactory} moduleFactory normal module factory |
| | | * @param {Trace} tracer tracer |
| | | */ |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Intercept all javascript modules plugin hooks. |
| | | * @param {Compilation} compilation compilation |
| | | * @param {Trace} tracer tracer |
| | | */ |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Intercept all css modules plugin hooks. |
| | | * @param {Compilation} compilation compilation |
| | | * @param {Trace} tracer tracer |
| | | */ |
| | |
| | | /** @typedef {(...args: EXPECTED_ANY[]) => EXPECTED_ANY | Promise<(...args: EXPECTED_ANY[]) => EXPECTED_ANY>} PluginFunction */ |
| | | |
| | | /** |
| | | * Creates interceptor for. |
| | | * @template T |
| | | * @param {string} instance instance |
| | | * @param {Trace} tracer tracer |
| | |
| | | */ |
| | | const makeInterceptorFor = (instance, tracer) => (hookName) => ({ |
| | | /** |
| | | * Returns modified full tap. |
| | | * @param {FullTap} tapInfo tap info |
| | | * @returns {FullTap} modified full tap |
| | | */ |
| | |
| | | }); |
| | | |
| | | /** |
| | | * Creates new profiled tap fn. |
| | | * @param {string} hookName Name of the hook to profile. |
| | | * @param {Trace} tracer The trace object. |
| | | * @param {object} options Options for the profiled fn. |
| | |
| | | fn( |
| | | ...args, |
| | | /** |
| | | * Handles the cat callback for this hook. |
| | | * @param {...EXPECTED_ANY[]} r result |
| | | */ |
| | | (...r) => { |
| | |
| | | id, |
| | | cat: defaultCategory |
| | | }); |
| | | /** @type {PluginFunction} */ |
| | | let r; |
| | | try { |
| | | r = fn(...args); |