Skip to content

Conversation

@aramissennyeydd
Copy link
Contributor

@aramissennyeydd aramissennyeydd commented May 14, 2025

Summary

Adds task-level metrics for reporting on how long specific plugins take to execute, like the Typescript, Jest, and Webpack plugins. These are currently only logged out to console in verbose mode.

Details

I copied most of the existing implementation of the recordMetrics hook to create a recordTaskMetrics hook - the idea here is being able to report on the specific amount of time that each task takes and add more granular reporting. Let me know what you think about the metric envelope.

How it was tested

Added a test heft-lifecycle-plugin that logs out the time taken for each task (you can still see the verbose logs too). Example:

 ---- build started ---- 
[build:typescript] Using TypeScript version 5.8.2
[lifecycle:example-lifecycle-plugin] Finished build:typescript in 822.40ms
[build:lint] Using ESLint version 8.57.0
[build:lint] Using TSLint version 5.20.1
[build:typescript] All requested file copy operations are up to date. Nothing to do.
[lifecycle:example-lifecycle-plugin] Finished build:lint in 0.49ms
[build:api-extractor] Using API Extractor version 7.52.8
[build:api-extractor] Analysis will use the bundled TypeScript version 5.8.2
[lifecycle:example-lifecycle-plugin] Finished build:api-extractor in 594.27ms
[lifecycle:example-lifecycle-plugin] Finished build:metadata-test in 595.94ms
 ---- build finished (1.815s) ---- 
[lifecycle:example-lifecycle-plugin] Finished build in 1815.37ms
 ---- test started ---- 
[test:jest] Using Jest version 29.5.0
[test:example-plugin-02] !!!!!!!!!!!!!!! Plugin "example-plugin-01" hook called !!!!!!!!!!!!!!! 
[lifecycle:example-lifecycle-plugin] Finished test:example-plugin-01 in 0.16ms
Determining test suites to run...[test:jest] 
[test:jest] Run start. 1 test suite
[test:jest] START lib/test/ExampleTest.test.js
[test:jest] PASS lib/test/ExampleTest.test.js (duration: 0.203s, 3 passed, 0 failed)
[test:jest] 
[test:jest] Tests finished:
[test:jest]   Successes: 3
[test:jest]   Failures: 0
[test:jest]   Total: 3
[lifecycle:example-lifecycle-plugin] Finished test:jest in 625.79ms
 ---- test finished (0.640s) ---- 
[lifecycle:example-lifecycle-plugin] Finished test in 640.48ms
-------------------- Finished (2.459s) --------------------

Impacted documentation

Not sure?

@github-project-automation github-project-automation bot moved this to Needs triage in Bug Triage May 14, 2025
@iclanton iclanton moved this from Needs triage to In Progress in Bug Triage May 19, 2025
{
"$schema": "http://json.schemastore.org/tsconfig",

"compilerOptions": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure we have a rig we should be extending for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmichon-msft Looking through a few other heft example plugins, I don't see anything - do you know which one that would be?

@aramissennyeydd
Copy link
Contributor Author

aramissennyeydd commented Jun 10, 2025

Realizing that I also want a recordPhaseMetrics hook for multi-phase execution. Taking a look now.

edit: I think what I'd be looking for would be start + end hooks for heft phases, which I don't love adding as public API rn. Task-level metrics are a good start :)

@aramissennyeydd aramissennyeydd changed the title [heft] feat: add new task-level timing metrics [heft] feat: add new task and phase-level timing metrics Jun 10, 2025
@aramissennyeydd aramissennyeydd force-pushed the sennyeya/heft-metrics branch from 28a094e to 3dac4c8 Compare June 11, 2025 01:12
@aramissennyeydd aramissennyeydd force-pushed the sennyeya/heft-metrics branch from 3dac4c8 to 9b9fe3b Compare June 11, 2025 01:16
@aramissennyeydd aramissennyeydd changed the title [heft] feat: add new task and phase-level timing metrics [heft] feat: add new task-level timing metrics Jun 11, 2025
@aramissennyeydd
Copy link
Contributor Author

@dmichon-msft What do you think about instead implementing this as beforeExecuteOperation, afterExecuteOperation, and afterExecuteOperationGroup hooks? I don't want to modify the operations in the hooks, just read state - recordTaskMetrics seems like a weird in between, when what I'm likely looking more for is operation lifecycle hooks.

@aramissennyeydd
Copy link
Contributor Author

closing in favor of #5250

@github-project-automation github-project-automation bot moved this from In Progress to Closed in Bug Triage Jun 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Closed

Development

Successfully merging this pull request may close these issues.

2 participants