Skip to content

Commit 98eee05

Browse files
authored
Trim NetEventSource when EventSource.IsSupported is false (#38828)
* Trim NetEventSource when EventSource.IsSupported is false Follow up to #38129. NetEventSource code was still left in even when EventSource.IsSupported is false, since all the usages of NetEventSource are keying off its own static property: NetEventSource.IsEnabled. Remove NetEventSource.IsEnabled so the linker can trim NetEventSource code when EventSource.IsSupported is false. * Remove HttpTelemetry.IsEnabled static property so the linker can trim EventSource code when EventSource.IsSupported is false. * Fix fake NetEventSource to match what is in the product.
1 parent 622b7d3 commit 98eee05

File tree

150 files changed

+1451
-1456
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+1451
-1456
lines changed

src/libraries/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.Ssl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ public static bool SslCheckHostnameMatch(SafeSslHandle handle, string hostName,
399399
case 1:
400400
return true;
401401
default:
402-
if (NetEventSource.IsEnabled)
402+
if (NetEventSource.Log.IsEnabled())
403403
NetEventSource.Error(null, $"AppleCryptoNative_SslIsHostnameMatch returned '{result}' for '{hostName}'");
404404
Debug.Fail($"AppleCryptoNative_SslIsHostnameMatch returned {result}");
405405
throw new SslException();

src/libraries/Common/src/Interop/Windows/HttpApi/Interop.HttpApi.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -663,13 +663,13 @@ internal static int IndexOfKnownHeader(string headerName)
663663

664664
private static unsafe string GetKnownHeader(HTTP_REQUEST* request, long fixup, int headerIndex)
665665
{
666-
if (NetEventSource.IsEnabled) { NetEventSource.Enter(null); }
666+
if (NetEventSource.Log.IsEnabled()) { NetEventSource.Enter(null); }
667667

668668
string header = null;
669669

670670
HTTP_KNOWN_HEADER* pKnownHeader = (&request->Headers.KnownHeaders) + headerIndex;
671671

672-
if (NetEventSource.IsEnabled)
672+
if (NetEventSource.Log.IsEnabled())
673673
{
674674
NetEventSource.Info(null, $"HttpApi::GetKnownHeader() pKnownHeader:0x{(IntPtr)pKnownHeader}");
675675
NetEventSource.Info(null, $"HttpApi::GetKnownHeader() pRawValue:0x{(IntPtr)pKnownHeader->pRawValue} RawValueLength:{pKnownHeader->RawValueLength}");
@@ -682,7 +682,7 @@ private static unsafe string GetKnownHeader(HTTP_REQUEST* request, long fixup, i
682682
header = new string(pKnownHeader->pRawValue + fixup, 0, pKnownHeader->RawValueLength);
683683
}
684684

685-
if (NetEventSource.IsEnabled) { NetEventSource.Exit(null, $"HttpApi::GetKnownHeader() return:{header}"); }
685+
if (NetEventSource.Log.IsEnabled()) { NetEventSource.Exit(null, $"HttpApi::GetKnownHeader() return:{header}"); }
686686
return header;
687687
}
688688

@@ -776,7 +776,7 @@ internal static unsafe WebHeaderCollection GetHeaders(IntPtr memoryBlob, IntPtr
776776

777777
internal static unsafe uint GetChunks(IntPtr memoryBlob, IntPtr originalAddress, ref int dataChunkIndex, ref uint dataChunkOffset, byte[] buffer, int offset, int size)
778778
{
779-
if (NetEventSource.IsEnabled)
779+
if (NetEventSource.Log.IsEnabled())
780780
{
781781
NetEventSource.Enter(null, $"HttpApi::GetChunks() memoryBlob:{memoryBlob}");
782782
}
@@ -828,7 +828,7 @@ internal static unsafe uint GetChunks(IntPtr memoryBlob, IntPtr originalAddress,
828828
dataChunkIndex = -1;
829829
}
830830

831-
if (NetEventSource.IsEnabled)
831+
if (NetEventSource.Log.IsEnabled())
832832
{
833833
NetEventSource.Exit(null);
834834
}
@@ -854,7 +854,7 @@ internal static unsafe HTTP_VERB GetKnownVerb(IntPtr memoryBlob, IntPtr original
854854

855855
internal static unsafe IPEndPoint GetRemoteEndPoint(IntPtr memoryBlob, IntPtr originalAddress)
856856
{
857-
if (NetEventSource.IsEnabled) NetEventSource.Enter(null);
857+
if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(null);
858858

859859
SocketAddress v4address = new SocketAddress(AddressFamily.InterNetwork, IPv4AddressSize);
860860
SocketAddress v6address = new SocketAddress(AddressFamily.InterNetworkV6, IPv6AddressSize);
@@ -874,13 +874,13 @@ internal static unsafe IPEndPoint GetRemoteEndPoint(IntPtr memoryBlob, IntPtr or
874874
endpoint = new IPEndPoint(IPAddress.IPv6Any, IPEndPoint.MinPort).Create(v6address) as IPEndPoint;
875875
}
876876

877-
if (NetEventSource.IsEnabled) NetEventSource.Exit(null);
877+
if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(null);
878878
return endpoint;
879879
}
880880

881881
internal static unsafe IPEndPoint GetLocalEndPoint(IntPtr memoryBlob, IntPtr originalAddress)
882882
{
883-
if (NetEventSource.IsEnabled) NetEventSource.Enter(null);
883+
if (NetEventSource.Log.IsEnabled()) NetEventSource.Enter(null);
884884

885885
SocketAddress v4address = new SocketAddress(AddressFamily.InterNetwork, IPv4AddressSize);
886886
SocketAddress v6address = new SocketAddress(AddressFamily.InterNetworkV6, IPv6AddressSize);
@@ -900,7 +900,7 @@ internal static unsafe IPEndPoint GetLocalEndPoint(IntPtr memoryBlob, IntPtr ori
900900
endpoint = s_ipv6Any.Create(v6address) as IPEndPoint;
901901
}
902902

903-
if (NetEventSource.IsEnabled) NetEventSource.Exit(null);
903+
if (NetEventSource.Log.IsEnabled()) NetEventSource.Exit(null);
904904
return endpoint;
905905
}
906906

src/libraries/Common/src/Interop/Windows/SChannel/UnmanagedCertificateContext.IntPtr.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ internal static X509Certificate2Collection GetRemoteCertificatesFromStoreContext
4040
}
4141

4242
var cert = new X509Certificate2(new IntPtr(next));
43-
if (NetEventSource.IsEnabled) NetEventSource.Info(certContext, $"Adding remote certificate:{cert}");
43+
if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(certContext, $"Adding remote certificate:{cert}");
4444

4545
result.Add(cert);
4646
last = next;

src/libraries/Common/src/Interop/Windows/SspiCli/NegotiationInfoClass.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ internal static partial class NegotiationInfoClass
1414
{
1515
if (safeHandle.IsInvalid)
1616
{
17-
if (NetEventSource.IsEnabled) NetEventSource.Info(null, $"Invalid handle:{safeHandle}");
17+
if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(null, $"Invalid handle:{safeHandle}");
1818
return null;
1919
}
2020

@@ -23,7 +23,7 @@ internal static partial class NegotiationInfoClass
2323
{
2424
safeHandle.DangerousAddRef(ref gotRef);
2525
IntPtr packageInfo = safeHandle.DangerousGetHandle();
26-
if (NetEventSource.IsEnabled) NetEventSource.Info(null, $"packageInfo:{packageInfo} negotiationState:{negotiationState:x}");
26+
if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(null, $"packageInfo:{packageInfo} negotiationState:{negotiationState:x}");
2727

2828
if (negotiationState == Interop.SspiCli.SECPKG_NEGOTIATION_COMPLETE ||
2929
negotiationState == Interop.SspiCli.SECPKG_NEGOTIATION_OPTIMISTIC)
@@ -34,7 +34,7 @@ internal static partial class NegotiationInfoClass
3434
name = Marshal.PtrToStringUni(((SecurityPackageInfo*)packageInfo)->Name);
3535
}
3636

37-
if (NetEventSource.IsEnabled) NetEventSource.Info(null, $"packageInfo:{packageInfo} negotiationState:{negotiationState:x} name:{name}");
37+
if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(null, $"packageInfo:{packageInfo} negotiationState:{negotiationState:x} name:{name}");
3838

3939
// An optimization for future string comparisons.
4040
return

src/libraries/Common/src/Interop/Windows/SspiCli/SSPIAuthType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public SecurityPackageInfoClass[]? SecurityPackages
2626

2727
public int EnumerateSecurityPackages(out int pkgnum, out SafeFreeContextBuffer pkgArray)
2828
{
29-
if (NetEventSource.IsEnabled) NetEventSource.Info(this);
29+
if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(this);
3030
return SafeFreeContextBuffer.EnumeratePackages(out pkgnum, out pkgArray);
3131
}
3232

src/libraries/Common/src/Interop/Windows/SspiCli/SSPISecureChannelType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public SecurityPackageInfoClass[]? SecurityPackages
2626

2727
public int EnumerateSecurityPackages(out int pkgnum, out SafeFreeContextBuffer pkgArray)
2828
{
29-
if (NetEventSource.IsEnabled) NetEventSource.Info(this);
29+
if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(this);
3030
return SafeFreeContextBuffer.EnumeratePackages(out pkgnum, out pkgArray);
3131
}
3232

0 commit comments

Comments
 (0)