public bool CmdHandlerQueue() { if (m_ScriptEngine.Worlds.Count == 0) { CmdHandlerQueueIsRunning = false; return(false); } CmdHandlerQueueIsRunning = true; IMonitorModule module = m_ScriptEngine.Worlds[0].RequestModuleInterface <IMonitorModule>(); int StartTime = Util.EnvironmentTickCount(); if (!Started) //Break early { return(true); } if (m_ScriptEngine.ConsoleDisabled || m_ScriptEngine.Disabled) { return(true); } //Check timers, etc bool didAnything = false; try { didAnything = m_ScriptEngine.DoOneScriptPluginPass(); } catch (Exception ex) { m_log.WarnFormat("[{0}]: Error in CmdHandlerPass, {1}", m_ScriptEngine.ScriptEngineName, ex); } Thread.Sleep(10); // don't burn cpu if (module != null) { foreach (Scene scene in m_ScriptEngine.Worlds) { ITimeMonitor scriptMonitor = (ITimeMonitor)module.GetMonitor(scene.RegionInfo.RegionID.ToString(), "Script Frame Time"); scriptMonitor.AddTime(Util.EnvironmentTickCountSubtract(StartTime)); } } if (didAnything) { CmdHandlerQueueIsRunning = true; threadpool.QueueEvent(CmdHandlerQueue, 2); } else { CmdHandlerQueueIsRunning = false; } return(false); }
/// <summary> /// Reset the values of the stats that require resetting (ones that use += and not =) /// </summary> public void ResetValues() { ITotalFrameTimeMonitor totalFrameMonitor = (ITotalFrameTimeMonitor)GetMonitor("Total Frame Time"); totalFrameMonitor.ResetStats(); SimFrameMonitor simMonitor = (SimFrameMonitor)GetMonitor("SimFrameStats"); simMonitor.ResetStats(); PhysicsFrameMonitor physMonitor = (PhysicsFrameMonitor)GetMonitor("Total Physics Frame Time"); physMonitor.ResetStats(); AgentUpdateMonitor agentUpdateMonitor = (AgentUpdateMonitor)GetMonitor("Agent Update Count"); agentUpdateMonitor.ResetStats(); ObjectUpdateMonitor objectUpdateMonitor = (ObjectUpdateMonitor)GetMonitor("PrimUpdates"); objectUpdateMonitor.ResetStats(); ImageFrameTimeMonitor imagesMonitor = (ImageFrameTimeMonitor)GetMonitor("Images Frame Time"); imagesMonitor.ResetStats(); ITimeMonitor physicsUpdateTime = (ITimeMonitor)GetMonitor("Physics Update Frame Time"); physicsUpdateTime.ResetStats(); ITimeMonitor physicsSyncTime = (ITimeMonitor)GetMonitor("Physics Sync Frame Time"); physicsSyncTime.ResetStats(); ITimeMonitor OtherFrameMonitor = (ITimeMonitor)GetMonitor("Other Frame Time"); OtherFrameMonitor.ResetStats(); ITimeMonitor SleepFrameMonitor = (ITimeMonitor)GetMonitor("Sleep Frame Time"); SleepFrameMonitor.ResetStats(); ScriptFrameTimeMonitor ScriptFrameTime = (ScriptFrameTimeMonitor)GetMonitor("Script Frame Time"); ScriptFrameTime.ResetStats(); }
private bool Update() { ISimFrameMonitor simFrameMonitor = (ISimFrameMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.SimFrameStats); ITotalFrameTimeMonitor totalFrameMonitor = (ITotalFrameTimeMonitor)RequestModuleInterface <IMonitorModule> ().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.TotalFrameTime); ISetMonitor lastFrameMonitor = (ISetMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.LastCompletedFrameAt); ITimeMonitor otherFrameMonitor = (ITimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.OtherFrameTime); ITimeMonitor sleepFrameMonitor = (ITimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.SleepFrameTime); while (true) { if (!ShouldRunHeartbeat) //If we arn't supposed to be running, kill ourselves { return(false); } int maintc = Util.EnvironmentTickCount(); int BeginningFrameTime = maintc; // Increment the frame counter ++m_frame; try { int OtherFrameTime = Util.EnvironmentTickCount(); if (m_frame % m_update_coarse_locations == 0) { List <Vector3> coarseLocations; List <UUID> avatarUUIDs; if (SceneGraph.GetCoarseLocations(out coarseLocations, out avatarUUIDs, 60)) { // Send coarse locations to clients foreach (IScenePresence presence in GetScenePresences()) { presence.SendCoarseLocations(coarseLocations, avatarUUIDs); } } } if (m_frame % m_update_entities == 0) { m_sceneGraph.UpdateEntities(); } BlankHandler[] events; lock (m_events) { events = new BlankHandler[m_events.Count]; m_events.CopyTo(events); m_events.Clear(); } foreach (BlankHandler h in events) { try { h(); } catch { } } if (m_frame % m_update_events == 0) { try { m_sceneGraph.PhysicsScene.UpdatesLoop(); } catch { } } if (m_frame % m_update_events == 0) { m_eventManager.TriggerOnFrame(); } //Now fix the sim stats int MonitorOtherFrameTime = Util.EnvironmentTickCountSubtract(OtherFrameTime); int MonitorLastCompletedFrame = Util.EnvironmentTickCount(); if (simFrameMonitor != null) { simFrameMonitor.AddFPS(1); lastFrameMonitor.SetValue(MonitorLastCompletedFrame); otherFrameMonitor.AddTime(MonitorOtherFrameTime); } else { simFrameMonitor = (ISimFrameMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.SimFrameStats); totalFrameMonitor = (ITotalFrameTimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.TotalFrameTime); lastFrameMonitor = (ISetMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.LastCompletedFrameAt); otherFrameMonitor = (ITimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.OtherFrameTime); sleepFrameMonitor = (ITimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.SleepFrameTime); } } catch (Exception e) { MainConsole.Instance.Error("[REGION]: Failed with exception " + e + " in region: " + RegionInfo.RegionName); return(true); } //Get the time between beginning and end maintc = Util.EnvironmentTickCountSubtract(BeginningFrameTime); //Beginning + (time between beginning and end) = end int MonitorEndFrameTime = BeginningFrameTime + maintc; int getSleepTime = GetHeartbeatSleepTime(maintc, false); if (getSleepTime > 0) { Thread.Sleep(getSleepTime); } if (sleepFrameMonitor != null) { sleepFrameMonitor.AddTime(maintc); totalFrameMonitor.AddFrameTime(MonitorEndFrameTime); } } }
private bool PhysUpdate() { IPhysicsFrameMonitor physicsFrameMonitor = (IPhysicsFrameMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.TotalPhysicsFrameTime); ITimeMonitor physicsFrameTimeMonitor = (ITimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.PhysicsUpdateFrameTime); IPhysicsMonitor monitor2 = RequestModuleInterface <IPhysicsMonitor>(); while (true) { if (!ShouldRunHeartbeat) //If we arn't supposed to be running, kill ourselves { return(false); } int maintc = Util.EnvironmentTickCount(); int BeginningFrameTime = maintc; if (PhysicsReturns.Count != 0) { lock (PhysicsReturns) { ILLClientInventory inventoryModule = RequestModuleInterface <ILLClientInventory>(); if (inventoryModule != null) { inventoryModule.ReturnObjects(PhysicsReturns.ToArray(), UUID.Zero); } PhysicsReturns.Clear(); } } int PhysicsUpdateTime = Util.EnvironmentTickCount(); if (m_frame % m_update_physics == 0) { TimeSpan SinceLastFrame = DateTime.UtcNow - m_lastphysupdate; if (!RegionInfo.RegionSettings.DisablePhysics && ApproxEquals((float)SinceLastFrame.TotalMilliseconds, m_updatetimespan, 3)) { m_sceneGraph.UpdatePreparePhysics(); m_sceneGraph.UpdatePhysics(SinceLastFrame.TotalSeconds); m_lastphysupdate = DateTime.UtcNow; int MonitorPhysicsUpdateTime = Util.EnvironmentTickCountSubtract(PhysicsUpdateTime); if (MonitorPhysicsUpdateTime != 0) { if (physicsFrameTimeMonitor != null) { physicsFrameTimeMonitor.AddTime(MonitorPhysicsUpdateTime); } if (monitor2 != null) { monitor2.AddPhysicsStats(RegionInfo.RegionID, PhysicsScene); } if (m_lastPhysicsChange != RegionInfo.RegionSettings.DisablePhysics) { StartPhysicsScene(); } } if (physicsFrameMonitor != null) { physicsFrameMonitor.AddFPS(1); } } else if (m_lastPhysicsChange != RegionInfo.RegionSettings.DisablePhysics) { StopPhysicsScene(); } m_lastPhysicsChange = RegionInfo.RegionSettings.DisablePhysics; } //Get the time between beginning and end maintc = Util.EnvironmentTickCountSubtract(BeginningFrameTime); if (maintc == 0) { continue; } int getSleepTime = GetHeartbeatSleepTime(maintc, true); if (getSleepTime > 0) { Thread.Sleep(getSleepTime); } } }
/// <summary> /// This loop deals with starting and stoping scripts /// </summary> /// <returns></returns> public bool ScriptChangeQueue() { IMonitorModule module = m_ScriptEngine.Worlds[0].RequestModuleInterface <IMonitorModule>(); int StartTime = Util.EnvironmentTickCount(); if (!Started) //Break early { return(true); } if (m_ScriptEngine.ConsoleDisabled || m_ScriptEngine.Disabled) { return(true); } ScriptChangeIsRunning = true; object oitems; if (LUQueue.GetNext(out oitems)) { LUStruct[] items = oitems as LUStruct[]; List <LUStruct> NeedsFired = new List <LUStruct>(); foreach (LUStruct item in items) { if (item.Action == LUType.Unload) { //Close item.ID.CloseAndDispose(true); } else if (item.Action == LUType.Load) { try { //Start if (item.ID.Start(false)) { NeedsFired.Add(item); } } catch (Exception ex) { m_log.Error("[" + m_ScriptEngine.ScriptEngineName + "]: LEAKED COMPILE ERROR: " + ex); } } else if (item.Action == LUType.Reupload) { try { //Start, but don't add to the queue's again if (item.ID.Start(true)) { NeedsFired.Add(item); } } catch (Exception ex) { m_log.Error("[" + m_ScriptEngine.ScriptEngineName + "]: LEAKED COMPILE ERROR: " + ex); } } } foreach (LUStruct item in NeedsFired) { //Fire the events afterward so that they all start at the same time item.ID.FireEvents(); } threadpool.QueueEvent(ScriptChangeQueue, 2); //Requeue us Thread.Sleep(5); return(false); } if (!FiredStartupEvent) { //If we are empty, we are all done with script startup and can tell the region that we are all done if (LUQueue.Count() == 0) { FiredStartupEvent = true; foreach (OpenSim.Region.Framework.Scenes.Scene scene in m_ScriptEngine.Worlds) { scene.EventManager.TriggerEmptyScriptCompileQueue(m_ScriptEngine.ScriptFailCount, m_ScriptEngine.ScriptErrorMessages); scene.EventManager.TriggerModuleFinishedStartup("ScriptEngine", new List <string>() { m_ScriptEngine.ScriptFailCount.ToString(), m_ScriptEngine.ScriptErrorMessages }); //Tell that we are done } } } ScriptChangeIsRunning = false; Thread.Sleep(20); if (module != null) { foreach (Scene scene in m_ScriptEngine.Worlds) { ITimeMonitor scriptMonitor = (ITimeMonitor)module.GetMonitor(scene.RegionInfo.RegionID.ToString(), "Script Frame Time"); scriptMonitor.AddTime(Util.EnvironmentTickCountSubtract(StartTime)); } } return(false); }
public void CmdHandlerQueue() { if (m_ScriptEngine.Worlds.Count == 0) { Interlocked.Exchange(ref CmdHandlerQueueIsRunning, 0); return; } Interlocked.Exchange(ref CmdHandlerQueueIsRunning, 1); IMonitorModule module = m_ScriptEngine.Worlds[0].RequestModuleInterface <IMonitorModule>(); int StartTime = Util.EnvironmentTickCount(); if (!Started) //Break early { return; } if (m_ScriptEngine.ConsoleDisabled || m_ScriptEngine.Disabled) { return; } //Check timers, etc bool didAnything = false; try { didAnything = m_ScriptEngine.DoOneScriptPluginPass(); } catch (Exception ex) { MainConsole.Instance.WarnFormat("[{0}]: Error in CmdHandlerPass, {1}", m_ScriptEngine.ScriptEngineName, ex); } if (module != null) { #if (!ISWIN) foreach (IScene scene in m_ScriptEngine.Worlds) { ITimeMonitor scriptMonitor = (ITimeMonitor)module.GetMonitor(scene.RegionInfo.RegionID.ToString(), MonitorModuleHelper.ScriptFrameTime); if (scriptMonitor != null) { scriptMonitor.AddTime(Util.EnvironmentTickCountSubtract(StartTime)); } } #else foreach (ITimeMonitor scriptMonitor in m_ScriptEngine.Worlds.Select(scene => (ITimeMonitor) module.GetMonitor(scene.RegionInfo.RegionID.ToString(), MonitorModuleHelper.ScriptFrameTime)).Where(scriptMonitor => scriptMonitor != null)) { scriptMonitor.AddTime(Util.EnvironmentTickCountSubtract(StartTime)); } #endif } if (didAnything) //If we did something, run us again soon { cmdThreadpool.QueueEvent(CmdHandlerQueue, 2); } else { Interlocked.Exchange(ref CmdHandlerQueueIsRunning, 0); } }
/// <summary> /// This loop deals with starting and stoping scripts /// </summary> /// <returns></returns> public void ScriptChangeQueue() { if (m_ScriptEngine.Worlds.Count == 0) { return; } IMonitorModule module = m_ScriptEngine.Worlds[0].RequestModuleInterface <IMonitorModule>(); int StartTime = Util.EnvironmentTickCount(); if (!Started) //Break early { return; } if (m_ScriptEngine.ConsoleDisabled || m_ScriptEngine.Disabled) { return; } ScriptChangeIsRunning = true; object oitems; bool broken = false; for (int i = 0; i < 5; i++) { if (LUQueue.GetNext(out oitems)) { StartScripts(oitems as LUStruct[]); } else { //None left, stop looping broken = true; break; } } if (!broken) { scriptChangeThreadpool.QueueEvent(ScriptChangeQueue, 2); //Requeue us, still more to do return; } if (!FiredStartupEvent) { //If we are empty, we are all done with script startup and can tell the region that we are all done if (LUQueue.Count() == 0) { FiredStartupEvent = true; foreach (IScene scene in m_ScriptEngine.Worlds) { scene.EventManager.TriggerEmptyScriptCompileQueue(m_ScriptEngine.ScriptFailCount, m_ScriptEngine.ScriptErrorMessages); scene.EventManager.TriggerModuleFinishedStartup("ScriptEngine", new List <string> { m_ScriptEngine. ScriptFailCount. ToString(), m_ScriptEngine. ScriptErrorMessages }); //Tell that we are done } } } ScriptChangeIsRunning = false; Thread.Sleep(20); if (module != null) { #if (!ISWIN) foreach (IScene scene in m_ScriptEngine.Worlds) { ITimeMonitor scriptMonitor = (ITimeMonitor)module.GetMonitor(scene.RegionInfo.RegionID.ToString(), MonitorModuleHelper.ScriptFrameTime); if (scriptMonitor != null) { scriptMonitor.AddTime(Util.EnvironmentTickCountSubtract(StartTime)); } } #else foreach (ITimeMonitor scriptMonitor in m_ScriptEngine.Worlds.Select(scene => (ITimeMonitor) module.GetMonitor(scene.RegionInfo.RegionID.ToString(), MonitorModuleHelper.ScriptFrameTime)).Where(scriptMonitor => scriptMonitor != null)) { scriptMonitor.AddTime(Util.EnvironmentTickCountSubtract(StartTime)); } #endif } }
/// <summary> /// This is called by a timer and makes a SimStats class of the current stats that we have in this simulator. /// It then sends the packet to the client and triggers the events to tell followers about the updated stats /// and updates the LastSet* values for monitors. /// </summary> /// <param name = "sender"></param> /// <param name = "e"></param> protected void statsHeartBeat(object sender, EventArgs e) { lock (m_report) m_report.Stop(); if (rb == null) { buildInitialRegionBlock(); } // Know what's not thread safe in Mono... modifying timers. lock (m_report) { ISimFrameMonitor simFrameMonitor = (ISimFrameMonitor)GetMonitor(MonitorModuleHelper.SimFrameStats); ITimeDilationMonitor timeDilationMonitor = (ITimeDilationMonitor)GetMonitor(MonitorModuleHelper.TimeDilation); ITotalFrameTimeMonitor totalFrameMonitor = (ITotalFrameTimeMonitor)GetMonitor(MonitorModuleHelper.TotalFrameTime); ITimeMonitor sleepFrameMonitor = (ITimeMonitor)GetMonitor(MonitorModuleHelper.SleepFrameTime); ITimeMonitor otherFrameMonitor = (ITimeMonitor)GetMonitor(MonitorModuleHelper.OtherFrameTime); IPhysicsFrameMonitor physicsFrameMonitor = (IPhysicsFrameMonitor)GetMonitor(MonitorModuleHelper.TotalPhysicsFrameTime); ITimeMonitor physicsSyncFrameMonitor = (ITimeMonitor)GetMonitor(MonitorModuleHelper.PhysicsSyncFrameTime); ITimeMonitor physicsTimeFrameMonitor = (ITimeMonitor)GetMonitor(MonitorModuleHelper.PhysicsUpdateFrameTime); IAgentUpdateMonitor agentUpdateFrameMonitor = (IAgentUpdateMonitor)GetMonitor(MonitorModuleHelper.AgentUpdateCount); INetworkMonitor networkMonitor = (INetworkMonitor)GetMonitor(MonitorModuleHelper.NetworkMonitor); IMonitor imagesMonitor = GetMonitor(MonitorModuleHelper.ImagesFrameTime); ITimeMonitor scriptMonitor = (ITimeMonitor)GetMonitor(MonitorModuleHelper.ScriptFrameTime); IScriptCountMonitor totalScriptMonitor = (IScriptCountMonitor)GetMonitor(MonitorModuleHelper.TotalScriptCount); #region various statistic googly moogly float simfps = simFrameMonitor.SimFPS / statsUpdateFactor; // save the reported value so there is something available for llGetRegionFPS simFrameMonitor.LastReportedSimFPS = simfps; float physfps = physicsFrameMonitor.PhysicsFPS / statsUpdateFactor; physicsFrameMonitor.LastReportedPhysicsFPS = physfps; //Update the time dilation with the newest physicsFPS timeDilationMonitor.SetPhysicsFPS(physfps); #endregion #region Add the stats packets //Some info on this packet http://wiki.secondlife.com/wiki/Statistics_Bar_Guide sb[0].StatID = (uint)Stats.TimeDilation; sb[0].StatValue = (float)timeDilationMonitor.GetValue(); sb[1].StatID = (uint)Stats.FPS; sb[1].StatValue = simfps; float realsimfps = simfps * 2; sb[2].StatID = (uint)Stats.PhysFPS; sb[2].StatValue = physfps; sb[3].StatID = (uint)Stats.AgentUpdates; sb[3].StatValue = (agentUpdateFrameMonitor.AgentUpdates / realsimfps); sb[4].StatID = (uint)Stats.FrameMS; float TotalFrames = (float)(totalFrameMonitor.GetValue() / realsimfps); sb[4].StatValue = TotalFrames; sb[5].StatID = (uint)Stats.NetMS; sb[5].StatValue = 0; //TODO: Implement this sb[6].StatID = (uint)Stats.SimOtherMS; float otherMS = (float)(otherFrameMonitor.GetValue() / realsimfps); sb[6].StatValue = otherMS; sb[7].StatID = (uint)Stats.SimPhysicsMS; float PhysicsMS = (float)(physicsTimeFrameMonitor.GetValue() / realsimfps); sb[7].StatValue = PhysicsMS; sb[8].StatID = (uint)Stats.AgentMS; sb[8].StatValue = (agentUpdateFrameMonitor.AgentFrameTime / realsimfps); sb[9].StatID = (uint)Stats.ImagesMS; float imageMS = (float)(imagesMonitor.GetValue() / realsimfps); sb[9].StatValue = imageMS; sb[10].StatID = (uint)Stats.ScriptMS; float ScriptMS = (float)(scriptMonitor.GetValue() / realsimfps); sb[10].StatValue = ScriptMS; sb[11].StatID = (uint)Stats.TotalObjects; sb[12].StatID = (uint)Stats.ActiveObjects; sb[13].StatID = (uint)Stats.NumAgentMain; sb[14].StatID = (uint)Stats.NumAgentChild; IEntityCountModule entityCountModule = m_currentScene.RequestModuleInterface <IEntityCountModule>(); if (entityCountModule != null) { sb[11].StatValue = entityCountModule.Objects; sb[12].StatValue = entityCountModule.ActiveObjects; sb[13].StatValue = entityCountModule.RootAgents; sb[14].StatValue = entityCountModule.ChildAgents; } sb[15].StatID = (uint)Stats.NumScriptActive; sb[15].StatValue = totalScriptMonitor.ActiveScripts; sb[16].StatID = (uint)Stats.LSLIPS; sb[16].StatValue = 0; //This isn't used anymore, and has been superseeded by LSLEPS sb[17].StatID = (uint)Stats.InPPS; sb[17].StatValue = (networkMonitor.InPacketsPerSecond / statsUpdateFactor); sb[18].StatID = (uint)Stats.OutPPS; sb[18].StatValue = (networkMonitor.OutPacketsPerSecond / statsUpdateFactor); sb[19].StatID = (uint)Stats.PendingDownloads; sb[19].StatValue = (networkMonitor.PendingDownloads); sb[20].StatID = (uint)Stats.PendingUploads; sb[20].StatValue = (networkMonitor.PendingUploads); //21 and 22 are forced to the GC memory as they WILL make memory usage go up rapidly otherwise! sb[21].StatID = (uint)Stats.VirtualSizeKB; sb[21].StatValue = GC.GetTotalMemory(false) / 1024; // System.Diagnostics.Process.GetCurrentProcess().WorkingSet64 / (1024); sb[22].StatID = (uint)Stats.ResidentSizeKB; sb[22].StatValue = GC.GetTotalMemory(false) / 1024; //(float)System.Diagnostics.Process.GetCurrentProcess().PrivateMemorySize64 / (1024); sb[23].StatID = (uint)Stats.PendingLocalUploads; sb[23].StatValue = (networkMonitor.PendingUploads / statsUpdateFactor); sb[24].StatID = (uint)Stats.TotalUnackedBytes; sb[24].StatValue = (networkMonitor.UnackedBytes); sb[25].StatID = (uint)Stats.PhysicsPinnedTasks; sb[25].StatValue = 0; sb[26].StatID = (uint)Stats.PhysicsLODTasks; sb[26].StatValue = 0; sb[27].StatID = (uint)Stats.SimPhysicsStepMS; sb[27].StatValue = m_currentScene.PhysicsScene.StepTime; sb[28].StatID = (uint)Stats.SimPhysicsShape; sb[28].StatValue = 0; sb[29].StatID = (uint)Stats.SimPhysicsOtherMS; sb[29].StatValue = (float)(physicsSyncFrameMonitor.GetValue() / realsimfps); sb[30].StatID = (uint)Stats.SimPhysicsMemory; sb[30].StatValue = 0; sb[31].StatID = (uint)Stats.ScriptEPS; sb[31].StatValue = totalScriptMonitor.ScriptEPS / statsUpdateFactor; sb[32].StatID = (uint)Stats.SimSpareTime; //Spare time is the total time minus the stats that are in the same category in the client // It is the sleep time, physics step, update physics shape, physics other, and pumpI0. // Note: take out agent Update and script time for now, as they are not a part of the heartbeat right now and will mess this calc up float SpareTime = TotalFrames - ( /*NetMS + */ PhysicsMS + otherMS + imageMS); // + /*(agentUpdateFrameMonitor.AgentFrameTime / statsUpdateFactor) +*/ // (imagesMonitor.GetValue() / statsUpdateFactor) /* + ScriptMS*/)); sb[32].StatValue = SpareTime; sb[33].StatID = (uint)Stats.SimSleepTime; sb[33].StatValue = (float)(sleepFrameMonitor.GetValue() / realsimfps); sb[34].StatID = (uint)Stats.IOPumpTime; sb[34].StatValue = 0; //TODO: implement this #endregion for (int i = 0; i < sb.Length; i++) { if (float.IsInfinity(sb[i].StatValue) || float.IsNaN(sb[i].StatValue)) { sb[i].StatValue = 0; //Don't send huge values } lastReportedSimStats[i] = sb[i].StatValue; } SimStats simStats = new SimStats(rb, sb, m_currentScene.RegionInfo.RegionID); //Fire the event and tell followers about the new stats m_module.SendStatsResults(simStats); //Tell all the scene presences about the new stats #if (!ISWIN) foreach (IScenePresence agent in m_currentScene.GetScenePresences()) { if (!agent.IsChildAgent) { agent.ControllingClient.SendSimStats(simStats); } } #else foreach (IScenePresence agent in m_currentScene.GetScenePresences().Where(agent => !agent.IsChildAgent)) { agent.ControllingClient.SendSimStats(simStats); } #endif //Now fix any values that require reseting ResetValues(); } lock (m_report) m_report.Start(); }
public WaitTime(ITimeMonitor timeMonitor) { _timeMonitor = timeMonitor; }
private bool Update() { ISimFrameMonitor simFrameMonitor = (ISimFrameMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.SimFrameStats); ITotalFrameTimeMonitor totalFrameMonitor = (ITotalFrameTimeMonitor)RequestModuleInterface <IMonitorModule> ().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.TotalFrameTime); ISetMonitor lastFrameMonitor = (ISetMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.LastCompletedFrameAt); ITimeMonitor otherFrameMonitor = (ITimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.OtherFrameTime); ITimeMonitor sleepFrameMonitor = (ITimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.SleepFrameTime); IPhysicsFrameMonitor physicsFrameMonitor = (IPhysicsFrameMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.TotalPhysicsFrameTime); ITimeMonitor physicsFrameTimeMonitor = (ITimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.PhysicsUpdateFrameTime); IPhysicsMonitor physicsMonitor = RequestModuleInterface <IPhysicsMonitor>(); while (true) { if (!ShouldRunHeartbeat) //If we arn't supposed to be running, kill ourselves { return(false); } int maintc = Util.EnvironmentTickCount(); int BeginningFrameTime = maintc; // Increment the frame counter ++m_frame; try { int OtherFrameTime = Util.EnvironmentTickCount(); if (PhysicsReturns.Count != 0) { lock (PhysicsReturns) { ILLClientInventory inventoryModule = RequestModuleInterface <ILLClientInventory>(); if (inventoryModule != null) { inventoryModule.ReturnObjects(PhysicsReturns.ToArray(), UUID.Zero); } PhysicsReturns.Clear(); } } if (m_frame % m_update_entities == 0) { m_sceneGraph.UpdateEntities(); } /*BlankHandler[] events; * lock (m_events) * { * events = new BlankHandler[m_events.Count]; * m_events.CopyTo(events); * m_events.Clear(); * } * foreach (BlankHandler h in events) * try { h(); } * catch { }*/ if (m_frame % m_update_events == 0) { m_sceneGraph.PhysicsScene.UpdatesLoop(); } if (m_frame % m_update_events == 0) { m_eventManager.TriggerOnFrame(); } if (m_frame % m_update_coarse_locations == 0) { List <Vector3> coarseLocations; List <UUID> avatarUUIDs; if (SceneGraph.GetCoarseLocations(out coarseLocations, out avatarUUIDs, 60)) { // Send coarse locations to clients foreach (IScenePresence presence in GetScenePresences()) { presence.SendCoarseLocations(coarseLocations, avatarUUIDs); } } } int PhysicsUpdateTime = Util.EnvironmentTickCount(); if (m_frame % m_update_physics == 0) { TimeSpan SinceLastFrame = DateTime.UtcNow - m_lastphysupdate; if (!RegionInfo.RegionSettings.DisablePhysics && ApproxEquals((float)SinceLastFrame.TotalMilliseconds, m_updatetimespan, 3)) { m_sceneGraph.UpdatePreparePhysics(); m_sceneGraph.UpdatePhysics(SinceLastFrame.TotalSeconds); m_lastphysupdate = DateTime.UtcNow; int MonitorPhysicsUpdateTime = Util.EnvironmentTickCountSubtract(PhysicsUpdateTime); if (MonitorPhysicsUpdateTime != 0) { if (physicsFrameTimeMonitor != null) { physicsFrameTimeMonitor.AddTime(MonitorPhysicsUpdateTime); } if (physicsMonitor != null) { physicsMonitor.AddPhysicsStats(RegionInfo.RegionID, PhysicsScene); } if (m_lastPhysicsChange != RegionInfo.RegionSettings.DisablePhysics) { StartPhysicsScene(); } } if (physicsFrameMonitor != null) { physicsFrameMonitor.AddFPS(1); } } else if (m_lastPhysicsChange != RegionInfo.RegionSettings.DisablePhysics) { StopPhysicsScene(); } m_lastPhysicsChange = RegionInfo.RegionSettings.DisablePhysics; } //Now fix the sim stats int MonitorOtherFrameTime = Util.EnvironmentTickCountSubtract(OtherFrameTime); int MonitorLastCompletedFrame = Util.EnvironmentTickCount(); if (simFrameMonitor != null) { simFrameMonitor.AddFPS(1); lastFrameMonitor.SetValue(MonitorLastCompletedFrame); otherFrameMonitor.AddTime(MonitorOtherFrameTime); } else { simFrameMonitor = (ISimFrameMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.SimFrameStats); totalFrameMonitor = (ITotalFrameTimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.TotalFrameTime); lastFrameMonitor = (ISetMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.LastCompletedFrameAt); otherFrameMonitor = (ITimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.OtherFrameTime); sleepFrameMonitor = (ITimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), MonitorModuleHelper.SleepFrameTime); } } catch (Exception e) { MainConsole.Instance.Error("[REGION]: Failed with exception " + e + " in region: " + RegionInfo.RegionName); return(true); } //Get the time between beginning and end maintc = Util.EnvironmentTickCountSubtract(BeginningFrameTime); //Beginning + (time between beginning and end) = end int MonitorEndFrameTime = BeginningFrameTime + maintc; int getSleepTime = GetHeartbeatSleepTime(maintc); if (getSleepTime > 0) { Thread.Sleep(getSleepTime); } if (sleepFrameMonitor != null) { sleepFrameMonitor.AddTime(getSleepTime); totalFrameMonitor.AddFrameTime(MonitorEndFrameTime); } } }
private bool Update() { if (!ShouldRunHeartbeat) //If we arn't supposed to be running, kill ourselves { return(false); } ISimFrameMonitor simFrameMonitor = (ISimFrameMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), "SimFrameStats"); ITotalFrameTimeMonitor totalFrameMonitor = (ITotalFrameTimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), "Total Frame Time"); ISetMonitor lastFrameMonitor = (ISetMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), "Last Completed Frame At"); ITimeMonitor otherFrameMonitor = (ITimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), "Other Frame Time"); ITimeMonitor sleepFrameMonitor = (ITimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), "Sleep Frame Time"); IPhysicsFrameMonitor physicsFrameMonitor = (IPhysicsFrameMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), "Total Physics Frame Time"); ITimeMonitor physicsSyncFrameMonitor = (ITimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), "Physics Sync Frame Time"); ITimeMonitor physicsFrameTimeMonitor = (ITimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), "Physics Update Frame Time"); int maintc = Util.EnvironmentTickCount(); int BeginningFrameTime = maintc; // Increment the frame counter ++m_frame; try { int OtherFrameTime = Util.EnvironmentTickCount(); if (PhysicsReturns.Count != 0) { lock (PhysicsReturns) { ILLClientInventory inventoryModule = RequestModuleInterface <ILLClientInventory>(); if (inventoryModule != null) { inventoryModule.ReturnObjects(PhysicsReturns.ToArray(), UUID.Zero); } PhysicsReturns.Clear(); } } if (m_frame % m_update_coarse_locations == 0) { List <Vector3> coarseLocations; List <UUID> avatarUUIDs; SceneGraph.GetCoarseLocations(out coarseLocations, out avatarUUIDs, 60); // Send coarse locations to clients foreach (IScenePresence presence in GetScenePresences()) { presence.SendCoarseLocations(coarseLocations, avatarUUIDs); } } if (m_frame % m_update_entities == 0) { m_sceneGraph.UpdateEntities(); } if (m_frame % m_update_events == 0) { m_eventManager.TriggerOnFrame(); } int PhysicsSyncTime = Util.EnvironmentTickCount(); TimeSpan SinceLastFrame = DateTime.UtcNow - m_lastphysupdate; if ((m_frame % m_update_physics == 0) && !RegionInfo.RegionSettings.DisablePhysics) { m_sceneGraph.UpdatePreparePhysics(); } int MonitorPhysicsSyncTime = Util.EnvironmentTickCountSubtract(PhysicsSyncTime); int PhysicsUpdateTime = Util.EnvironmentTickCount(); if (m_frame % m_update_physics == 0) { if (!RegionInfo.RegionSettings.DisablePhysics && SinceLastFrame.TotalSeconds > m_physicstimespan) { m_sceneGraph.UpdatePhysics(SinceLastFrame.TotalSeconds); m_lastphysupdate = DateTime.UtcNow; } } int MonitorPhysicsUpdateTime = Util.EnvironmentTickCountSubtract(PhysicsUpdateTime) + MonitorPhysicsSyncTime; physicsFrameTimeMonitor.AddTime(MonitorPhysicsUpdateTime); physicsFrameMonitor.AddFPS(1); physicsSyncFrameMonitor.AddTime(MonitorPhysicsSyncTime); IPhysicsMonitor monitor = RequestModuleInterface <IPhysicsMonitor>(); if (monitor != null) { monitor.AddPhysicsStats(RegionInfo.RegionID, PhysicsScene); } //Now fix the sim stats int MonitorOtherFrameTime = Util.EnvironmentTickCountSubtract(OtherFrameTime); int MonitorLastCompletedFrame = Util.EnvironmentTickCount(); simFrameMonitor.AddFPS(1); lastFrameMonitor.SetValue(MonitorLastCompletedFrame); otherFrameMonitor.AddTime(MonitorOtherFrameTime); maintc = Util.EnvironmentTickCountSubtract(maintc); maintc = (int)(m_updatetimespan * 1000) - maintc; } catch (Exception e) { m_log.Error("[REGION]: Failed with exception " + e.ToString() + " in region: " + RegionInfo.RegionName); return(true); } int MonitorEndFrameTime = Util.EnvironmentTickCountSubtract(BeginningFrameTime) + maintc; if (maintc > 0) { Thread.Sleep(maintc); } sleepFrameMonitor.AddTime(maintc); totalFrameMonitor.AddFrameTime(MonitorEndFrameTime); return(true); }