48 lines
1.6 KiB
C#
48 lines
1.6 KiB
C#
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 += "<table>";
|
|
foreach (var el in list)
|
|
{
|
|
result += string.Format("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><tr/>", el.ProcedureName, el.TotalMs, el.Count, el.Average);
|
|
}
|
|
result += "</table>";
|
|
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<PerformanceMeasuereElement> list = new List<PerformanceMeasuereElement>();
|
|
private class PerformanceMeasuereElement
|
|
{
|
|
public string ProcedureName = string.Empty;
|
|
public int Count = 0;
|
|
public double TotalMs = 0;
|
|
public double Average = 0;
|
|
}
|
|
}
|
|
}
|