From 4338f4e1d7c841ba447eb2d7481daaa009182bc7 Mon Sep 17 00:00:00 2001
From: Teravus Ovares (Dan Olivares)
Date: Sun, 29 Nov 2009 05:06:25 -0500
Subject: * Patch from Misterblue to fix Environment.TickCount for statistics
purposes. Resolves the wrap-around of the 32 bit uint. * Teravus moved the
Environment methods to the Util class
---
OpenSim/Region/Framework/Scenes/ScenePresence.cs | 60 +++++++++++++++++-------
1 file changed, 42 insertions(+), 18 deletions(-)
(limited to 'OpenSim/Region/Framework/Scenes/ScenePresence.cs')
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index 5604e3d..bcad335 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -755,13 +755,37 @@ namespace OpenSim.Region.Framework.Scenes
///
public void SendPrimUpdates()
{
- m_perfMonMS = Environment.TickCount;
+ m_perfMonMS = EnvironmentTickCount();
m_sceneViewer.SendPrimUpdates();
- m_scene.StatsReporter.AddAgentTime(Environment.TickCount - m_perfMonMS);
+ m_scene.StatsReporter.AddAgentTime(EnvironmentTickCountSubtract(m_perfMonMS));
}
+ ///
+ /// Environment.TickCount is an int but it counts all 32 bits so it goes positive
+ /// and negative every 24.9 days. This trims down TickCount so it doesn't wrap
+ /// for the callers.
+ /// This trims it to a 12 day interval so don't let your frame time get too long.
+ ///
+ ///
+ const Int32 EnvironmentTickCountMask = 0x3fffffff;
+ private static Int32 EnvironmentTickCount() {
+ return Environment.TickCount & EnvironmentTickCountMask;
+ }
+
+ ///
+ /// Environment.TickCount is an int but it counts all 32 bits so it goes positive
+ /// and negative every 24.9 days. Subtracts the passed value (previously fetched by
+ /// 'EnvironmentTickCount()') and accounts for any wrapping.
+ ///
+ /// subtraction of passed prevValue from current Environment.TickCount
+ private static Int32 EnvironmentTickCountSubtract(Int32 prevValue) {
+ Int32 diff = EnvironmentTickCount() - prevValue;
+ return (diff >= 0) ? diff : (diff + EnvironmentTickCountMask + 1);
+ }
+
+
#region Status Methods
///
@@ -1148,7 +1172,7 @@ namespace OpenSim.Region.Framework.Scenes
// return;
//}
- m_perfMonMS = Environment.TickCount;
+ m_perfMonMS = EnvironmentTickCount();
++m_movementUpdateCount;
if (m_movementUpdateCount < 1)
@@ -1464,7 +1488,7 @@ namespace OpenSim.Region.Framework.Scenes
m_scene.EventManager.TriggerOnClientMovement(this);
- m_scene.StatsReporter.AddAgentTime(Environment.TickCount - m_perfMonMS);
+ m_scene.StatsReporter.AddAgentTime(EnvironmentTickCountSubtract(m_perfMonMS));
}
public void DoAutoPilot(uint not_used, Vector3 Pos, IClientAPI remote_client)
@@ -1924,7 +1948,7 @@ namespace OpenSim.Region.Framework.Scenes
return;
}
- m_perfMonMS = Environment.TickCount;
+ m_perfMonMS = EnvironmentTickCount();
Rotation = rotation;
Vector3 direc = vec * rotation;
@@ -1966,7 +1990,7 @@ namespace OpenSim.Region.Framework.Scenes
// TODO: Add the force instead of only setting it to support multiple forces per frame?
m_forceToApply = direc;
- m_scene.StatsReporter.AddAgentTime(Environment.TickCount - m_perfMonMS);
+ m_scene.StatsReporter.AddAgentTime(EnvironmentTickCountSubtract(m_perfMonMS));
}
#endregion
@@ -2032,7 +2056,7 @@ namespace OpenSim.Region.Framework.Scenes
// server.
if (remoteClient.IsActive)
{
- m_perfMonMS = Environment.TickCount;
+ m_perfMonMS = EnvironmentTickCount();
PhysicsActor actor = m_physicsActor;
Vector3 velocity = (actor != null) ? actor.Velocity : Vector3.Zero;
@@ -2045,7 +2069,7 @@ namespace OpenSim.Region.Framework.Scenes
remoteClient.SendAvatarTerseUpdate(new SendAvatarTerseData(m_rootRegionHandle, (ushort)(m_scene.TimeDilation * ushort.MaxValue), LocalId,
pos, velocity, Vector3.Zero, m_bodyRot, CollisionPlane, m_uuid, null, GetUpdatePriority(remoteClient)));
- m_scene.StatsReporter.AddAgentTime(Environment.TickCount - m_perfMonMS);
+ m_scene.StatsReporter.AddAgentTime(EnvironmentTickCountSubtract(m_perfMonMS));
m_scene.StatsReporter.AddAgentUpdates(1);
}
}
@@ -2055,11 +2079,11 @@ namespace OpenSim.Region.Framework.Scenes
///
public void SendTerseUpdateToAllClients()
{
- m_perfMonMS = Environment.TickCount;
+ m_perfMonMS = EnvironmentTickCount();
m_scene.ForEachClient(SendTerseUpdateToClient);
- m_scene.StatsReporter.AddAgentTime(Environment.TickCount - m_perfMonMS);
+ m_scene.StatsReporter.AddAgentTime(EnvironmentTickCountSubtract(m_perfMonMS));
}
public void SendCoarseLocations()
@@ -2079,7 +2103,7 @@ namespace OpenSim.Region.Framework.Scenes
public void SendCoarseLocationsDefault(UUID sceneId, ScenePresence p)
{
- m_perfMonMS = Environment.TickCount;
+ m_perfMonMS = EnvironmentTickCount();
List CoarseLocations = new List();
List AvatarUUIDs = new List();
@@ -2115,7 +2139,7 @@ namespace OpenSim.Region.Framework.Scenes
m_controllingClient.SendCoarseLocationUpdate(AvatarUUIDs, CoarseLocations);
- m_scene.StatsReporter.AddAgentTime(Environment.TickCount - m_perfMonMS);
+ m_scene.StatsReporter.AddAgentTime(EnvironmentTickCountSubtract(m_perfMonMS));
}
public void CoarseLocationChange()
@@ -2152,7 +2176,7 @@ namespace OpenSim.Region.Framework.Scenes
///
public void SendInitialFullUpdateToAllClients()
{
- m_perfMonMS = Environment.TickCount;
+ m_perfMonMS = EnvironmentTickCount();
ScenePresence[] avatars = m_scene.GetScenePresences();
@@ -2178,14 +2202,14 @@ namespace OpenSim.Region.Framework.Scenes
}
m_scene.StatsReporter.AddAgentUpdates(avatars.Length);
- m_scene.StatsReporter.AddAgentTime(Environment.TickCount - m_perfMonMS);
+ m_scene.StatsReporter.AddAgentTime(EnvironmentTickCountSubtract(m_perfMonMS));
//Animator.SendAnimPack();
}
public void SendFullUpdateToAllClients()
{
- m_perfMonMS = Environment.TickCount;
+ m_perfMonMS = EnvironmentTickCount();
// only send update from root agents to other clients; children are only "listening posts"
List avatars = m_scene.GetAvatars();
@@ -2195,7 +2219,7 @@ namespace OpenSim.Region.Framework.Scenes
}
m_scene.StatsReporter.AddAgentUpdates(avatars.Count);
- m_scene.StatsReporter.AddAgentTime(Environment.TickCount - m_perfMonMS);
+ m_scene.StatsReporter.AddAgentTime(EnvironmentTickCountSubtract(m_perfMonMS));
Animator.SendAnimPack();
}
@@ -2237,7 +2261,7 @@ namespace OpenSim.Region.Framework.Scenes
///
public void SendAppearanceToAllOtherAgents()
{
- m_perfMonMS = Environment.TickCount;
+ m_perfMonMS = EnvironmentTickCount();
m_scene.ForEachScenePresence(delegate(ScenePresence scenePresence)
{
@@ -2247,7 +2271,7 @@ namespace OpenSim.Region.Framework.Scenes
}
});
- m_scene.StatsReporter.AddAgentTime(Environment.TickCount - m_perfMonMS);
+ m_scene.StatsReporter.AddAgentTime(EnvironmentTickCountSubtract(m_perfMonMS));
}
///
--
cgit v1.1