Пример #1
0
        private void LogSimStats(SimStats stats)
        {
            SimStatsPacket pack = new SimStatsPacket();

            pack.Region                = new SimStatsPacket.RegionBlock();
            pack.Region.RegionX        = stats.RegionX;
            pack.Region.RegionY        = stats.RegionY;
            pack.Region.RegionFlags    = stats.RegionFlags;
            pack.Region.ObjectCapacity = stats.ObjectCapacity;
            //pack.Region = //stats.RegionBlock;
            pack.Stat            = stats.StatsBlock;
            pack.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();
                        m_statLog.StartTime = now;
                        m_statLog.Path      = (m_statsDir.Length > 0 ? m_statsDir + System.IO.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)
                {
                    m_log.Error("statistics gathering failed: " + ex.Message, ex);
                    if (m_statLog != null && m_statLog.Log != null)
                    {
                        m_statLog.Log.Close();
                    }
                    m_statLog = null;
                }
            }
            return;
        }
        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
                                                        : "")
                                        + 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("[Binary stats]: Statistics gathering failed: {0}", ex);
                    if (m_statLog != null && m_statLog.Log != null)
                    {
                        m_statLog.Log.Close();
                    }
                    m_statLog = null;
                }
            }
            return;
        }
        private void LogSimStats(SimStats stats)
        {
            SimStatsPacket pack = new SimStatsPacket();
            pack.Region = stats.RegionBlock;
            pack.Stat = stats.StatsBlock;
            pack.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();
                        m_statLog.StartTime = now;
                        m_statLog.Path = (m_statsDir.Length > 0 ? m_statsDir + System.IO.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)
                {
                    m_log.Error("statistics gathering failed: " + ex.Message, ex);
                    if (m_statLog != null && m_statLog.Log != null)
                    {
                        m_statLog.Log.Close();
                    }
                    m_statLog = null;
                }
            }
            return;
        }