Skip to content
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

Application profiling #8695

Merged
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
256072e
Move profiler to new @parcel/profiler pkg
marcins Dec 12, 2022
4809e23
Refactor Profiler -> SamplingProfiler
marcins Dec 12, 2022
523330d
Initial implementation of ApplicationProfiler
marcins Dec 12, 2022
56a5336
Plumb in applicationProfiler to child/worker/reporter system
marcins Dec 12, 2022
64b5887
Add initial application profile reporter
marcins Dec 12, 2022
cc8036f
Implement CLI integration for application profiler
marcins Dec 13, 2022
643bf9b
Implement profiling for packaging
marcins Dec 13, 2022
ddce2f3
Implement profiling for bundling
marcins Dec 13, 2022
be15f38
Implement enabling app profiling in workers
marcins Dec 14, 2022
bbd7f61
Implement profiling for Babel transforms
marcins Dec 15, 2022
3b0a3a6
Fix race condition with closing trace writeStream
marcins Dec 15, 2022
097cd15
Implement profiling for top level phases
marcins Dec 16, 2022
53425d6
Implement profiling for resolution
marcins Dec 16, 2022
6984ff3
Implement profiling for optimization
marcins Dec 16, 2022
a69f537
Implement profiling for bundle naming
marcins Dec 16, 2022
5520673
Bump profiler to 2.8.3 to match rest
marcins Mar 1, 2023
5e75260
Refactor to use PluginApplicationProfiler
marcins Mar 2, 2023
4acce7c
Refactor createMeasurement to avoid redundant obj allocations
marcins Mar 2, 2023
bda0790
Document PluginApplicationProfiler API
marcins Mar 2, 2023
be724e1
Implement injection of PluginApplicationProfiler
marcins Mar 2, 2023
7b63807
Implement reporting for reporters..
marcins Mar 2, 2023
7113a75
Implement application profiling for applyRuntime
marcins Mar 2, 2023
62b5530
Add application profiling to compressor
marcins Mar 2, 2023
66fffa1
Fix an errant relative path
marcins Mar 2, 2023
fb8d6c1
Remove redundant profiler enabled check
marcins Mar 3, 2023
a08566f
Fix bad rebase
marcins Mar 3, 2023
bbd64ec
Fix bad commit to core package.json
marcins Mar 3, 2023
5b05f6d
Add app profiler reporter as dependency of CLI
marcins Mar 3, 2023
20b32b2
Fix types / documentation for PluginAppProfiler
marcins Mar 3, 2023
81a87ca
Add unit tests for application profiler
marcins Mar 5, 2023
6f92c62
Remove a redundant allocation
marcins Mar 5, 2023
d111d17
Move transform measurement to better location
marcins Mar 6, 2023
5e1e4b6
Minor improvements to some measurements
marcins Mar 7, 2023
afeab07
Prevent double-end of measurement
marcins Mar 7, 2023
89695ef
Improve profile reporter
marcins Mar 8, 2023
b1c5af1
Add basic integration test for app profiling
marcins Mar 8, 2023
96566ac
Merge remote-tracking branch 'upstream/v2' into mszczepanski/applicat…
marcins Mar 22, 2023
d70dd06
Merge remote-tracking branch 'upstream/v2' into mszczepanski/applicat…
marcins Mar 30, 2023
ae25e62
Fix linting issues
marcins Mar 30, 2023
0b91a04
Merge branch 'v2' into mszczepanski/application-profiling
lettertwo Mar 31, 2023
b8d4ec4
Merge branch 'v2' into mszczepanski/application-profiling
lettertwo Apr 4, 2023
3c45509
Rename ApplicationProfiler -> Tracer
lettertwo Apr 4, 2023
322e740
Merge branch 'v2' into mszczepanski/application-profiling
lettertwo Apr 4, 2023
7621579
Merge remote-tracking branch 'upstream/v2' into mszczepanski/applicat…
marcins May 10, 2023
5869002
Fix some missing shouldProfileApplication -> shouldTrace
marcins May 11, 2023
414d499
Merge branch 'v2' into mszczepanski/application-profiling
devongovett May 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@parcel/logger": "2.8.3",
"@parcel/package-manager": "2.8.3",
"@parcel/plugin": "2.8.3",
"@parcel/profiler": "2.8.3",
"@parcel/source-map": "^2.1.1",
"@parcel/types": "2.8.3",
"@parcel/utils": "2.8.3",
Expand Down
19 changes: 19 additions & 0 deletions packages/core/core/src/PackagerRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import {createBuildCache} from './buildCache';
import {getInvalidationId, getInvalidationHash} from './assetUtils';
import {optionsProxy} from './utils';
import {invalidateDevDeps} from './requests/DevDepRequest';
import {tracer, PluginTracer} from '@parcel/profiler';

type Opts = {|
config: ParcelConfig,
Expand Down Expand Up @@ -275,6 +276,7 @@ export default class PackagerRunner {
config: new PublicConfig(config, this.options),
options: new PluginOptions(this.options),
logger: new PluginLogger({origin: plugin.name}),
tracer: new PluginTracer({origin: plugin.name, category: 'loadConfig'}),
});
bundleConfigs.set(plugin.name, config);
}
Expand Down Expand Up @@ -394,7 +396,11 @@ export default class PackagerRunner {

let packager = await this.config.getPackager(bundle.name);
let {name, resolveFrom, plugin} = packager;
let measurement;
try {
measurement = tracer.createMeasurement(name, 'packaging', bundle.name, {
type: bundle.type,
});
return await plugin.package({
config: configs.get(name)?.result,
bundleConfig: bundleConfigs.get(name)?.result,
Expand All @@ -409,6 +415,7 @@ export default class PackagerRunner {
},
options: this.pluginOptions,
logger: new PluginLogger({origin: name}),
tracer: new PluginTracer({origin: name, category: 'package'}),
getInlineBundleContents: async (
bundle: BundleType,
bundleGraph: BundleGraphType<NamedBundleType>,
Expand Down Expand Up @@ -438,6 +445,7 @@ export default class PackagerRunner {
}),
});
} finally {
measurement && measurement.end();
// Add dev dependency for the packager. This must be done AFTER running it due to
// the potential for lazy require() that aren't executed until the request runs.
let devDepRequest = await createDevDependency(
Expand Down Expand Up @@ -495,7 +503,13 @@ export default class PackagerRunner {
};

for (let optimizer of optimizers) {
let measurement;
try {
measurement = tracer.createMeasurement(
optimizer.name,
'optimize',
bundle.name,
);
let next = await optimizer.plugin.optimize({
config: configs.get(optimizer.name)?.result,
bundleConfig: bundleConfigs.get(optimizer.name)?.result,
Expand All @@ -508,6 +522,10 @@ export default class PackagerRunner {
},
options: this.pluginOptions,
logger: new PluginLogger({origin: optimizer.name}),
tracer: new PluginTracer({
origin: optimizer.name,
category: 'optimize',
}),
});

optimized.type = next.type ?? optimized.type;
Expand All @@ -521,6 +539,7 @@ export default class PackagerRunner {
}),
});
} finally {
measurement && measurement.end();
// Add dev dependency for the optimizer. This must be done AFTER running it due to
// the potential for lazy require() that aren't executed until the request runs.
let devDepRequest = await createDevDependency(
Expand Down
5 changes: 5 additions & 0 deletions packages/core/core/src/Parcel.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {Disposable} from '@parcel/events';
import {init as initSourcemaps} from '@parcel/source-map';
import {init as initHash} from '@parcel/hash';
import {toProjectPath} from './projectPath';
import {tracer} from '@parcel/profiler';

registerCoreWithSerializer();

Expand Down Expand Up @@ -104,6 +105,7 @@ export default class Parcel {
} else {
this.#farm = createWorkerFarm({
shouldPatchConsole: resolvedOptions.shouldPatchConsole,
shouldTrace: resolvedOptions.shouldTrace,
});
}

Expand Down Expand Up @@ -257,6 +259,9 @@ export default class Parcel {
if (options.shouldProfile) {
await this.startProfiling();
}
if (options.shouldTrace) {
tracer.enable();
}
this.#reporterRunner.report({
type: 'buildStart',
});
Expand Down
14 changes: 14 additions & 0 deletions packages/core/core/src/ReporterRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import logger, {
} from '@parcel/logger';
import PluginOptions from './public/PluginOptions';
import BundleGraph from './BundleGraph';
import {tracer, PluginTracer} from '@parcel/profiler';

type Opts = {|
config: ParcelConfig,
Expand All @@ -44,6 +45,7 @@ export default class ReporterRunner {
this.pluginOptions = new PluginOptions(this.options);

logger.onLog(event => this.report(event));
tracer.onTrace(event => this.report(event));

bus.on('reporterEvent', this.eventHandler);
instances.add(this);
Expand Down Expand Up @@ -93,14 +95,26 @@ export default class ReporterRunner {
}

for (let reporter of this.reporters) {
let measurement;
try {
// To avoid an infinite loop we don't measure trace events, as they'll
// result in another trace!
if (event.type !== 'trace') {
measurement = tracer.createMeasurement(reporter.name, 'reporter');
}
await reporter.plugin.report({
event,
options: this.pluginOptions,
logger: new PluginLogger({origin: reporter.name}),
tracer: new PluginTracer({
origin: reporter.name,
category: 'reporter',
}),
});
} catch (reportError) {
INTERNAL_ORIGINAL_CONSOLE.error(reportError);
} finally {
measurement && measurement.end();
}
}
} catch (err) {
Expand Down
18 changes: 18 additions & 0 deletions packages/core/core/src/Transformation.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import {
} from './projectPath';
import {invalidateOnFileCreateToInternal} from './utils';
import invariant from 'assert';
import {tracer, PluginTracer} from '@parcel/profiler';

type GenerateFunc = (input: UncommittedAsset) => Promise<GenerateOutput>;

Expand Down Expand Up @@ -463,6 +464,12 @@ export default class Transformation {
}

try {
const measurement = tracer.createMeasurement(
transformer.name,
'transform',
fromProjectPathRelative(initialAsset.value.filePath),
);

let transformerResults = await this.runTransformer(
pipeline,
asset,
Expand All @@ -473,6 +480,8 @@ export default class Transformation {
this.parcelConfig,
);

measurement && measurement.end();

for (let result of transformerResults) {
if (result instanceof UncommittedAsset) {
resultingAssets.push(result);
Expand Down Expand Up @@ -739,6 +748,10 @@ export default class Transformation {
parcelConfig: ParcelConfig,
): Promise<$ReadOnlyArray<TransformerResult | UncommittedAsset>> {
const logger = new PluginLogger({origin: transformerName});
const tracer = new PluginTracer({
origin: transformerName,
category: 'transform',
});

const resolve = async (
from: FilePath,
Expand Down Expand Up @@ -794,6 +807,7 @@ export default class Transformation {
ast: asset.ast,
options: pipeline.pluginOptions,
logger,
tracer,
})) &&
asset.generate
) {
Expand All @@ -814,6 +828,7 @@ export default class Transformation {
options: pipeline.pluginOptions,
resolve,
logger,
tracer,
});
if (ast) {
asset.setAST(ast);
Expand All @@ -830,6 +845,7 @@ export default class Transformation {
options: pipeline.pluginOptions,
resolve,
logger,
tracer,
});
let results = await normalizeAssets(this.options, transfomerResult);

Expand All @@ -842,6 +858,7 @@ export default class Transformation {
ast: asset.ast,
options: pipeline.pluginOptions,
logger,
tracer,
});
asset.clearAST();
return Promise.resolve(generated);
Expand All @@ -863,6 +880,7 @@ export default class Transformation {
options: pipeline.pluginOptions,
resolve,
logger,
tracer,
});

return Promise.all(
Expand Down
8 changes: 8 additions & 0 deletions packages/core/core/src/Validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {Asset} from './public/Asset';
import PluginOptions from './public/PluginOptions';
import summarizeRequest from './summarizeRequest';
import {fromProjectPath, fromProjectPathRelative} from './projectPath';
import {PluginTracer} from '@parcel/profiler';

export type ValidationOpts = {|
config: ParcelConfig,
Expand Down Expand Up @@ -66,6 +67,10 @@ export default class Validation {
if (assets) {
let plugin = this.allValidators[validatorName];
let validatorLogger = new PluginLogger({origin: validatorName});
let validatorTracer = new PluginTracer({
origin: validatorName,
category: 'validator',
});
let validatorResults: Array<?ValidateResult> = [];
try {
// If the plugin supports the single-threading validateAll method, pass all assets to it.
Expand All @@ -74,6 +79,7 @@ export default class Validation {
assets: assets.map(asset => new Asset(asset)),
options: pluginOptions,
logger: validatorLogger,
tracer: validatorTracer,
resolveConfigWithPath: (
configNames: Array<string>,
assetFilePath: string,
Expand All @@ -98,6 +104,7 @@ export default class Validation {
asset: publicAsset,
options: pluginOptions,
logger: validatorLogger,
tracer: validatorTracer,
resolveConfig: (configNames: Array<string>) =>
resolveConfig(
this.options.inputFS,
Expand All @@ -113,6 +120,7 @@ export default class Validation {
options: pluginOptions,
config,
logger: validatorLogger,
tracer: validatorTracer,
});
validatorResults.push(validatorResult);
}),
Expand Down
16 changes: 15 additions & 1 deletion packages/core/core/src/applyRuntimes.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {mergeEnvironments} from './Environment';
import createAssetGraphRequest from './requests/AssetGraphRequest';
import {createDevDependency, runDevDepRequest} from './requests/DevDepRequest';
import {toProjectPath, fromProjectPathRelative} from './projectPath';
import {tracer, PluginTracer} from '@parcel/profiler';

type RuntimeConnection = {|
bundle: InternalBundle,
Expand Down Expand Up @@ -73,9 +74,16 @@ export default async function applyRuntimes<TResult>({

for (let bundle of bundles) {
for (let runtime of runtimes) {
let measurement;
try {
const namedBundle = NamedBundle.get(bundle, bundleGraph, options);
measurement = tracer.createMeasurement(
runtime.name,
'applyRuntime',
namedBundle.displayName,
);
let applied = await runtime.plugin.apply({
bundle: NamedBundle.get(bundle, bundleGraph, options),
bundle: namedBundle,
bundleGraph: new BundleGraph<INamedBundle>(
bundleGraph,
NamedBundle.get.bind(NamedBundle),
Expand All @@ -84,6 +92,10 @@ export default async function applyRuntimes<TResult>({
config: configs.get(runtime.name)?.result,
options: pluginOptions,
logger: new PluginLogger({origin: runtime.name}),
tracer: new PluginTracer({
origin: runtime.name,
category: 'applyRuntime',
}),
});

if (applied) {
Expand Down Expand Up @@ -152,6 +164,8 @@ export default async function applyRuntimes<TResult>({
origin: runtime.name,
}),
});
} finally {
measurement && measurement.end();
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions packages/core/core/src/assetUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
} from './projectPath';
import {hashString} from '@parcel/hash';
import {BundleBehavior as BundleBehaviorMap} from './types';
import {PluginTracer} from '@parcel/profiler';

type AssetOptions = {|
id?: string,
Expand Down Expand Up @@ -172,6 +173,7 @@ async function _generateFromAST(asset: CommittedAsset | UncommittedAsset) {
ast,
options: new PluginOptions(asset.options),
logger: new PluginLogger({origin: pluginName}),
tracer: new PluginTracer({origin: pluginName, category: 'asset-generate'}),
});

let mapBuffer = map?.toBuffer();
Expand Down
Loading