예제 #1
0
파일: Scene.cs 프로젝트: shangcheng/Aurora
 /// <summary>
 /// Send out simstats data to all clients
 /// </summary>
 /// <param name="stats">Stats on the Simulator's performance</param>
 private void SendSimStatsPackets(SimStats stats)
 {
     ForEachScenePresence(
         delegate(ScenePresence agent)
         {
             if (!agent.IsChildAgent)
                 agent.ControllingClient.SendSimStats(stats);
         }
     );
 }
예제 #2
0
        public void ReceiveClassicSimStatsPacket(SimStats stats)
        {
            if (!enabled)
            {
                return;
            }

            try
            {
                // Ignore the update if there's a report running right now
                // ignore the update if there hasn't been a hit in 30 seconds.
                if (concurrencyCounter > 0 || Util.EnvironmentTickCount() - lastHit > 30000)
                    return;

                if ((updateLogCounter++ % updateLogMod) == 0)
                {
                    m_loglines = readLogLines(10);
                    if (updateLogCounter > 10000) updateLogCounter = 1;
                }

                USimStatsData ss = m_simstatsCounters[stats.RegionUUID];

                if ((++ss.StatsCounter % updateStatsMod) == 0)
                {
                    ss.ConsumeSimStats(stats);
                }
            } 
            catch (KeyNotFoundException)
            {
            }
        }
예제 #3
0
 public void SendSimStats(SimStats stats)
 {
 }
예제 #4
0
        /// <summary>
        /// This is the method on which the classic sim stats reporter (which collects stats for
        /// client purposes) sends information to listeners.
        /// </summary>
        /// <param name="pack"></param>
        public void ReceiveClassicSimStatsPacket(SimStats stats)
        {
            // FIXME: SimStats shouldn't allow an arbitrary stat packing order (which is inherited from the original
            // SimStatsPacket that was being used).

            // For an unknown reason the original designers decided not to
            // include the spare MS statistic inside of this class, this is
            // located inside the StatsBlock at location 21, thus it is skipped
            timeDilation            = stats.StatsBlock[0].StatValue;
            simFps                  = stats.StatsBlock[1].StatValue;
            physicsFps              = stats.StatsBlock[2].StatValue;
            agentUpdates            = stats.StatsBlock[3].StatValue;
            rootAgents              = stats.StatsBlock[4].StatValue;
            childAgents             = stats.StatsBlock[5].StatValue;
            totalPrims              = stats.StatsBlock[6].StatValue;
            activePrims             = stats.StatsBlock[7].StatValue;
            totalFrameTime          = stats.StatsBlock[8].StatValue;
            netFrameTime            = stats.StatsBlock[9].StatValue;
            physicsFrameTime        = stats.StatsBlock[10].StatValue;
            otherFrameTime          = stats.StatsBlock[11].StatValue;
            imageFrameTime          = stats.StatsBlock[12].StatValue;
            inPacketsPerSecond      = stats.StatsBlock[13].StatValue;
            outPacketsPerSecond     = stats.StatsBlock[14].StatValue;
            unackedBytes            = stats.StatsBlock[15].StatValue;
            agentFrameTime          = stats.StatsBlock[16].StatValue;
            pendingDownloads        = stats.StatsBlock[17].StatValue;
            pendingUploads          = stats.StatsBlock[18].StatValue;
            activeScripts           = stats.StatsBlock[19].StatValue;
            scriptLinesPerSecond    = stats.StatsBlock[20].StatValue;
            m_frameDilation         = stats.StatsBlock[22].StatValue;
            m_usersLoggingIn        = stats.StatsBlock[23].StatValue;
            m_totalGeoPrims         = stats.StatsBlock[24].StatValue;
            m_totalMeshes           = stats.StatsBlock[25].StatValue;
            m_inUseThreads          = stats.StatsBlock[26].StatValue;
            m_inByteRate            = stats.StatsBlock[27].StatValue;
            m_outByteRate           = stats.StatsBlock[28].StatValue;
            m_errorPacketRate       = stats.StatsBlock[29].StatValue;
            m_queueSize             = stats.StatsBlock[30].StatValue;
            m_clientPing            = stats.StatsBlock[31].StatValue;
        }
        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)m_objectCapacity, rb, sb, m_scene.RegionInfo.originRegionID);

                handlerSendStatResult = OnSendStatsResult;
                if (handlerSendStatResult != null)
                {
                    handlerSendStatResult(simStats);
                }
                resetvalues();
            }
        }
예제 #6
0
            /// <summary>
            ///   This is called by a timer and makes a SimStats class of the current stats that we have in this simulator.
            ///   It then sends the packet to the client and triggers the events to tell followers about the updated stats
            ///   and updates the LastSet* values for monitors.
            /// </summary>
            /// <param name = "sender"></param>
            /// <param name = "e"></param>
            protected void statsHeartBeat(object sender, EventArgs e)
            {
                lock (m_report)
                    m_report.Stop();
                if (rb == null)
                {
                    buildInitialRegionBlock();
                }

                // Know what's not thread safe in Mono... modifying timers.
                lock (m_report)
                {
                    ISimFrameMonitor     simFrameMonitor     = (ISimFrameMonitor)GetMonitor(MonitorModuleHelper.SimFrameStats);
                    ITimeDilationMonitor timeDilationMonitor =
                        (ITimeDilationMonitor)GetMonitor(MonitorModuleHelper.TimeDilation);
                    ITotalFrameTimeMonitor totalFrameMonitor =
                        (ITotalFrameTimeMonitor)GetMonitor(MonitorModuleHelper.TotalFrameTime);
                    ITimeMonitor         sleepFrameMonitor   = (ITimeMonitor)GetMonitor(MonitorModuleHelper.SleepFrameTime);
                    ITimeMonitor         otherFrameMonitor   = (ITimeMonitor)GetMonitor(MonitorModuleHelper.OtherFrameTime);
                    IPhysicsFrameMonitor physicsFrameMonitor =
                        (IPhysicsFrameMonitor)GetMonitor(MonitorModuleHelper.TotalPhysicsFrameTime);
                    ITimeMonitor physicsSyncFrameMonitor =
                        (ITimeMonitor)GetMonitor(MonitorModuleHelper.PhysicsSyncFrameTime);
                    ITimeMonitor physicsTimeFrameMonitor =
                        (ITimeMonitor)GetMonitor(MonitorModuleHelper.PhysicsUpdateFrameTime);
                    IAgentUpdateMonitor agentUpdateFrameMonitor =
                        (IAgentUpdateMonitor)GetMonitor(MonitorModuleHelper.AgentUpdateCount);
                    INetworkMonitor     networkMonitor     = (INetworkMonitor)GetMonitor(MonitorModuleHelper.NetworkMonitor);
                    IMonitor            imagesMonitor      = GetMonitor(MonitorModuleHelper.ImagesFrameTime);
                    ITimeMonitor        scriptMonitor      = (ITimeMonitor)GetMonitor(MonitorModuleHelper.ScriptFrameTime);
                    IScriptCountMonitor totalScriptMonitor =
                        (IScriptCountMonitor)GetMonitor(MonitorModuleHelper.TotalScriptCount);

                    #region various statistic googly moogly

                    float simfps = simFrameMonitor.SimFPS / statsUpdateFactor;
                    // save the reported value so there is something available for llGetRegionFPS
                    simFrameMonitor.LastReportedSimFPS = simfps;

                    float physfps = physicsFrameMonitor.PhysicsFPS / statsUpdateFactor;
                    physicsFrameMonitor.LastReportedPhysicsFPS = physfps;
                    //Update the time dilation with the newest physicsFPS
                    timeDilationMonitor.SetPhysicsFPS(physfps);

                    #endregion

                    #region Add the stats packets

                    //Some info on this packet http://wiki.secondlife.com/wiki/Statistics_Bar_Guide

                    sb[0].StatID    = (uint)Stats.TimeDilation;
                    sb[0].StatValue = (float)timeDilationMonitor.GetValue();

                    sb[1].StatID    = (uint)Stats.FPS;
                    sb[1].StatValue = simfps;

                    float realsimfps = simfps * 2;

                    sb[2].StatID    = (uint)Stats.PhysFPS;
                    sb[2].StatValue = physfps;

                    sb[3].StatID    = (uint)Stats.AgentUpdates;
                    sb[3].StatValue = (agentUpdateFrameMonitor.AgentUpdates / realsimfps);

                    sb[4].StatID = (uint)Stats.FrameMS;
                    float TotalFrames = (float)(totalFrameMonitor.GetValue() / realsimfps);
                    sb[4].StatValue = TotalFrames;

                    sb[5].StatID    = (uint)Stats.NetMS;
                    sb[5].StatValue = 0; //TODO: Implement this

                    sb[6].StatID = (uint)Stats.SimOtherMS;
                    float otherMS = (float)(otherFrameMonitor.GetValue() / realsimfps);
                    sb[6].StatValue = otherMS;

                    sb[7].StatID = (uint)Stats.SimPhysicsMS;
                    float PhysicsMS = (float)(physicsTimeFrameMonitor.GetValue() / realsimfps);
                    sb[7].StatValue = PhysicsMS;

                    sb[8].StatID    = (uint)Stats.AgentMS;
                    sb[8].StatValue = (agentUpdateFrameMonitor.AgentFrameTime / realsimfps);

                    sb[9].StatID = (uint)Stats.ImagesMS;
                    float imageMS = (float)(imagesMonitor.GetValue() / realsimfps);
                    sb[9].StatValue = imageMS;

                    sb[10].StatID = (uint)Stats.ScriptMS;
                    float ScriptMS = (float)(scriptMonitor.GetValue() / realsimfps);
                    sb[10].StatValue = ScriptMS;

                    sb[11].StatID = (uint)Stats.TotalObjects;
                    sb[12].StatID = (uint)Stats.ActiveObjects;
                    sb[13].StatID = (uint)Stats.NumAgentMain;
                    sb[14].StatID = (uint)Stats.NumAgentChild;

                    IEntityCountModule entityCountModule = m_currentScene.RequestModuleInterface <IEntityCountModule>();
                    if (entityCountModule != null)
                    {
                        sb[11].StatValue = entityCountModule.Objects;

                        sb[12].StatValue = entityCountModule.ActiveObjects;

                        sb[13].StatValue = entityCountModule.RootAgents;

                        sb[14].StatValue = entityCountModule.ChildAgents;
                    }

                    sb[15].StatID    = (uint)Stats.NumScriptActive;
                    sb[15].StatValue = totalScriptMonitor.ActiveScripts;

                    sb[16].StatID    = (uint)Stats.LSLIPS;
                    sb[16].StatValue = 0; //This isn't used anymore, and has been superseeded by LSLEPS

                    sb[17].StatID    = (uint)Stats.InPPS;
                    sb[17].StatValue = (networkMonitor.InPacketsPerSecond / statsUpdateFactor);

                    sb[18].StatID    = (uint)Stats.OutPPS;
                    sb[18].StatValue = (networkMonitor.OutPacketsPerSecond / statsUpdateFactor);

                    sb[19].StatID    = (uint)Stats.PendingDownloads;
                    sb[19].StatValue = (networkMonitor.PendingDownloads);

                    sb[20].StatID    = (uint)Stats.PendingUploads;
                    sb[20].StatValue = (networkMonitor.PendingUploads);

                    //21 and 22 are forced to the GC memory as they WILL make memory usage go up rapidly otherwise!
                    sb[21].StatID    = (uint)Stats.VirtualSizeKB;
                    sb[21].StatValue = GC.GetTotalMemory(false) / 1024;
                    // System.Diagnostics.Process.GetCurrentProcess().WorkingSet64 / (1024);

                    sb[22].StatID    = (uint)Stats.ResidentSizeKB;
                    sb[22].StatValue = GC.GetTotalMemory(false) / 1024;
                    //(float)System.Diagnostics.Process.GetCurrentProcess().PrivateMemorySize64 / (1024);

                    sb[23].StatID    = (uint)Stats.PendingLocalUploads;
                    sb[23].StatValue = (networkMonitor.PendingUploads / statsUpdateFactor);

                    sb[24].StatID    = (uint)Stats.TotalUnackedBytes;
                    sb[24].StatValue = (networkMonitor.UnackedBytes);

                    sb[25].StatID    = (uint)Stats.PhysicsPinnedTasks;
                    sb[25].StatValue = 0;

                    sb[26].StatID    = (uint)Stats.PhysicsLODTasks;
                    sb[26].StatValue = 0;

                    sb[27].StatID    = (uint)Stats.SimPhysicsStepMS;
                    sb[27].StatValue = m_currentScene.PhysicsScene.StepTime;

                    sb[28].StatID    = (uint)Stats.SimPhysicsShape;
                    sb[28].StatValue = 0;

                    sb[29].StatID    = (uint)Stats.SimPhysicsOtherMS;
                    sb[29].StatValue = (float)(physicsSyncFrameMonitor.GetValue() / realsimfps);

                    sb[30].StatID    = (uint)Stats.SimPhysicsMemory;
                    sb[30].StatValue = 0;

                    sb[31].StatID    = (uint)Stats.ScriptEPS;
                    sb[31].StatValue = totalScriptMonitor.ScriptEPS / statsUpdateFactor;

                    sb[32].StatID = (uint)Stats.SimSpareTime;
                    //Spare time is the total time minus the stats that are in the same category in the client
                    // It is the sleep time, physics step, update physics shape, physics other, and pumpI0.
                    // Note: take out agent Update and script time for now, as they are not a part of the heartbeat right now and will mess this calc up
                    float SpareTime = TotalFrames - (
                        /*NetMS + */ PhysicsMS + otherMS + imageMS);
//                         + /*(agentUpdateFrameMonitor.AgentFrameTime / statsUpdateFactor) +*/
//                        (imagesMonitor.GetValue() / statsUpdateFactor) /* + ScriptMS*/));

                    sb[32].StatValue = SpareTime;

                    sb[33].StatID    = (uint)Stats.SimSleepTime;
                    sb[33].StatValue = (float)(sleepFrameMonitor.GetValue() / realsimfps);

                    sb[34].StatID    = (uint)Stats.IOPumpTime;
                    sb[34].StatValue = 0; //TODO: implement this

                    #endregion

                    for (int i = 0; i < sb.Length; i++)
                    {
                        if (float.IsInfinity(sb[i].StatValue) ||
                            float.IsNaN(sb[i].StatValue))
                        {
                            sb[i].StatValue = 0; //Don't send huge values
                        }
                        lastReportedSimStats[i] = sb[i].StatValue;
                    }

                    SimStats simStats
                        = new SimStats(rb, sb, m_currentScene.RegionInfo.RegionID);

                    //Fire the event and tell followers about the new stats
                    m_module.SendStatsResults(simStats);

                    //Tell all the scene presences about the new stats
#if (!ISWIN)
                    foreach (IScenePresence agent in m_currentScene.GetScenePresences())
                    {
                        if (!agent.IsChildAgent)
                        {
                            agent.ControllingClient.SendSimStats(simStats);
                        }
                    }
#else
                    foreach (IScenePresence agent in m_currentScene.GetScenePresences().Where(agent => !agent.IsChildAgent))
                    {
                        agent.ControllingClient.SendSimStats(simStats);
                    }
#endif
                    //Now fix any values that require reseting
                    ResetValues();
                }
                lock (m_report)
                    m_report.Start();
            }
예제 #7
0
파일: SimFSM.cs 프로젝트: I4N-T/office-sim
 void Start()
 {
     //GET SCRIPTS
     simAIScript    = gameObject.GetComponent <SimAI>();
     simStatsScript = gameObject.GetComponent <SimStats>();
 }
예제 #8
0
        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 statsHeartBeat(object sender, EventArgs e)
        {
            if (!m_scene.Active)
            {
                return;
            }

            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();
            }
        }
예제 #10
0
        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 actually 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);
            }
        }
예제 #11
0
 void Start()
 {
     //simNodeList = GameStats.nodeList;
     isGoing        = true;
     simStatsScript = gameObject.GetComponent <SimStats>();
 }
예제 #12
0
 public void SendSimStats(SimStats stats)
 {
     throw new System.NotImplementedException();
 }
예제 #13
0
        private void LogSimStats(SimStats stats)
        {
            SimStatsPacket pack = new SimStatsPacket
                                      {Region = stats.RegionBlock, Stat = stats.StatsBlock, Header = {Reliable = false}};

            // note that we are inside the reporter lock when called
            DateTime now = DateTime.Now;

            // hide some time information into the packet
            pack.Header.Sequence = (uint) now.Ticks;

            lock (m_statLockObject) // m_statLog is shared so make sure there is only executer here
            {
                try
                {
                    if (m_statLog == null || now > m_statLog.StartTime + m_statLogPeriod)
                    {
                        // First log file or time has expired, start writing to a new log file
                        if (m_statLog != null && m_statLog.Log != null)
                        {
                            m_statLog.Log.Close();
                        }
                        m_statLog = new StatLogger
                                        {
                                            StartTime = now,
                                            Path = (m_statsDir.Length > 0
                                                        ? m_statsDir + Path.DirectorySeparatorChar.ToString()
                                                        : "")
                                                   + String.Format("stats-{0}.log", now.ToString("yyyyMMddHHmmss"))
                                        };
                        m_statLog.Log = new BinaryWriter(File.Open(m_statLog.Path, FileMode.Append, FileAccess.Write));
                    }

                    // Write the serialized data to disk
                    if (m_statLog != null && m_statLog.Log != null)
                        m_statLog.Log.Write(pack.ToBytes());
                }
                catch (Exception ex)
                {
                    MainConsole.Instance.ErrorFormat("statistics gathering failed: {0}", ex.ToString());
                    if (m_statLog != null && m_statLog.Log != null)
                    {
                        m_statLog.Log.Close();
                    }
                    m_statLog = null;
                }
            }
            return;
        }
 /// <summary>
 /// This is the method on which the classic sim stats reporter (which collects stats for
 /// client purposes) sends information to listeners.
 /// </summary>
 /// <param name="pack"></param>
 public void ReceiveClassicSimStatsPacket(SimStats stats)
 {
     // FIXME: SimStats shouldn't allow an arbitrary stat packing order (which is inherited from the original
     // SimStatsPacket that was being used).
     timeDilation            = stats.StatsBlock[0].StatValue;
     simFps                  = stats.StatsBlock[1].StatValue;
     physicsFps              = stats.StatsBlock[2].StatValue;
     agentUpdates            = stats.StatsBlock[3].StatValue;
     rootAgents              = stats.StatsBlock[4].StatValue;
     childAgents             = stats.StatsBlock[5].StatValue;
     totalPrims              = stats.StatsBlock[6].StatValue;
     activePrims             = stats.StatsBlock[7].StatValue;
     totalFrameTime          = stats.StatsBlock[8].StatValue;
     netFrameTime            = stats.StatsBlock[9].StatValue;
     physicsFrameTime        = stats.StatsBlock[10].StatValue;
     otherFrameTime          = stats.StatsBlock[11].StatValue;
     imageFrameTime          = stats.StatsBlock[12].StatValue;
     inPacketsPerSecond      = stats.StatsBlock[13].StatValue;
     outPacketsPerSecond     = stats.StatsBlock[14].StatValue;
     unackedBytes            = stats.StatsBlock[15].StatValue;
     agentFrameTime          = stats.StatsBlock[16].StatValue;
     pendingDownloads        = stats.StatsBlock[17].StatValue;
     pendingUploads          = stats.StatsBlock[18].StatValue;
     activeScripts           = stats.StatsBlock[19].StatValue;
     scriptLinesPerSecond    = stats.StatsBlock[20].StatValue;
 }
예제 #15
0
        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;
                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 < 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;

                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();
            }
        }
예제 #16
0
 public void ConsumeSimStats(SimStats stats)
 {
     m_regionID = stats.RegionUUID;
     m_timeDilation = stats.StatsBlock[0].StatValue;
     m_simFps = stats.StatsBlock[1].StatValue;
     m_physicsFps = stats.StatsBlock[2].StatValue;
     m_agentUpdates = stats.StatsBlock[3].StatValue;
     m_rootAgents = stats.StatsBlock[4].StatValue;
     m_childAgents = stats.StatsBlock[5].StatValue;
     m_totalPrims = stats.StatsBlock[6].StatValue;
     m_activePrims = stats.StatsBlock[7].StatValue;
     m_totalFrameTime = stats.StatsBlock[8].StatValue;
     m_netFrameTime = stats.StatsBlock[9].StatValue;
     m_physicsFrameTime = stats.StatsBlock[10].StatValue;
     m_otherFrameTime = stats.StatsBlock[11].StatValue;
     m_imageFrameTime = stats.StatsBlock[12].StatValue;
     m_inPacketsPerSecond = stats.StatsBlock[13].StatValue;
     m_outPacketsPerSecond = stats.StatsBlock[14].StatValue;
     m_unackedBytes = stats.StatsBlock[15].StatValue;
     m_agentFrameTime = stats.StatsBlock[16].StatValue;
     m_pendingDownloads = stats.StatsBlock[17].StatValue;
     m_pendingUploads = stats.StatsBlock[18].StatValue;
     m_activeScripts = stats.StatsBlock[19].StatValue;
     m_scriptLinesPerSecond = stats.StatsBlock[20].StatValue;
 }
예제 #17
0
    // Use this for initialization
    void Start()
    {
        //GET SCRIPT COMPONENTS
        simStatsScript = gameObject.GetComponent <SimStats>();
        simAIScript    = gameObject.GetComponent <AltSimAI>();

        //ADD THIS SIM TO THE SIMLIST
        GameStats.simList.Add(gameObject);

        //to test the sim list
        foreach (GameObject sim in GameStats.simList)
        {
            SimStats theScript = sim.GetComponent <SimStats>();
            //print("simList: " + theScript.simName);
        }


        //GET OTHER SIM OBJECTS ARRAY
        //otherSimArray = GameObject.FindGameObjectsWithTag("Sim");

        //GET CANVAS OBJECT
        canvasObj = transform.GetChild(0).gameObject;

        //GET TEXT OBJECT COMPONENTS
        simNameTextObj = transform.GetChild(0).GetChild(0).gameObject;
        //simNameTextObj = GameObject.Find("SimText");

        simStatusTextObj = transform.GetChild(0).GetChild(1).gameObject;
        //simStatusTextObj = GameObject.Find("SimStatusText");

        simEnergyTextObj = transform.GetChild(0).GetChild(2).gameObject;
        //simEnergyTextObj = GameObject.Find("EnergyText");

        simHungerTextObj = transform.GetChild(0).GetChild(3).gameObject;
        //simHungerTextObj = GameObject.Find("HungerText");

        simItemTextObj = transform.GetChild(0).GetChild(4).gameObject;


        //GET ACTUAL CANVAS FROM CANVAS OBJECT
        canvas = canvasObj.GetComponent <Canvas>();

        //SET CANVAS RENDER CAMERA
        canvas.renderMode  = RenderMode.ScreenSpaceCamera;
        canvas.worldCamera = Camera.main;

        //GET ACTUAL TEXT COMPONENTS FROM OBJECTS
        simNameText   = simNameTextObj.GetComponent <Text>();
        simStatusText = simStatusTextObj.GetComponent <Text>();
        simEnergyText = simEnergyTextObj.GetComponent <Text>();
        simHungerText = simHungerTextObj.GetComponent <Text>();
        simItemText   = simItemTextObj.GetComponent <Text>();

        //INITIALIZATION OF NEEDS
        simStatsScript.energy = 100;
        simStatsScript.hunger = 100;

        simNameText.enabled = false;
        //simNameText.text = "Name: " + simStatsScript.simName;

        simEnergyText.enabled = false;
        simHungerText.enabled = false;
        //simHungerText.text = "Hunger: " + simStatsScript.hunger + "/" + "100";

        simItemText.enabled = false;
    }