Пример #1
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.Error("statistics gathering failed: " + ex.Message, ex);
                    if (m_statLog != null && m_statLog.Log != null)
                    {
                        m_statLog.Log.Close();
                    }
                    m_statLog = null;
                }
            }
            return;
        }
Пример #2
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();
            }
 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;
 }
Пример #4
0
 public void SendStatsResults(SimStats simStats)
 {
     SendStatResult handlerSendStatResult = OnSendStatsResult;
     if (handlerSendStatResult != null)
     {
         handlerSendStatResult(simStats);
     }
 }