/// <summary> /// Logs a statistics. /// </summary> /// <param name="level">The log level used for logging the statistics</param> /// <param name="recursive">Bool telling if the log should be recursive, or just display averages.</param> /// <param name="statistics">The statistics to be logged</param> public static void Log(LogLevel level, bool recursive, StatisticsSet statistics) { XmlElement el = statistics.GetXmlElement(doc, recursive); using (StringWriter sw = new StringWriter()) { XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.NewLineOnAttributes = false; settings.OmitXmlDeclaration = true; settings.Encoding = Encoding.UTF8; XmlWriter writer = XmlWriter.Create(sw, settings); el.WriteTo(writer); writer.Flush(); Platform.Log(level, sw.ToString()); writer.Close(); } foreach (IStatisticsLoggerListener extension in _extensions) { extension.OnStatisticsLogged(statistics); } }
public object Clone() { // create an instance of this specific type instead of StatisticsSet object newObject = Activator.CreateInstance(GetType()); // copy the basic stuff StatisticsSet copy = newObject as StatisticsSet; copy.Name = Name; copy.Description = Description; copy.Context = Context; // perform deep copy foreach (IStatistics field in Fields) { copy.AddField(field.Clone() as IStatistics); } foreach (StatisticsSet substat in SubStatistics) { copy.AddSubStats(substat.Clone() as StatisticsSet); } return(copy); }
/// <summary> /// Logs a statistics. /// </summary> /// <param name="logName">The name of the target log.</param> /// <param name="level">The log level used for logging the statistics</param> /// <param name="recursive">Bool telling if the log should be recursive, or just display averages.</param> /// <param name="statistics">The statistics to be logged</param> public static void Log(string logName, LogLevel level, bool recursive, StatisticsSet statistics) { Platform.Log(logName, level, GetLogString(statistics, recursive)); foreach (IStatisticsLoggerListener extension in _extensions) extension.OnStatisticsLogged(statistics); }
/// <summary> /// Logs a statistics. /// </summary> /// <param name="level">The log level used for logging the statistics</param> /// <param name="recursive">Bool telling if the log should be recursive, or just display averages.</param> /// <param name="statistics">The statistics to be logged</param> public static void Log(LogLevel level, bool recursive, StatisticsSet statistics) { Platform.Log(level, GetLogString(statistics, recursive)); foreach (IStatisticsLoggerListener extension in _extensions) { extension.OnStatisticsLogged(statistics); } }
protected virtual void ComputeAverage(StatisticsSet statistics) { foreach (IStatistics field in statistics.Fields) { IAverageStatistics average = field.NewAverageStatistics(); if (average == null) { continue; } object key = StatisticsHelper.ResolveID(average); if (this[key] != null) { average = this[key] as IAverageStatistics; Debug.Assert(average != null); } else { AddField(average); } if (field is Statistics <int> ) { average.AddSample(((Statistics <int>)field).Value); } else if (field is Statistics <uint> ) { average.AddSample(((Statistics <uint>)field).Value); } else if (field is Statistics <long> ) { //sum += ((Statistics<long>)field).Value; average.AddSample(((Statistics <long>)field).Value); } else if (field is Statistics <ulong> ) { average.AddSample(((Statistics <ulong>)field).Value); } else if (field is Statistics <double> ) { average.AddSample(((Statistics <double>)field).Value); } else if (field is TimeSpanStatistics) { TimeSpanStatistics stat = field as TimeSpanStatistics; if (stat.IsSet) { average.AddSample(((TimeSpanStatistics)field).Value); } } } }
private static string GetLogString(StatisticsSet statistics, bool recursive) { XmlElement el = statistics.GetXmlElement(_doc, recursive); using (var sw = new StringWriter()) { var settings = new XmlWriterSettings { Indent = true, NewLineOnAttributes = false, OmitXmlDeclaration = true, Encoding = Encoding.UTF8 }; using (XmlWriter writer = XmlWriter.Create(sw, settings)) { el.WriteTo(writer); writer.Flush(); return(sw.ToString()); } } }
private static string GetLogString(StatisticsSet statistics, bool recursive) { XmlElement el = statistics.GetXmlElement(_doc, recursive); using (var sw = new StringWriter()) { var settings = new XmlWriterSettings { Indent = true, NewLineOnAttributes = false, OmitXmlDeclaration = true, Encoding = Encoding.UTF8 }; using (XmlWriter writer = XmlWriter.Create(sw, settings)) { el.WriteTo(writer); writer.Flush(); return sw.ToString(); } } }
/// <summary> /// Logs a statistics. /// </summary> /// <param name="logName">The name of the target log.</param> /// <param name="level">The log level used for logging the statistics</param> /// <param name="statistics">The statistics to be logged</param> public static void Log(string logName, LogLevel level, StatisticsSet statistics) { Log(logName, level, true, statistics); }
/// <summary> /// Logs a statistics. /// </summary> /// <param name="level">The log level used for logging the statistics</param> /// <param name="statistics">The statistics to be logged</param> public static void Log(LogLevel level, StatisticsSet statistics) { Log(level, true, statistics); }
/// <summary> /// Adds a sub-statistics. /// </summary> /// <param name="stat"></param> public void AddSubStats(StatisticsSet stat) { Debug.Assert(stat.Context != null); Platform.CheckForNullReference(stat, "stat"); _subStatistics.Add(stat); }
protected virtual void ComputeAverage(StatisticsSet statistics) { foreach (IStatistics field in statistics.Fields) { IAverageStatistics average = field.NewAverageStatistics(); if (average == null) continue; object key = StatisticsHelper.ResolveID(average); if (this[key] != null) { average = this[key] as IAverageStatistics; Debug.Assert(average != null); } else { AddField(average); } if (field is Statistics<int>) { average.AddSample(((Statistics<int>) field).Value); } else if (field is Statistics<uint>) { average.AddSample(((Statistics<uint>) field).Value); } else if (field is Statistics<long>) { //sum += ((Statistics<long>)field).Value; average.AddSample(((Statistics<long>) field).Value); } else if (field is Statistics<ulong>) { average.AddSample(((Statistics<ulong>) field).Value); } else if (field is Statistics<double>) { average.AddSample(((Statistics<double>) field).Value); } else if (field is TimeSpanStatistics) { TimeSpanStatistics stat = field as TimeSpanStatistics; if (stat.IsSet) average.AddSample(((TimeSpanStatistics) field).Value); } } }