Enable Dev18 Python profiling through Diagnostics Hub - #8591
Conversation
Route Dev18 profiling through the Diagnostics Hub Python target, package the compatible etwtrace runtimes, and add the bootstrap needed to attach Python function instrumentation to the collector. Also make the profiler command service dynamically consumable by Diagnostics Hub and pin the Dev18 System.Text.Json reference to its intended assembly version. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 22382edc-142c-40c6-b272-404c67b61fea
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
🔒 Automated review in progress — @heejaechang is auto-reviewing this PR. |
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Pull request overview
Enables Python profiling in VS Dev18 by routing the existing PTVS “Launch Python Profiling” entrypoint to Diagnostics Hub, supplying a new command/input service and bootstrap script so Diagnostics Hub can run python-etwtrace-based instrumentation while preserving legacy behavior for older VS targets.
Changes:
- Route Dev18 profiling launch to Diagnostics Hub and register the
PythonProfilingEnabledDiagnostics Hub feature flag. - Introduce a package-independent
PythonProfilerCommandService+ reworked command argument construction for Diagnostics Hub ownership of session/report. - Add
diaghub_profile.pyplus build/packaging updates to ship coherentetwtracepayloads (legacy + current) and include CPython 3.14 wheels.
Show a summary per file
| File | Description |
|---|---|
| Python/Product/PythonTools/PythonTools.csproj | Pins Dev18 System.Text.Json reference to resolve an assembly conflict. |
| Python/Product/Profiling/PythonProfilingPackage.cs | Routes Dev18 profiling launch through Diagnostics Hub command. |
| Python/Product/Profiling/ProvidePythonProfilingFeatureFlagAttribute.cs | Registers Diagnostics Hub PythonProfilingEnabled feature flag for Dev18. |
| Python/Product/Profiling/Profiling/UserInputDialog.cs | Decouples dialog creation from PythonProfilingPackage by using IServiceProvider. |
| Python/Product/Profiling/Profiling/PythonProfilerCommandService.cs | Exposes a shared, public command service for Diagnostics Hub to construct and query. |
| Python/Product/Profiling/Profiling/CommandArgumentBuilder.cs | Reworks argument building so PTVS supplies interpreter/script/env while Diagnostics Hub owns sessions. |
| Python/Product/Profiling/Profiling.csproj | Ships diaghub_profile.py and includes both current + legacy etwtrace payloads in the VSIX. |
| Python/Product/Profiling/diaghub_profile.py | Adds the bootstrapper that launches a child process and activates etwtrace for profiling. |
| Build/PreBuild.ps1 | Downloads both current and legacy etwtrace payloads and removes unwanted unsigned test DLLs. |
| Build/install_pypi_package.py | Extends wheel selection to include CPython 3.14 (cp314). |
Review details
Comments suppressed due to low confidence (1)
Python/Product/Profiling/Profiling/PythonProfilerCommandService.cs:62
- The exception handler shows a hard-coded, non-localized dialog title/message ("An unexpected error occurred" / "Error"), and it also swallows critical exceptions (OOM/AV/etc.) that should not be handled. This will produce inconsistent user-facing strings and can mask fatal failures.
} catch (Exception ex) {
Debug.Fail($"Error displaying user input dialog: {ex.Message}");
MessageBox.Show($"An unexpected error occurred: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
- Files reviewed: 10/10 changed files
- Comments generated: 0
- Review effort level: Low
Preserve python -m semantics, validate malformed targets, carry child arguments through a JSON environment payload, and report expected collector startup failures without tracebacks. Add focused coverage for supported versions, target validation, argument transport, script execution, and module execution. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 22382edc-142c-40c6-b272-404c67b61fea
|
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Review details
Comments suppressed due to low confidence (1)
Python/Product/Profiling/Profiling/PythonProfilerCommandService.cs:62
- Avoid hard-coded UI strings in product code. This dialog title is the literal "Error" and the message prefix is not localized; elsewhere in the profiling UI, message boxes use resource strings (e.g., Strings.ProductTitle / other Strings.). Consider using Strings.ProductTitle for the title (and ideally a Strings. resource for the message prefix) to keep localization consistent.
} catch (Exception ex) {
Debug.Fail($"Error displaying user input dialog: {ex.Message}");
MessageBox.Show($"An unexpected error occurred: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
- Files reviewed: 13/13 changed files
- Comments generated: 0 new
- Review effort level: Low
|
PR was also sent on the diagnostics hub side: https://devdiv.visualstudio.com/DevDiv/_git/DiagnosticsHub/pullrequest/763766 |



Context
Python profiling in Dev18 is currently unavailable. The legacy PTVS path depends on
VSPerfMon.exeandVSPerfCmd.exe, which were removed from the Dev18 shipping manifest, and its native bridge only understands CPython layouts through Python 3.10. This is the PTVS half of moving basic function instrumentation to the existing Diagnostics Hub Python target andmicrosoft/python-etwtracepipeline. It addresses the user-visible failure tracked by #8276.This PR is not standalone. It requires companion Diagnostics Hub changes to:
TargetProperties.Pythonas script instrumentation instead of opening the native executable/PDB planner;Those companion changes are currently on the DiagnosticsHub branch
feature/ptvs-python-profiling.PTVS changes
PythonProfilingEnabledDiagnostics Hub feature flag for Dev18.PythonProfilerCommandServicethat Diagnostics Hub can construct dynamically with the global VS service provider.diaghub_profile.py, which:etwtracefor the lifetime of the interpreter, including worker threads;-mexecution;etwtracepayloads:0.1b8for CPython 3.9-3.11;0.1b9for CPython 3.12-3.14.System.Text.Jsonassembly reference to remove the existing MSB3277 conflict warning.Runtime flow
Manual validation
Validated in a Dev18 Experimental instance with the companion Diagnostics Hub changes:
.diagsessionreport is produced;main,calculate_batch,transform, andwait_for_ioresolve with call counts, total time, and self time;rn- focused bootstrap tests pass on Python 3.9 and 3.14 and through the existing ProfilingTests MSTest project.Current limitations
etwtracewheels are available, so 32-bit Python is not supported by this path..vsp/Performance Explorer pipeline.Cross-repo rollout note
The DataWarehouse label fix was locally validated with an unsigned Release analyzer copied to both destinations listed by DiagnosticsHub's
DataWarehouseManaged.list. Production validation requires the normal signed Diagnostics Hub build/insertion pipeline.