Move population of common MetricsContext fields to record_compilation_metrics (#141291)
Summary:
Fix outstanding TODOs related to logging of CompilationMetrics by moving the population of common fields to record_compilation_metrics() instead of populating those independently wherever we use a the metrics_context contextmanager:
* Keep track of start and end time in MetricsContext and pass those to record_compilation_metrics() and populate those fields in that function.
* Pass exception info to record_compilation_metrics() and populate those field in that function.
* Add a new contextmanager, chromium_event_timed, to create the start/end "dynamo" event. This is important because I want this contextmanager to complete _after_ building the CompilationMetrics.
* Populate the compile_id field centrally in record_compilation_metrics().
* Populate the structured_logging_overhead centrally in record_compilation_metrics().
* Add the CompilationMetrics to the current chromium event in record_compilation_metrics(), after all common fields have been added. In a future diff, I can also add _all_ compilation metrics to the chromium event.
X-link: https://github.com/pytorch/pytorch/pull/141291
Approved by: https://github.com/jamesjwu
Reviewed By: jovianjaison
Differential Revision: D66458953
Pulled By: masnesral
fbshipit-source-id: 4cfc0a21063abea4ac45ce12f9774fc369ca5a9a