@@ -10,91 +10,119 @@ internal static class ProfilerCountersInfo
1010#if UNITY_2020_2_OR_NEWER && ENABLE_PROFILER
1111 // Operations
1212 private static readonly ProfilerCounterValue < int > k_ConnectionsCounterValue =
13- new ProfilerCounterValue < int > ( ProfilerCategory . Network , ProfilerConstants . NumberOfConnections ,
13+ new ProfilerCounterValue < int > ( ProfilerCategory . Network , ProfilerConstants . Connections ,
1414 ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame ) ;
1515
1616 private static readonly ProfilerCounterValue < int > k_TickRateCounterValue =
1717 new ProfilerCounterValue < int > ( ProfilerCategory . Network , ProfilerConstants . ReceiveTickRate ,
18- ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame ) ;
18+ ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame | ProfilerCounterOptions . ResetToZeroOnFlush ) ;
1919
2020 // Messages
2121 private static readonly ProfilerCounterValue < int > k_NamedMessagesCounterValue =
2222 new ProfilerCounterValue < int > ( ProfilerCategory . Network , ProfilerConstants . NumberOfNamedMessages ,
23- ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame ) ;
23+ ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame | ProfilerCounterOptions . ResetToZeroOnFlush ) ;
2424
2525 private static readonly ProfilerCounterValue < int > k_UnnamedMessagesCounterValue =
2626 new ProfilerCounterValue < int > ( ProfilerCategory . Network , ProfilerConstants . NumberOfUnnamedMessages ,
27- ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame ) ;
27+ ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame | ProfilerCounterOptions . ResetToZeroOnFlush ) ;
2828
2929 private static readonly ProfilerCounterValue < int > k_BytesSentCounterValue =
3030 new ProfilerCounterValue < int > ( ProfilerCategory . Network , ProfilerConstants . NumberBytesSent ,
31- ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame ) ;
31+ ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame | ProfilerCounterOptions . ResetToZeroOnFlush ) ;
3232
3333 private static readonly ProfilerCounterValue < int > k_BytesReceivedCounterValue =
3434 new ProfilerCounterValue < int > ( ProfilerCategory . Network , ProfilerConstants . NumberBytesReceived ,
35- ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame ) ;
35+ ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame | ProfilerCounterOptions . ResetToZeroOnFlush ) ;
3636
3737 private static readonly ProfilerCounterValue < int > k_NetworkVarsCounterValue =
3838 new ProfilerCounterValue < int > ( ProfilerCategory . Network , ProfilerConstants . NumberNetworkVarsReceived ,
39- ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame ) ;
39+ ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame | ProfilerCounterOptions . ResetToZeroOnFlush ) ;
4040
4141 // RPCs
4242 private static readonly ProfilerCounterValue < int > k_RPCsSentCounterValue =
4343 new ProfilerCounterValue < int > ( ProfilerCategory . Network , ProfilerConstants . NumberOfRPCsSent ,
44- ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame ) ;
44+ ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame | ProfilerCounterOptions . ResetToZeroOnFlush ) ;
4545
4646 private static readonly ProfilerCounterValue < int > k_RPCsReceivedCounterValue =
4747 new ProfilerCounterValue < int > ( ProfilerCategory . Network , ProfilerConstants . NumberOfRPCsReceived ,
48- ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame ) ;
48+ ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame | ProfilerCounterOptions . ResetToZeroOnFlush ) ;
4949
5050 private static readonly ProfilerCounterValue < int > k_RPCBatchesSentCounterValue =
5151 new ProfilerCounterValue < int > ( ProfilerCategory . Network , ProfilerConstants . NumberOfRPCBatchesSent ,
52- ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame ) ;
52+ ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame | ProfilerCounterOptions . ResetToZeroOnFlush ) ;
5353
5454 private static readonly ProfilerCounterValue < int > k_RPCBatchesReceivedCounterValue =
5555 new ProfilerCounterValue < int > ( ProfilerCategory . Network , ProfilerConstants . NumberOfRPCBatchesReceived ,
56- ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame ) ;
56+ ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame | ProfilerCounterOptions . ResetToZeroOnFlush ) ;
5757
5858 private static readonly ProfilerCounterValue < int > k_RPCQueueProcessedCounterValue =
5959 new ProfilerCounterValue < int > ( ProfilerCategory . Network , ProfilerConstants . NumberOfRPCQueueProcessed ,
60- ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame ) ;
60+ ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame | ProfilerCounterOptions . ResetToZeroOnFlush ) ;
6161
6262 private static readonly ProfilerCounterValue < int > k_RPCsInQueueSizeCounterValue =
6363 new ProfilerCounterValue < int > ( ProfilerCategory . Network , ProfilerConstants . NumberOfRPCsInQueueSize ,
64- ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame ) ;
64+ ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame | ProfilerCounterOptions . ResetToZeroOnFlush ) ;
6565
6666 private static readonly ProfilerCounterValue < int > k_RPCsOutQueueSizeCounterValue =
6767 new ProfilerCounterValue < int > ( ProfilerCategory . Network , ProfilerConstants . NumberOfRPCsOutQueueSize ,
68- ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame ) ;
68+ ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame | ProfilerCounterOptions . ResetToZeroOnFlush ) ;
6969
7070 [ RuntimeInitializeOnLoadMethod ]
7171 private static void RegisterMLAPIPerformanceEvent ( )
7272 {
73+ InitializeCounters ( ) ;
7374 NetworkManager . OnPerformanceDataEvent += OnPerformanceTickData ;
7475 }
7576
77+ private static void InitializeCounters ( )
78+ {
79+ k_ConnectionsCounterValue . Value = 0 ;
80+ k_TickRateCounterValue . Value = 0 ;
81+
82+ k_NamedMessagesCounterValue . Value = 0 ;
83+ k_UnnamedMessagesCounterValue . Value = 0 ;
84+ k_BytesSentCounterValue . Value = 0 ;
85+ k_BytesReceivedCounterValue . Value = 0 ;
86+ k_NetworkVarsCounterValue . Value = 0 ;
87+
88+ k_RPCsSentCounterValue . Value = 0 ;
89+ k_RPCsReceivedCounterValue . Value = 0 ;
90+ k_RPCBatchesSentCounterValue . Value = 0 ;
91+ k_RPCBatchesReceivedCounterValue . Value = 0 ;
92+ k_RPCQueueProcessedCounterValue . Value = 0 ;
93+ k_RPCsInQueueSizeCounterValue . Value = 0 ;
94+ k_RPCsOutQueueSizeCounterValue . Value = 0 ;
95+ }
96+
7697 private static void OnPerformanceTickData ( PerformanceTickData tickData )
7798 {
7899 // Operations
79- k_ConnectionsCounterValue . Value = tickData . GetData ( ProfilerConstants . NumberOfConnections ) ;
80- k_TickRateCounterValue . Value = tickData . GetData ( ProfilerConstants . ReceiveTickRate ) ;
100+ UpdateIntCounter ( tickData , k_ConnectionsCounterValue , ProfilerConstants . Connections ) ;
101+ UpdateIntCounter ( tickData , k_TickRateCounterValue , ProfilerConstants . ReceiveTickRate ) ;
81102
82103 // Messages
83- k_NamedMessagesCounterValue . Value = tickData . GetData ( ProfilerConstants . NumberOfNamedMessages ) ;
84- k_UnnamedMessagesCounterValue . Value = tickData . GetData ( ProfilerConstants . NumberOfUnnamedMessages ) ;
85- k_BytesSentCounterValue . Value = tickData . GetData ( ProfilerConstants . NumberBytesSent ) ;
86- k_BytesReceivedCounterValue . Value = tickData . GetData ( ProfilerConstants . NumberBytesReceived ) ;
87- k_NetworkVarsCounterValue . Value = tickData . GetData ( ProfilerConstants . NumberNetworkVarsReceived ) ;
104+ UpdateIntCounter ( tickData , k_NamedMessagesCounterValue , ProfilerConstants . NumberOfNamedMessages ) ;
105+ UpdateIntCounter ( tickData , k_UnnamedMessagesCounterValue , ProfilerConstants . NumberOfUnnamedMessages ) ;
106+ UpdateIntCounter ( tickData , k_BytesSentCounterValue , ProfilerConstants . NumberBytesSent ) ;
107+ UpdateIntCounter ( tickData , k_BytesReceivedCounterValue , ProfilerConstants . NumberBytesReceived ) ;
108+ UpdateIntCounter ( tickData , k_NetworkVarsCounterValue , ProfilerConstants . NumberNetworkVarsReceived ) ;
88109
89110 // RPCs
90- k_RPCsSentCounterValue . Value = tickData . GetData ( ProfilerConstants . NumberOfRPCsSent ) ;
91- k_RPCsReceivedCounterValue . Value = tickData . GetData ( ProfilerConstants . NumberOfRPCsReceived ) ;
92- k_RPCBatchesSentCounterValue . Value = tickData . GetData ( ProfilerConstants . NumberOfRPCBatchesSent ) ;
93- k_RPCBatchesReceivedCounterValue . Value = tickData . GetData ( ProfilerConstants . NumberOfRPCBatchesReceived ) ;
94- k_RPCBatchesReceivedCounterValue . Value = tickData . GetData ( ProfilerConstants . NumberOfRPCBatchesReceived ) ;
95- k_RPCQueueProcessedCounterValue . Value = tickData . GetData ( ProfilerConstants . NumberOfRPCQueueProcessed ) ;
96- k_RPCsInQueueSizeCounterValue . Value = tickData . GetData ( ProfilerConstants . NumberOfRPCsInQueueSize ) ;
97- k_RPCsOutQueueSizeCounterValue . Value = tickData . GetData ( ProfilerConstants . NumberOfRPCsOutQueueSize ) ;
111+ UpdateIntCounter ( tickData , k_RPCsSentCounterValue , ProfilerConstants . NumberOfRPCsSent ) ;
112+ UpdateIntCounter ( tickData , k_RPCsReceivedCounterValue , ProfilerConstants . NumberOfRPCsReceived ) ;
113+ UpdateIntCounter ( tickData , k_RPCBatchesSentCounterValue , ProfilerConstants . NumberOfRPCBatchesSent ) ;
114+ UpdateIntCounter ( tickData , k_RPCBatchesReceivedCounterValue , ProfilerConstants . NumberOfRPCBatchesReceived ) ;
115+ UpdateIntCounter ( tickData , k_RPCBatchesReceivedCounterValue , ProfilerConstants . NumberOfRPCQueueProcessed ) ;
116+ UpdateIntCounter ( tickData , k_RPCQueueProcessedCounterValue , ProfilerConstants . NumberOfRPCsInQueueSize ) ;
117+ UpdateIntCounter ( tickData , k_RPCsInQueueSizeCounterValue , ProfilerConstants . NumberOfRPCsOutQueueSize ) ;
118+ }
119+
120+ private static void UpdateIntCounter ( PerformanceTickData tickData , ProfilerCounterValue < int > counter , string fieldName )
121+ {
122+ if ( tickData . HasData ( fieldName ) )
123+ {
124+ counter . Value += tickData . GetData ( fieldName ) ;
125+ }
98126 }
99127#endif
100128 }
0 commit comments