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

Add PythonProfilderCommandService to support new profiler #8150

Merged
merged 7 commits into from
Jan 28, 2025

Conversation

StellaHuang95
Copy link
Contributor

@StellaHuang95 StellaHuang95 commented Jan 27, 2025

Implementation:

The IPythonProfilerCommandService interface is where the core functionality is. The VS team can use MEF to import this type into their codebase and call GetCommandArgsFromUserInput to retrieve a PythonProfilingCommandArgs. This object includes properties such as PythonExePath, WorkingDir, ScriptPath, Args, and EnvVars, basically all the arguments required by the Diagnostics Hub team to run the command that invokes the etwtrace package.

When the GetCommandArgsFromUserInput in PythonProfilerCommandService is called, first, UserInputDialog.ShowDialog() displays a user input dialog, allowing users to specify script arguments. Then, CommandArgumentBuilder.BuildCommandArgsFromTarget() is called to construct the command arguments from user input and returns the result to the service caller.

Testing:

Current testing is performed manually by calling the service from the existing profiling dialog. A breakpoint is set in PythonProfilingPackages.cs right after the user opens the Python profiler window to verify that the expected object is returned.
Unit tests will be added later, but for now, the focus is on rapid iteration and validation.

For example,

Here's user input in the dialog
image

Here's the value the service returns
image

@StellaHuang95 StellaHuang95 requested a review from a team as a code owner January 27, 2025 22:11
@StellaHuang95 StellaHuang95 requested a review from rchiodo January 27, 2025 22:27
@StellaHuang95
Copy link
Contributor Author

@rchiodo Could you also take a look when you get a chance? Just to get a second opinion on it before passing it to the VS team.

@StellaHuang95 StellaHuang95 changed the title Add user input service to support new profiler Add Python profiler command service to support new profiler Jan 28, 2025
@StellaHuang95 StellaHuang95 changed the title Add Python profiler command service to support new profiler Add PythonProfilderCommandService to support new profiler Jan 28, 2025
@StellaHuang95
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@StellaHuang95
Copy link
Contributor Author

I’ve finished addressing all the feedback, updated the PR description to reflect the new file and interface naming, and did all the tests again to ensure that the expected values are returned. I’ll let the insertion PR run first since it takes about a day to complete, but please take another look whenever you have a chance tomorrow @AdamYoblick before I merge this into the VS main branch.

The service call works as intended within PTVS. By MEF exporting the service interface and the returned interface, the Diagnostics Hub team should be able to compile without issues using MEF.

When passing this to the Diagnostics Hub team, I will share the following details, but let me know if there’s anything else you want to add. Thanks!

  1. The new service will be inserted into the VS main branch, as it does not impact the current user profiling workflow. However, feel free to let us know if you’d prefer it to remain in a topic branch.

  2. Please use the following command to invoke the etwtrace package: <path to python.exe> -m etwtrace --diaghub -- <path to script.py> <args>. Reference to etwtrace doc is at etwtrace PyPI page. This provides some command-line examples. Steve should also be able to provide more details if needed.

  3. The etwtrace package is bundled in the latest IntPreview version of Visual Studio with PTVS, which can be found at
    %LocalAppData%\Microsoft\VisualStudio\<Version>\Extensions\Microsoft Corporation\Python - Profiling\<Version>\etwtrace. Previously, to invoke the etwtrace package in PTVS, I had to append the etwtrace module path to the existing PYTHONPATH in the environment variables.

  4. To get the command line arguments, use MEF to call IPythonProfilerCommandService.GetCommandArgsFromUserInput(). This method should returns an IPythonProfilingCommandArgs object that contains all the needed arguments.

@StellaHuang95 StellaHuang95 merged commit dbac8cc into main Jan 28, 2025
7 checks passed
@StellaHuang95 StellaHuang95 deleted the userInputService branch January 28, 2025 21:15
@StellaHuang95
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants