This commit is contained in:
2026-06-15 18:18:16 +08:00
parent 97c9fba14e
commit 2b9f134e5f
4164 changed files with 386922 additions and 79 deletions

View File

@@ -0,0 +1,51 @@
#if BESTHTTP_PROFILE && UNITY_2021_2_OR_NEWER
using Unity.Profiling;
namespace Best.HTTP.Profiler.Network
{
public sealed class NetworkStats
{
public const string CategoryName = "Best - Network";
public static readonly ProfilerCategory Category = new ProfilerCategory(CategoryName, ProfilerCategoryColor.Scripts);
// Sent
public const string BufferedToSendName = "Buffered to Send";
public static readonly ProfilerCounterValue<long> BufferedToSend = new ProfilerCounterValue<long>(Category, BufferedToSendName, ProfilerMarkerDataUnit.Bytes, ProfilerCounterOptions.FlushOnEndOfFrame | ProfilerCounterOptions.ResetToZeroOnFlush);
public const string SentSinceLastFrameName = "Sent (Since Last Frame)";
public static readonly ProfilerCounterValue<long> SentSinceLastFrame = new ProfilerCounterValue<long>(Category, SentSinceLastFrameName, ProfilerMarkerDataUnit.Bytes, ProfilerCounterOptions.FlushOnEndOfFrame | ProfilerCounterOptions.ResetToZeroOnFlush);
public const string SentTotalName = "Sent Total";
public static readonly ProfilerCounterValue<long> SentTotal = new ProfilerCounterValue<long>(Category, SentTotalName, ProfilerMarkerDataUnit.Bytes, ProfilerCounterOptions.FlushOnEndOfFrame | ProfilerCounterOptions.ResetToZeroOnFlush);
// Received
public const string ReceivedSinceLastFrameName = "Received (Since Last Frame)";
public static readonly ProfilerCounterValue<long> ReceivedSinceLastFrame = new ProfilerCounterValue<long>(Category, ReceivedSinceLastFrameName, ProfilerMarkerDataUnit.Bytes, ProfilerCounterOptions.FlushOnEndOfFrame | ProfilerCounterOptions.ResetToZeroOnFlush);
public const string ReceivedAndUnprocessedName = "Received and Unprocessed";
public static readonly ProfilerCounterValue<long> ReceivedAndUnprocessed = new ProfilerCounterValue<long>(Category, ReceivedAndUnprocessedName, ProfilerMarkerDataUnit.Bytes, ProfilerCounterOptions.FlushOnEndOfFrame | ProfilerCounterOptions.ResetToZeroOnFlush);
public const string ReceivedTotalName = "Received Total";
public static readonly ProfilerCounterValue<long> ReceivedTotal = new ProfilerCounterValue<long>(Category, ReceivedTotalName, ProfilerMarkerDataUnit.Bytes, ProfilerCounterOptions.FlushOnEndOfFrame | ProfilerCounterOptions.ResetToZeroOnFlush);
// Connections
public const string OpenConnectionsName = "Open Connections";
public static readonly ProfilerCounterValue<int> OpenConnectionsCounter = new ProfilerCounterValue<int>(Category, OpenConnectionsName, ProfilerMarkerDataUnit.Count, ProfilerCounterOptions.FlushOnEndOfFrame);
public const string TotalConnectionsName = "Total Connections";
public static readonly ProfilerCounterValue<int> TotalConnectionsCounter = new ProfilerCounterValue<int>(Category, TotalConnectionsName, ProfilerMarkerDataUnit.Count, ProfilerCounterOptions.FlushOnEndOfFrame);
// DNS
public const string TotalDNSCacheHits = "DNS Cache Hits";
public static readonly ProfilerCounterValue<int> TotalDNSCacheHitsCounter = new ProfilerCounterValue<int>(Category, TotalDNSCacheHits, ProfilerMarkerDataUnit.Count, ProfilerCounterOptions.FlushOnEndOfFrame);
public const string TotalDNSCacheMiss = "DNS Cache Miss";
public static readonly ProfilerCounterValue<int> TotalDNSCacheMissCounter = new ProfilerCounterValue<int>(Category, TotalDNSCacheMiss, ProfilerMarkerDataUnit.Count, ProfilerCounterOptions.FlushOnEndOfFrame);
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: aab4369fdf2a1d04f8e02cd9cc1977d8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,53 @@
using System;
using System.Threading;
namespace Best.HTTP.Profiler.Network
{
public static class NetworkStatsCollector
{
public static long TotalNetworkBytesReceived { get => _totalNetworkBytesReceived; }
private static long _totalNetworkBytesReceived;
public static long TotalNetworkBytesSent { get => _totalNetworkBytesSent; }
private static long _totalNetworkBytesSent;
public static int TotalConnections { get => _totalConnections; }
private static int _totalConnections;
public static int OpenConnections { get => _openConnections; }
private static int _openConnections;
public static int BufferedToSend { get => _bufferedToSend; }
private static int _bufferedToSend;
public static int ReceivedAndUnprocessed { get => _receivedAndUnprocessed; }
private static int _receivedAndUnprocessed;
internal static void IncrementCurrentConnections()
{
Interlocked.Increment(ref _totalConnections);
Interlocked.Increment(ref _openConnections);
}
internal static void DecrementCurrentConnections() => Interlocked.Decrement(ref _openConnections);
internal static void IncrementTotalNetworkBytesReceived(int amount) => Interlocked.Add(ref _totalNetworkBytesReceived, amount);
internal static void IncrementTotalNetworkBytesSent(int amount) => Interlocked.Add(ref _totalNetworkBytesSent, amount);
internal static void IncrementBufferedToSend(int amount) => Interlocked.Add(ref _bufferedToSend, amount);
internal static void IncrementReceivedAndUnprocessed(int amount) => Interlocked.Add(ref _receivedAndUnprocessed, amount);
internal static void ResetNetworkStats()
{
Interlocked.Exchange(ref _totalNetworkBytesReceived, 0);
Interlocked.Exchange(ref _totalNetworkBytesSent, 0);
Interlocked.Exchange(ref _totalConnections, 0);
Interlocked.Exchange(ref _openConnections, 0);
Interlocked.Exchange(ref _bufferedToSend, 0);
Interlocked.Exchange(ref _receivedAndUnprocessed, 0);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2eade542690505e47bed8b5045c1cd3c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: