Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
V1 of counter implementation
  • Loading branch information
rzikm committed Feb 8, 2024
commit 49142ad2f001f08d210dcabfed2732867134551b
Original file line number Diff line number Diff line change
Expand Up @@ -63,31 +63,31 @@ public int SetParam(MsQuicSafeHandle handle, uint param, uint bufferLength, void
bool success = false;
try
{
handle.DangerousAddRef(ref success);
return ApiTable->SetParam(handle.QuicHandle, param, bufferLength, buffer);
handle?.DangerousAddRef(ref success);
return ApiTable->SetParam(handle != null ? handle.QuicHandle : null, param, bufferLength, buffer);
}
finally
{
if (success)
{
handle.DangerousRelease();
handle!.DangerousRelease();
}
}
}

public int GetParam(MsQuicSafeHandle handle, uint param, uint* bufferLength, void* buffer)
public int GetParam(MsQuicSafeHandle? handle, uint param, uint* bufferLength, void* buffer)
{
bool success = false;
try
{
handle.DangerousAddRef(ref success);
return ApiTable->GetParam(handle.QuicHandle, param, bufferLength, buffer);
handle?.DangerousAddRef(ref success);
return ApiTable->GetParam(handle != null ? handle.QuicHandle : null, param, bufferLength, buffer);
}
finally
{
if (success)
{
handle.DangerousRelease();
handle!.DangerousRelease();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ private MsQuicApi(QUIC_API_TABLE* apiTable)
ThrowHelper.ThrowIfMsQuicError(ApiTable->RegistrationOpen(&cfg, &handle), "RegistrationOpen failed");

Registration = new MsQuicSafeHandle(handle, apiTable->RegistrationClose, SafeHandleType.Registration);
// QuicTelemetry.EnsureInitialized();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ internal static unsafe T GetMsQuicParameter<T>(MsQuicSafeHandle handle, uint par
GetMsQuicParameter(handle, parameter, (uint)sizeof(T), (byte*)&value);
return value;
}
internal static unsafe void GetMsQuicParameter(MsQuicSafeHandle handle, uint parameter, uint length, byte* value)
internal static unsafe void GetMsQuicParameter(MsQuicSafeHandle? handle, uint parameter, uint length, byte* value)
{
int status = MsQuicApi.Api.GetParam(
handle,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.Tracing;
using System.Net.Quic;

using Microsoft.Quic;
using static Microsoft.Quic.MsQuic;

namespace System.Net
{
internal sealed partial class NetEventSource
{
private static readonly long[] s_counters = new long[(int)QUIC_PERFORMANCE_COUNTERS.MAX];

private IncrementingPollingCounter? _connCreated;
private IncrementingPollingCounter? _connHandshakeFail;
private IncrementingPollingCounter? _connAppReject;
private IncrementingPollingCounter? _connLoadReject;

protected override void OnEventCommand(EventCommandEventArgs command)
{
if (command.Command == EventCommand.Enable && MsQuicApi.IsQuicSupported)
{
_connCreated ??= new IncrementingPollingCounter("CONN_CREATED", this, () => GetCounter(QUIC_PERFORMANCE_COUNTERS.CONN_CREATED))
{
DisplayName = "Connections Created",
DisplayRateTimeScale = TimeSpan.FromSeconds(1)
};

_connHandshakeFail ??= new IncrementingPollingCounter("CONN_HANDSHAKE_FAIL", this, () => GetCounter(QUIC_PERFORMANCE_COUNTERS.CONN_HANDSHAKE_FAIL))
{
DisplayName = "Connection Handshake Failures",
DisplayRateTimeScale = TimeSpan.FromSeconds(1)
};

_connAppReject ??= new IncrementingPollingCounter("CONN_APP_REJECT", this, () => GetCounter(QUIC_PERFORMANCE_COUNTERS.CONN_APP_REJECT))
{
DisplayName = "Connections Rejected on Application Layer",
DisplayRateTimeScale = TimeSpan.FromSeconds(1)
};

_connLoadReject ??= new IncrementingPollingCounter("CONN_LOAD_REJECT", this, () => GetCounter(QUIC_PERFORMANCE_COUNTERS.CONN_LOAD_REJECT))
{
DisplayName = "Connections Rejected due to worker load",
DisplayRateTimeScale = TimeSpan.FromSeconds(1)
};
}
}

[NonEvent]
private void UpdateCounters()
{
// if (!MsQuicApi.IsQuicSupported)
// {
// // MsQuicApi static ctor also uses this event source for logging, so if this event source is enabled, logging can
// // actually transitively call this method. Since IsQuicSupported is set at the very end of that method, we just
// return;
// }

unsafe
{
fixed (long* pCounters = s_counters)
{
MsQuicHelpers.GetMsQuicParameter(null, QUIC_PARAM_GLOBAL_PERF_COUNTERS, (uint)s_counters.Length * sizeof(long), (byte*)pCounters);
}
}
}

[NonEvent]
private long GetCounter(QUIC_PERFORMANCE_COUNTERS counter)
{
UpdateCounters();
return s_counters[(int)counter];
}
}
}