private void Initialize(CMModel model, CMView view, Scene scene, int channel) { lock (this) { m_estateModule = scene.RequestModuleInterface<IEstateModule>(); Watchdog.StartThread(MainLoop, "Content Management", ThreadPriority.Normal, true); m_state = State.NONE; } }
private void statsHeartBeat(object sender, EventArgs e) { if (!m_scene.Active) return; // dont do it if if still been done if(Monitor.TryEnter(m_statsLock)) { // m_log.Debug("Firing Stats Heart Beat"); SimStatsPacket.StatBlock[] sb = new SimStatsPacket.StatBlock[m_statisticViewerArraySize]; SimStatsPacket.StatBlock[] sbex = new SimStatsPacket.StatBlock[m_statisticExtraArraySize]; SimStatsPacket.RegionBlock rb = new SimStatsPacket.RegionBlock(); uint regionFlags = 0; try { if (estateModule == null) estateModule = m_scene.RequestModuleInterface<IEstateModule>(); regionFlags = estateModule != null ? estateModule.GetRegionFlags() : (uint) 0; } catch (Exception) { // leave region flags at 0 } #region various statistic googly moogly double timeTmp = m_lastUpdateTS; m_lastUpdateTS = Util.GetTimeStampMS(); float updateElapsed = (float)((m_lastUpdateTS - timeTmp)/1000.0); // factor to consider updates integration time float updateTimeFactor = 1.0f / updateElapsed; // scene frame stats float reportedFPS; float physfps; float timeDilation; float agentMS; float physicsMS; float otherMS; float sleeptime; float scriptTimeMS; float totalFrameTime; float invFrameElapsed; // get a copy under lock and reset lock(m_statsFrameLock) { timeDilation = m_timeDilation; reportedFPS = m_fps; physfps = m_pfps; agentMS = m_agentMS; physicsMS = m_physicsMS; otherMS = m_otherMS; sleeptime = m_sleeptimeMS; scriptTimeMS = m_scriptTimeMS; totalFrameTime = m_frameMS; // still not inv invFrameElapsed = (float)((m_FrameStatsTS - m_prevFrameStatsTS) / 1000.0); ResetFrameStats(); } if (invFrameElapsed / updateElapsed < 0.8) // scene is in trouble, its account of time is most likely wrong // can even be in stall invFrameElapsed = updateTimeFactor; else invFrameElapsed = 1.0f / invFrameElapsed; float perframefactor; if (reportedFPS <= 0) { reportedFPS = 0.0f; physfps = 0.0f; perframefactor = 1.0f; timeDilation = 0.0f; } else { timeDilation /= reportedFPS; reportedFPS *= m_statisticsFPSfactor; perframefactor = 1.0f / (float)reportedFPS; reportedFPS *= invFrameElapsed; physfps *= invFrameElapsed * m_statisticsFPSfactor; } // some engines track frame time with error related to the simulation step size if(physfps > reportedFPS) physfps = reportedFPS; // save the reported value so there is something available for llGetRegionFPS lastReportedSimFPS = reportedFPS; // scale frame stats totalFrameTime *= perframefactor; sleeptime *= perframefactor; otherMS *= perframefactor; physicsMS *= perframefactor; agentMS *= perframefactor; scriptTimeMS *= perframefactor; // estimate spare time float sparetime; sparetime = m_targetFrameTime - (physicsMS + agentMS + otherMS); if (sparetime < 0) sparetime = 0; else if (sparetime > totalFrameTime) sparetime = totalFrameTime; #endregion m_rootAgents = m_scene.SceneGraph.GetRootAgentCount(); m_childAgents = m_scene.SceneGraph.GetChildAgentCount(); m_numPrim = m_scene.SceneGraph.GetTotalObjectsCount(); m_numGeoPrim = m_scene.SceneGraph.GetTotalPrimObjectsCount(); m_numMesh = m_scene.SceneGraph.GetTotalMeshObjectsCount(); m_activePrim = m_scene.SceneGraph.GetActiveObjectsCount(); m_activeScripts = m_scene.SceneGraph.GetActiveScriptsCount(); m_scriptLinesPerSecond = m_scene.SceneGraph.GetScriptLPS(); // FIXME: Checking for stat sanity is a complex approach. What we really need to do is fix the code // so that stat numbers are always consistent. CheckStatSanity(); for (int i = 0; i < m_statisticViewerArraySize; i++) { sb[i] = new SimStatsPacket.StatBlock(); } sb[0].StatID = (uint) Stats.TimeDilation; sb[0].StatValue = (Single.IsNaN(timeDilation)) ? 0.0f : (float)Math.Round(timeDilation,3); sb[1].StatID = (uint) Stats.SimFPS; sb[1].StatValue = (float)Math.Round(reportedFPS,1);; sb[2].StatID = (uint) Stats.PhysicsFPS; sb[2].StatValue = (float)Math.Round(physfps,1); sb[3].StatID = (uint) Stats.AgentUpdates; sb[3].StatValue = m_agentUpdates * updateTimeFactor; sb[4].StatID = (uint) Stats.Agents; sb[4].StatValue = m_rootAgents; sb[5].StatID = (uint) Stats.ChildAgents; sb[5].StatValue = m_childAgents; sb[6].StatID = (uint) Stats.TotalPrim; sb[6].StatValue = m_numPrim; sb[7].StatID = (uint) Stats.ActivePrim; sb[7].StatValue = m_activePrim; sb[8].StatID = (uint)Stats.FrameMS; sb[8].StatValue = totalFrameTime; sb[9].StatID = (uint)Stats.NetMS; sb[9].StatValue = m_netMS * perframefactor; sb[10].StatID = (uint)Stats.PhysicsMS; sb[10].StatValue = physicsMS; sb[11].StatID = (uint)Stats.ImageMS ; sb[11].StatValue = m_imageMS * perframefactor; sb[12].StatID = (uint)Stats.OtherMS; sb[12].StatValue = otherMS; sb[13].StatID = (uint)Stats.InPacketsPerSecond; sb[13].StatValue = (float)Math.Round(m_inPacketsPerSecond * updateTimeFactor); sb[14].StatID = (uint)Stats.OutPacketsPerSecond; sb[14].StatValue = (float)Math.Round(m_outPacketsPerSecond * updateTimeFactor); sb[15].StatID = (uint)Stats.UnAckedBytes; sb[15].StatValue = m_unAckedBytes; sb[16].StatID = (uint)Stats.AgentMS; sb[16].StatValue = agentMS; sb[17].StatID = (uint)Stats.PendingDownloads; sb[17].StatValue = m_pendingDownloads; sb[18].StatID = (uint)Stats.PendingUploads; sb[18].StatValue = m_pendingUploads; sb[19].StatID = (uint)Stats.ActiveScripts; sb[19].StatValue = m_activeScripts; sb[20].StatID = (uint)Stats.SimSleepMs; sb[20].StatValue = sleeptime; sb[21].StatID = (uint)Stats.SimSpareMs; sb[21].StatValue = sparetime; // this should came from phys engine sb[22].StatID = (uint)Stats.SimPhysicsStepMs; sb[22].StatValue = 20; // send the ones we dont have as zeros, to clean viewers state // specially arriving from regions with wrond IDs in use sb[23].StatID = (uint)Stats.VirtualSizeKb; sb[23].StatValue = 0; sb[24].StatID = (uint)Stats.ResidentSizeKb; sb[24].StatValue = 0; sb[25].StatID = (uint)Stats.PendingLocalUploads; sb[25].StatValue = 0; sb[26].StatID = (uint)Stats.PhysicsPinnedTasks; sb[26].StatValue = 0; sb[27].StatID = (uint)Stats.PhysicsLodTasks; sb[27].StatValue = 0; sb[28].StatID = (uint)Stats.ScriptEps; // we actuall have this, but not messing array order AGAIN sb[28].StatValue = (float)Math.Round(m_scriptEventsPerSecond * updateTimeFactor); sb[29].StatID = (uint)Stats.SimAIStepTimeMS; sb[29].StatValue = 0; sb[30].StatID = (uint)Stats.SimIoPumpTime; sb[30].StatValue = 0; sb[31].StatID = (uint)Stats.SimPCTSscriptsRun; sb[31].StatValue = 0; sb[32].StatID = (uint)Stats.SimRegionIdle; sb[32].StatValue = 0; sb[33].StatID = (uint)Stats.SimRegionIdlePossible; sb[33].StatValue = 0; sb[34].StatID = (uint)Stats.SimSkippedSillouet_PS; sb[34].StatValue = 0; sb[35].StatID = (uint)Stats.SimSkippedCharsPerC; sb[35].StatValue = 0; sb[36].StatID = (uint)Stats.SimPhysicsMemory; sb[36].StatValue = 0; sb[37].StatID = (uint)Stats.ScriptMS; sb[37].StatValue = scriptTimeMS; for (int i = 0; i < m_statisticViewerArraySize; i++) { lastReportedSimStats[i] = sb[i].StatValue; } // add extra stats for internal use for (int i = 0; i < m_statisticExtraArraySize; i++) { sbex[i] = new SimStatsPacket.StatBlock(); } sbex[0].StatID = (uint)Stats.LSLScriptLinesPerSecond; sbex[0].StatValue = m_scriptLinesPerSecond * updateTimeFactor; lastReportedSimStats[38] = m_scriptLinesPerSecond * updateTimeFactor; sbex[1].StatID = (uint)Stats.FrameDilation2; sbex[1].StatValue = (Single.IsNaN(timeDilation)) ? 0.1f : timeDilation; lastReportedSimStats[39] = (Single.IsNaN(timeDilation)) ? 0.1f : timeDilation; sbex[2].StatID = (uint)Stats.UsersLoggingIn; sbex[2].StatValue = m_usersLoggingIn; lastReportedSimStats[40] = m_usersLoggingIn; sbex[3].StatID = (uint)Stats.TotalGeoPrim; sbex[3].StatValue = m_numGeoPrim; lastReportedSimStats[41] = m_numGeoPrim; sbex[4].StatID = (uint)Stats.TotalMesh; sbex[4].StatValue = m_numMesh; lastReportedSimStats[42] = m_numMesh; sbex[5].StatID = (uint)Stats.ThreadCount; sbex[5].StatValue = m_inUseThreads; lastReportedSimStats[43] = m_inUseThreads; SimStats simStats = new SimStats( ReportingRegion.RegionLocX, ReportingRegion.RegionLocY, regionFlags, (uint)m_objectCapacity, rb, sb, sbex, m_scene.RegionInfo.originRegionID); handlerSendStatResult = OnSendStatsResult; if (handlerSendStatResult != null) { handlerSendStatResult(simStats); } // Extra statistics that aren't currently sent to clients if (m_scene.PhysicsScene != null) { lock (m_lastReportedExtraSimStats) { m_lastReportedExtraSimStats[LastReportedObjectUpdateStatName] = m_objectUpdates * updateTimeFactor; m_lastReportedExtraSimStats[SlowFramesStat.ShortName] = (float)SlowFramesStat.Value; Dictionary<string, float> physicsStats = m_scene.PhysicsScene.GetStats(); if (physicsStats != null) { foreach (KeyValuePair<string, float> tuple in physicsStats) { // FIXME: An extremely dirty hack to divide MS stats per frame rather than per second // Need to change things so that stats source can indicate whether they are per second or // per frame. if (tuple.Key.EndsWith("MS")) m_lastReportedExtraSimStats[tuple.Key] = tuple.Value * perframefactor; else m_lastReportedExtraSimStats[tuple.Key] = tuple.Value * updateTimeFactor; } } } } // LastReportedObjectUpdates = m_objectUpdates / m_statsUpdateFactor; ResetValues(); Monitor.Exit(m_statsLock); } }
private void statsHeartBeat(object sender, EventArgs e) { SimStatsPacket.StatBlock[] sb = new SimStatsPacket.StatBlock[21]; SimStatsPacket.RegionBlock rb = new SimStatsPacket.RegionBlock(); // Know what's not thread safe in Mono... modifying timers. // m_log.Debug("Firing Stats Heart Beat"); lock (m_report) { uint regionFlags = 0; try { if (estateModule == null) { estateModule = m_scene.RequestModuleInterface <IEstateModule>(); } regionFlags = estateModule != null?estateModule.GetRegionFlags() : (uint)0; } catch (Exception) { // leave region flags at 0 } #region various statistic googly moogly // Our FPS is actually 10fps, so multiplying by 5 to get the amount that people expect there // 0-50 is pretty close to 0-45 float simfps = (int)((m_fps * 5)); // save the reported value so there is something available for llGetRegionFPS lastReportedSimFPS = (float)simfps / statsUpdateFactor; //if (simfps > 45) //simfps = simfps - (simfps - 45); //if (simfps < 0) //simfps = 0; // float physfps = ((m_pfps / 1000)); //if (physfps > 600) //physfps = physfps - (physfps - 600); if (physfps < 0) { physfps = 0; } #endregion //Our time dilation is 0.91 when we're running a full speed, // therefore to make sure we get an appropriate range, // we have to factor in our error. (0.10f * statsUpdateFactor) // multiplies the fix for the error times the amount of times it'll occur a second // / 10 divides the value by the number of times the sim heartbeat runs (10fps) // Then we divide the whole amount by the amount of seconds pass in between stats updates. // 'statsUpdateFactor' is how often stats packets are sent in seconds. Used below to change // values to X-per-second values. for (int i = 0; i < 21; i++) { sb[i] = new SimStatsPacket.StatBlock(); } 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[1].StatID = (uint)Stats.SimFPS; sb[1].StatValue = simfps / statsUpdateFactor; sb[2].StatID = (uint)Stats.PhysicsFPS; sb[2].StatValue = physfps / statsUpdateFactor; sb[3].StatID = (uint)Stats.AgentUpdates; sb[3].StatValue = (m_agentUpdates / statsUpdateFactor); sb[4].StatID = (uint)Stats.Agents; sb[4].StatValue = m_rootAgents; sb[5].StatID = (uint)Stats.ChildAgents; sb[5].StatValue = m_childAgents; sb[6].StatID = (uint)Stats.TotalPrim; sb[6].StatValue = m_numPrim; sb[7].StatID = (uint)Stats.ActivePrim; sb[7].StatValue = m_activePrim; sb[8].StatID = (uint)Stats.FrameMS; sb[8].StatValue = m_frameMS / statsUpdateFactor; sb[9].StatID = (uint)Stats.NetMS; sb[9].StatValue = m_netMS / statsUpdateFactor; sb[10].StatID = (uint)Stats.PhysicsMS; sb[10].StatValue = m_physicsMS / statsUpdateFactor; sb[11].StatID = (uint)Stats.ImageMS; sb[11].StatValue = m_imageMS / statsUpdateFactor; sb[12].StatID = (uint)Stats.OtherMS; sb[12].StatValue = m_otherMS / statsUpdateFactor; sb[13].StatID = (uint)Stats.InPacketsPerSecond; sb[13].StatValue = (m_inPacketsPerSecond / statsUpdateFactor); sb[14].StatID = (uint)Stats.OutPacketsPerSecond; sb[14].StatValue = (m_outPacketsPerSecond / statsUpdateFactor); sb[15].StatID = (uint)Stats.UnAckedBytes; sb[15].StatValue = m_unAckedBytes; sb[16].StatID = (uint)Stats.AgentMS; sb[16].StatValue = m_agentMS / statsUpdateFactor; sb[17].StatID = (uint)Stats.PendingDownloads; sb[17].StatValue = m_pendingDownloads; sb[18].StatID = (uint)Stats.PendingUploads; sb[18].StatValue = m_pendingUploads; sb[19].StatID = (uint)Stats.ActiveScripts; sb[19].StatValue = m_activeScripts; sb[20].StatID = (uint)Stats.ScriptLinesPerSecond; sb[20].StatValue = m_scriptLinesPerSecond / statsUpdateFactor; for (int i = 0; i < 21; i++) { lastReportedSimStats[i] = sb[i].StatValue; } SimStats simStats = new SimStats( ReportingRegion.RegionLocX, ReportingRegion.RegionLocY, regionFlags, (uint)objectCapacity, rb, sb, m_scene.RegionInfo.originRegionID); handlerSendStatResult = OnSendStatsResult; if (handlerSendStatResult != null) { handlerSendStatResult(simStats); } resetvalues(); } }
/// <summary> /// Load region settings data /// </summary> /// <param name="scene"></param> /// <param name="settingsPath"></param> /// <param name="data"></param> /// <param name="dearchivedScenes"></param> /// <returns> /// true if settings were loaded successfully, false otherwise /// </returns> private bool LoadRegionSettings(Scene scene, string settingsPath, byte[] data, DearchiveScenesInfo dearchivedScenes) { RegionSettings loadedRegionSettings; try { loadedRegionSettings = RegionSettingsSerializer.Deserialize(data); } catch (Exception e) { m_log.ErrorFormat( "[ARCHIVER]: Could not parse region settings file {0}. Ignoring. Exception was {1}", settingsPath, e); return(false); } RegionSettings currentRegionSettings = scene.RegionInfo.RegionSettings; currentRegionSettings.AgentLimit = loadedRegionSettings.AgentLimit; currentRegionSettings.AllowDamage = loadedRegionSettings.AllowDamage; currentRegionSettings.AllowLandJoinDivide = loadedRegionSettings.AllowLandJoinDivide; currentRegionSettings.AllowLandResell = loadedRegionSettings.AllowLandResell; currentRegionSettings.BlockFly = loadedRegionSettings.BlockFly; currentRegionSettings.BlockShowInSearch = loadedRegionSettings.BlockShowInSearch; currentRegionSettings.BlockTerraform = loadedRegionSettings.BlockTerraform; currentRegionSettings.DisableCollisions = loadedRegionSettings.DisableCollisions; currentRegionSettings.DisablePhysics = loadedRegionSettings.DisablePhysics; currentRegionSettings.DisableScripts = loadedRegionSettings.DisableScripts; currentRegionSettings.Elevation1NE = loadedRegionSettings.Elevation1NE; currentRegionSettings.Elevation1NW = loadedRegionSettings.Elevation1NW; currentRegionSettings.Elevation1SE = loadedRegionSettings.Elevation1SE; currentRegionSettings.Elevation1SW = loadedRegionSettings.Elevation1SW; currentRegionSettings.Elevation2NE = loadedRegionSettings.Elevation2NE; currentRegionSettings.Elevation2NW = loadedRegionSettings.Elevation2NW; currentRegionSettings.Elevation2SE = loadedRegionSettings.Elevation2SE; currentRegionSettings.Elevation2SW = loadedRegionSettings.Elevation2SW; currentRegionSettings.FixedSun = loadedRegionSettings.FixedSun; currentRegionSettings.SunPosition = loadedRegionSettings.SunPosition; currentRegionSettings.ObjectBonus = loadedRegionSettings.ObjectBonus; currentRegionSettings.RestrictPushing = loadedRegionSettings.RestrictPushing; currentRegionSettings.TerrainLowerLimit = loadedRegionSettings.TerrainLowerLimit; currentRegionSettings.TerrainRaiseLimit = loadedRegionSettings.TerrainRaiseLimit; currentRegionSettings.TerrainTexture1 = loadedRegionSettings.TerrainTexture1; currentRegionSettings.TerrainTexture2 = loadedRegionSettings.TerrainTexture2; currentRegionSettings.TerrainTexture3 = loadedRegionSettings.TerrainTexture3; currentRegionSettings.TerrainTexture4 = loadedRegionSettings.TerrainTexture4; currentRegionSettings.UseEstateSun = loadedRegionSettings.UseEstateSun; currentRegionSettings.WaterHeight = loadedRegionSettings.WaterHeight; currentRegionSettings.TelehubObject = loadedRegionSettings.TelehubObject; currentRegionSettings.ClearSpawnPoints(); foreach (SpawnPoint sp in loadedRegionSettings.SpawnPoints()) { currentRegionSettings.AddSpawnPoint(sp); } currentRegionSettings.LoadedCreationDateTime = dearchivedScenes.LoadedCreationDateTime; currentRegionSettings.LoadedCreationID = dearchivedScenes.GetOriginalRegionID(scene.RegionInfo.RegionID).ToString(); currentRegionSettings.Save(); scene.TriggerEstateSunUpdate(); IEstateModule estateModule = scene.RequestModuleInterface <IEstateModule>(); if (estateModule != null) { estateModule.sendRegionHandshakeToAll(); } return(true); }
private void statsHeartBeat(object sender, EventArgs e) { if (statsRunning) return; try { statsRunning = true; SimStatsPacket.StatBlock[] sb = new SimStatsPacket.StatBlock[21]; SimStatsPacket.RegionBlock rb = new SimStatsPacket.RegionBlock(); uint regionFlags = 0; try { if (estateModule == null) estateModule = m_scene.RequestModuleInterface<IEstateModule>(); regionFlags = estateModule != null ? estateModule.GetRegionFlags() : (uint)0; } catch (Exception) { // leave region flags at 0 } float simfps = (int)m_fps; // save the reported value so there is something available for llGetRegionFPS lastReportedSimFPS = (float)simfps / statsUpdateFactor; float physfps = m_pfps; if (physfps < 0) physfps = 0; //Our time dilation is 0.91 when we're running a full speed, // therefore to make sure we get an appropriate range, // we have to factor in our error. (0.10f * statsUpdateFactor) // multiplies the fix for the error times the amount of times it'll occur a second // / 10 divides the value by the number of times the sim heartbeat runs (10fps) // Then we divide the whole amount by the amount of seconds pass in between stats updates. for (int i = 0; i < 21; i++) { sb[i] = new SimStatsPacket.StatBlock(); } 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[1].StatID = (uint)Stats.SimFPS; sb[1].StatValue = simfps / statsUpdateFactor; sb[2].StatID = (uint)Stats.PhysicsFPS; sb[2].StatValue = physfps; sb[3].StatID = (uint)Stats.AgentUpdates; sb[3].StatValue = (m_agentUpdates / statsUpdateFactor); sb[4].StatID = (uint)Stats.Agents; sb[4].StatValue = m_rootAgents; sb[5].StatID = (uint)Stats.ChildAgents; sb[5].StatValue = m_childAgents; sb[6].StatID = (uint)Stats.TotalPrim; sb[6].StatValue = m_numPrim; sb[7].StatID = (uint)Stats.ActivePrim; sb[7].StatValue = m_activePrim; sb[8].StatID = (uint)Stats.FrameMS; sb[8].StatValue = m_frameMS / statsUpdateFactor; sb[9].StatID = (uint)Stats.NetMS; sb[9].StatValue = m_netMS / statsUpdateFactor; sb[10].StatID = (uint)Stats.PhysicsMS; sb[10].StatValue = m_physicsMS / statsUpdateFactor; sb[11].StatID = (uint)Stats.ImageMS; sb[11].StatValue = m_imageMS / statsUpdateFactor; sb[12].StatID = (uint)Stats.OtherMS; sb[12].StatValue = m_otherMS / statsUpdateFactor; sb[13].StatID = (uint)Stats.InPacketsPerSecond; sb[13].StatValue = (m_inPacketsPerSecond); sb[14].StatID = (uint)Stats.OutPacketsPerSecond; sb[14].StatValue = (m_outPacketsPerSecond / statsUpdateFactor); sb[15].StatID = (uint)Stats.UnAckedBytes; sb[15].StatValue = m_unAckedBytes; sb[16].StatID = (uint)Stats.AgentMS; sb[16].StatValue = m_agentMS / statsUpdateFactor; sb[17].StatID = (uint)Stats.PendingDownloads; sb[17].StatValue = m_pendingDownloads; sb[18].StatID = (uint)Stats.PendingUploads; sb[18].StatValue = m_pendingUploads; sb[19].StatID = (uint)Stats.ActiveScripts; sb[19].StatValue = m_activeScripts; sb[20].StatID = (uint)Stats.ScriptLinesPerSecond; sb[20].StatValue = m_scriptLinesPerSecond / statsUpdateFactor; SimStats simStats = new SimStats( ReportingRegion.RegionLocX, ReportingRegion.RegionLocY, regionFlags, (uint)objectCapacity, rb, sb, m_scene.RegionInfo.originRegionID); handlerSendStatResult = OnSendStatsResult; if (handlerSendStatResult != null) { handlerSendStatResult(simStats); } resetvalues(); } finally { statsRunning = false; } }
private void Initialize(CMModel model, CMView view, Scene scene, int channel) { lock (this) { m_estateModule = scene.RequestModuleInterface<IEstateModule>(); m_thread = new Thread(MainLoop); m_thread.Name = "Content Management"; m_thread.IsBackground = true; m_thread.Start(); ThreadTracker.Add(m_thread); m_state = State.NONE; } }
private void statsHeartBeat(object sender, EventArgs e) { if (!m_scene.Active) { return; } // dont do it if if still been done if (Monitor.TryEnter(m_statsLock)) { // m_log.Debug("Firing Stats Heart Beat"); SimStatsPacket.StatBlock[] sb = new SimStatsPacket.StatBlock[m_statisticViewerArraySize]; SimStatsPacket.StatBlock[] sbex = new SimStatsPacket.StatBlock[m_statisticExtraArraySize]; SimStatsPacket.RegionBlock rb = new SimStatsPacket.RegionBlock(); uint regionFlags = 0; try { if (estateModule == null) { estateModule = m_scene.RequestModuleInterface <IEstateModule>(); } regionFlags = estateModule != null?estateModule.GetRegionFlags() : (uint)0; } catch (Exception) { // leave region flags at 0 } #region various statistic googly moogly double timeTmp = m_lastUpdateTS; m_lastUpdateTS = Util.GetTimeStampMS(); float updateElapsed = (float)((m_lastUpdateTS - timeTmp) / 1000.0); // factor to consider updates integration time float updateTimeFactor = 1.0f / updateElapsed; // scene frame stats float reportedFPS; float physfps; float timeDilation; float agentMS; float physicsMS; float otherMS; float sleeptime; float scriptTimeMS; float totalFrameTime; float invFrameElapsed; // get a copy under lock and reset lock (m_statsFrameLock) { timeDilation = m_timeDilation; reportedFPS = m_fps; physfps = m_pfps; agentMS = m_agentMS; physicsMS = m_physicsMS; otherMS = m_otherMS; sleeptime = m_sleeptimeMS; scriptTimeMS = m_scriptTimeMS; totalFrameTime = m_frameMS; // still not inv invFrameElapsed = (float)((m_FrameStatsTS - m_prevFrameStatsTS) / 1000.0); ResetFrameStats(); } if (invFrameElapsed / updateElapsed < 0.8) { // scene is in trouble, its account of time is most likely wrong // can even be in stall invFrameElapsed = updateTimeFactor; } else { invFrameElapsed = 1.0f / invFrameElapsed; } float perframefactor; if (reportedFPS <= 0) { reportedFPS = 0.0f; physfps = 0.0f; perframefactor = 1.0f; timeDilation = 0.0f; } else { timeDilation /= reportedFPS; reportedFPS *= m_statisticsFPSfactor; perframefactor = 1.0f / (float)reportedFPS; reportedFPS *= invFrameElapsed; physfps *= invFrameElapsed * m_statisticsFPSfactor; } // some engines track frame time with error related to the simulation step size if (physfps > reportedFPS) { physfps = reportedFPS; } // save the reported value so there is something available for llGetRegionFPS lastReportedSimFPS = reportedFPS; // scale frame stats totalFrameTime *= perframefactor; sleeptime *= perframefactor; otherMS *= perframefactor; physicsMS *= perframefactor; agentMS *= perframefactor; scriptTimeMS *= perframefactor; // estimate spare time float sparetime; sparetime = m_targetFrameTime - (physicsMS + agentMS + otherMS); if (sparetime < 0) { sparetime = 0; } else if (sparetime > totalFrameTime) { sparetime = totalFrameTime; } #endregion m_rootAgents = m_scene.SceneGraph.GetRootAgentCount(); m_childAgents = m_scene.SceneGraph.GetChildAgentCount(); m_numPrim = m_scene.SceneGraph.GetTotalObjectsCount(); m_numGeoPrim = m_scene.SceneGraph.GetTotalPrimObjectsCount(); m_numMesh = m_scene.SceneGraph.GetTotalMeshObjectsCount(); m_activePrim = m_scene.SceneGraph.GetActiveObjectsCount(); m_activeScripts = m_scene.SceneGraph.GetActiveScriptsCount(); m_scriptLinesPerSecond = m_scene.SceneGraph.GetScriptLPS(); // FIXME: Checking for stat sanity is a complex approach. What we really need to do is fix the code // so that stat numbers are always consistent. CheckStatSanity(); for (int i = 0; i < m_statisticViewerArraySize; i++) { sb[i] = new SimStatsPacket.StatBlock(); } sb[0].StatID = (uint)Stats.TimeDilation; sb[0].StatValue = (Single.IsNaN(timeDilation)) ? 0.0f : (float)Math.Round(timeDilation, 3); sb[1].StatID = (uint)Stats.SimFPS; sb[1].StatValue = (float)Math.Round(reportedFPS, 1);; sb[2].StatID = (uint)Stats.PhysicsFPS; sb[2].StatValue = (float)Math.Round(physfps, 1); sb[3].StatID = (uint)Stats.AgentUpdates; sb[3].StatValue = m_agentUpdates * updateTimeFactor; sb[4].StatID = (uint)Stats.Agents; sb[4].StatValue = m_rootAgents; sb[5].StatID = (uint)Stats.ChildAgents; sb[5].StatValue = m_childAgents; sb[6].StatID = (uint)Stats.TotalPrim; sb[6].StatValue = m_numPrim; sb[7].StatID = (uint)Stats.ActivePrim; sb[7].StatValue = m_activePrim; sb[8].StatID = (uint)Stats.FrameMS; sb[8].StatValue = totalFrameTime; sb[9].StatID = (uint)Stats.NetMS; sb[9].StatValue = m_netMS * perframefactor; sb[10].StatID = (uint)Stats.PhysicsMS; sb[10].StatValue = physicsMS; sb[11].StatID = (uint)Stats.ImageMS; sb[11].StatValue = m_imageMS * perframefactor; sb[12].StatID = (uint)Stats.OtherMS; sb[12].StatValue = otherMS; sb[13].StatID = (uint)Stats.InPacketsPerSecond; sb[13].StatValue = (float)Math.Round(m_inPacketsPerSecond * updateTimeFactor); sb[14].StatID = (uint)Stats.OutPacketsPerSecond; sb[14].StatValue = (float)Math.Round(m_outPacketsPerSecond * updateTimeFactor); sb[15].StatID = (uint)Stats.UnAckedBytes; sb[15].StatValue = m_unAckedBytes; sb[16].StatID = (uint)Stats.AgentMS; sb[16].StatValue = agentMS; sb[17].StatID = (uint)Stats.PendingDownloads; sb[17].StatValue = m_pendingDownloads; sb[18].StatID = (uint)Stats.PendingUploads; sb[18].StatValue = m_pendingUploads; sb[19].StatID = (uint)Stats.ActiveScripts; sb[19].StatValue = m_activeScripts; sb[20].StatID = (uint)Stats.SimSleepMs; sb[20].StatValue = sleeptime; sb[21].StatID = (uint)Stats.SimSpareMs; sb[21].StatValue = sparetime; // this should came from phys engine sb[22].StatID = (uint)Stats.SimPhysicsStepMs; sb[22].StatValue = 20; // send the ones we dont have as zeros, to clean viewers state // specially arriving from regions with wrond IDs in use sb[23].StatID = (uint)Stats.VirtualSizeKb; sb[23].StatValue = 0; sb[24].StatID = (uint)Stats.ResidentSizeKb; sb[24].StatValue = 0; sb[25].StatID = (uint)Stats.PendingLocalUploads; sb[25].StatValue = 0; sb[26].StatID = (uint)Stats.PhysicsPinnedTasks; sb[26].StatValue = 0; sb[27].StatID = (uint)Stats.PhysicsLodTasks; sb[27].StatValue = 0; sb[28].StatID = (uint)Stats.ScriptEps; // we actuall have this, but not messing array order AGAIN sb[28].StatValue = (float)Math.Round(m_scriptEventsPerSecond * updateTimeFactor); sb[29].StatID = (uint)Stats.SimAIStepTimeMS; sb[29].StatValue = 0; sb[30].StatID = (uint)Stats.SimIoPumpTime; sb[30].StatValue = 0; sb[31].StatID = (uint)Stats.SimPCTSscriptsRun; sb[31].StatValue = 0; sb[32].StatID = (uint)Stats.SimRegionIdle; sb[32].StatValue = 0; sb[33].StatID = (uint)Stats.SimRegionIdlePossible; sb[33].StatValue = 0; sb[34].StatID = (uint)Stats.SimSkippedSillouet_PS; sb[34].StatValue = 0; sb[35].StatID = (uint)Stats.SimSkippedCharsPerC; sb[35].StatValue = 0; sb[36].StatID = (uint)Stats.SimPhysicsMemory; sb[36].StatValue = 0; sb[37].StatID = (uint)Stats.ScriptMS; sb[37].StatValue = scriptTimeMS; for (int i = 0; i < m_statisticViewerArraySize; i++) { lastReportedSimStats[i] = sb[i].StatValue; } // add extra stats for internal use for (int i = 0; i < m_statisticExtraArraySize; i++) { sbex[i] = new SimStatsPacket.StatBlock(); } sbex[0].StatID = (uint)Stats.LSLScriptLinesPerSecond; sbex[0].StatValue = m_scriptLinesPerSecond * updateTimeFactor; lastReportedSimStats[38] = m_scriptLinesPerSecond * updateTimeFactor; sbex[1].StatID = (uint)Stats.FrameDilation2; sbex[1].StatValue = (Single.IsNaN(timeDilation)) ? 0.1f : timeDilation; lastReportedSimStats[39] = (Single.IsNaN(timeDilation)) ? 0.1f : timeDilation; sbex[2].StatID = (uint)Stats.UsersLoggingIn; sbex[2].StatValue = m_usersLoggingIn; lastReportedSimStats[40] = m_usersLoggingIn; sbex[3].StatID = (uint)Stats.TotalGeoPrim; sbex[3].StatValue = m_numGeoPrim; lastReportedSimStats[41] = m_numGeoPrim; sbex[4].StatID = (uint)Stats.TotalMesh; sbex[4].StatValue = m_numMesh; lastReportedSimStats[42] = m_numMesh; sbex[5].StatID = (uint)Stats.ThreadCount; sbex[5].StatValue = m_inUseThreads; lastReportedSimStats[43] = m_inUseThreads; SimStats simStats = new SimStats( ReportingRegion.RegionLocX, ReportingRegion.RegionLocY, regionFlags, (uint)m_objectCapacity, rb, sb, sbex, m_scene.RegionInfo.originRegionID); handlerSendStatResult = OnSendStatsResult; if (handlerSendStatResult != null) { handlerSendStatResult(simStats); } // Extra statistics that aren't currently sent to clients if (m_scene.PhysicsScene != null) { lock (m_lastReportedExtraSimStats) { m_lastReportedExtraSimStats[LastReportedObjectUpdateStatName] = m_objectUpdates * updateTimeFactor; m_lastReportedExtraSimStats[SlowFramesStat.ShortName] = (float)SlowFramesStat.Value; Dictionary <string, float> physicsStats = m_scene.PhysicsScene.GetStats(); if (physicsStats != null) { foreach (KeyValuePair <string, float> tuple in physicsStats) { // FIXME: An extremely dirty hack to divide MS stats per frame rather than per second // Need to change things so that stats source can indicate whether they are per second or // per frame. if (tuple.Key.EndsWith("MS")) { m_lastReportedExtraSimStats[tuple.Key] = tuple.Value * perframefactor; } else { m_lastReportedExtraSimStats[tuple.Key] = tuple.Value * updateTimeFactor; } } } } } // LastReportedObjectUpdates = m_objectUpdates / m_statsUpdateFactor; ResetValues(); Monitor.Exit(m_statsLock); } }
/// <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) { SimStatsPacket.RegionBlock rb = new SimStatsPacket.RegionBlock(); // Know what's not thread safe in Mono... modifying timers. lock (m_report) { uint regionFlags = 0; try { if (m_estateModule == null) m_estateModule = m_currentScene.RequestModuleInterface<IEstateModule>(); regionFlags = m_estateModule != null ? m_estateModule.GetRegionFlags() : (uint)0; } catch (Exception) { // leave region flags at 0 } rb.ObjectCapacity = (uint)m_currentScene.RegionInfo.ObjectCapacity; rb.RegionFlags = regionFlags; rb.RegionX = (uint)m_currentScene.RegionInfo.RegionLocX / Constants.RegionSize; rb.RegionY = (uint)m_currentScene.RegionInfo.RegionLocY / Constants.RegionSize; ISimFrameMonitor simFrameMonitor = (ISimFrameMonitor)GetMonitor("SimFrameStats"); ITimeDilationMonitor timeDilationMonitor = (ITimeDilationMonitor)GetMonitor("Time Dilation"); ITotalFrameTimeMonitor totalFrameMonitor = (ITotalFrameTimeMonitor)GetMonitor("Total Frame Time"); ITimeMonitor sleepFrameMonitor = (ITimeMonitor)GetMonitor("Sleep Frame Time"); ITimeMonitor otherFrameMonitor = (ITimeMonitor)GetMonitor("Other Frame Time"); IPhysicsFrameMonitor physicsFrameMonitor = (IPhysicsFrameMonitor)GetMonitor("Total Physics Frame Time"); ITimeMonitor physicsSyncFrameMonitor = (ITimeMonitor)GetMonitor("Physics Sync Frame Time"); ITimeMonitor physicsTimeFrameMonitor = (ITimeMonitor)GetMonitor("Physics Update Frame Time"); IAgentUpdateMonitor agentUpdateFrameMonitor = (IAgentUpdateMonitor)GetMonitor("Agent Update Count"); INetworkMonitor networkMonitor = (INetworkMonitor)GetMonitor("Network Monitor"); IMonitor imagesMonitor = GetMonitor("Images Frame Time"); ITimeMonitor scriptMonitor = (ITimeMonitor)GetMonitor("Script Frame Time"); IScriptCountMonitor totalScriptMonitor = (IScriptCountMonitor)GetMonitor("Total Script Count"); #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 = (float)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; sb[6].StatValue = (float)(otherFrameMonitor.GetValue() / realsimfps); 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; sb[9].StatValue = (float)(imagesMonitor.GetValue() / realsimfps); 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 = (float)(networkMonitor.InPacketsPerSecond / statsUpdateFactor); sb[18].StatID = (uint)Stats.OutPPS; sb[18].StatValue = (float)(networkMonitor.OutPacketsPerSecond / statsUpdateFactor); sb[19].StatID = (uint)Stats.PendingDownloads; sb[19].StatValue = (float)(networkMonitor.PendingDownloads); sb[20].StatID = (uint)Stats.PendingUploads; sb[20].StatValue = (float)(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 = (float)(networkMonitor.PendingUploads / statsUpdateFactor); sb[24].StatID = (uint)Stats.TotalUnackedBytes; sb[24].StatValue = (float)(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 = (float)(TotalFrames - (/*NetMS + */ PhysicsMS + otherFrameMonitor.GetValue() + /*(agentUpdateFrameMonitor.AgentFrameTime / statsUpdateFactor) +*/ (imagesMonitor.GetValue() / statsUpdateFactor) /* + ScriptMS*/)); sb[32].StatValue = SpareTime; sb[33].StatID = (uint)Stats.SimSleepTime; sb[33].StatValue = (float)(sleepFrameMonitor.GetValue() / realsimfps); //Info about this stat: http://blogs.secondlife.com/message/66098 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; 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 foreach (IScenePresence agent in m_currentScene.GetScenePresences ()) { if (!agent.IsChildAgent) agent.ControllingClient.SendSimStats(simStats); } //Now fix any values that require reseting ResetValues(); } }
private void statsHeartBeat(object sender, EventArgs e) { double totalSumFrameTime; double simulationSumFrameTime; double physicsSumFrameTime; double networkSumFrameTime; float frameDilation; int currentFrame; if (!m_scene.Active) { return; } // Create arrays to hold the statistics for this current scene, // these will be passed to the SimExtraStatsCollector, they are also // sent to the SimStats class SimStatsPacket.StatBlock[] sb = new SimStatsPacket.StatBlock[m_statisticArraySize]; SimStatsPacket.RegionBlock rb = new SimStatsPacket.RegionBlock(); // Know what's not thread safe in Mono... modifying timers. // m_log.Debug("Firing Stats Heart Beat"); lock (m_report) { uint regionFlags = 0; try { if (estateModule == null) { estateModule = m_scene.RequestModuleInterface <IEstateModule>(); } regionFlags = estateModule != null?estateModule.GetRegionFlags() : (uint)0; } catch (Exception) { // leave region flags at 0 } #region various statistic googly moogly int reportedFPS = (int)(m_fps * m_statisticsFPSfactor); // save the reported value so there is something available for llGetRegionFPS lastReportedSimFPS = reportedFPS / m_statsUpdateFactor; // ORIGINAL code commented out until we have time to add our own // statistics to the statistics window //float physfps = ((m_pfps / 1000)); float physfps = m_numberPhysicsFrames * m_statisticsFPSfactor; //if (physfps > 600) //physfps = physfps - (physfps - 600); if (physfps < 0) { physfps = 0; } #endregion m_rootAgents = m_scene.SceneGraph.GetRootAgentCount(); m_childAgents = m_scene.SceneGraph.GetChildAgentCount(); m_numPrim = m_scene.SceneGraph.GetTotalObjectsCount(); m_numGeoPrim = m_scene.SceneGraph.GetTotalPrimObjectsCount(); m_numMesh = m_scene.SceneGraph.GetTotalMeshObjectsCount(); m_activePrim = m_scene.SceneGraph.GetActiveObjectsCount(); m_activeScripts = m_scene.SceneGraph.GetActiveScriptsCount(); // FIXME: Checking for stat sanity is a complex approach. What we really need to do is fix the code // so that stat numbers are always consistent. CheckStatSanity(); //Our time dilation is 0.91 when we're running a full speed, // therefore to make sure we get an appropriate range, // we have to factor in our error. (0.10f * statsUpdateFactor) // multiplies the fix for the error times the amount of times it'll occur a second // / 10 divides the value by the number of times the sim heartbeat runs (10fps) // Then we divide the whole amount by the amount of seconds pass in between stats updates. // 'statsUpdateFactor' is how often stats packets are sent in seconds. Used below to change // values to X-per-second values. uint thisFrame = m_scene.Frame; uint numFrames = thisFrame - m_lastUpdateFrame; float framesUpdated = (float)numFrames * m_statisticsFPSfactor; m_lastUpdateFrame = thisFrame; // Avoid div-by-zero if somehow we've not updated any frames. if (framesUpdated == 0) { framesUpdated = 1; } for (int i = 0; i < m_statisticArraySize; i++) { sb[i] = new SimStatsPacket.StatBlock(); } // Resetting the sums of the frame times to prevent any errors // in calculating the moving average for frame time totalSumFrameTime = 0; simulationSumFrameTime = 0; physicsSumFrameTime = 0; networkSumFrameTime = 0; // Loop through all the frames that were stored for the current // heartbeat to process the moving average of frame times for (int i = 0; i < m_numberFramesStored; i++) { // Sum up each frame time in order to calculate the moving // average of frame time totalSumFrameTime += m_totalFrameTimeMilliseconds[i]; simulationSumFrameTime += m_simulationFrameTimeMilliseconds[i]; physicsSumFrameTime += m_physicsFrameTimeMilliseconds[i]; networkSumFrameTime += m_networkFrameTimeMilliseconds[i]; } // Get the index that represents the current frame based on the next one known; go back // to the last index if next one is stated to restart at 0 if (m_nextLocation == 0) { currentFrame = m_numberFramesStored - 1; } else { currentFrame = m_nextLocation - 1; } // Calculate the frame dilation; which is currently based on the ratio between the sum of the // physics and simulation rate, and the set minimum time to run a scene's frame frameDilation = (float)(m_simulationFrameTimeMilliseconds[currentFrame] + m_physicsFrameTimeMilliseconds[currentFrame]) / m_scene.MinFrameTicks; // ORIGINAL code commented out until we have time to add our own 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[1].StatID = (uint)Stats.SimFPS; sb[1].StatValue = reportedFPS / m_statsUpdateFactor; sb[2].StatID = (uint)Stats.PhysicsFPS; sb[2].StatValue = physfps / m_statsUpdateFactor; sb[3].StatID = (uint)Stats.AgentUpdates; sb[3].StatValue = (m_agentUpdates / m_statsUpdateFactor); sb[4].StatID = (uint)Stats.Agents; sb[4].StatValue = m_rootAgents; sb[5].StatID = (uint)Stats.ChildAgents; sb[5].StatValue = m_childAgents; sb[6].StatID = (uint)Stats.TotalPrim; sb[6].StatValue = m_numPrim; sb[7].StatID = (uint)Stats.ActivePrim; sb[7].StatValue = m_activePrim; // ORIGINAL code commented out until we have time to add our own // statistics to the statistics window sb[8].StatID = (uint)Stats.FrameMS; //sb[8].StatValue = m_frameMS / framesUpdated; sb[8].StatValue = (float)totalSumFrameTime / m_numberFramesStored / m_statisticsFPSfactor; sb[9].StatID = (uint)Stats.NetMS; //sb[9].StatValue = m_netMS / framesUpdated; sb[9].StatValue = (float)networkSumFrameTime / m_numberFramesStored / m_statisticsFPSfactor; sb[10].StatID = (uint)Stats.PhysicsMS; //sb[10].StatValue = m_physicsMS / framesUpdated; sb[10].StatValue = (float)physicsSumFrameTime / m_numberFramesStored / m_statisticsFPSfactor; 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 / m_statisticsFPSfactor; sb[13].StatID = (uint)Stats.InPacketsPerSecond; sb[13].StatValue = (m_inPacketsPerSecond / m_statsUpdateFactor); sb[14].StatID = (uint)Stats.OutPacketsPerSecond; sb[14].StatValue = (m_outPacketsPerSecond / m_statsUpdateFactor); sb[15].StatID = (uint)Stats.UnAckedBytes; sb[15].StatValue = m_unAckedBytes; sb[16].StatID = (uint)Stats.AgentMS; sb[16].StatValue = m_agentMS / framesUpdated; sb[17].StatID = (uint)Stats.PendingDownloads; sb[17].StatValue = m_pendingDownloads; sb[18].StatID = (uint)Stats.PendingUploads; sb[18].StatValue = m_pendingUploads; sb[19].StatID = (uint)Stats.ActiveScripts; sb[19].StatValue = m_activeScripts; sb[20].StatID = (uint)Stats.ScriptLinesPerSecond; sb[20].StatValue = m_scriptLinesPerSecond / m_statsUpdateFactor; sb[21].StatID = (uint)Stats.SimSpareMs; sb[21].StatValue = m_spareMS / framesUpdated; // Current ratio between the sum of physics and sim rate, and the // minimum time to run a scene's frame sb[22].StatID = (uint)Stats.FrameDilation; sb[22].StatValue = frameDilation; // Current number of users currently attemptint to login to region sb[23].StatID = (uint)Stats.UsersLoggingIn; sb[23].StatValue = m_usersLoggingIn; // Total number of geometric primitives in the scene sb[24].StatID = (uint)Stats.TotalGeoPrim; sb[24].StatValue = m_numGeoPrim; // Total number of mesh objects in the scene sb[25].StatID = (uint)Stats.TotalMesh; sb[25].StatValue = m_numMesh; // Current number of threads that XEngine is using 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; } SimStats simStats = new SimStats( ReportingRegion.RegionLocX, ReportingRegion.RegionLocY, regionFlags, (uint)m_objectCapacity, rb, sb, m_scene.RegionInfo.originRegionID); handlerSendStatResult = OnSendStatsResult; if (handlerSendStatResult != null) { handlerSendStatResult(simStats); } // Extra statistics that aren't currently sent to clients lock (m_lastReportedExtraSimStats) { m_lastReportedExtraSimStats[LastReportedObjectUpdateStatName] = m_objectUpdates / m_statsUpdateFactor; m_lastReportedExtraSimStats[SlowFramesStat.ShortName] = (float)SlowFramesStat.Value; Dictionary <string, float> physicsStats = m_scene.PhysicsScene.GetStats(); if (physicsStats != null) { foreach (KeyValuePair <string, float> tuple in physicsStats) { // FIXME: An extremely dirty hack to divide MS stats per frame rather than per second // Need to change things so that stats source can indicate whether they are per second or // per frame. if (tuple.Key.EndsWith("MS")) { m_lastReportedExtraSimStats[tuple.Key] = tuple.Value / framesUpdated; } else { m_lastReportedExtraSimStats[tuple.Key] = tuple.Value / m_statsUpdateFactor; } } } } ResetValues(); } }
private void OnCheck(object sender, ElapsedEventArgs e) { IEstateModule mod = m_scene.RequestModuleInterface <IEstateModule>(); if (AllowDisableScripts && m_statsReporter.LastReportedSimFPS < BaseRateFramesPerSecond * (PercentToBeginShutDownOfServices / 100) && m_statsReporter.LastReportedSimFPS != 0) { //Less than the percent to start shutting things down... Lets kill some stuff if (mod != null) { mod.SetSceneCoreDebug(false, m_scene.RegionInfo.RegionSettings.DisableCollisions, m_scene.RegionInfo.RegionSettings.DisablePhysics); } //These are opposite of what you want the value to be... go figure DisabledScriptStartTime = DateTime.Now; } if (m_scene.RegionInfo.RegionSettings.DisableScripts && AllowDisableScripts && SimZeroFPSStartTime != DateTime.MinValue && //This makes sure we don't screw up the setting if the user disabled physics manually SimZeroFPSStartTime.AddSeconds(TimeAfterToReenableScripts) > DateTime.Now) { DisabledScriptStartTime = DateTime.MinValue; if (mod != null) { mod.SetSceneCoreDebug(true, m_scene.RegionInfo.RegionSettings.DisableCollisions, m_scene.RegionInfo.RegionSettings.DisablePhysics); } //These are opposite of what you want the value to be... go figure } if (m_statsReporter.LastReportedSimFPS == 0 && KillSimOnZeroFPS) { if (SimZeroFPSStartTime == DateTime.MinValue) { SimZeroFPSStartTime = DateTime.Now; } if (SimZeroFPSStartTime.AddMinutes(MinutesBeforeZeroFPSKills) > SimZeroFPSStartTime) { MainConsole.Instance.RunCommand("shutdown"); } } else if (SimZeroFPSStartTime != DateTime.MinValue) { SimZeroFPSStartTime = DateTime.MinValue; } float[] stats = m_scene.RequestModuleInterface <IMonitorModule>().GetRegionStats(m_scene); if (stats[2] < BaseRateFramesPerSecond * (PercentToBeginShutDownOfServices / 100) && stats[2] != 0 && AllowDisablePhysics && !m_scene.RegionInfo.RegionSettings.DisablePhysics) //Don't redisable physics again, physics will be frozen at the last FPS { DisabledPhysicsStartTime = DateTime.Now; if (mod != null) { mod.SetSceneCoreDebug(m_scene.RegionInfo.RegionSettings.DisableScripts, m_scene.RegionInfo.RegionSettings.DisableCollisions, false); } //These are opposite of what you want the value to be... go figure } if (m_scene.RegionInfo.RegionSettings.DisablePhysics && AllowDisablePhysics && DisabledPhysicsStartTime != DateTime.MinValue && //This makes sure we don't screw up the setting if the user disabled physics manually DisabledPhysicsStartTime.AddSeconds(TimeAfterToReenablePhysics) > DateTime.Now) { DisabledPhysicsStartTime = DateTime.MinValue; if (mod != null) { mod.SetSceneCoreDebug(m_scene.RegionInfo.RegionSettings.DisableScripts, m_scene.RegionInfo.RegionSettings.DisableCollisions, true); } //These are opposite of what you want the value to be... go figure } }
private void statsHeartBeat(object sender, EventArgs e) { SimStatsPacket.StatBlock[] sb = new SimStatsPacket.StatBlock[22]; SimStatsPacket.RegionBlock rb = new SimStatsPacket.RegionBlock(); // Know what's not thread safe in Mono... modifying timers. // m_log.Debug("Firing Stats Heart Beat"); lock (m_report) { uint regionFlags = 0; try { if (estateModule == null) { estateModule = m_scene.RequestModuleInterface <IEstateModule>(); } regionFlags = estateModule != null?estateModule.GetRegionFlags() : (uint)0; } catch (Exception) { // leave region flags at 0 } #region various statistic googly moogly // 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); // save the reported value so there is something available for llGetRegionFPS lastReportedSimFPS = reportedFPS / m_statsUpdateFactor; float physfps = ((m_pfps / 1000)); //if (physfps > 600) //physfps = physfps - (physfps - 600); if (physfps < 0) { physfps = 0; } #endregion m_rootAgents = m_scene.SceneGraph.GetRootAgentCount(); m_childAgents = m_scene.SceneGraph.GetChildAgentCount(); m_numPrim = m_scene.SceneGraph.GetTotalObjectsCount(); m_activePrim = m_scene.SceneGraph.GetActiveObjectsCount(); m_activeScripts = m_scene.SceneGraph.GetActiveScriptsCount(); // FIXME: Checking for stat sanity is a complex approach. What we really need to do is fix the code // so that stat numbers are always consistent. CheckStatSanity(); //Our time dilation is 0.91 when we're running a full speed, // therefore to make sure we get an appropriate range, // we have to factor in our error. (0.10f * statsUpdateFactor) // multiplies the fix for the error times the amount of times it'll occur a second // / 10 divides the value by the number of times the sim heartbeat runs (10fps) // Then we divide the whole amount by the amount of seconds pass in between stats updates. // 'statsUpdateFactor' is how often stats packets are sent in seconds. Used below to change // values to X-per-second values. uint thisFrame = m_scene.Frame; float framesUpdated = (float)(thisFrame - m_lastUpdateFrame) * m_reportedFpsCorrectionFactor; m_lastUpdateFrame = thisFrame; // Avoid div-by-zero if somehow we've not updated any frames. if (framesUpdated == 0) { framesUpdated = 1; } for (int i = 0; i < 22; i++) { sb[i] = new SimStatsPacket.StatBlock(); } 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[1].StatID = (uint)Stats.SimFPS; sb[1].StatValue = reportedFPS / m_statsUpdateFactor; sb[2].StatID = (uint)Stats.PhysicsFPS; sb[2].StatValue = physfps / m_statsUpdateFactor; sb[3].StatID = (uint)Stats.AgentUpdates; sb[3].StatValue = (m_agentUpdates / m_statsUpdateFactor); sb[4].StatID = (uint)Stats.Agents; sb[4].StatValue = m_rootAgents; sb[5].StatID = (uint)Stats.ChildAgents; sb[5].StatValue = m_childAgents; sb[6].StatID = (uint)Stats.TotalPrim; sb[6].StatValue = m_numPrim; sb[7].StatID = (uint)Stats.ActivePrim; sb[7].StatValue = m_activePrim; sb[8].StatID = (uint)Stats.FrameMS; sb[8].StatValue = m_frameMS / framesUpdated; sb[9].StatID = (uint)Stats.NetMS; sb[9].StatValue = m_netMS / framesUpdated; sb[10].StatID = (uint)Stats.PhysicsMS; sb[10].StatValue = m_physicsMS / framesUpdated; 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[13].StatID = (uint)Stats.InPacketsPerSecond; sb[13].StatValue = (m_inPacketsPerSecond / m_statsUpdateFactor); sb[14].StatID = (uint)Stats.OutPacketsPerSecond; sb[14].StatValue = (m_outPacketsPerSecond / m_statsUpdateFactor); sb[15].StatID = (uint)Stats.UnAckedBytes; sb[15].StatValue = m_unAckedBytes; sb[16].StatID = (uint)Stats.AgentMS; sb[16].StatValue = m_agentMS / framesUpdated; sb[17].StatID = (uint)Stats.PendingDownloads; sb[17].StatValue = m_pendingDownloads; sb[18].StatID = (uint)Stats.PendingUploads; sb[18].StatValue = m_pendingUploads; sb[19].StatID = (uint)Stats.ActiveScripts; sb[19].StatValue = m_activeScripts; sb[20].StatID = (uint)Stats.ScriptLinesPerSecond; sb[20].StatValue = m_scriptLinesPerSecond / m_statsUpdateFactor; sb[21].StatID = (uint)Stats.SimSpareMs; sb[21].StatValue = m_spareMS / framesUpdated; for (int i = 0; i < 22; i++) { lastReportedSimStats[i] = sb[i].StatValue; } SimStats simStats = new SimStats( ReportingRegion.RegionLocX, ReportingRegion.RegionLocY, regionFlags, (uint)m_objectCapacity, rb, sb, m_scene.RegionInfo.originRegionID); handlerSendStatResult = OnSendStatsResult; if (handlerSendStatResult != null) { handlerSendStatResult(simStats); } // Extra statistics that aren't currently sent to clients lock (m_lastReportedExtraSimStats) { m_lastReportedExtraSimStats[LastReportedObjectUpdateStatName] = m_objectUpdates / m_statsUpdateFactor; Dictionary <string, float> physicsStats = m_scene.PhysicsScene.GetStats(); if (physicsStats != null) { foreach (KeyValuePair <string, float> tuple in physicsStats) { // FIXME: An extremely dirty hack to divide MS stats per frame rather than per second // Need to change things so that stats source can indicate whether they are per second or // per frame. if (tuple.Key.EndsWith("MS")) { m_lastReportedExtraSimStats[tuple.Key] = tuple.Value / framesUpdated; } else { m_lastReportedExtraSimStats[tuple.Key] = tuple.Value / m_statsUpdateFactor; } } } } ResetValues(); } }
private void statsHeartBeat(object sender, EventArgs e) { if (statsRunning) { return; } try { statsRunning = true; SimStatsPacket.StatBlock[] sb = new SimStatsPacket.StatBlock[21]; SimStatsPacket.RegionBlock rb = new SimStatsPacket.RegionBlock(); uint regionFlags = 0; try { if (estateModule == null) { estateModule = m_scene.RequestModuleInterface <IEstateModule>(); } regionFlags = estateModule != null?estateModule.GetRegionFlags() : (uint)0; } catch (Exception) { // leave region flags at 0 } float simfps = (int)m_fps; // save the reported value so there is something available for llGetRegionFPS lastReportedSimFPS = (float)simfps / statsUpdateFactor; float physfps = m_pfps; if (physfps < 0) { physfps = 0; } //Our time dilation is 0.91 when we're running a full speed, // therefore to make sure we get an appropriate range, // we have to factor in our error. (0.10f * statsUpdateFactor) // multiplies the fix for the error times the amount of times it'll occur a second // / 10 divides the value by the number of times the sim heartbeat runs (10fps) // Then we divide the whole amount by the amount of seconds pass in between stats updates. for (int i = 0; i < 21; i++) { sb[i] = new SimStatsPacket.StatBlock(); } 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[1].StatID = (uint)Stats.SimFPS; sb[1].StatValue = simfps / statsUpdateFactor; sb[2].StatID = (uint)Stats.PhysicsFPS; sb[2].StatValue = physfps; sb[3].StatID = (uint)Stats.AgentUpdates; sb[3].StatValue = (m_agentUpdates / statsUpdateFactor); sb[4].StatID = (uint)Stats.Agents; sb[4].StatValue = m_rootAgents; sb[5].StatID = (uint)Stats.ChildAgents; sb[5].StatValue = m_childAgents; sb[6].StatID = (uint)Stats.TotalPrim; sb[6].StatValue = m_numPrim; sb[7].StatID = (uint)Stats.ActivePrim; sb[7].StatValue = m_activePrim; sb[8].StatID = (uint)Stats.FrameMS; sb[8].StatValue = m_frameMS / statsUpdateFactor; sb[9].StatID = (uint)Stats.NetMS; sb[9].StatValue = m_netMS / statsUpdateFactor; sb[10].StatID = (uint)Stats.PhysicsMS; sb[10].StatValue = m_physicsMS / statsUpdateFactor; sb[11].StatID = (uint)Stats.ImageMS; sb[11].StatValue = m_imageMS / statsUpdateFactor; sb[12].StatID = (uint)Stats.OtherMS; sb[12].StatValue = m_otherMS / statsUpdateFactor; sb[13].StatID = (uint)Stats.InPacketsPerSecond; sb[13].StatValue = (m_inPacketsPerSecond); sb[14].StatID = (uint)Stats.OutPacketsPerSecond; sb[14].StatValue = (m_outPacketsPerSecond / statsUpdateFactor); sb[15].StatID = (uint)Stats.UnAckedBytes; sb[15].StatValue = m_unAckedBytes; sb[16].StatID = (uint)Stats.AgentMS; sb[16].StatValue = m_agentMS / statsUpdateFactor; sb[17].StatID = (uint)Stats.PendingDownloads; sb[17].StatValue = m_pendingDownloads; sb[18].StatID = (uint)Stats.PendingUploads; sb[18].StatValue = m_pendingUploads; sb[19].StatID = (uint)Stats.ActiveScripts; sb[19].StatValue = m_activeScripts; sb[20].StatID = (uint)Stats.ScriptLinesPerSecond; sb[20].StatValue = m_scriptLinesPerSecond / statsUpdateFactor; SimStats simStats = new SimStats( ReportingRegion.RegionLocX, ReportingRegion.RegionLocY, regionFlags, (uint)objectCapacity, rb, sb, m_scene.RegionInfo.originRegionID); handlerSendStatResult = OnSendStatsResult; if (handlerSendStatResult != null) { handlerSendStatResult(simStats); } resetvalues(); } finally { statsRunning = false; } }
/// <summary> /// The god has requested that we update something in the region configuration /// </summary> /// <param name="client"></param> /// <param name="BillableFactor"></param> /// <param name="PricePerMeter"></param> /// <param name="EstateID"></param> /// <param name="RegionFlags"></param> /// <param name="SimName"></param> /// <param name="RedirectX"></param> /// <param name="RedirectY"></param> public void GodUpdateRegionInfoUpdate(IClientAPI client, float BillableFactor, int PricePerMeter, ulong EstateID, ulong RegionFlags, byte [] SimName, int RedirectX, int RedirectY) { IEstateConnector estateConnector = Framework.Utilities.DataManager.RequestPlugin <IEstateConnector> (); //Check god perms if (!client.Scene.Permissions.IsGod(client.AgentId)) { return; } string oldRegionName = client.Scene.RegionInfo.RegionName; //Update their current region with new information if (Utils.BytesToString(SimName) != oldRegionName) { client.Scene.RegionInfo.RegionName = Utils.BytesToString(SimName); MainConsole.Instance.InfoFormat("[REGION GOD] Region {0} has been renamed to {1}", oldRegionName, Utils.BytesToString(SimName)); client.SendAgentAlertMessage("Region has been renamed to " + Utils.BytesToString(SimName), true); } // Save the old region locations int oldRegionLocX = client.Scene.RegionInfo.RegionLocX; int oldRegionLocY = client.Scene.RegionInfo.RegionLocY; int newRegionLocX = client.Scene.RegionInfo.RegionLocX; int newRegionLocY = client.Scene.RegionInfo.RegionLocY; //Set the region loc X and Y if (RedirectX != 0) { client.Scene.RegionInfo.RegionLocX = RedirectX * Constants.RegionSize; newRegionLocX = RedirectX; } if (RedirectY != 0) { client.Scene.RegionInfo.RegionLocY = RedirectY * Constants.RegionSize; newRegionLocY = RedirectY; } // Check if there's changes to display the new coords on the console and inworld if (newRegionLocX != oldRegionLocX || newRegionLocY != oldRegionLocY) { MainConsole.Instance.InfoFormat("[REGION GOD] Region {0} has been moved from {1},{2} to {3},{4}", client.Scene.RegionInfo.RegionName, (oldRegionLocX / Constants.RegionSize), (oldRegionLocY / Constants.RegionSize), (client.Scene.RegionInfo.RegionLocX / Constants.RegionSize), (client.Scene.RegionInfo.RegionLocY / Constants.RegionSize)); client.SendAgentAlertMessage("Region has been moved from " + (oldRegionLocX / Constants.RegionSize) + "," + (oldRegionLocY / Constants.RegionSize) + " to " + newRegionLocX + "," + newRegionLocY, true); } //Update the estate ID if (client.Scene.RegionInfo.EstateSettings.EstateID != EstateID) { bool changed = estateConnector.LinkRegion(client.Scene.RegionInfo.RegionID, (int)EstateID); if (!changed) { client.SendAgentAlertMessage("Unable to connect to the given estate.", false); } else { client.Scene.RegionInfo.EstateSettings.EstateID = (uint)EstateID; estateConnector.SaveEstateSettings(client.Scene.RegionInfo.EstateSettings); } } //Set the other settings client.Scene.RegionInfo.EstateSettings.BillableFactor = BillableFactor; client.Scene.RegionInfo.EstateSettings.PricePerMeter = PricePerMeter; client.Scene.RegionInfo.EstateSettings.SetFromFlags(RegionFlags); client.Scene.RegionInfo.RegionSettings.AllowDamage = ((RegionFlags & (ulong)OpenMetaverse.RegionFlags.AllowDamage) == (ulong)OpenMetaverse.RegionFlags.AllowDamage); client.Scene.RegionInfo.RegionSettings.FixedSun = ((RegionFlags & (ulong)OpenMetaverse.RegionFlags.SunFixed) == (ulong)OpenMetaverse.RegionFlags.SunFixed); client.Scene.RegionInfo.RegionSettings.BlockTerraform = ((RegionFlags & (ulong)OpenMetaverse.RegionFlags.BlockTerraform) == (ulong)OpenMetaverse.RegionFlags.BlockTerraform); client.Scene.RegionInfo.RegionSettings.Sandbox = ((RegionFlags & (ulong)OpenMetaverse.RegionFlags.Sandbox) == (ulong)OpenMetaverse.RegionFlags.Sandbox); //Update skipping scripts/physics/collisions IEstateModule mod = client.Scene.RequestModuleInterface <IEstateModule> (); if (mod != null) { mod.SetSceneCoreDebug( ((RegionFlags & (ulong)OpenMetaverse.RegionFlags.SkipScripts) == (ulong)OpenMetaverse.RegionFlags.SkipScripts), ((RegionFlags & (ulong)OpenMetaverse.RegionFlags.SkipCollisions) == (ulong)OpenMetaverse.RegionFlags.SkipCollisions), ((RegionFlags & (ulong)OpenMetaverse.RegionFlags.SkipPhysics) == (ulong)OpenMetaverse.RegionFlags.SkipPhysics)); } //Save the changes estateConnector.SaveEstateSettings(client.Scene.RegionInfo.EstateSettings); //Tell the clients to update all references to the new settings foreach (IScenePresence sp in client.Scene.GetScenePresences()) { HandleRegionInfoRequest(sp.ControllingClient, client.Scene); } //Update the grid server as well IGridRegisterModule gridRegisterModule = client.Scene.RequestModuleInterface <IGridRegisterModule> (); if (gridRegisterModule != null) { gridRegisterModule.UpdateGridRegion(client.Scene); } }
private void statsHeartBeat(object sender, EventArgs e) { SimStatsPacket.StatBlock[] sb = new SimStatsPacket.StatBlock[23]; SimStatsPacket.RegionBlock rb = new SimStatsPacket.RegionBlock(); float factorByframe; float factor; // Know what's not thread safe in Mono... modifying timers. // m_log.Debug("Firing Stats Heart Beat"); lock (m_report) { uint regionFlags = 0; try { if (estateModule == null) estateModule = m_scene.RequestModuleInterface<IEstateModule>(); regionFlags = estateModule != null ? estateModule.GetRegionFlags() : (uint) 0; } catch (Exception) { // leave region flags at 0 } #region various statistic googly moogly // Our FPS is actually 10fps, so multiplying by 5 to get the amount that people expect there // 0-50 is pretty close to 0-45 // show real float simfps = (int) ((m_fps)); if (simfps == 0.0) simfps = 10; // we still don't have stats on this // factor to convert things to per second factor = 1 / statsUpdateFactor; // factor to convert things for time per frame need because how acumulators work // factorByframe = factor / simfps; factorByframe = 1 / simfps; // save the reported value so there is something available for llGetRegionFPS lastReportedSimFPS = simfps * factor; float physfps = ((m_pfps)); if (physfps < 0) physfps = 0; #endregion for (int i = 0; i < 23; i++) { sb[i] = new SimStatsPacket.StatBlock(); } 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[1].StatID = (uint) Stats.SimFPS; sb[1].StatValue = simfps * factor; sb[2].StatID = (uint) Stats.PhysicsFPS; sb[2].StatValue = physfps * factor; sb[3].StatID = (uint) Stats.AgentUpdates; sb[3].StatValue = (m_agentUpdates * factor); sb[4].StatID = (uint) Stats.Agents; sb[4].StatValue = m_rootAgents; sb[5].StatID = (uint) Stats.ChildAgents; sb[5].StatValue = m_childAgents; sb[6].StatID = (uint) Stats.TotalPrim; sb[6].StatValue = m_numPrim; sb[7].StatID = (uint) Stats.ActivePrim; sb[7].StatValue = m_activePrim; sb[8].StatID = (uint)Stats.FrameMS; // sb[8].StatValue = m_frameMS * factorByframe; float simFrameTime = 1000.0f / (simfps * factor); sb[8].StatValue = simFrameTime; sb[9].StatID = (uint)Stats.NetMS; sb[9].StatValue = m_netMS * factorByframe; sb[10].StatID = (uint)Stats.PhysicsMS; sb[10].StatValue = m_physicsMS * factorByframe; sb[11].StatID = (uint)Stats.ImageMS ; sb[11].StatValue = m_imageMS * factorByframe; sb[12].StatID = (uint)Stats.OtherMS; float othertmp = m_frameMS - m_physicsMS - m_imageMS - m_netMS - m_agentMS; if (othertmp < 0) othertmp = 0; sb[12].StatValue = othertmp * factorByframe; sb[13].StatID = (uint)Stats.InPacketsPerSecond; sb[13].StatValue = (m_inPacketsPerSecond * factor); sb[14].StatID = (uint)Stats.OutPacketsPerSecond; sb[14].StatValue = (m_outPacketsPerSecond * factor); sb[15].StatID = (uint)Stats.UnAckedBytes; sb[15].StatValue = m_unAckedBytes; sb[16].StatID = (uint)Stats.AgentMS; sb[16].StatValue = m_agentMS * factorByframe; sb[17].StatID = (uint)Stats.PendingDownloads; sb[17].StatValue = m_pendingDownloads; sb[18].StatID = (uint)Stats.PendingUploads; sb[18].StatValue = m_pendingUploads; sb[19].StatID = (uint)Stats.ActiveScripts; sb[19].StatValue = m_activeScripts; sb[20].StatID = (uint)Stats.ScriptLinesPerSecond; sb[20].StatValue = m_scriptLinesPerSecond * factor; float spare = m_scene.m_simframetime - m_frameMS * factorByframe; if (spare < 0) spare = 0; sb[21].StatID = (uint)Stats.SimSpareTime; sb[21].StatValue = spare; sb[22].StatID = (uint)Stats.SimSleepTime; sb[22].StatValue = m_sleeptimeMS * factorByframe; for (int i = 0; i < 23; i++) { lastReportedSimStats[i] = sb[i].StatValue; } SimStats simStats = new SimStats( ReportingRegion.RegionLocX, ReportingRegion.RegionLocY, regionFlags, (uint)m_objectCapacity, rb, sb, m_scene.RegionInfo.originRegionID); handlerSendStatResult = OnSendStatsResult; if (handlerSendStatResult != null) { handlerSendStatResult(simStats); } // Extra statistics that aren't currently sent to clients LastReportedObjectUpdates = m_objectUpdates / statsUpdateFactor; resetvalues(); } }
public void RegionLoaded(Scene scene) { if (!Enabled) { return; } m_estateModule = scene.RequestModuleInterface <IEstateModule>(); if (m_estateModule == null) { Enabled = false; return; } m_eventQueue = m_scene.RequestModuleInterface <IEventQueue>(); if (m_eventQueue == null) { Enabled = false; return; } m_assetService = m_scene.AssetService; if (m_assetService == null) { Enabled = false; return; } m_landChannel = m_scene.LandChannel; if (m_landChannel == null) { Enabled = false; return; } if (m_DefaultEnv == null) { AssetBase defEnv = m_assetService.Get(m_defaultDayAssetID); if (defEnv != null) { byte[] envData = defEnv.Data; try { OSD oenv = OSDParser.Deserialize(envData); m_DefaultEnv = new ViewerEnvironment(); m_DefaultEnv.CycleFromOSD(oenv); } catch (Exception e) { m_DefaultEnv = null; m_log.WarnFormat("[Environment {0}]: failed to decode default environment asset: {1}", m_scene.Name, e.Message); } } } if (m_DefaultEnv == null) { m_DefaultEnv = new ViewerEnvironment(); } string senv = scene.SimulationDataService.LoadRegionEnvironmentSettings(scene.RegionInfo.RegionID); if (!string.IsNullOrEmpty(senv)) { try { OSD oenv = OSDParser.Deserialize(senv); ViewerEnvironment VEnv = new ViewerEnvironment(); if (oenv is OSDArray) { VEnv.FromWLOSD(oenv); } else { VEnv.FromOSD(oenv); } scene.RegionEnvironment = VEnv; m_regionEnvVersion = VEnv.version; } catch (Exception e) { m_log.ErrorFormat("[Environment {0}] failed to load initial Environment {1}", m_scene.Name, e.Message); scene.RegionEnvironment = null; m_regionEnvVersion = -1; } } else { scene.RegionEnvironment = null; m_regionEnvVersion = -1; } m_framets = 0; UpdateEnvTime(); scene.EventManager.OnRegisterCaps += OnRegisterCaps; scene.EventManager.OnFrame += UpdateEnvTime; scene.EventManager.OnAvatarEnteringNewParcel += OnAvatarEnteringNewParcel; }
private void statsHeartBeat(object sender, EventArgs e) { SimStatsPacket.StatBlock[] sb = new SimStatsPacket.StatBlock[22]; SimStatsPacket.RegionBlock rb = new SimStatsPacket.RegionBlock(); // Know what's not thread safe in Mono... modifying timers. // m_log.Debug("Firing Stats Heart Beat"); lock (m_report) { uint regionFlags = 0; try { if (estateModule == null) estateModule = m_scene.RequestModuleInterface<IEstateModule>(); regionFlags = estateModule != null ? estateModule.GetRegionFlags() : (uint) 0; } catch (Exception) { // leave region flags at 0 } #region various statistic googly moogly // 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); // save the reported value so there is something available for llGetRegionFPS lastReportedSimFPS = reportedFPS / m_statsUpdateFactor; float physfps = ((m_pfps / 1000)); //if (physfps > 600) //physfps = physfps - (physfps - 600); if (physfps < 0) physfps = 0; #endregion m_rootAgents = m_scene.SceneGraph.GetRootAgentCount(); m_childAgents = m_scene.SceneGraph.GetChildAgentCount(); m_numPrim = m_scene.SceneGraph.GetTotalObjectsCount(); m_activePrim = m_scene.SceneGraph.GetActiveObjectsCount(); m_activeScripts = m_scene.SceneGraph.GetActiveScriptsCount(); // FIXME: Checking for stat sanity is a complex approach. What we really need to do is fix the code // so that stat numbers are always consistent. CheckStatSanity(); //Our time dilation is 0.91 when we're running a full speed, // therefore to make sure we get an appropriate range, // we have to factor in our error. (0.10f * statsUpdateFactor) // multiplies the fix for the error times the amount of times it'll occur a second // / 10 divides the value by the number of times the sim heartbeat runs (10fps) // Then we divide the whole amount by the amount of seconds pass in between stats updates. // 'statsUpdateFactor' is how often stats packets are sent in seconds. Used below to change // values to X-per-second values. uint thisFrame = m_scene.Frame; float framesUpdated = (float)(thisFrame - m_lastUpdateFrame) * m_reportedFpsCorrectionFactor; m_lastUpdateFrame = thisFrame; // Avoid div-by-zero if somehow we've not updated any frames. if (framesUpdated == 0) framesUpdated = 1; for (int i = 0; i < 22; i++) { sb[i] = new SimStatsPacket.StatBlock(); } 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[1].StatID = (uint) Stats.SimFPS; sb[1].StatValue = reportedFPS / m_statsUpdateFactor; sb[2].StatID = (uint) Stats.PhysicsFPS; sb[2].StatValue = physfps / m_statsUpdateFactor; sb[3].StatID = (uint) Stats.AgentUpdates; sb[3].StatValue = (m_agentUpdates / m_statsUpdateFactor); sb[4].StatID = (uint) Stats.Agents; sb[4].StatValue = m_rootAgents; sb[5].StatID = (uint) Stats.ChildAgents; sb[5].StatValue = m_childAgents; sb[6].StatID = (uint) Stats.TotalPrim; sb[6].StatValue = m_numPrim; sb[7].StatID = (uint) Stats.ActivePrim; sb[7].StatValue = m_activePrim; sb[8].StatID = (uint)Stats.FrameMS; sb[8].StatValue = m_frameMS / framesUpdated; sb[9].StatID = (uint)Stats.NetMS; sb[9].StatValue = m_netMS / framesUpdated; sb[10].StatID = (uint)Stats.PhysicsMS; sb[10].StatValue = m_physicsMS / framesUpdated; 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[13].StatID = (uint)Stats.InPacketsPerSecond; sb[13].StatValue = (m_inPacketsPerSecond / m_statsUpdateFactor); sb[14].StatID = (uint)Stats.OutPacketsPerSecond; sb[14].StatValue = (m_outPacketsPerSecond / m_statsUpdateFactor); sb[15].StatID = (uint)Stats.UnAckedBytes; sb[15].StatValue = m_unAckedBytes; sb[16].StatID = (uint)Stats.AgentMS; sb[16].StatValue = m_agentMS / framesUpdated; sb[17].StatID = (uint)Stats.PendingDownloads; sb[17].StatValue = m_pendingDownloads; sb[18].StatID = (uint)Stats.PendingUploads; sb[18].StatValue = m_pendingUploads; sb[19].StatID = (uint)Stats.ActiveScripts; sb[19].StatValue = m_activeScripts; sb[20].StatID = (uint)Stats.ScriptLinesPerSecond; sb[20].StatValue = m_scriptLinesPerSecond / m_statsUpdateFactor; sb[21].StatID = (uint)Stats.SimSpareMs; sb[21].StatValue = m_spareMS / framesUpdated; for (int i = 0; i < 22; i++) { lastReportedSimStats[i] = sb[i].StatValue; } SimStats simStats = new SimStats( ReportingRegion.RegionLocX, ReportingRegion.RegionLocY, regionFlags, (uint)m_objectCapacity, rb, sb, m_scene.RegionInfo.originRegionID); handlerSendStatResult = OnSendStatsResult; if (handlerSendStatResult != null) { handlerSendStatResult(simStats); } // Extra statistics that aren't currently sent to clients lock (m_lastReportedExtraSimStats) { m_lastReportedExtraSimStats[LastReportedObjectUpdateStatName] = m_objectUpdates / m_statsUpdateFactor; m_lastReportedExtraSimStats[SlowFramesStat.ShortName] = (float)SlowFramesStat.Value; Dictionary<string, float> physicsStats = m_scene.PhysicsScene.GetStats(); if (physicsStats != null) { foreach (KeyValuePair<string, float> tuple in physicsStats) { // FIXME: An extremely dirty hack to divide MS stats per frame rather than per second // Need to change things so that stats source can indicate whether they are per second or // per frame. if (tuple.Key.EndsWith("MS")) m_lastReportedExtraSimStats[tuple.Key] = tuple.Value / framesUpdated; else m_lastReportedExtraSimStats[tuple.Key] = tuple.Value / m_statsUpdateFactor; } } } ResetValues(); } }
/// <summary> /// The god has requested that we update something in the region configs /// </summary> /// <param name="client"></param> /// <param name="BillableFactor"></param> /// <param name="PricePerMeter"></param> /// <param name="EstateID"></param> /// <param name="RegionFlags"></param> /// <param name="SimName"></param> /// <param name="RedirectX"></param> /// <param name="RedirectY"></param> public void GodUpdateRegionInfoUpdate(IClientAPI client, float BillableFactor, int PricePerMeter, ulong EstateID, ulong RegionFlags, byte[] SimName, int RedirectX, int RedirectY) { //Check god perms if (!client.Scene.Permissions.IsGod(client.AgentId)) { return; } //Update their current region with new information client.Scene.RegionInfo.RegionName = Utils.BytesToString(SimName); //Set the region loc X and Y if (RedirectX != 0) { client.Scene.RegionInfo.RegionLocX = RedirectX * Constants.RegionSize; } if (RedirectY != 0) { client.Scene.RegionInfo.RegionLocY = RedirectY * Constants.RegionSize; } //Update the estate ID if (client.Scene.RegionInfo.EstateSettings.EstateID != EstateID) { bool changed = Framework.Utilities.DataManager.RequestPlugin <IEstateConnector>().LinkRegion( client.Scene.RegionInfo.RegionID, (int)EstateID); if (!changed) { client.SendAgentAlertMessage("Unable to connect to the given estate.", false); } else { client.Scene.RegionInfo.EstateSettings.EstateID = (uint)EstateID; Aurora.Framework.Utilities.DataManager.RequestPlugin <IEstateConnector>(). SaveEstateSettings(client.Scene.RegionInfo.EstateSettings); } } //Set the other settings client.Scene.RegionInfo.EstateSettings.BillableFactor = BillableFactor; client.Scene.RegionInfo.EstateSettings.PricePerMeter = PricePerMeter; client.Scene.RegionInfo.EstateSettings.SetFromFlags(RegionFlags); client.Scene.RegionInfo.RegionSettings.AllowDamage = ((RegionFlags & (ulong)OpenMetaverse.RegionFlags.AllowDamage) == (ulong)OpenMetaverse.RegionFlags.AllowDamage); client.Scene.RegionInfo.RegionSettings.FixedSun = ((RegionFlags & (ulong)OpenMetaverse.RegionFlags.SunFixed) == (ulong)OpenMetaverse.RegionFlags.SunFixed); client.Scene.RegionInfo.RegionSettings.BlockTerraform = ((RegionFlags & (ulong)OpenMetaverse.RegionFlags.BlockTerraform) == (ulong)OpenMetaverse.RegionFlags.BlockTerraform); client.Scene.RegionInfo.RegionSettings.Sandbox = ((RegionFlags & (ulong)OpenMetaverse.RegionFlags.Sandbox) == (ulong)OpenMetaverse.RegionFlags.Sandbox); //Update skipping scripts/physics/collisions IEstateModule mod = client.Scene.RequestModuleInterface <IEstateModule>(); if (mod != null) { mod.SetSceneCoreDebug( ((RegionFlags & (ulong)OpenMetaverse.RegionFlags.SkipScripts) == (ulong)OpenMetaverse.RegionFlags.SkipScripts), ((RegionFlags & (ulong)OpenMetaverse.RegionFlags.SkipCollisions) == (ulong)OpenMetaverse.RegionFlags.SkipCollisions), ((RegionFlags & (ulong)OpenMetaverse.RegionFlags.SkipPhysics) == (ulong)OpenMetaverse.RegionFlags.SkipPhysics)); } //Save the changes Aurora.Framework.Utilities.DataManager.RequestPlugin <IEstateConnector>(). SaveEstateSettings(client.Scene.RegionInfo.EstateSettings); //Tell the clients to update all references to the new settings foreach (IScenePresence sp in client.Scene.GetScenePresences()) { HandleRegionInfoRequest(sp.ControllingClient, client.Scene); } //Update the grid server as well IGridRegisterModule gridRegisterModule = client.Scene.RequestModuleInterface <IGridRegisterModule>(); if (gridRegisterModule != null) { gridRegisterModule.UpdateGridRegion(client.Scene); } }
private void statsHeartBeat(object sender, EventArgs e) { double totalSumFrameTime; double simulationSumFrameTime; double physicsSumFrameTime; double networkSumFrameTime; float frameDilation; int currentFrame; if (!m_scene.Active) return; // Create arrays to hold the statistics for this current scene, // these will be passed to the SimExtraStatsCollector, they are also // sent to the SimStats class SimStatsPacket.StatBlock[] sb = new SimStatsPacket.StatBlock[m_statisticArraySize]; SimStatsPacket.RegionBlock rb = new SimStatsPacket.RegionBlock(); // Know what's not thread safe in Mono... modifying timers. // m_log.Debug("Firing Stats Heart Beat"); lock (m_report) { uint regionFlags = 0; try { if (estateModule == null) estateModule = m_scene.RequestModuleInterface<IEstateModule>(); regionFlags = estateModule != null ? estateModule.GetRegionFlags() : (uint) 0; } catch (Exception) { // leave region flags at 0 } #region various statistic googly moogly // 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 lastReportedSimFPS = reportedFPS / m_statsUpdateFactor; // ORIGINAL code commented out until we have time to add our own // statistics to the statistics window //float physfps = ((m_pfps / 1000)); float physfps = m_numberPhysicsFrames; //if (physfps > 600) //physfps = physfps - (physfps - 600); if (physfps < 0) physfps = 0; #endregion m_rootAgents = m_scene.SceneGraph.GetRootAgentCount(); m_childAgents = m_scene.SceneGraph.GetChildAgentCount(); m_numPrim = m_scene.SceneGraph.GetTotalObjectsCount(); m_numGeoPrim = m_scene.SceneGraph.GetTotalPrimObjectsCount(); m_numMesh = m_scene.SceneGraph.GetTotalMeshObjectsCount(); m_activePrim = m_scene.SceneGraph.GetActiveObjectsCount(); m_activeScripts = m_scene.SceneGraph.GetActiveScriptsCount(); // FIXME: Checking for stat sanity is a complex approach. What we really need to do is fix the code // so that stat numbers are always consistent. CheckStatSanity(); //Our time dilation is 0.91 when we're running a full speed, // therefore to make sure we get an appropriate range, // we have to factor in our error. (0.10f * statsUpdateFactor) // multiplies the fix for the error times the amount of times it'll occur a second // / 10 divides the value by the number of times the sim heartbeat runs (10fps) // Then we divide the whole amount by the amount of seconds pass in between stats updates. // 'statsUpdateFactor' is how often stats packets are sent in seconds. Used below to change // values to X-per-second values. uint thisFrame = m_scene.Frame; 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. if (framesUpdated == 0) framesUpdated = 1; for (int i = 0; i < m_statisticArraySize; i++) { sb[i] = new SimStatsPacket.StatBlock(); } // Resetting the sums of the frame times to prevent any errors // in calculating the moving average for frame time totalSumFrameTime = 0; simulationSumFrameTime = 0; physicsSumFrameTime = 0; networkSumFrameTime = 0; // Loop through all the frames that were stored for the current // heartbeat to process the moving average of frame times for (int i = 0; i < m_numberFramesStored; i++) { // Sum up each frame time in order to calculate the moving // average of frame time totalSumFrameTime += m_totalFrameTimeMilliseconds[i]; simulationSumFrameTime += m_simulationFrameTimeMilliseconds[i]; physicsSumFrameTime += m_physicsFrameTimeMilliseconds[i]; networkSumFrameTime += m_networkFrameTimeMilliseconds[i]; } // Get the index that represents the current frame based on the next one known; go back // to the last index if next one is stated to restart at 0 if (m_nextLocation == 0) currentFrame = m_numberFramesStored - 1; else currentFrame = m_nextLocation - 1; // Calculate the frame dilation; which is currently based on the ratio between the sum of the // physics and simulation rate, and the set minimum time to run a scene's frame frameDilation = (float)(m_simulationFrameTimeMilliseconds[currentFrame] + m_physicsFrameTimeMilliseconds[currentFrame]) / m_scene.MinFrameTicks; // ORIGINAL code commented out until we have time to add our own 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[1].StatID = (uint) Stats.SimFPS; sb[1].StatValue = reportedFPS / m_statsUpdateFactor; sb[2].StatID = (uint) Stats.PhysicsFPS; sb[2].StatValue = physfps / m_statsUpdateFactor; sb[3].StatID = (uint) Stats.AgentUpdates; sb[3].StatValue = (m_agentUpdates / m_statsUpdateFactor); sb[4].StatID = (uint) Stats.Agents; sb[4].StatValue = m_rootAgents; sb[5].StatID = (uint) Stats.ChildAgents; sb[5].StatValue = m_childAgents; sb[6].StatID = (uint) Stats.TotalPrim; sb[6].StatValue = m_numPrim; sb[7].StatID = (uint) Stats.ActivePrim; sb[7].StatValue = m_activePrim; // ORIGINAL code commented out until we have time to add our own // 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[9].StatID = (uint)Stats.NetMS; //sb[9].StatValue = m_netMS / framesUpdated; 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[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[13].StatID = (uint)Stats.InPacketsPerSecond; sb[13].StatValue = (m_inPacketsPerSecond / m_statsUpdateFactor); sb[14].StatID = (uint)Stats.OutPacketsPerSecond; sb[14].StatValue = (m_outPacketsPerSecond / m_statsUpdateFactor); sb[15].StatID = (uint)Stats.UnAckedBytes; sb[15].StatValue = m_unAckedBytes; sb[16].StatID = (uint)Stats.AgentMS; sb[16].StatValue = m_agentMS / framesUpdated; sb[17].StatID = (uint)Stats.PendingDownloads; sb[17].StatValue = m_pendingDownloads; sb[18].StatID = (uint)Stats.PendingUploads; sb[18].StatValue = m_pendingUploads; sb[19].StatID = (uint)Stats.ActiveScripts; sb[19].StatValue = m_activeScripts; sb[20].StatID = (uint)Stats.ScriptLinesPerSecond; sb[20].StatValue = m_scriptLinesPerSecond / m_statsUpdateFactor; sb[21].StatID = (uint)Stats.SimSpareMs; sb[21].StatValue = m_spareMS / framesUpdated; // Current ratio between the sum of physics and sim rate, and the // minimum time to run a scene's frame sb[22].StatID = (uint)Stats.FrameDilation; sb[22].StatValue = frameDilation; // Current number of users currently attemptint to login to region sb[23].StatID = (uint)Stats.UsersLoggingIn; sb[23].StatValue = m_usersLoggingIn; // Total number of geometric primitives in the scene sb[24].StatID = (uint)Stats.TotalGeoPrim; sb[24].StatValue = m_numGeoPrim; // Total number of mesh objects in the scene sb[25].StatID = (uint)Stats.TotalMesh; sb[25].StatValue = m_numMesh; // Current number of threads that XEngine is using 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; } SimStats simStats = new SimStats( ReportingRegion.RegionLocX, ReportingRegion.RegionLocY, regionFlags, (uint)m_objectCapacity, rb, sb, m_scene.RegionInfo.originRegionID); handlerSendStatResult = OnSendStatsResult; if (handlerSendStatResult != null) { handlerSendStatResult(simStats); } // Extra statistics that aren't currently sent to clients lock (m_lastReportedExtraSimStats) { m_lastReportedExtraSimStats[LastReportedObjectUpdateStatName] = m_objectUpdates / m_statsUpdateFactor; m_lastReportedExtraSimStats[SlowFramesStat.ShortName] = (float)SlowFramesStat.Value; Dictionary<string, float> physicsStats = m_scene.PhysicsScene.GetStats(); if (physicsStats != null) { foreach (KeyValuePair<string, float> tuple in physicsStats) { // FIXME: An extremely dirty hack to divide MS stats per frame rather than per second // Need to change things so that stats source can indicate whether they are per second or // per frame. if (tuple.Key.EndsWith("MS")) m_lastReportedExtraSimStats[tuple.Key] = tuple.Value / framesUpdated; else m_lastReportedExtraSimStats[tuple.Key] = tuple.Value / m_statsUpdateFactor; } } } ResetValues(); } }
protected void buildInitialRegionBlock() { rb = new SimStatsPacket.RegionBlock(); uint regionFlags = 0; try { if (m_estateModule == null) m_estateModule = m_currentScene.RequestModuleInterface<IEstateModule>(); regionFlags = m_estateModule != null ? (uint)m_estateModule.GetRegionFlags() : 0; } catch (Exception) { // leave region flags at 0 } rb.ObjectCapacity = (uint) m_currentScene.RegionInfo.ObjectCapacity; rb.RegionFlags = regionFlags; rb.RegionX = (uint) m_currentScene.RegionInfo.RegionLocX/Constants.RegionSize; rb.RegionY = (uint) m_currentScene.RegionInfo.RegionLocY/Constants.RegionSize; }
private void statsHeartBeat(object sender, EventArgs e) { SimStatsPacket.StatBlock[] sb = new SimStatsPacket.StatBlock[21]; SimStatsPacket.RegionBlock rb = new SimStatsPacket.RegionBlock(); // Know what's not thread safe in Mono... modifying timers. // m_log.Debug("Firing Stats Heart Beat"); lock (m_report) { uint regionFlags = 0; try { if (estateModule == null) estateModule = m_scene.RequestModuleInterface<IEstateModule>(); regionFlags = estateModule != null ? estateModule.GetRegionFlags() : (uint) 0; } catch (Exception) { // leave region flags at 0 } #region various statistic googly moogly // 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); // save the reported value so there is something available for llGetRegionFPS lastReportedSimFPS = reportedFPS / statsUpdateFactor; float physfps = ((m_pfps / 1000)); //if (physfps > 600) //physfps = physfps - (physfps - 600); if (physfps < 0) physfps = 0; #endregion //Our time dilation is 0.91 when we're running a full speed, // therefore to make sure we get an appropriate range, // we have to factor in our error. (0.10f * statsUpdateFactor) // multiplies the fix for the error times the amount of times it'll occur a second // / 10 divides the value by the number of times the sim heartbeat runs (10fps) // Then we divide the whole amount by the amount of seconds pass in between stats updates. // 'statsUpdateFactor' is how often stats packets are sent in seconds. Used below to change // values to X-per-second values. for (int i = 0; i < 21; i++) { sb[i] = new SimStatsPacket.StatBlock(); } 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[1].StatID = (uint) Stats.SimFPS; sb[1].StatValue = reportedFPS / statsUpdateFactor; sb[2].StatID = (uint) Stats.PhysicsFPS; sb[2].StatValue = physfps / statsUpdateFactor; sb[3].StatID = (uint) Stats.AgentUpdates; sb[3].StatValue = (m_agentUpdates / statsUpdateFactor); sb[4].StatID = (uint) Stats.Agents; sb[4].StatValue = m_rootAgents; sb[5].StatID = (uint) Stats.ChildAgents; sb[5].StatValue = m_childAgents; sb[6].StatID = (uint) Stats.TotalPrim; sb[6].StatValue = m_numPrim; sb[7].StatID = (uint) Stats.ActivePrim; sb[7].StatValue = m_activePrim; sb[8].StatID = (uint)Stats.FrameMS; sb[8].StatValue = m_frameMS / statsUpdateFactor; sb[9].StatID = (uint)Stats.NetMS; sb[9].StatValue = m_netMS / statsUpdateFactor; sb[10].StatID = (uint)Stats.PhysicsMS; sb[10].StatValue = m_physicsMS / statsUpdateFactor; sb[11].StatID = (uint)Stats.ImageMS ; sb[11].StatValue = m_imageMS / statsUpdateFactor; sb[12].StatID = (uint)Stats.OtherMS; sb[12].StatValue = m_otherMS / statsUpdateFactor; sb[13].StatID = (uint)Stats.InPacketsPerSecond; sb[13].StatValue = (m_inPacketsPerSecond / statsUpdateFactor); sb[14].StatID = (uint)Stats.OutPacketsPerSecond; sb[14].StatValue = (m_outPacketsPerSecond / statsUpdateFactor); sb[15].StatID = (uint)Stats.UnAckedBytes; sb[15].StatValue = m_unAckedBytes; sb[16].StatID = (uint)Stats.AgentMS; sb[16].StatValue = m_agentMS / statsUpdateFactor; sb[17].StatID = (uint)Stats.PendingDownloads; sb[17].StatValue = m_pendingDownloads; sb[18].StatID = (uint)Stats.PendingUploads; sb[18].StatValue = m_pendingUploads; sb[19].StatID = (uint)Stats.ActiveScripts; sb[19].StatValue = m_activeScripts; sb[20].StatID = (uint)Stats.ScriptLinesPerSecond; sb[20].StatValue = m_scriptLinesPerSecond / statsUpdateFactor; for (int i = 0; i < 21; i++) { lastReportedSimStats[i] = sb[i].StatValue; } SimStats simStats = new SimStats( ReportingRegion.RegionLocX, ReportingRegion.RegionLocY, regionFlags, (uint)m_objectCapacity, rb, sb, m_scene.RegionInfo.originRegionID); handlerSendStatResult = OnSendStatsResult; if (handlerSendStatResult != null) { handlerSendStatResult(simStats); } // Extra statistics that aren't currently sent to clients LastReportedObjectUpdates = m_objectUpdates / statsUpdateFactor; resetvalues(); } }
/// <summary> /// Dearchive the region embodied in this request. /// </summary> public void DearchiveRegion() { int successfulAssetRestores = 0; int failedAssetRestores = 0; DearchiveScenesInfo dearchivedScenes; // We dearchive all the scenes at once, because the files in the TAR archive might be mixed. // Therefore, we have to keep track of the dearchive context of all the scenes. Dictionary <UUID, DearchiveContext> sceneContexts = new Dictionary <UUID, DearchiveContext>(); string fullPath = "NONE"; TarArchiveReader archive = null; byte[] data; TarArchiveReader.TarEntryType entryType; try { FindAndLoadControlFile(out archive, out dearchivedScenes); while ((data = archive.ReadEntry(out fullPath, out entryType)) != null) { //m_log.DebugFormat( // "[ARCHIVER]: Successfully read {0} ({1} bytes)", filePath, data.Length); if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY == entryType) { continue; } // Find the scene that this file belongs to Scene scene; string filePath; if (!dearchivedScenes.GetRegionFromPath(fullPath, out scene, out filePath)) { continue; // this file belongs to a region that we're not loading } DearchiveContext sceneContext = null; if (scene != null) { if (!sceneContexts.TryGetValue(scene.RegionInfo.RegionID, out sceneContext)) { sceneContext = new DearchiveContext(scene); sceneContexts.Add(scene.RegionInfo.RegionID, sceneContext); } } // Process the file if (filePath.StartsWith(ArchiveConstants.OBJECTS_PATH) && !m_noObjects) { sceneContext.SerialisedSceneObjects.Add(Encoding.UTF8.GetString(data)); } else if (filePath.StartsWith(ArchiveConstants.ASSETS_PATH) && !m_skipAssets) { if (LoadAsset(filePath, data)) { successfulAssetRestores++; } else { failedAssetRestores++; } if ((successfulAssetRestores + failedAssetRestores) % 250 == 0) { m_log.Debug("[ARCHIVER]: Loaded " + successfulAssetRestores + " assets and failed to load " + failedAssetRestores + " assets..."); } } else if (filePath.StartsWith(ArchiveConstants.TERRAINS_PATH) && (!m_merge || m_forceTerrain)) { LoadTerrain(scene, filePath, data); } else if (!m_merge && filePath.StartsWith(ArchiveConstants.SETTINGS_PATH)) { LoadRegionSettings(scene, filePath, data, dearchivedScenes); } else if (filePath.StartsWith(ArchiveConstants.LANDDATA_PATH) && (!m_merge || m_forceParcels)) { sceneContext.SerialisedParcels.Add(Encoding.UTF8.GetString(data)); } else if (filePath == ArchiveConstants.CONTROL_FILE_PATH) { // Ignore, because we already read the control file } } //m_log.Debug("[ARCHIVER]: Reached end of archive"); } catch (Exception e) { m_log.Error( String.Format("[ARCHIVER]: Aborting load with error in archive file {0} ", fullPath), e); m_errorMessage += e.ToString(); m_rootScene.EventManager.TriggerOarFileLoaded(m_requestId, new List <UUID>(), m_errorMessage); return; } finally { if (archive != null) { archive.Close(); } } if (!m_skipAssets) { m_log.InfoFormat("[ARCHIVER]: Restored {0} assets", successfulAssetRestores); if (failedAssetRestores > 0) { m_log.ErrorFormat("[ARCHIVER]: Failed to load {0} assets", failedAssetRestores); m_errorMessage += String.Format("Failed to load {0} assets", failedAssetRestores); } } foreach (DearchiveContext sceneContext in sceneContexts.Values) { m_log.InfoFormat("[ARCHIVER]: Loading region {0}", sceneContext.Scene.RegionInfo.RegionName); if (!m_merge) { m_log.Info("[ARCHIVER]: Clearing all existing scene objects"); sceneContext.Scene.DeleteAllSceneObjects(); } try { LoadParcels(sceneContext.Scene, sceneContext.SerialisedParcels); LoadObjects(sceneContext.Scene, sceneContext.SerialisedSceneObjects, sceneContext.SceneObjects); // Inform any interested parties that the region has changed. We waited until now so that all // of the region's objects will be loaded when we send this notification. IEstateModule estateModule = sceneContext.Scene.RequestModuleInterface <IEstateModule>(); if (estateModule != null) { estateModule.TriggerRegionInfoChange(); } } catch (Exception e) { m_log.Error("[ARCHIVER]: Error loading parcels or objects ", e); m_errorMessage += e.ToString(); m_rootScene.EventManager.TriggerOarFileLoaded(m_requestId, new List <UUID>(), m_errorMessage); return; } } // Start the scripts. We delayed this because we want the OAR to finish loading ASAP, so // that users can enter the scene. If we allow the scripts to start in the loop above // then they significantly increase the time until the OAR finishes loading. Util.RunThreadNoTimeout(delegate(object o) { Thread.Sleep(15000); m_log.Info("[ARCHIVER]: Starting scripts in scene objects"); foreach (DearchiveContext sceneContext in sceneContexts.Values) { foreach (SceneObjectGroup sceneObject in sceneContext.SceneObjects) { sceneObject.CreateScriptInstances(0, false, sceneContext.Scene.DefaultScriptEngine, 0); // StateSource.RegionStart sceneObject.ResumeScripts(); } sceneContext.SceneObjects.Clear(); } }, "ReadArchiveStartScripts", null); m_log.InfoFormat("[ARCHIVER]: Successfully loaded archive"); m_rootScene.EventManager.TriggerOarFileLoaded(m_requestId, dearchivedScenes.GetLoadedScenes(), m_errorMessage); }
private void statsHeartBeat(object sender, EventArgs e) { SimStatsPacket.StatBlock[] sb = new SimStatsPacket.StatBlock[33]; SimStatsPacket.RegionBlock rb = new SimStatsPacket.RegionBlock(); // Know what's not thread safe in Mono... modifying timers. // m_log.Debug("Firing Stats Heart Beat"); lock (m_report) { uint regionFlags = 0; try { if (estateModule == null) estateModule = m_scene.RequestModuleInterface<IEstateModule>(); regionFlags = estateModule != null ? estateModule.GetRegionFlags() : (uint) 0; } catch (Exception) { // leave region flags at 0 } #region various statistic googly moogly // Our FPS is actually 10fps, so multiplying by 5 to get the amount that people expect there // 0-50 is pretty close to 0-45 float simfps = (int) ((m_fps * 5)); // save the reported value so there is something available for llGetRegionFPS lastReportedSimFPS = (float)simfps / statsUpdateFactor; //if (simfps > 45) //simfps = simfps - (simfps - 45); //if (simfps < 0) //simfps = 0; // float physfps = ((m_pfps / 1000)); //if (physfps > 600) //physfps = physfps - (physfps - 600); if (physfps < 0) physfps = 0; #endregion //Our time dilation is 0.91 when we're running a full speed, // therefore to make sure we get an appropriate range, // we have to factor in our error. (0.10f * statsUpdateFactor) // multiplies the fix for the error times the amount of times it'll occur a second // / 10 divides the value by the number of times the sim heartbeat runs (10fps) // Then we divide the whole amount by the amount of seconds pass in between stats updates. // 'statsUpdateFactor' is how often stats packets are sent in seconds. Used below to change // values to X-per-second values. for (int i = 0; i<33;i++) { sb[i] = new SimStatsPacket.StatBlock(); } 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[1].StatID = (uint) Stats.SimFPS; sb[1].StatValue = simfps/statsUpdateFactor; sb[2].StatID = (uint) Stats.PhysicsFPS; sb[2].StatValue = physfps / statsUpdateFactor; sb[3].StatID = (uint) Stats.AgentUpdates; sb[3].StatValue = (m_agentUpdates / statsUpdateFactor); sb[4].StatID = (uint) Stats.Agents; sb[4].StatValue = m_rootAgents; sb[5].StatID = (uint) Stats.ChildAgents; sb[5].StatValue = m_childAgents; sb[6].StatID = (uint) Stats.TotalPrim; sb[6].StatValue = m_numPrim; sb[7].StatID = (uint) Stats.ActivePrim; sb[7].StatValue = m_activePrim; sb[8].StatID = (uint)Stats.FrameMS; sb[8].StatValue = m_frameMS / statsUpdateFactor; sb[9].StatID = (uint)Stats.NetMS; sb[9].StatValue = m_netMS / statsUpdateFactor; sb[10].StatID = (uint)Stats.PhysicsMS; sb[10].StatValue = m_physicsMS / statsUpdateFactor; sb[11].StatID = (uint)Stats.ImageMS ; sb[11].StatValue = m_imageMS / statsUpdateFactor; sb[12].StatID = (uint)Stats.OtherMS; sb[12].StatValue = m_otherMS / statsUpdateFactor; sb[13].StatID = (uint)Stats.InPacketsPerSecond; sb[13].StatValue = (m_inPacketsPerSecond / statsUpdateFactor); sb[14].StatID = (uint)Stats.OutPacketsPerSecond; sb[14].StatValue = (m_outPacketsPerSecond / statsUpdateFactor); sb[15].StatID = (uint)Stats.UnAckedBytes; sb[15].StatValue = m_unAckedBytes; sb[16].StatID = (uint)Stats.AgentMS; sb[16].StatValue = m_agentMS / statsUpdateFactor; sb[17].StatID = (uint)Stats.PendingDownloads; sb[17].StatValue = m_pendingDownloads; sb[18].StatID = (uint)Stats.PendingUploads; sb[18].StatValue = m_pendingUploads; sb[19].StatID = (uint)Stats.ActiveScripts; sb[19].StatValue = m_activeScripts; sb[20].StatID = (uint)Stats.ScriptEventsPerSecond; sb[20].StatValue = m_scriptEventsPerSecond / statsUpdateFactor; sb[21].StatID = (uint)Stats.SpareTime; sb[21].StatValue = 0; sb[22].StatID = (uint)Stats.SleepTime; sb[22].StatValue = m_sleepTime; sb[23].StatID = (uint)Stats.PumpIO; sb[23].StatValue = 0; long pws = System.Diagnostics.Process.GetCurrentProcess().WorkingSet64; if (pws > Int32.MaxValue) pws = Int32.MaxValue; if (pws < 0) pws = 0; sb[25].StatID = (uint)Stats.MemoryAllocated; sb[25].StatValue = pws / 4096000; sb[26].StatID = (uint)Stats.PhysicsOther; sb[26].StatValue = m_physicsOther; sb[27].StatID = (uint)Stats.UpdatePhysicsShapes; sb[27].StatValue = 0; sb[28].StatID = (uint)Stats.PhysicsStep; sb[28].StatValue = m_physicsStep; sb[29].StatID = (uint)Stats.LowLodObjects; sb[29].StatValue = 0; sb[30].StatID = (uint)Stats.PinnedObjects; sb[30].StatValue = 0; sb[31].StatID = (uint)Stats.UnknownA; sb[31].StatValue = 0; sb[32].StatID = (uint)Stats.UnknownB; sb[32].StatValue = 0; sb[24].StatID = (uint)Stats.UnknownC; sb[24].StatValue = 0; for (int i = 0; i < 33; i++) { lastReportedSimStats[i] = sb[i].StatValue; } SimStats simStats = new SimStats( ReportingRegion.RegionLocX, ReportingRegion.RegionLocY, regionFlags, (uint)objectCapacity, rb, sb, m_scene.RegionInfo.RegionID); handlerSendStatResult = OnSendStatsResult; if (handlerSendStatResult != null) { handlerSendStatResult(simStats); } resetvalues(); } }
private void statsHeartBeat(object sender, EventArgs e) { if (!m_scene.Active) { return; } // dont do it if if still been done if (Monitor.TryEnter(m_statsLock)) { // m_log.Debug("Firing Stats Heart Beat"); float[] newvalues = new float[(int)StatsIndex.ArraySize]; uint regionFlags = 0; try { if (estateModule == null) { estateModule = m_scene.RequestModuleInterface <IEstateModule>(); } regionFlags = estateModule != null?estateModule.GetRegionFlags() : (uint)0; } catch (Exception) { // leave region flags at 0 } #region various statistic googly moogly double timeTmp = m_lastUpdateTS; m_lastUpdateTS = Util.GetTimeStampMS(); float updateElapsed = (float)((m_lastUpdateTS - timeTmp) / 1000.0); // factor to consider updates integration time float updateTimeFactor = 1.0f / updateElapsed; // scene frame stats float reportedFPS; float physfps; float timeDilation; float agentMS; float physicsMS; float otherMS; float sleeptime; float scriptTimeMS; float totalFrameTime; float invFrameElapsed; // get a copy under lock and reset lock (m_statsFrameLock) { timeDilation = m_timeDilation; reportedFPS = m_fps; physfps = m_pfps; agentMS = m_agentMS; physicsMS = m_physicsMS; otherMS = m_otherMS; sleeptime = m_sleeptimeMS; scriptTimeMS = m_scriptTimeMS; totalFrameTime = m_frameMS; // still not inv invFrameElapsed = (float)((m_FrameStatsTS - m_prevFrameStatsTS) / 1000.0); ResetFrameStats(); } if (invFrameElapsed / updateElapsed < 0.8) { // scene is in trouble, its account of time is most likely wrong // can even be in stall invFrameElapsed = updateTimeFactor; } else { invFrameElapsed = 1.0f / invFrameElapsed; } float perframefactor; if (reportedFPS <= 0) { reportedFPS = 0.0f; physfps = 0.0f; perframefactor = 1.0f; timeDilation = 0.0f; } else { timeDilation /= reportedFPS; reportedFPS *= m_statisticsFPSfactor; perframefactor = 1.0f / (float)reportedFPS; reportedFPS *= invFrameElapsed; physfps *= invFrameElapsed * m_statisticsFPSfactor; } // some engines track frame time with error related to the simulation step size if (physfps > reportedFPS) { physfps = reportedFPS; } // save the reported value so there is something available for llGetRegionFPS lastReportedSimFPS = reportedFPS; // scale frame stats totalFrameTime *= perframefactor; sleeptime *= perframefactor; otherMS *= perframefactor; physicsMS *= perframefactor; agentMS *= perframefactor; scriptTimeMS *= perframefactor; // estimate spare time float sparetime; sparetime = m_targetFrameTime - (physicsMS + agentMS + otherMS); if (sparetime < 0) { sparetime = 0; } else if (sparetime > totalFrameTime) { sparetime = totalFrameTime; } #endregion SceneGraph SG = m_scene.SceneGraph; OnStatsIncorrect?.Invoke(); // number of agents may still drift so fix m_activeScripts = SG.GetActiveScriptsCount(); m_scriptLinesPerSecond = SG.GetScriptLPS(); newvalues[(int)StatsIndex.TimeDilation] = (Single.IsNaN(timeDilation)) ? 0.0f : (float)Math.Round(timeDilation, 3); newvalues[(int)StatsIndex.SimFPS] = (float)Math.Round(reportedFPS, 1); newvalues[(int)StatsIndex.PhysicsFPS] = (float)Math.Round(physfps, 1); newvalues[(int)StatsIndex.AgentUpdates] = m_agentUpdates * updateTimeFactor; newvalues[(int)StatsIndex.Agents] = SG.GetRootAgentCount(); newvalues[(int)StatsIndex.ChildAgents] = SG.GetChildAgentCount(); newvalues[(int)StatsIndex.TotalPrim] = SG.GetTotalPrimObjectsCount(); newvalues[(int)StatsIndex.ActivePrim] = SG.GetActiveObjectsCount(); newvalues[(int)StatsIndex.FrameMS] = totalFrameTime; newvalues[(int)StatsIndex.NetMS] = (float)Math.Round(m_netMS * perframefactor, 3); newvalues[(int)StatsIndex.PhysicsMS] = (float)Math.Round(physicsMS, 3); newvalues[(int)StatsIndex.ImageMS] = (float)Math.Round(m_imageMS * perframefactor, 3); newvalues[(int)StatsIndex.OtherMS] = (float)Math.Round(otherMS, 3); newvalues[(int)StatsIndex.InPacketsPerSecond] = (float)Math.Round(m_inPacketsPerSecond * updateTimeFactor); newvalues[(int)StatsIndex.OutPacketsPerSecond] = (float)Math.Round(m_outPacketsPerSecond * updateTimeFactor); newvalues[(int)StatsIndex.UnAckedBytes] = m_unAckedBytes; newvalues[(int)StatsIndex.AgentMS] = agentMS; newvalues[(int)StatsIndex.PendingDownloads] = m_pendingDownloads; newvalues[(int)StatsIndex.PendingUploads] = m_pendingUploads; newvalues[(int)StatsIndex.ActiveScripts] = m_activeScripts; newvalues[(int)StatsIndex.SimSleepMs] = (float)Math.Round(sleeptime, 3); newvalues[(int)StatsIndex.SimSpareMs] = (float)Math.Round(sparetime, 3); newvalues[(int)StatsIndex.SimPhysicsStepMs] = 20; // this should came from phys engine newvalues[(int)StatsIndex.ScriptMS] = scriptTimeMS; newvalues[(int)StatsIndex.ScriptEps] = (float)Math.Round(m_scriptEventsPerSecond * updateTimeFactor); // add extra stats for internal use newvalues[(int)StatsIndex.LSLScriptLinesPerSecond] = (float)Math.Round(m_scriptLinesPerSecond * updateTimeFactor, 3); newvalues[(int)StatsIndex.FrameDilation2] = (Single.IsNaN(timeDilation)) ? 0.1f : (float)Math.Round(timeDilation, 1); newvalues[(int)StatsIndex.UsersLoggingIn] = m_usersLoggingIn; newvalues[(int)StatsIndex.TotalGeoPrim] = SG.GetTotalPrimObjectsCount(); newvalues[(int)StatsIndex.TotalMesh] = SG.GetTotalMeshObjectsCount(); newvalues[(int)StatsIndex.ScriptEngineThreadCount] = m_inUseThreads; newvalues[(int)StatsIndex.NPCs] = SG.GetRootNPCCount(); lastReportedSimStats = newvalues; OnSendStatsResult?.Invoke(new SimStats( ReportingRegion.RegionLocX, ReportingRegion.RegionLocY, ReportingRegion.RegionSizeX, ReportingRegion.RegionSizeY, regionFlags, (uint)m_objectCapacity, newvalues, m_scene.RegionInfo.originRegionID, m_scene.RegionInfo.RegionName) ); // Extra statistics that aren't currently sent elsewhere if (m_scene.PhysicsScene != null) { lock (m_lastReportedExtraSimStats) { m_lastReportedExtraSimStats["LastReportedObjectUpdates"] = m_objectUpdates * updateTimeFactor; m_lastReportedExtraSimStats[SlowFramesStat.ShortName] = (float)SlowFramesStat.Value; Dictionary <string, float> physicsStats = m_scene.PhysicsScene.GetStats(); if (physicsStats != null) { foreach (KeyValuePair <string, float> tuple in physicsStats) { // FIXME: An extremely dirty hack to divide MS stats per frame rather than per second // Need to change things so that stats source can indicate whether they are per second or // per frame. if (tuple.Key.EndsWith("MS")) { m_lastReportedExtraSimStats[tuple.Key] = tuple.Value * perframefactor; } else { m_lastReportedExtraSimStats[tuple.Key] = tuple.Value * updateTimeFactor; } } } } } // LastReportedObjectUpdates = m_objectUpdates / m_statsUpdateFactor; ResetValues(); Monitor.Exit(m_statsLock); } }