From 1d0a9e521c57c95987008fd48b8a44e3a966fe54 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 19 Mar 2014 00:28:57 +0000 Subject: Allow a snapshot of stats to be dumped to a file with a "stats save" command --- OpenSim/Framework/Monitoring/StatsLogger.cs | 49 +++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/OpenSim/Framework/Monitoring/StatsLogger.cs b/OpenSim/Framework/Monitoring/StatsLogger.cs index 1e4fa11..5822794 100644 --- a/OpenSim/Framework/Monitoring/StatsLogger.cs +++ b/OpenSim/Framework/Monitoring/StatsLogger.cs @@ -26,7 +26,10 @@ */ using System; +using System.Collections.Generic; +using System.IO; using System.Reflection; +using System.Text; using System.Timers; using log4net; @@ -52,6 +55,15 @@ namespace OpenSim.Framework.Monitoring "Control whether stats are being regularly recorded to a separate file.", "For debug purposes. Experimental.", HandleStatsRecordCommand); + + console.Commands.AddCommand( + "General", + false, + "stats save", + "stats save ", + "Save stats snapshot to a file. If the file already exists, then the report is appended.", + "For debug purposes. Experimental.", + HandleStatsSaveCommand); } public static void HandleStatsRecordCommand(string module, string[] cmd) @@ -76,6 +88,27 @@ namespace OpenSim.Framework.Monitoring } } + public static void HandleStatsSaveCommand(string module, string[] cmd) + { + ICommandConsole con = MainConsole.Instance; + + if (cmd.Length != 3) + { + con.Output("Usage: stats save "); + return; + } + + string path = cmd[2]; + + using (StreamWriter sw = new StreamWriter(path, true)) + { + foreach (string line in GetReport()) + sw.WriteLine(line); + } + + MainConsole.Instance.OutputFormat("Stats saved to file {0}", path); + } + public static void Start() { if (m_loggingTimer != null) @@ -97,12 +130,22 @@ namespace OpenSim.Framework.Monitoring private static void Log(object sender, ElapsedEventArgs e) { - m_statsLog.InfoFormat("*** STATS REPORT AT {0} ***", DateTime.Now); + foreach (string line in GetReport()) + m_statsLog.Info(line); + + m_loggingTimer.Start(); + } + + private static List GetReport() + { + List lines = new List(); + + lines.Add(string.Format("*** STATS REPORT AT {0} ***", DateTime.Now)); foreach (string report in StatsManager.GetAllStatsReports()) - m_statsLog.Info(report); + lines.Add(report); - m_loggingTimer.Start(); + return lines; } } } \ No newline at end of file -- cgit v1.1