-
Notifications
You must be signed in to change notification settings - Fork 459
fix: Report messages properly that are locally executed as 0 bytes #1162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
46a8a76
e20f7b4
fa83415
190d122
04da50a
e73c020
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -222,12 +222,18 @@ internal void __endSendClientRpc(NetworkSerializer serializer, uint rpcMethodId, | |
#if DEVELOPMENT_BUILD || UNITY_EDITOR | ||
if (NetworkManager.__rpc_name_table.TryGetValue(rpcMethodId, out var rpcMethodName)) | ||
{ | ||
NetworkManager.NetworkMetrics.TrackRpcSent( | ||
NetworkManager.ConnectedClients.Select(x => x.Key).ToArray(), | ||
NetworkObjectId, | ||
rpcMethodName, | ||
__getTypeName(), | ||
messageSize); | ||
foreach (var client in NetworkManager.ConnectedClients) | ||
{ | ||
var bytesReported = NetworkManager.LocalClientId == client.Key | ||
? 0 | ||
: messageSize; | ||
NetworkManager.NetworkMetrics.TrackRpcSent( | ||
client.Key, | ||
NetworkObjectId, | ||
rpcMethodName, | ||
__getTypeName(), | ||
bytesReported); | ||
} | ||
} | ||
#endif | ||
} | ||
|
@@ -582,13 +588,17 @@ private void NetworkVariableUpdate(ulong clientId, int behaviourIndex) | |
m_NetworkVariableIndexesToReset.Add(k); | ||
} | ||
|
||
var bytesReported = NetworkManager.LocalClientId == clientId | ||
? 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: a comment explaining why we return 0 here might be useful (like "not a failure but success with 0") — also applies to other 0 returning ternaries below. |
||
: bufferSizeCapture.Flush(); | ||
|
||
NetworkManager.NetworkMetrics.TrackNetworkVariableDeltaSent( | ||
clientId, | ||
NetworkObjectId, | ||
name, | ||
NetworkVariableFields[k].Name, | ||
__getTypeName(), | ||
bufferSizeCapture.Flush()); | ||
bytesReported); | ||
} | ||
} | ||
|
||
|
@@ -678,13 +688,17 @@ internal void HandleNetworkVariableDeltas(Stream stream, ulong clientId) | |
long readStartPos = stream.Position; | ||
|
||
NetworkVariableFields[i].ReadDelta(stream, NetworkManager.IsServer); | ||
|
||
var bytesReported = NetworkManager.LocalClientId == clientId | ||
? 0 | ||
: stream.Length; | ||
NetworkManager.NetworkMetrics.TrackNetworkVariableDeltaReceived( | ||
clientId, | ||
NetworkObjectId, | ||
name, | ||
NetworkVariableFields[i].Name, | ||
__getTypeName(), | ||
stream.Length); | ||
bytesReported); | ||
|
||
(stream as NetworkBuffer).SkipPadBits(); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1116,7 +1116,10 @@ private void OnServerLoadedScene(Scene scene) | |
SceneEventData.OnWrite(nonNullContext.NetworkWriter); | ||
|
||
var size = bufferSizeCapture.StopMeasureSegment(); | ||
m_NetworkManager.NetworkMetrics.TrackSceneEventSent(clientId, (uint)SceneEventData.SceneEventType, scene.name, size); | ||
var bytesReported = m_NetworkManager.LocalClientId == clientId | ||
? 0 | ||
: size; | ||
m_NetworkManager.NetworkMetrics.TrackSceneEventSent(clientId, (uint)SceneEventData.SceneEventType, scene.name, bytesReported); | ||
} | ||
else | ||
{ | ||
|
@@ -1230,8 +1233,11 @@ internal void SynchronizeNetworkObjects(ulong clientId) | |
ClientSynchEventData.OnWrite(nonNullContext.NetworkWriter); | ||
|
||
var size = bufferSizeCapture.StopMeasureSegment(); | ||
var bytesReported = m_NetworkManager.LocalClientId == clientId | ||
? 0 | ||
: size; | ||
Comment on lines
+1236
to
+1238
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Late feedback on this part, but I wonder if it makes sense to add an internal utility function to network manager? Something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean at that point it could be part of the BufferSizeCapture utility class There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe, I don't know if BufferSizeCapture should know anything about client ids though. this eval only work if you know networkManager.LocalClientId There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is one statement. I don't see too huge of a reason to refactor a single statement into a function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mainly proposed this because you're using the same pattern a bunch of times across the codebase, so it is a bit of a code smell. I agree that for such a small expression it's not a big deal There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I agree with Beck. I know it's just one statement, but anywhere these functions are used without this statement will be a bug that's inconsistent with the others, so I think there should be a function that can be called that takes care of this ternary as well |
||
m_NetworkManager.NetworkMetrics.TrackSceneEventSent( | ||
clientId, (uint)ClientSynchEventData.SceneEventType, "", size); | ||
clientId, (uint)ClientSynchEventData.SceneEventType, "", bytesReported); | ||
} | ||
|
||
// Notify the local server that the client has been sent the SceneEventData.SceneEventTypes.S2C_Event_Sync event | ||
|
@@ -1577,8 +1583,12 @@ internal void HandleSceneEvent(ulong clientId, Stream stream) | |
SceneEventData.OnRead(reader); | ||
NetworkReaderPool.PutBackInPool(reader); | ||
|
||
var bytesReported = m_NetworkManager.LocalClientId == clientId | ||
? 0 | ||
: stream.Length; | ||
|
||
m_NetworkManager.NetworkMetrics.TrackSceneEventReceived( | ||
clientId, (uint)SceneEventData.SceneEventType, ScenesInBuild[(int)SceneEventData.SceneIndex], stream.Length); | ||
clientId, (uint)SceneEventData.SceneEventType, ScenesInBuild[(int)SceneEventData.SceneIndex], bytesReported); | ||
|
||
if (SceneEventData.IsSceneEventClientSide()) | ||
{ | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pattern of computing
bytesReported
is repeated so often that personally I think it should be extracted out to other function(s) before merging. As is this is a little fragile, because any of theseTrack
functions called without the ternary will be result in bugs as their behavior will be inconsistent with the rest. I think this work could be done in theNetworkMetrics
Track functions themselves, so that at least all of this is taken care of in one file if it can't be done in a single function.