Skip to content

Commit

Permalink
Add instrumentation to metro-file-map worker initialisation
Browse files Browse the repository at this point in the history
Summary:
Add perflogger marks to start and end of `jest-worker` initialisation in `metro-file-map`. Behind the scenes, this spawns either processes or threads.

Changlog: [Internal]

Reviewed By: huntie

Differential Revision: D44012845

fbshipit-source-id: 3a1fd3e9fd238a16c575c0429d1e5ea99eacb866
  • Loading branch information
robhogan authored and facebook-github-bot committed Mar 13, 2023
1 parent 3766321 commit 78ebd9b
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions packages/metro-file-map/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ export default class HasteMap extends EventEmitter {
moduleMap: RawModuleMap,
filePath: Path,
fileMetadata: FileMetaData,
workerOptions?: {forceInBand: boolean},
workerOptions?: {forceInBand?: ?boolean, perfLogger?: ?PerfLogger},
): ?Promise<void> {
const rootDir = this._options.rootDir;

Expand Down Expand Up @@ -738,7 +738,9 @@ export default class HasteMap extends EventEmitter {
this._options.rootDir,
relativeFilePath,
);
const maybePromise = this._processFile(moduleMap, filePath, fileData);
const maybePromise = this._processFile(moduleMap, filePath, fileData, {
perfLogger: this._startupPerfLogger,
});
if (maybePromise) {
promises.push(
maybePromise.catch(e => {
Expand Down Expand Up @@ -819,20 +821,26 @@ export default class HasteMap extends EventEmitter {
/**
* Creates workers or parses files and extracts metadata in-process.
*/
_getWorker(options?: {forceInBand: boolean}): WorkerInterface {
_getWorker(options?: {
forceInBand?: ?boolean,
perfLogger?: ?PerfLogger,
}): WorkerInterface {
if (!this._worker) {
if ((options && options.forceInBand) || this._options.maxWorkers <= 1) {
const {forceInBand, perfLogger} = options ?? {};
if (forceInBand === true || this._options.maxWorkers <= 1) {
this._worker = {worker};
} else {
this._worker = new Worker<WorkerObj>(require.resolve('./worker'), {
const workerPath = require.resolve('./worker');
perfLogger?.point('initWorkers_start');
this._worker = new Worker<WorkerObj>(workerPath, {
exposedMethods: ['worker'],
maxRetries: 3,
numWorkers: this._options.maxWorkers,
});
perfLogger?.point('initWorkers_end');
}
}

return this._worker;
return nullthrows(this._worker);
}

_removeIfExists(
Expand Down

0 comments on commit 78ebd9b

Please sign in to comment.