use GetTimeStampMS to increase heartbeat and stats timing resolution. some rearrange on stat code ( MOSES special ones still out )

avinationmerge
UbitUmarov 2015-09-04 12:05:31 +01:00
parent f0c865555b
commit 08f9c54554
2 changed files with 122 additions and 106 deletions

View File

@ -398,16 +398,16 @@ namespace OpenSim.Region.Framework.Scenes
private int m_update_coarse_locations = 50; private int m_update_coarse_locations = 50;
private int m_update_temp_cleaning = 180; private int m_update_temp_cleaning = 180;
private int agentMS; private float agentMS;
private int frameMS; private float frameMS;
private int physicsMS2; private float physicsMS2;
private int physicsMS; private float physicsMS;
private int otherMS; private float otherMS;
private int tempOnRezMS; private float tempOnRezMS;
private int eventMS; private float eventMS;
private int backupMS; private float backupMS;
private int terrainMS; private float terrainMS;
private int landMS; private float landMS;
// A temporary configuration flag to enable using FireAndForget to process // A temporary configuration flag to enable using FireAndForget to process
// collisions from the physics engine. There is a problem with collisions // collisions from the physics engine. There is a problem with collisions
@ -785,15 +785,15 @@ namespace OpenSim.Region.Framework.Scenes
get { return m_capsModule; } get { return m_capsModule; }
} }
public int MonitorFrameTime { get { return frameMS; } } public int MonitorFrameTime { get { return (int)frameMS; } }
public int MonitorPhysicsUpdateTime { get { return physicsMS; } } public int MonitorPhysicsUpdateTime { get { return (int)physicsMS; } }
public int MonitorPhysicsSyncTime { get { return physicsMS2; } } public int MonitorPhysicsSyncTime { get { return (int)physicsMS2; } }
public int MonitorOtherTime { get { return otherMS; } } public int MonitorOtherTime { get { return (int)otherMS; } }
public int MonitorTempOnRezTime { get { return tempOnRezMS; } } public int MonitorTempOnRezTime { get { return (int)tempOnRezMS; } }
public int MonitorEventTime { get { return eventMS; } } // This may need to be divided into each event? public int MonitorEventTime { get { return (int)eventMS; } } // This may need to be divided into each event?
public int MonitorBackupTime { get { return backupMS; } } public int MonitorBackupTime { get { return (int)backupMS; } }
public int MonitorTerrainTime { get { return terrainMS; } } public int MonitorTerrainTime { get { return (int)terrainMS; } }
public int MonitorLandTime { get { return landMS; } } public int MonitorLandTime { get { return (int)landMS; } }
public int MonitorLastFrameTick { get { return m_lastFrameTick; } } public int MonitorLastFrameTick { get { return m_lastFrameTick; } }
public UpdatePrioritizationSchemes UpdatePrioritizationScheme { get; set; } public UpdatePrioritizationSchemes UpdatePrioritizationScheme { get; set; }
@ -1714,20 +1714,21 @@ namespace OpenSim.Region.Framework.Scenes
float physicsFPS = 0f; float physicsFPS = 0f;
int tmpMS;
int previousFrameTick; int previousFrameTick;
int maintc;
int sleepMS; double tmpMS;
int framestart; double tmpMS2;
double framestart;
float sleepMS;
while (!m_shuttingDown && ((endFrame == null && Active) || Frame < endFrame)) while (!m_shuttingDown && ((endFrame == null && Active) || Frame < endFrame))
{ {
framestart = Util.EnvironmentTickCount(); framestart = Util.GetTimeStampMS();
++Frame; ++Frame;
// m_log.DebugFormat("[SCENE]: Processing frame {0} in {1}", Frame, RegionInfo.RegionName); // m_log.DebugFormat("[SCENE]: Processing frame {0} in {1}", Frame, RegionInfo.RegionName);
agentMS = tempOnRezMS = eventMS = backupMS = terrainMS = landMS = 0; agentMS = tempOnRezMS = eventMS = backupMS = terrainMS = landMS = 0f;
try try
{ {
@ -1735,7 +1736,8 @@ namespace OpenSim.Region.Framework.Scenes
// Apply taints in terrain module to terrain in physics scene // Apply taints in terrain module to terrain in physics scene
tmpMS = Util.EnvironmentTickCount(); tmpMS = Util.GetTimeStampMS();
if (Frame % 4 == 0) if (Frame % 4 == 0)
{ {
CheckTerrainUpdates(); CheckTerrainUpdates();
@ -1746,26 +1748,29 @@ namespace OpenSim.Region.Framework.Scenes
UpdateTerrain(); UpdateTerrain();
} }
terrainMS = Util.EnvironmentTickCountSubtract(tmpMS); tmpMS2 = Util.GetTimeStampMS();
tmpMS = Util.EnvironmentTickCount(); terrainMS = (float)(tmpMS2 - tmpMS);
tmpMS = tmpMS2;
if (PhysicsEnabled && Frame % m_update_physics == 0) if (PhysicsEnabled && Frame % m_update_physics == 0)
m_sceneGraph.UpdatePreparePhysics(); m_sceneGraph.UpdatePreparePhysics();
physicsMS2 = Util.EnvironmentTickCountSubtract(tmpMS); tmpMS2 = Util.GetTimeStampMS();
physicsMS2 = (float)(tmpMS2 - tmpMS);
tmpMS = tmpMS2;
// Apply any pending avatar force input to the avatar's velocity // Apply any pending avatar force input to the avatar's velocity
tmpMS = Util.EnvironmentTickCount();
if (Frame % m_update_entitymovement == 0) if (Frame % m_update_entitymovement == 0)
m_sceneGraph.UpdateScenePresenceMovement(); m_sceneGraph.UpdateScenePresenceMovement();
// Get the simulation frame time that the avatar force input // Get the simulation frame time that the avatar force input
// took // took
agentMS = Util.EnvironmentTickCountSubtract(tmpMS); tmpMS2 = Util.GetTimeStampMS();
agentMS = (float)(tmpMS2 - tmpMS);
tmpMS = tmpMS2;
// Perform the main physics update. This will do the actual work of moving objects and avatars according to their // Perform the main physics update. This will do the actual work of moving objects and avatars according to their
// velocity // velocity
tmpMS = Util.EnvironmentTickCount();
if (Frame % m_update_physics == 0) if (Frame % m_update_physics == 0)
{ {
if (PhysicsEnabled) if (PhysicsEnabled)
@ -1774,12 +1779,10 @@ namespace OpenSim.Region.Framework.Scenes
if (SynchronizeScene != null) if (SynchronizeScene != null)
SynchronizeScene(this); SynchronizeScene(this);
} }
// Add the main physics update time to the prepare physics time tmpMS2 = Util.GetTimeStampMS();
physicsMS = Util.EnvironmentTickCountSubtract(tmpMS); physicsMS = (float)(tmpMS2 - tmpMS);
tmpMS = tmpMS2;
// Start the stopwatch for the remainder of the simulation
tmpMS = Util.EnvironmentTickCount();
// Check if any objects have reached their targets // Check if any objects have reached their targets
CheckAtTargets(); CheckAtTargets();
@ -1794,29 +1797,37 @@ namespace OpenSim.Region.Framework.Scenes
if (Frame % m_update_presences == 0) if (Frame % m_update_presences == 0)
m_sceneGraph.UpdatePresences(); m_sceneGraph.UpdatePresences();
agentMS += Util.EnvironmentTickCountSubtract(tmpMS); tmpMS2 = Util.GetTimeStampMS();
agentMS += (float)(tmpMS2 - tmpMS);
tmpMS = tmpMS2;
// Delete temp-on-rez stuff // Delete temp-on-rez stuff
if (Frame % m_update_temp_cleaning == 0 && !m_cleaningTemps) if (Frame % m_update_temp_cleaning == 0 && !m_cleaningTemps)
{ {
tmpMS = Util.EnvironmentTickCount();
m_cleaningTemps = true; m_cleaningTemps = true;
Util.FireAndForget(delegate { CleanTempObjects(); m_cleaningTemps = false; }); Util.FireAndForget(delegate { CleanTempObjects(); m_cleaningTemps = false; });
tempOnRezMS = Util.EnvironmentTickCountSubtract(tmpMS); tmpMS2 = Util.GetTimeStampMS();
tempOnRezMS = (float)(tmpMS2 - tmpMS); // bad.. counts the FireAndForget, not CleanTempObjects
tmpMS = tmpMS2;
} }
if (Frame % m_update_events == 0) if (Frame % m_update_events == 0)
{ {
tmpMS = Util.EnvironmentTickCount();
UpdateEvents(); UpdateEvents();
eventMS = Util.EnvironmentTickCountSubtract(tmpMS);
tmpMS2 = Util.GetTimeStampMS();
eventMS = (float)(tmpMS2 - tmpMS);
tmpMS = tmpMS2;
} }
if (PeriodicBackup && Frame % m_update_backup == 0) if (PeriodicBackup && Frame % m_update_backup == 0)
{ {
tmpMS = Util.EnvironmentTickCount();
UpdateStorageBackup(); UpdateStorageBackup();
backupMS = Util.EnvironmentTickCountSubtract(tmpMS);
tmpMS2 = Util.GetTimeStampMS();
backupMS = (float)(tmpMS2 - tmpMS);
tmpMS = tmpMS2;
} }
//if (Frame % m_update_land == 0) //if (Frame % m_update_land == 0)
@ -1887,20 +1898,26 @@ namespace OpenSim.Region.Framework.Scenes
StatsReporter.addOtherMS(otherMS); StatsReporter.addOtherMS(otherMS);
StatsReporter.addScriptLines(m_sceneGraph.GetScriptLPS()); StatsReporter.addScriptLines(m_sceneGraph.GetScriptLPS());
tmpMS = Util.GetTimeStampMS();
previousFrameTick = m_lastFrameTick; previousFrameTick = m_lastFrameTick;
m_lastFrameTick = Util.EnvironmentTickCount(); m_lastFrameTick = (int)(tmpMS + 0.5);
tmpMS = Util.EnvironmentTickCountSubtract(m_lastFrameTick, framestart);
tmpMS = (int)(MinFrameTime * 1000) - tmpMS; // estimate sleep time
tmpMS2 = tmpMS - framestart;
tmpMS2 = (double)MinFrameTime * 1000.0D - tmpMS2;
m_firstHeartbeat = false; m_firstHeartbeat = false;
sleepMS = Util.EnvironmentTickCount(); // sleep if we can
if (tmpMS2 > 0)
Thread.Sleep((int)(tmpMS2 +0.5));
if (tmpMS > 0) tmpMS2 = Util.GetTimeStampMS();
Thread.Sleep(tmpMS);
sleepMS = Util.EnvironmentTickCountSubtract(sleepMS); sleepMS = (float)(tmpMS2 - tmpMS);
frameMS = Util.EnvironmentTickCountSubtract(framestart); frameMS = (float)(tmpMS2 - framestart);
StatsReporter.addSleepMS(sleepMS); StatsReporter.addSleepMS(sleepMS);
StatsReporter.addFrameMS(frameMS); StatsReporter.addFrameMS(frameMS);

View File

@ -90,7 +90,7 @@ namespace OpenSim.Region.Framework.Scenes
Agents = 13, Agents = 13,
ChildAgents = 14, ChildAgents = 14,
ActiveScripts = 15, ActiveScripts = 15,
ScriptLinesPerSecond = 16, LSLScriptLinesPerSecond = 16, // viewers don't like this
InPacketsPerSecond = 17, InPacketsPerSecond = 17,
OutPacketsPerSecond = 18, OutPacketsPerSecond = 18,
PendingDownloads = 19, PendingDownloads = 19,
@ -109,11 +109,18 @@ namespace OpenSim.Region.Framework.Scenes
SimSpareMs = 32, SimSpareMs = 32,
SimSleepMs = 33, SimSleepMs = 33,
SimIoPumpTime = 34, SimIoPumpTime = 34,
FrameDilation = 35, SimPCTSscriptsRun = 35,
UsersLoggingIn = 36, SimRegionIdle = 36, // dataserver only
TotalGeoPrim = 37, SimRegionIdlePossible = 37, // dataserver only
TotalMesh = 38, SimAIStepTimeMS = 38,
ThreadCount = 39 SimSkippedSillouet_PS = 39,
SimSkippedCharsPerC = 40,
MOSESFrameDilation = 100,
MOSESUsersLoggingIn = 101,
MOSESTotalGeoPrim = 102,
MOSESTotalMesh = 103,
MOSESThreadCount = 104
} }
/// <summary> /// <summary>
@ -170,7 +177,7 @@ namespace OpenSim.Region.Framework.Scenes
/// <summary> /// <summary>
/// Our nominal fps target, as expected in fps stats when a sim is running normally. /// Our nominal fps target, as expected in fps stats when a sim is running normally.
/// </summary> /// </summary>
private float m_nominalReportedFps = 55; private float m_nominalReportedFps = 11;
/// <summary> /// <summary>
/// Parameter to adjust reported scene fps /// Parameter to adjust reported scene fps
@ -197,17 +204,14 @@ namespace OpenSim.Region.Framework.Scenes
/// </summary> /// </summary>
private int m_objectUpdates; private int m_objectUpdates;
private int m_frameMS; private float m_frameMS;
private int m_netMS; private float m_netMS;
private int m_agentMS; private float m_agentMS;
private int m_physicsMS; private float m_physicsMS;
private int m_imageMS; private float m_imageMS;
private int m_otherMS; private float m_otherMS;
private int m_sleeptimeMS; private float m_sleeptimeMS;
//Ckrinke: (3-21-08) Comment out to remove a compiler warning. Bring back into play when needed.
//Ckrinke private int m_scriptMS = 0;
private int m_rootAgents; private int m_rootAgents;
private int m_childAgents; private int m_childAgents;
@ -221,7 +225,7 @@ namespace OpenSim.Region.Framework.Scenes
private int m_pendingDownloads; private int m_pendingDownloads;
private int m_pendingUploads = 0; // FIXME: Not currently filled in private int m_pendingUploads = 0; // FIXME: Not currently filled in
private int m_activeScripts; private int m_activeScripts;
private int m_scriptLinesPerSecond; // private int m_scriptLinesPerSecond;
private int m_objectCapacity = 45000; private int m_objectCapacity = 45000;
@ -264,8 +268,10 @@ namespace OpenSim.Region.Framework.Scenes
public SimStatsReporter(Scene scene) public SimStatsReporter(Scene scene)
{ {
m_scene = scene; m_scene = scene;
m_reportedFpsCorrectionFactor = scene.MinFrameTime * m_nominalReportedFps; // m_reportedFpsCorrectionFactor = 5.0f; // needs to come from config
m_statsUpdateFactor = (float)(m_statsUpdatesEveryMS / 1000); m_reportedFpsCorrectionFactor = 1.0f; // needs to come from config
m_nominalReportedFps *= m_reportedFpsCorrectionFactor;
m_statsUpdateFactor = (float)(m_statsUpdatesEveryMS / 1000.0f);
ReportingRegion = scene.RegionInfo; ReportingRegion = scene.RegionInfo;
m_objectCapacity = scene.RegionInfo.ObjectCapacity; m_objectCapacity = scene.RegionInfo.ObjectCapacity;
@ -310,7 +316,7 @@ namespace OpenSim.Region.Framework.Scenes
public void SetUpdateMS(int ms) public void SetUpdateMS(int ms)
{ {
m_statsUpdatesEveryMS = ms; m_statsUpdatesEveryMS = ms;
m_statsUpdateFactor = (float)(m_statsUpdatesEveryMS / 1000); m_statsUpdateFactor = (float)(m_statsUpdatesEveryMS / 1000.0f);
m_report.Interval = m_statsUpdatesEveryMS; m_report.Interval = m_statsUpdatesEveryMS;
} }
@ -333,8 +339,8 @@ namespace OpenSim.Region.Framework.Scenes
if (!m_scene.Active) if (!m_scene.Active)
return; return;
SimStatsPacket.StatBlock[] sb = new SimStatsPacket.StatBlock[23]; SimStatsPacket.StatBlock[] sb = new SimStatsPacket.StatBlock[23];
SimStatsPacket.RegionBlock rb = new SimStatsPacket.RegionBlock(); SimStatsPacket.RegionBlock rb = new SimStatsPacket.RegionBlock();
// Know what's not thread safe in Mono... modifying timers. // Know what's not thread safe in Mono... modifying timers.
// m_log.Debug("Firing Stats Heart Beat"); // m_log.Debug("Firing Stats Heart Beat");
@ -354,21 +360,14 @@ namespace OpenSim.Region.Framework.Scenes
} }
#region various statistic googly moogly #region various statistic googly moogly
int reportedFPS = (int)(m_fps * m_reportedFpsCorrectionFactor);
// ORIGINAL code commented out until we have time to add our own
// statistics to the statistics window, this will be done as a
// new section given the title of our current project
// We're going to lie about the FPS because we've been lying since 2008. The actual FPS is currently
// locked at a maximum of 11. Maybe at some point this can change so that we're not lying.
//int reportedFPS = (int)(m_fps * m_reportedFpsCorrectionFactor);
int reportedFPS = m_fps;
// save the reported value so there is something available for llGetRegionFPS // save the reported value so there is something available for llGetRegionFPS
lastReportedSimFPS = reportedFPS / m_statsUpdateFactor; lastReportedSimFPS = reportedFPS / m_statsUpdateFactor;
// ORIGINAL code commented out until we have time to add our own // ORIGINAL code commented out until we have time to add our own
// statistics to the statistics window // statistics to the statistics window
float physfps = ((m_pfps / 1000)); float physfps = ((m_pfps / 1000.0f));
//if (physfps > 600) //if (physfps > 600)
//physfps = physfps - (physfps - 600); //physfps = physfps - (physfps - 600);
@ -377,7 +376,7 @@ namespace OpenSim.Region.Framework.Scenes
physfps = 0; physfps = 0;
#endregion #endregion
float factor = 1 / m_statsUpdateFactor; float factor = 1.0f / m_statsUpdateFactor;
if (reportedFPS <= 0) if (reportedFPS <= 0)
reportedFPS = 1; reportedFPS = 1;
@ -386,7 +385,7 @@ namespace OpenSim.Region.Framework.Scenes
float TotalFrameTime = m_frameMS * perframe; float TotalFrameTime = m_frameMS * perframe;
float targetframetime = 1100.0f / (float)m_nominalReportedFps; float targetframetime = 1000.0f / (float)m_nominalReportedFps;
float sparetime; float sparetime;
float sleeptime; float sleeptime;
@ -431,10 +430,9 @@ namespace OpenSim.Region.Framework.Scenes
{ {
sb[i] = new SimStatsPacket.StatBlock(); sb[i] = new SimStatsPacket.StatBlock();
} }
sb[0].StatID = (uint) Stats.TimeDilation; sb[0].StatID = (uint) Stats.TimeDilation;
sb[0].StatValue = (Single.IsNaN(m_timeDilation)) ? 0.1f : m_timeDilation ; //((((m_timeDilation + (0.10f * statsUpdateFactor)) /10) / statsUpdateFactor)); sb[0].StatValue = (Single.IsNaN(m_timeDilation)) ? 0.1f : m_timeDilation ;
sb[1].StatID = (uint) Stats.SimFPS; sb[1].StatID = (uint) Stats.SimFPS;
sb[1].StatValue = reportedFPS / m_statsUpdateFactor; sb[1].StatValue = reportedFPS / m_statsUpdateFactor;
@ -493,14 +491,15 @@ namespace OpenSim.Region.Framework.Scenes
sb[19].StatID = (uint)Stats.ActiveScripts; sb[19].StatID = (uint)Stats.ActiveScripts;
sb[19].StatValue = m_activeScripts; sb[19].StatValue = m_activeScripts;
sb[20].StatID = (uint)Stats.ScriptLinesPerSecond; sb[20].StatID = (uint)Stats.SimSpareMs;
sb[20].StatValue = m_scriptLinesPerSecond / m_statsUpdateFactor; sb[20].StatValue = sparetime;
sb[21].StatID = (uint)Stats.SimSpareMs; sb[21].StatID = (uint)Stats.SimSleepMs;
sb[21].StatValue = sparetime; sb[21].StatValue = sleeptime;
sb[22].StatID = (uint)Stats.SimSleepMs; // this should came from phys engine
sb[22].StatValue = sleeptime; sb[22].StatID = (uint)Stats.SimPhysicsStepMs;
sb[22].StatValue = 20;
for (int i = 0; i < 23; i++) for (int i = 0; i < 23; i++)
{ {
@ -563,7 +562,7 @@ namespace OpenSim.Region.Framework.Scenes
//m_inPacketsPerSecond = 0; //m_inPacketsPerSecond = 0;
//m_outPacketsPerSecond = 0; //m_outPacketsPerSecond = 0;
m_unAckedBytes = 0; m_unAckedBytes = 0;
m_scriptLinesPerSecond = 0; // m_scriptLinesPerSecond = 0;
m_frameMS = 0; m_frameMS = 0;
m_agentMS = 0; m_agentMS = 0;
@ -571,7 +570,6 @@ namespace OpenSim.Region.Framework.Scenes
m_physicsMS = 0; m_physicsMS = 0;
m_imageMS = 0; m_imageMS = 0;
m_otherMS = 0; m_otherMS = 0;
// m_spareMS = 0;
m_sleeptimeMS = 0; m_sleeptimeMS = 0;
//Ckrinke This variable is not used, so comment to remove compiler warning until it is used. //Ckrinke This variable is not used, so comment to remove compiler warning until it is used.
@ -646,7 +644,7 @@ namespace OpenSim.Region.Framework.Scenes
if (m_unAckedBytes < 0) m_unAckedBytes = 0; if (m_unAckedBytes < 0) m_unAckedBytes = 0;
} }
public void addFrameMS(int ms) public void addFrameMS(float ms)
{ {
m_frameMS += ms; m_frameMS += ms;
@ -656,32 +654,32 @@ namespace OpenSim.Region.Framework.Scenes
SlowFramesStat.Value++; SlowFramesStat.Value++;
} }
public void addNetMS(int ms) public void addNetMS(float ms)
{ {
m_netMS += ms; m_netMS += ms;
} }
public void addAgentMS(int ms) public void addAgentMS(float ms)
{ {
m_agentMS += ms; m_agentMS += ms;
} }
public void addPhysicsMS(int ms) public void addPhysicsMS(float ms)
{ {
m_physicsMS += ms; m_physicsMS += ms;
} }
public void addImageMS(int ms) public void addImageMS(float ms)
{ {
m_imageMS += ms; m_imageMS += ms;
} }
public void addOtherMS(int ms) public void addOtherMS(float ms)
{ {
m_otherMS += ms; m_otherMS += ms;
} }
public void addSleepMS(int ms) public void addSleepMS(float ms)
{ {
m_sleeptimeMS += ms; m_sleeptimeMS += ms;
} }
@ -698,7 +696,8 @@ namespace OpenSim.Region.Framework.Scenes
public void addScriptLines(int count) public void addScriptLines(int count)
{ {
m_scriptLinesPerSecond += count; // we need events not lines
// m_scriptLinesPerSecond += count;
} }
public void AddPacketsStats(int inPackets, int outPackets, int unAckedBytes) public void AddPacketsStats(int inPackets, int outPackets, int unAckedBytes)