Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PetaPocoGlimpse
[GlimpsePlugin]
public class PetaPocoGlimpsePlugin : IGlimpsePlugin
{
public object GetData(HttpContextBase context)
{
if (context.Items[DataProfiler.PetaKey] == null)
return new List<object[]> { new[] { "Log" }, new[] { "No database requests or database logging not switched on (Compilation debug='true' or ForceLogging='true' on
PetaPoco.DatabaseWithLogging)", "warn" } };
var sqls = new List<object[]> {new[] {"#", "Time(ms)", "Sql", "Parameters"}};
var i = 1;
foreach (var item in DataProfiler.CurrentRequestInfo)
{
var parameterHeadings = new List<object[]> {new[] {"Name", "Type", "Value"}};
parameterHeadings.AddRange(item.Parameters.Cast<IDataParameter>().Select(pm => new[] { pm.ParameterName, pm.Value.GetType().Name, pm.Value }));
object parameters = parameterHeadings.Count > 1 ? parameterHeadings : null;
var formattedTime = item.Time.ToString("0.#0");
var time = item.Time > 100 ? "*"+formattedTime+"*" : formattedTime;
sqls.Add(new[] { i++, time, item.Sql, parameters });
}
return sqls;
}
public void SetupInit()
{
}
public string Name
{
get { return "PetaPoco"; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment