Skip to content

Instantly share code, notes, and snippets.

@taylonr
Created December 15, 2011 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taylonr/1481512 to your computer and use it in GitHub Desktop.
Save taylonr/1481512 to your computer and use it in GitHub Desktop.
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