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.
0.8.2-post-fixes
Oren Hurvitz 2015-07-31 15:34:43 +03:00
parent 5679cd0100
commit d24528b3bc
3 changed files with 66 additions and 35 deletions

View File

@ -444,6 +444,11 @@ namespace OpenSim.Region.Framework.Scenes
/// </summary>
private int m_lastMaintenanceTick;
/// <summary>
/// Total script execution time (in Stopwatch Ticks) since the last frame
/// </summary>
private long m_scriptExecutionTime = 0;
/// <summary>
/// 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;
}
/// <summary>
/// Adds the execution time of one script to the total scripts execution time for this region.
/// </summary>
/// <param name="ticks">Elapsed Stopwatch ticks</param>
public void AddScriptExecutionTime(long ticks)
{
Interlocked.Add(ref m_scriptExecutionTime, ticks);
}
/// <summary>
/// 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.
/// </summary>
/// <returns>Time in milliseconds</returns>
private long GetAndResetScriptExecutionTime()
{
long ticks = Interlocked.Exchange(ref m_scriptExecutionTime, 0);
return (ticks * 1000) / Stopwatch.Frequency;
}
public void AddGroupTarget(SceneObjectGroup grp)
{
lock (m_groupsWithTargets)

View File

@ -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;
/// <summary>
/// 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.
@ -516,8 +515,7 @@ namespace OpenSim.Region.Framework.Scenes
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,6 +745,11 @@ namespace OpenSim.Region.Framework.Scenes
m_otherMS += ms;
}
public void AddScriptMS(int ms)
{
m_scriptMS += ms;
}
public void addPhysicsFrame(int frames)
{
// Add the number of physics frames to the correct total physics

View File

@ -764,6 +764,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
{
timer.Stop();
ExecutionTime.AddSample(timer);
Part.ParentGroup.Scene.AddScriptExecutionTime(timer.ElapsedTicks);
}
}
}