From d24528b3bc2c277edae3507428bfeb23e5d81f57 Mon Sep 17 00:00:00 2001 From: Oren Hurvitz Date: Fri, 31 Jul 2015 15:34:43 +0300 Subject: Show Script Time in the statistics panel The value shown is the number of milliseconds per frame that were spent executing scripts in this region. --- OpenSim/Region/Framework/Scenes/Scene.cs | 26 +++++++ .../Region/Framework/Scenes/SimStatsReporter.cs | 80 ++++++++++++---------- 2 files changed, 68 insertions(+), 38 deletions(-) (limited to 'OpenSim/Region/Framework') diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 2a69ee1..24c95d1 100755 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -445,6 +445,11 @@ namespace OpenSim.Region.Framework.Scenes private int m_lastMaintenanceTick; /// + /// Total script execution time (in Stopwatch Ticks) since the last frame + /// + private long m_scriptExecutionTime = 0; + + /// /// Signals whether temporary objects are currently being cleaned up. Needed because this is launched /// asynchronously from the update loop. /// @@ -1926,6 +1931,7 @@ namespace OpenSim.Region.Framework.Scenes StatsReporter.addOtherMS(otherMS); StatsReporter.AddSpareMS(spareMS); StatsReporter.addScriptLines(m_sceneGraph.GetScriptLPS()); + StatsReporter.AddScriptMS((int) GetAndResetScriptExecutionTime()); // Send the correct time values to the stats reporter for the // frame times @@ -1953,6 +1959,26 @@ namespace OpenSim.Region.Framework.Scenes return spareMS >= 0; } + /// + /// Adds the execution time of one script to the total scripts execution time for this region. + /// + /// Elapsed Stopwatch ticks + public void AddScriptExecutionTime(long ticks) + { + Interlocked.Add(ref m_scriptExecutionTime, ticks); + } + + /// + /// Returns the total execution time of all the scripts in the region since the last frame + /// (in milliseconds), and clears the value in preparation for the next frame. + /// + /// Time in milliseconds + private long GetAndResetScriptExecutionTime() + { + long ticks = Interlocked.Exchange(ref m_scriptExecutionTime, 0); + return (ticks * 1000) / Stopwatch.Frequency; + } + public void AddGroupTarget(SceneObjectGroup grp) { lock (m_groupsWithTargets) diff --git a/OpenSim/Region/Framework/Scenes/SimStatsReporter.cs b/OpenSim/Region/Framework/Scenes/SimStatsReporter.cs index 8918c3b..4847696 100755 --- a/OpenSim/Region/Framework/Scenes/SimStatsReporter.cs +++ b/OpenSim/Region/Framework/Scenes/SimStatsReporter.cs @@ -63,7 +63,7 @@ namespace OpenSim.Region.Framework.Scenes // Determines the size of the array that is used to collect StatBlocks // for sending to the SimStats and SimExtraStatsCollector - private const int m_statisticArraySize = 27; + private const int m_statisticArraySize = 28; /// /// These are the IDs of stats sent in the StatsPacket to the viewer. @@ -204,9 +204,7 @@ namespace OpenSim.Region.Framework.Scenes private int m_physicsMS; private int m_imageMS; private int m_otherMS; - -//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_scriptMS; private int m_rootAgents; private int m_childAgents; @@ -428,7 +426,8 @@ namespace OpenSim.Region.Framework.Scenes // values to X-per-second values. uint thisFrame = m_scene.Frame; - float framesUpdated = (float)(thisFrame - m_lastUpdateFrame) * m_reportedFpsCorrectionFactor; + uint numFrames = thisFrame - m_lastUpdateFrame; + float framesUpdated = (float)numFrames * m_reportedFpsCorrectionFactor; m_lastUpdateFrame = thisFrame; // Avoid div-by-zero if somehow we've not updated any frames. @@ -501,23 +500,22 @@ namespace OpenSim.Region.Framework.Scenes // statistics to the statistics window sb[8].StatID = (uint)Stats.FrameMS; //sb[8].StatValue = m_frameMS / framesUpdated; - sb[8].StatValue = (float) totalSumFrameTime / m_numberFramesStored; + sb[8].StatValue = (float) totalSumFrameTime / m_numberFramesStored; sb[9].StatID = (uint)Stats.NetMS; //sb[9].StatValue = m_netMS / framesUpdated; - sb[9].StatValue = (float) networkSumFrameTime / m_numberFramesStored; + sb[9].StatValue = (float) networkSumFrameTime / m_numberFramesStored; sb[10].StatID = (uint)Stats.PhysicsMS; //sb[10].StatValue = m_physicsMS / framesUpdated; - sb[10].StatValue = (float) physicsSumFrameTime / m_numberFramesStored; + sb[10].StatValue = (float) physicsSumFrameTime / m_numberFramesStored; sb[11].StatID = (uint)Stats.ImageMS ; sb[11].StatValue = m_imageMS / framesUpdated; sb[12].StatID = (uint)Stats.OtherMS; //sb[12].StatValue = m_otherMS / framesUpdated; - sb[12].StatValue = (float) simulationSumFrameTime / - m_numberFramesStored; + sb[12].StatValue = (float) simulationSumFrameTime / m_numberFramesStored; sb[13].StatID = (uint)Stats.InPacketsPerSecond; sb[13].StatValue = (m_inPacketsPerSecond / m_statsUpdateFactor); @@ -567,6 +565,9 @@ namespace OpenSim.Region.Framework.Scenes sb[26].StatID = (uint)Stats.ThreadCount; sb[26].StatValue = m_inUseThreads; + sb[27].StatID = (uint)Stats.ScriptMS; + sb[27].StatValue = (numFrames <= 0) ? 0 : ((float)m_scriptMS / numFrames); + for (int i = 0; i < m_statisticArraySize; i++) { lastReportedSimStats[i] = sb[i].StatValue; @@ -632,10 +633,8 @@ namespace OpenSim.Region.Framework.Scenes m_physicsMS = 0; m_imageMS = 0; m_otherMS = 0; + m_scriptMS = 0; m_spareMS = 0; - -//Ckrinke This variable is not used, so comment to remove compiler warning until it is used. -//Ckrinke m_scriptMS = 0; } # region methods called from Scene @@ -746,31 +745,36 @@ namespace OpenSim.Region.Framework.Scenes m_otherMS += ms; } - public void addPhysicsFrame(int frames) - { - // Add the number of physics frames to the correct total physics - // frames - m_numberPhysicsFrames += frames; - } - - public void addFrameTimeMilliseconds(double total, double simulation, - double physics, double network) - { - // Save the frame times from the current frame into the appropriate - // arrays - m_totalFrameTimeMilliseconds[m_nextLocation] = total; - m_simulationFrameTimeMilliseconds[m_nextLocation] = simulation; - m_physicsFrameTimeMilliseconds[m_nextLocation] = physics; - m_networkFrameTimeMilliseconds[m_nextLocation] = network; - - // Update to the next location in the list - m_nextLocation++; - - // Since the list will begin to overwrite the oldest frame values - // first, the next location needs to loop back to the beginning of the - // list whenever it reaches the end - m_nextLocation = m_nextLocation % m_numberFramesStored; - } + public void AddScriptMS(int ms) + { + m_scriptMS += ms; + } + + public void addPhysicsFrame(int frames) + { + // Add the number of physics frames to the correct total physics + // frames + m_numberPhysicsFrames += frames; + } + + public void addFrameTimeMilliseconds(double total, double simulation, + double physics, double network) + { + // Save the frame times from the current frame into the appropriate + // arrays + m_totalFrameTimeMilliseconds[m_nextLocation] = total; + m_simulationFrameTimeMilliseconds[m_nextLocation] = simulation; + m_physicsFrameTimeMilliseconds[m_nextLocation] = physics; + m_networkFrameTimeMilliseconds[m_nextLocation] = network; + + // Update to the next location in the list + m_nextLocation++; + + // Since the list will begin to overwrite the oldest frame values + // first, the next location needs to loop back to the beginning of the + // list whenever it reaches the end + m_nextLocation = m_nextLocation % m_numberFramesStored; + } public void AddPendingDownloads(int count) { -- cgit v1.1