-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Metrics Feature Switch #91767
Metrics Feature Switch #91767
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with a couple questions inline
@@ -52,6 +52,11 @@ protected Instrument(Meter meter, string name, string? unit, string? description | |||
/// <param name="tags">A span of key-value pair tags associated with the measurement.</param> | |||
protected void RecordMeasurement(T measurement, ReadOnlySpan<KeyValuePair<string, object?>> tags) | |||
{ | |||
if (!Meter.IsSupported) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we avoid adding this check and count on _subscription.First to be null? It looks like you already blocked all the code paths that could have registered a subscription.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we can do that. According to my understanding (per @eerhardt explanation) jit is going to optimize that in tier two and will fully remove this check. I was hoping when IsSupported
is false, the linker can empty the whole method body including accessing the static fields. Let me know if you still think we should remove this check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you confirm the JIT does optimize it as expected. As long as that is confirmed then I have no qualms leaving it there :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding this check will allow the trimmer to remove the rest of the method body, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding this check will allow the trimmer to remove the rest of the method body, right?
Correct - and all the methods it calls that aren't called elsewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created a simple app using my private built. The app and the runtime were built as a release. I have IsSupported = true
to test the normal case. I run it under the debugger, and I am seeing the call Meter.IsSupported
is not removed inside RecordMeasurement
method. I'll remove this check from there as this is a hot path, we want to avoid regressions there.
src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/Meter.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also have a trimming test that ensures certain things are trimmed?
Can you show a before and after size comparison (maybe using ILSpy or https://github.com/MichalStrehovsky/sizoscope) that shows what is all trimmed when this switch is set?
...libraries/System.Diagnostics.DiagnosticSource/src/System.Diagnostics.DiagnosticSource.csproj
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/Meter.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks, @tarekgh.
src/libraries/System.Diagnostics.DiagnosticSource/src/ILLink/ILLink.Substitutions.Shared.xml
Outdated
Show resolved
Hide resolved
/backport to release/8.0 |
Started backporting to release/8.0: https://github.com/dotnet/runtime/actions/runs/6165846484 |
@tarekgh backporting to release/8.0 failed, the patch most likely resulted in conflicts: $ git am --3way --ignore-whitespace --keep-non-patch changes.patch
Applying: Metrics Feature Switch
Using index info to reconstruct a base tree...
M docs/workflow/trimming/feature-switches.md
M src/libraries/System.Diagnostics.DiagnosticSource/src/System.Diagnostics.DiagnosticSource.csproj
Falling back to patching base and 3-way merge...
Auto-merging src/libraries/System.Diagnostics.DiagnosticSource/src/System.Diagnostics.DiagnosticSource.csproj
CONFLICT (content): Merge conflict in src/libraries/System.Diagnostics.DiagnosticSource/src/System.Diagnostics.DiagnosticSource.csproj
Auto-merging docs/workflow/trimming/feature-switches.md
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 Metrics Feature Switch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128 Please backport manually! |
@tarekgh an error occurred while backporting to release/8.0, please check the run log for details! Error: git am failed, most likely due to a merge conflict. |
#89880