using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DataAccessLayer
{
public static class SqlPerformanceMeasure
{
public static string ToHtml()
{
list = list.OrderBy(x => x.ProcedureName).ToList();
string result = string.Empty;
result += "
";
foreach (var el in list)
{
result += string.Format("{0} | {1} | {2} | {3} |
", el.ProcedureName, el.TotalMs, el.Count, el.Average);
}
result += "
";
return result;
}
public static void AddPerformanceEntry(string procedureName, double totalMs)
{
PerformanceMeasuereElement tmp = list.Where(x => x.ProcedureName.ToLower() == procedureName.ToLower()).FirstOrDefault();
if (tmp == null)
{
tmp = new PerformanceMeasuereElement()
{
ProcedureName = procedureName.ToLower()
};
list.Add(tmp);
}
tmp.TotalMs += totalMs;
tmp.Count++;
tmp.Average = tmp.TotalMs / tmp.Count;
}
private static List list = new List();
private class PerformanceMeasuereElement
{
public string ProcedureName = string.Empty;
public int Count = 0;
public double TotalMs = 0;
public double Average = 0;
}
}
}