Skip to content

Add MethodInvocation trace for overload tracing #21320

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

Merged
merged 3 commits into from
Jul 14, 2025

Conversation

jborean93
Copy link
Collaborator

@jborean93 jborean93 commented Mar 8, 2024

PR Summary

Adds a new trace source called MethodInvocation which can be used to trace what .NET methods PowerShell invokes. This is useful for both seeing what .NET methods the code is calling but also for seeing what overload PowerShell has selected based on the arguments provided.

This only applies to .NET methods, ETS members are not covered by this trace source but could potentially be added in the future.

PR Context

To be able to debug PowerShell behaviour like why " ".Split(" ") has changed across .NET versions. Also provides an analogue of ParameterBinding but for .NET methods.

For example

Trace-Command -PSHost -Name MethodInvocation -Expression {
    "abc def ghi".Split("", 2)
}

Shows

DEBUG: 2024-03-08 12:05:54.6860 MethodInvocation Information: 0 : Invoking method: string[] Split(string separator, int count, System.StringSplitOptions options = System.StringSplitOptions.None)

PR Checklist

This PR has 111 quantified lines of changes. In general, a change size of upto 200 lines is ideal for the best PR experience!


Quantification details

Label      : Medium
Size       : +111 -0
Percentile : 42.2%

Total files changed: 3

Change summary by file extension:
.cs : +16 -0
.ps1 : +95 -0

Change counts above are quantified counts, based on the PullRequestQuantifier customizations.

Why proper sizing of changes matters

Optimal pull request sizes drive a better predictable PR flow as they strike a
balance between between PR complexity and PR review overhead. PRs within the
optimal size (typical small, or medium sized PRs) mean:

  • Fast and predictable releases to production:
    • Optimal size changes are more likely to be reviewed faster with fewer
      iterations.
    • Similarity in low PR complexity drives similar review times.
  • Review quality is likely higher as complexity is lower:
    • Bugs are more likely to be detected.
    • Code inconsistencies are more likely to be detected.
  • Knowledge sharing is improved within the participants:
    • Small portions can be assimilated better.
  • Better engineering practices are exercised:
    • Solving big problems by dividing them in well contained, smaller problems.
    • Exercising separation of concerns within the code changes.

What can I do to optimize my changes

  • Use the PullRequestQuantifier to quantify your PR accurately
    • Create a context profile for your repo using the context generator
    • Exclude files that are not necessary to be reviewed or do not increase the review complexity. Example: Autogenerated code, docs, project IDE setting files, binaries, etc. Check out the Excluded section from your prquantifier.yaml context profile.
    • Understand your typical change complexity, drive towards the desired complexity by adjusting the label mapping in your prquantifier.yaml context profile.
    • Only use the labels that matter to you, see context specification to customize your prquantifier.yaml context profile.
  • Change your engineering behaviors
    • For PRs that fall outside of the desired spectrum, review the details and check if:
      • Your PR could be split in smaller, self-contained PRs instead
      • Your PR only solves one particular issue. (For example, don't refactor and code new features in the same PR).

How to interpret the change counts in git diff output

  • One line was added: +1 -0
  • One line was deleted: +0 -1
  • One line was modified: +1 -1 (git diff doesn't know about modified, it will
    interpret that line like one addition plus one deletion)
  • Change percentiles: Change characteristics (addition, deletion, modification)
    of this PR in relation to all other PRs within the repository.


Was this comment helpful? 👍  :ok_hand:  :thumbsdown: (Email)
Customize PullRequestQuantifier for this repository.

@jborean93 jborean93 force-pushed the method-invocation branch from a37cc7e to b041aa8 Compare March 8, 2024 02:00

This PR has 113 quantified lines of changes. In general, a change size of upto 200 lines is ideal for the best PR experience!


Quantification details

Label      : Medium
Size       : +113 -0
Percentile : 42.6%

Total files changed: 3

Change summary by file extension:
.cs : +16 -0
.ps1 : +97 -0

Change counts above are quantified counts, based on the PullRequestQuantifier customizations.

Why proper sizing of changes matters

Optimal pull request sizes drive a better predictable PR flow as they strike a
balance between between PR complexity and PR review overhead. PRs within the
optimal size (typical small, or medium sized PRs) mean:

  • Fast and predictable releases to production:
    • Optimal size changes are more likely to be reviewed faster with fewer
      iterations.
    • Similarity in low PR complexity drives similar review times.
  • Review quality is likely higher as complexity is lower:
    • Bugs are more likely to be detected.
    • Code inconsistencies are more likely to be detected.
  • Knowledge sharing is improved within the participants:
    • Small portions can be assimilated better.
  • Better engineering practices are exercised:
    • Solving big problems by dividing them in well contained, smaller problems.
    • Exercising separation of concerns within the code changes.

What can I do to optimize my changes

  • Use the PullRequestQuantifier to quantify your PR accurately
    • Create a context profile for your repo using the context generator
    • Exclude files that are not necessary to be reviewed or do not increase the review complexity. Example: Autogenerated code, docs, project IDE setting files, binaries, etc. Check out the Excluded section from your prquantifier.yaml context profile.
    • Understand your typical change complexity, drive towards the desired complexity by adjusting the label mapping in your prquantifier.yaml context profile.
    • Only use the labels that matter to you, see context specification to customize your prquantifier.yaml context profile.
  • Change your engineering behaviors
    • For PRs that fall outside of the desired spectrum, review the details and check if:
      • Your PR could be split in smaller, self-contained PRs instead
      • Your PR only solves one particular issue. (For example, don't refactor and code new features in the same PR).

How to interpret the change counts in git diff output

  • One line was added: +1 -0
  • One line was deleted: +0 -1
  • One line was modified: +1 -1 (git diff doesn't know about modified, it will
    interpret that line like one addition plus one deletion)
  • Change percentiles: Change characteristics (addition, deletion, modification)
    of this PR in relation to all other PRs within the repository.


Was this comment helpful? 👍  :ok_hand:  :thumbsdown: (Email)
Customize PullRequestQuantifier for this repository.

@microsoft-github-policy-service microsoft-github-policy-service bot added the Review - Needed The PR is being reviewed label Mar 15, 2024
@jborean93 jborean93 force-pushed the method-invocation branch from b041aa8 to 07d6f4e Compare May 23, 2024 22:41
@jborean93 jborean93 force-pushed the method-invocation branch from 07d6f4e to 25b209a Compare July 7, 2024 22:18
@kilasuit kilasuit added WG-Interactive-Debugging debugging PowerShell script WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module WG-NeedsReview Needs a review by the labeled Working Group labels Jul 26, 2024
Copy link
Collaborator

@kilasuit kilasuit left a comment

Choose a reason for hiding this comment

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

I think this looks good and would be a great help in script debugging & would be good to get this merged in!

@SteveL-MSFT
Copy link
Member

The @PowerShell/wg-powershell-cmdlets discussed this, we are in favor of adding more diagnosability to PowerShell, but defer to the Engine WG to review.

@SteveL-MSFT SteveL-MSFT added WG-Engine core PowerShell engine, interpreter, and runtime and removed WG-Interactive-Debugging debugging PowerShell script WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module labels Aug 21, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot removed the Review - Needed The PR is being reviewed label Aug 21, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the Review - Needed The PR is being reviewed label Aug 28, 2024
@IISResetMe IISResetMe self-assigned this Feb 10, 2025
@IISResetMe IISResetMe added WG-Reviewed A Working Group has reviewed this and made a recommendation and removed WG-NeedsReview Needs a review by the labeled Working Group labels Feb 10, 2025
@IISResetMe
Copy link
Collaborator

WG-Engine reviewed this PR, and we endorse the proposed new trace source.

@IISResetMe IISResetMe removed their assignment Feb 10, 2025
@powercode powercode removed the Review - Needed The PR is being reviewed label Feb 12, 2025
@microsoft-github-policy-service microsoft-github-policy-service bot added the Review - Needed The PR is being reviewed label Feb 19, 2025
@iSazonov iSazonov added PowerShell-Docs needed The PR was reviewed and a PowerShell Docs update is needed and removed PowerShell-Docs needed The PR was reviewed and a PowerShell Docs update is needed labels Feb 20, 2025
@microsoft-github-policy-service microsoft-github-policy-service bot removed the Review - Needed The PR is being reviewed label Feb 20, 2025
@microsoft-github-policy-service microsoft-github-policy-service bot added the Review - Needed The PR is being reviewed label Feb 27, 2025
Adds a new trace source called MethodInvocation which can be used to
trace what .NET methods PowerShell invokes. This is useful for both
seeing what .NET methods the code is calling but also for seeing what
overload PowerShell has selected based on the arguments provided.

This only applies to .NET methods, ETS members are not covered by this
trace source but could potentially be added in the future.
@iSazonov iSazonov added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Apr 14, 2025
Copy link
Member

@daxian-dbw daxian-dbw left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you, @jborean93!

Copy link
Collaborator

@SeeminglyScience SeeminglyScience left a comment

Choose a reason for hiding this comment

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

LGTM!

@daxian-dbw daxian-dbw merged commit c6329dd into PowerShell:master Jul 14, 2025
34 checks passed
@daxian-dbw daxian-dbw removed Review - Needed The PR is being reviewed Medium labels Jul 14, 2025
@daxian-dbw daxian-dbw self-assigned this Jul 14, 2025
@jborean93 jborean93 deleted the method-invocation branch July 14, 2025 22:45
@jborean93
Copy link
Collaborator Author

Thanks for the review and merge, I've opened a PR to document this new feature MicrosoftDocs/PowerShell-Docs#12226. Up to the docs gods to make it prettier and more presentable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log WG-Engine core PowerShell engine, interpreter, and runtime WG-Reviewed A Working Group has reviewed this and made a recommendation
Projects
Development

Successfully merging this pull request may close these issues.

8 participants