diff options
author | John Hurliman | 2009-11-05 12:01:40 -0800 |
---|---|---|
committer | John Hurliman | 2009-11-05 12:01:40 -0800 |
commit | e6d7303b296468a06ada761706e25d49587b308f (patch) | |
tree | 3739865dcf478eaadf9b75a58a9e9615b64c6afa /OpenSim/Region/Framework/Scenes | |
parent | Change the permissions module to use the friend list cache already in the (diff) | |
download | opensim-SC_OLD-e6d7303b296468a06ada761706e25d49587b308f.zip opensim-SC_OLD-e6d7303b296468a06ada761706e25d49587b308f.tar.gz opensim-SC_OLD-e6d7303b296468a06ada761706e25d49587b308f.tar.bz2 opensim-SC_OLD-e6d7303b296468a06ada761706e25d49587b308f.tar.xz |
Applying #4332, optional packet statistics logging
Diffstat (limited to 'OpenSim/Region/Framework/Scenes')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/Scene.cs | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 093ca3e..6edef11 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs | |||
@@ -36,6 +36,7 @@ using System.Timers; | |||
36 | using System.Xml; | 36 | using System.Xml; |
37 | using Nini.Config; | 37 | using Nini.Config; |
38 | using OpenMetaverse; | 38 | using OpenMetaverse; |
39 | using OpenMetaverse.Packets; | ||
39 | using OpenMetaverse.Imaging; | 40 | using OpenMetaverse.Imaging; |
40 | using OpenSim.Framework; | 41 | using OpenSim.Framework; |
41 | using OpenSim.Services.Interfaces; | 42 | using OpenSim.Services.Interfaces; |
@@ -397,6 +398,73 @@ namespace OpenSim.Region.Framework.Scenes | |||
397 | 398 | ||
398 | #endregion | 399 | #endregion |
399 | 400 | ||
401 | #region BinaryStats | ||
402 | |||
403 | public class StatLogger | ||
404 | { | ||
405 | public DateTime StartTime; | ||
406 | public string Path; | ||
407 | public System.IO.BinaryWriter Log; | ||
408 | } | ||
409 | static StatLogger m_statLog = null; | ||
410 | static TimeSpan m_statLogPeriod = TimeSpan.FromSeconds(300); | ||
411 | static string m_statsDir = String.Empty; | ||
412 | static Object m_statLockObject = new Object(); | ||
413 | private void LogSimStats(SimStats stats) | ||
414 | { | ||
415 | SimStatsPacket pack = new SimStatsPacket(); | ||
416 | pack.Region = new SimStatsPacket.RegionBlock(); | ||
417 | pack.Region.RegionX = stats.RegionX; | ||
418 | pack.Region.RegionY = stats.RegionY; | ||
419 | pack.Region.RegionFlags = stats.RegionFlags; | ||
420 | pack.Region.ObjectCapacity = stats.ObjectCapacity; | ||
421 | //pack.Region = //stats.RegionBlock; | ||
422 | pack.Stat = stats.StatsBlock; | ||
423 | pack.Header.Reliable = false; | ||
424 | |||
425 | // note that we are inside the reporter lock when called | ||
426 | DateTime now = DateTime.Now; | ||
427 | |||
428 | // hide some time information into the packet | ||
429 | pack.Header.Sequence = (uint)now.Ticks; | ||
430 | |||
431 | lock (m_statLockObject) // m_statLog is shared so make sure there is only executer here | ||
432 | { | ||
433 | try | ||
434 | { | ||
435 | if (m_statLog == null || now > m_statLog.StartTime + m_statLogPeriod) | ||
436 | { | ||
437 | // First log file or time has expired, start writing to a new log file | ||
438 | if (m_statLog != null && m_statLog.Log != null) | ||
439 | { | ||
440 | m_statLog.Log.Close(); | ||
441 | } | ||
442 | m_statLog = new StatLogger(); | ||
443 | m_statLog.StartTime = now; | ||
444 | m_statLog.Path = (m_statsDir.Length > 0 ? m_statsDir + System.IO.Path.DirectorySeparatorChar.ToString() : "") | ||
445 | + String.Format("stats-{0}.log", now.ToString("yyyyMMddHHmmss")); | ||
446 | m_statLog.Log = new BinaryWriter(File.Open(m_statLog.Path, FileMode.Append, FileAccess.Write)); | ||
447 | } | ||
448 | |||
449 | // Write the serialized data to disk | ||
450 | if (m_statLog != null && m_statLog.Log != null) | ||
451 | m_statLog.Log.Write(pack.ToBytes()); | ||
452 | } | ||
453 | catch (Exception ex) | ||
454 | { | ||
455 | m_log.Error("statistics gathering failed: " + ex.Message, ex); | ||
456 | if (m_statLog != null && m_statLog.Log != null) | ||
457 | { | ||
458 | m_statLog.Log.Close(); | ||
459 | } | ||
460 | m_statLog = null; | ||
461 | } | ||
462 | } | ||
463 | return; | ||
464 | } | ||
465 | |||
466 | #endregion | ||
467 | |||
400 | #region Constructors | 468 | #region Constructors |
401 | 469 | ||
402 | public Scene(RegionInfo regInfo, AgentCircuitManager authen, | 470 | public Scene(RegionInfo regInfo, AgentCircuitManager authen, |
@@ -582,6 +650,38 @@ namespace OpenSim.Region.Framework.Scenes | |||
582 | } | 650 | } |
583 | 651 | ||
584 | m_log.Info("[SCENE]: Using the " + m_update_prioritization_scheme + " prioritization scheme"); | 652 | m_log.Info("[SCENE]: Using the " + m_update_prioritization_scheme + " prioritization scheme"); |
653 | |||
654 | #region BinaryStats | ||
655 | |||
656 | try | ||
657 | { | ||
658 | IConfig statConfig = m_config.Configs["Statistics.Binary"]; | ||
659 | if (statConfig.Contains("enabled") && statConfig.GetBoolean("enabled")) | ||
660 | { | ||
661 | if (statConfig.Contains("collect_region_stats")) | ||
662 | { | ||
663 | if (statConfig.GetBoolean("collect_region_stats")) | ||
664 | { | ||
665 | // if enabled, add us to the event. If not enabled, I won't get called | ||
666 | StatsReporter.OnSendStatsResult += LogSimStats; | ||
667 | } | ||
668 | } | ||
669 | if (statConfig.Contains("region_stats_period_seconds")) | ||
670 | { | ||
671 | m_statLogPeriod = TimeSpan.FromSeconds(statConfig.GetInt("region_stats_period_seconds")); | ||
672 | } | ||
673 | if (statConfig.Contains("stats_dir")) | ||
674 | { | ||
675 | m_statsDir = statConfig.GetString("stats_dir"); | ||
676 | } | ||
677 | } | ||
678 | } | ||
679 | catch | ||
680 | { | ||
681 | // if it doesn't work, we don't collect anything | ||
682 | } | ||
683 | |||
684 | #endregion BinaryStats | ||
585 | } | 685 | } |
586 | catch | 686 | catch |
587 | { | 687 | { |