I’m using this code to print the sql timings in a console window:
private static Dictionary<string, List<CustomTiming>> GetSqlTimings(MiniProfiler mp)
{
var dictionary = new Dictionary<string, List<CustomTiming>>();
foreach (var timing in mp.GetTimingHierarchy())
{
if (timing.HasCustomTimings == false) continue;
foreach (var customTiming in timing.CustomTimings["sql"])
{
List<CustomTiming> list;
if (dictionary.TryGetValue(customTiming.CommandString, out list) == false)
{
list = new List<CustomTiming>();
dictionary.Add(customTiming.CommandString, list);
}
list.Add(customTiming);
}
}
return dictionary;
}
and
var sqlTimings = GetSqlTimings(MiniProfiler.Current);
if (sqlTimings.Any(x => x.Value.Count > 1))
{
foreach (var commandString in sqlTimings.Keys.OrderBy(x => sqlTimings[x].Sum(t => t.DurationMilliseconds)))
{
var count = sqlTimings[commandString].Count;
if (count > 1)
{
Console.WriteLine("DUPLICATES");
var sum = sqlTimings[commandString].Sum(t => t.DurationMilliseconds);
Console.WriteLine(new string('*', 40));
Console.WriteLine("{0}ms for {1} query duplicates\n{2}", sum, count, commandString);
}
}
}
This works fine, I’m able to see which queries are duplicated. However, I can’t seem to find the varying query parameters. Is there a way to access those parameters? It would be helpful to be able to see how they vary in order to understand which part of the linq statements that are turned into duplicates.
Thanks!