-
Notifications
You must be signed in to change notification settings - Fork 341
Enable event tracing in SNI.dll #650
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
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
13857f2
Merge pull request #2 from dotnet/master
b807d0b
Merge remote-tracking branch 'upstream/master'
johnnypham 26b0f35
Set up CI with Azure Pipelines
3da84f8
Delete azure-pipelines.yml
9b49213
Merge remote-tracking branch 'upstream/master'
johnnypham d02b69c
Set up CI with Azure Pipelines
896caa1
Delete azure-pipelines.yml
0c04741
Merge branch 'master' of https://github.com/johnnypham/SqlClient
johnnypham 035ef3d
Merge remote-tracking branch 'upstream/master'
johnnypham d1dc8bb
Merge remote-tracking branch 'upstream/master'
johnnypham acbb0a5
Merge remote-tracking branch 'upstream/master'
johnnypham acac0cc
Event tracing in SNI.dll
johnnypham 74a7b8c
Update BUILDGUIDE.md
johnnypham 5bdcb33
Update BUILDGUIDE.md
johnnypham c789541
Address feedback
johnnypham 63ce706
spacing
johnnypham f6e8be3
Update SqlClientEventSource.Windows.cs
johnnypham 4e174c5
Update SqlClientEventSource.Windows.cs
johnnypham 2637d6c
check for managed networking
johnnypham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlClientEventSource.Windows.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System; | ||
| using System.Diagnostics; | ||
| using System.Diagnostics.Tracing; | ||
|
|
||
| namespace Microsoft.Data.SqlClient | ||
| { | ||
| internal partial class SqlClientEventSource : EventSource | ||
| { | ||
| private bool _traceLoggingProviderEnabled = false; | ||
|
|
||
| /// <summary> | ||
| /// Captures application flow traces from native networking implementation | ||
| /// </summary> | ||
| private const EventCommand SNINativeTrace = (EventCommand)8192; | ||
|
|
||
| /// <summary> | ||
| /// Captures scope trace events from native networking implementation | ||
| /// </summary> | ||
| private const EventCommand SNINativeScope = (EventCommand)16384; | ||
|
|
||
| /// <summary> | ||
| /// Disables all event tracing in native networking implementation | ||
| /// </summary> | ||
| private const EventCommand SNINativeDisable = (EventCommand)32768; | ||
|
|
||
| protected override void OnEventCommand(EventCommandEventArgs e) | ||
| { | ||
| // Internally, EventListener.EnableEvents sends an event command, with a reserved value of 0, -2, or -3. | ||
| // When a command is sent via EnableEvents or SendCommand, check if it is a user-defined value | ||
| // to enable or disable event tracing in sni.dll. | ||
| // If registration fails, all write and unregister commands will be a no-op. | ||
|
|
||
| // If managed networking is enabled, don't call native wrapper methods | ||
| #if netcoreapp | ||
| if (AppContext.TryGetSwitch("Switch.Microsoft.Data.SqlClient.UseManagedNetworkingOnWindows", out bool isEnabled) && isEnabled) | ||
| { | ||
| return; | ||
| } | ||
| #endif | ||
| // Only register the provider if it's not already registered. Registering a provider that is already | ||
| // registered can lead to unpredictable behaviour. | ||
| if (!_traceLoggingProviderEnabled && e.Command > 0 && (e.Command & (SNINativeTrace | SNINativeScope)) != 0) | ||
| { | ||
| int eventKeyword = (int)(e.Command & (SNINativeTrace | SNINativeScope)); | ||
| _traceLoggingProviderEnabled = SNINativeMethodWrapper.RegisterTraceProvider(eventKeyword); | ||
|
karinazhou marked this conversation as resolved.
|
||
| Debug.Assert(_traceLoggingProviderEnabled, "Failed to enable TraceLogging provider."); | ||
| } | ||
| else if (_traceLoggingProviderEnabled && (e.Command == SNINativeDisable)) | ||
| { | ||
| // Only unregister the provider if it's currently registered. | ||
| SNINativeMethodWrapper.UnregisterTraceProvider(); | ||
| _traceLoggingProviderEnabled = false; | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.