-
-
Notifications
You must be signed in to change notification settings - Fork 33.5k
lib: add diagnostics_channel events to module loading #44340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -189,6 +189,9 @@ let { startTimer, endTimer } = debugWithTimer('module_timer', (start, end) => { | |
endTimer = end; | ||
}); | ||
|
||
const { tracingChannel } = require('diagnostics_channel'); | ||
const onRequire = getLazy(() => tracingChannel('module.require')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. getLazy is required otherwise it will cause segmentation fault on nodejs build. I haven't figured it out in-depth, but I suspect some module required by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My guess would be that |
||
|
||
const isWindows = process.platform === 'win32'; | ||
|
||
const relativeResolveCache = { __proto__: null }; | ||
|
@@ -209,7 +212,11 @@ function wrapModuleLoad(request, parent, isMain) { | |
startTimer(logLabel, traceLabel); | ||
|
||
try { | ||
return Module._load(request, parent, isMain); | ||
return onRequire().traceSync(Module._load, { | ||
__proto__: null, | ||
parentFilename: parent?.filename, | ||
id: request, | ||
}, Module, request, parent, isMain); | ||
} finally { | ||
endTimer(logLabel, traceLabel); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,9 @@ const { | |
} = require('internal/modules/helpers'); | ||
let defaultResolve, defaultLoad, defaultLoadSync, importMetaInitializer; | ||
|
||
const { tracingChannel } = require('diagnostics_channel'); | ||
const onImport = tracingChannel('module.import'); | ||
|
||
/** | ||
* @typedef {import('url').URL} URL | ||
*/ | ||
|
@@ -211,10 +214,17 @@ class ModuleLoader { | |
return compileSourceTextModule(url, source, this); | ||
}; | ||
const { ModuleJob } = require('internal/modules/esm/module_job'); | ||
const job = new ModuleJob( | ||
this, url, undefined, evalInstance, false, false); | ||
this.loadCache.set(url, undefined, job); | ||
const { module } = await job.run(isEntryPoint); | ||
const module = await onImport.tracePromise(async () => { | ||
const job = new ModuleJob( | ||
this, url, undefined, evalInstance, false, false); | ||
this.loadCache.set(url, undefined, job); | ||
const { module } = await job.run(isEntryPoint); | ||
return module; | ||
}, { | ||
__proto__: null, | ||
parentURL: '<eval>', | ||
url, | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this is capturing ESM code that comes from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe? I'm not sure we actually need this here. I'm still working on this and figuring out testing and some changes that probably need to be made. |
||
|
||
return { | ||
__proto__: null, | ||
|
@@ -470,9 +480,15 @@ class ModuleLoader { | |
* @returns {Promise<ModuleExports>} | ||
*/ | ||
async import(specifier, parentURL, importAttributes, isEntryPoint = false) { | ||
const moduleJob = await this.getModuleJob(specifier, parentURL, importAttributes); | ||
const { module } = await moduleJob.run(isEntryPoint); | ||
return module.getNamespace(); | ||
return onImport.tracePromise(async () => { | ||
const moduleJob = await this.getModuleJob(specifier, parentURL, importAttributes); | ||
Flarna marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const { module } = await moduleJob.run(isEntryPoint); | ||
return module.getNamespace(); | ||
}, { | ||
__proto__: null, | ||
parentURL, | ||
url: specifier, | ||
}); | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ Trace: foo | |
at * | ||
at * | ||
at * | ||
at * |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,5 +11,6 @@ Error: Should include grayed stack trace | |
[90m at *[39m | ||
[90m at *[39m | ||
[90m at *[39m | ||
[90m at *[39m | ||
|
||
Node.js * |
Uh oh!
There was an error while loading. Please reload this page.