asp.net mvc ef 性能监控调试工具 MiniProfiler

  MiniProfiler是一款针对.NET, Ruby, Go and Node.js的性能分析的轻量级程序。可以对一个页面本身,及该页面通过直接引用、Ajax、Iframe形式访问的其它页面进行监控,监控内容包括数据库内容,并可以显示数据库访问的SQL(支持EF、EF CodeFirst等 )。并且以很友好的方式展现在页面上。

一、MiniProfiler官网:http://miniprofiler.com/

二、GIT地址:https://github.com/MiniProfiler/dotnet(源码-示例)

  1.AspNet.Core

  2.Console-ConsoleCore

  3.Mvc5.EFCore

  4.Mvc5

  5.具体使用推荐博客(https://www.cnblogs.com/jiekzou/p/6374726.html)

三、简介、

  MiniProfiler的一个特别有用的功能是它与数据库框架的集成。除了.NET原生的 DbConnection类,MiniProfiler还内置了对实体框架(Entity Framework)以及LINQ to SQL、RavenDb和MongoDB的支持。任何执行的Step都会包括当时查询的次数和所花费的时间。为了检测常见的错误,如N+1反模式,profiler将检测仅有参数值存在差异的多个查询。

    MiniProfiler是以Apache License V2.0协议发布的,你可以在NuGet找到。

  过去一直使用Sqlserver Profiler,但是发现实在是太痛苦了,你不得不进行新建、过滤、清除、关闭等操作,而且过滤筛选往往比较难以控制。后来发现MiniProfiler工具非常好用。

  同类监控工具有NanoProfiler,下载地址:https://github.com/ef-labs/nanoprofiler/issues/1

四、具体使用方法,推荐https://www.cnblogs.com/jiekzou/p/6374726.html

五、使用SQL Server时如何配置(……或其他任何使用ADO.NET)

MiniProfiler采用包装方法进行分析,这意味着分析SQL Server、MySQL等都是相同的,因为它们都基于ADO.NET基类和接口,比如DbConnection。

举例来说,要配置SQL Server,在使用之前只需包装连接,如下所示:

public DbConnection GetConnection()
{
    DbConnection connection = new System.Data.SqlClient.SqlConnection("...");
    return new StackExchange.Profiling.Data.ProfiledDbConnection(connection, MiniProfiler.Current);
}

配置SQLite的方法也类似,列如

public static DbConnection GetConnection()
{
    DbConnection connection = new System.Data.SQLite.SQLiteConnection("Data Source=:memory:");
    return new StackExchange.Profiling.Data.ProfiledDbConnection(connection, MiniProfiler.Current);
}

然后使用此连接,无论您想访问任何基于SQL的数据库,可以使用DAPPER或LIQ2SQL,或者使用任何访问SQL的方法都可以对他们进行分析。

posted @ 2018-10-16 15:40  无聊的蚂蚁  阅读(444)  评论(0编辑  收藏  举报