@@ -10,91 +10,119 @@ internal static class ProfilerCountersInfo
10
10
#if UNITY_2020_2_OR_NEWER && ENABLE_PROFILER
11
11
// Operations
12
12
private static readonly ProfilerCounterValue < int > k_ConnectionsCounterValue =
13
- new ProfilerCounterValue < int > ( ProfilerCategory . Network , ProfilerConstants . NumberOfConnections ,
13
+ new ProfilerCounterValue < int > ( ProfilerCategory . Network , ProfilerConstants . Connections ,
14
14
ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame ) ;
15
15
16
16
private static readonly ProfilerCounterValue < int > k_TickRateCounterValue =
17
17
new ProfilerCounterValue < int > ( ProfilerCategory . Network , ProfilerConstants . ReceiveTickRate ,
18
- ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame ) ;
18
+ ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame | ProfilerCounterOptions . ResetToZeroOnFlush ) ;
19
19
20
20
// Messages
21
21
private static readonly ProfilerCounterValue < int > k_NamedMessagesCounterValue =
22
22
new ProfilerCounterValue < int > ( ProfilerCategory . Network , ProfilerConstants . NumberOfNamedMessages ,
23
- ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame ) ;
23
+ ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame | ProfilerCounterOptions . ResetToZeroOnFlush ) ;
24
24
25
25
private static readonly ProfilerCounterValue < int > k_UnnamedMessagesCounterValue =
26
26
new ProfilerCounterValue < int > ( ProfilerCategory . Network , ProfilerConstants . NumberOfUnnamedMessages ,
27
- ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame ) ;
27
+ ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame | ProfilerCounterOptions . ResetToZeroOnFlush ) ;
28
28
29
29
private static readonly ProfilerCounterValue < int > k_BytesSentCounterValue =
30
30
new ProfilerCounterValue < int > ( ProfilerCategory . Network , ProfilerConstants . NumberBytesSent ,
31
- ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame ) ;
31
+ ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame | ProfilerCounterOptions . ResetToZeroOnFlush ) ;
32
32
33
33
private static readonly ProfilerCounterValue < int > k_BytesReceivedCounterValue =
34
34
new ProfilerCounterValue < int > ( ProfilerCategory . Network , ProfilerConstants . NumberBytesReceived ,
35
- ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame ) ;
35
+ ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame | ProfilerCounterOptions . ResetToZeroOnFlush ) ;
36
36
37
37
private static readonly ProfilerCounterValue < int > k_NetworkVarsCounterValue =
38
38
new ProfilerCounterValue < int > ( ProfilerCategory . Network , ProfilerConstants . NumberNetworkVarsReceived ,
39
- ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame ) ;
39
+ ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame | ProfilerCounterOptions . ResetToZeroOnFlush ) ;
40
40
41
41
// RPCs
42
42
private static readonly ProfilerCounterValue < int > k_RPCsSentCounterValue =
43
43
new ProfilerCounterValue < int > ( ProfilerCategory . Network , ProfilerConstants . NumberOfRPCsSent ,
44
- ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame ) ;
44
+ ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame | ProfilerCounterOptions . ResetToZeroOnFlush ) ;
45
45
46
46
private static readonly ProfilerCounterValue < int > k_RPCsReceivedCounterValue =
47
47
new ProfilerCounterValue < int > ( ProfilerCategory . Network , ProfilerConstants . NumberOfRPCsReceived ,
48
- ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame ) ;
48
+ ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame | ProfilerCounterOptions . ResetToZeroOnFlush ) ;
49
49
50
50
private static readonly ProfilerCounterValue < int > k_RPCBatchesSentCounterValue =
51
51
new ProfilerCounterValue < int > ( ProfilerCategory . Network , ProfilerConstants . NumberOfRPCBatchesSent ,
52
- ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame ) ;
52
+ ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame | ProfilerCounterOptions . ResetToZeroOnFlush ) ;
53
53
54
54
private static readonly ProfilerCounterValue < int > k_RPCBatchesReceivedCounterValue =
55
55
new ProfilerCounterValue < int > ( ProfilerCategory . Network , ProfilerConstants . NumberOfRPCBatchesReceived ,
56
- ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame ) ;
56
+ ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame | ProfilerCounterOptions . ResetToZeroOnFlush ) ;
57
57
58
58
private static readonly ProfilerCounterValue < int > k_RPCQueueProcessedCounterValue =
59
59
new ProfilerCounterValue < int > ( ProfilerCategory . Network , ProfilerConstants . NumberOfRPCQueueProcessed ,
60
- ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame ) ;
60
+ ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame | ProfilerCounterOptions . ResetToZeroOnFlush ) ;
61
61
62
62
private static readonly ProfilerCounterValue < int > k_RPCsInQueueSizeCounterValue =
63
63
new ProfilerCounterValue < int > ( ProfilerCategory . Network , ProfilerConstants . NumberOfRPCsInQueueSize ,
64
- ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame ) ;
64
+ ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame | ProfilerCounterOptions . ResetToZeroOnFlush ) ;
65
65
66
66
private static readonly ProfilerCounterValue < int > k_RPCsOutQueueSizeCounterValue =
67
67
new ProfilerCounterValue < int > ( ProfilerCategory . Network , ProfilerConstants . NumberOfRPCsOutQueueSize ,
68
- ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame ) ;
68
+ ProfilerMarkerDataUnit . Count , ProfilerCounterOptions . FlushOnEndOfFrame | ProfilerCounterOptions . ResetToZeroOnFlush ) ;
69
69
70
70
[ RuntimeInitializeOnLoadMethod ]
71
71
private static void RegisterMLAPIPerformanceEvent ( )
72
72
{
73
+ InitializeCounters ( ) ;
73
74
NetworkManager . OnPerformanceDataEvent += OnPerformanceTickData ;
74
75
}
75
76
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
+
76
97
private static void OnPerformanceTickData ( PerformanceTickData tickData )
77
98
{
78
99
// 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 ) ;
81
102
82
103
// 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 ) ;
88
109
89
110
// 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
+ }
98
126
}
99
127
#endif
100
128
}
0 commit comments