<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          【中間件】.net和.net Core中使用MiniProfiler進行性能分析

          共 2075字,需瀏覽 5分鐘

           ·

          2022-03-08 05:23


          介紹

          作為一個開發(fā)人員,我們應該知道如何分析自己開發(fā)的Api性能么!

          MiniProfiler 是一個用于分析您的應用程序的庫和 UI。通過讓您查看您的時間花在哪里、運行了哪些查詢以及您想要添加的任何其他自定義時間,MiniProfiler 可以幫助您調(diào)試問題并優(yōu)化性能。

          ?

          MiniProfiler v4 在 .NET 4.6.1 及更高版本或 .NET Standard 1.5 及更高版本上運行。由于 v4 中添加了所有支持,因此需要 .NET 4.6.1+ async。如果您需要使用早于 .NET 4.6.1 的版本,MiniProfiler v3.x 適合您。

          ?

          官方地址:https://miniprofiler.com/dotnet/


          ?第一步打開VS新建.net項目我這里用的是.net core webapi 進行演示(提示: MiniProfiler在ASP.NET和控制臺程序中也可以使用哦。)





          第二步 使用Nuget安裝MiniProfiler.AspNetCore.Mvc包

          ?




          第三步配置Startup.cs

          ?

          在ConfigureServices方法中添加MiniProfiler服務

               public void ConfigureServices(IServiceCollection services)  {     services.AddMiniProfiler(options =>      options.RouteBasePath = "/profiler"     );  }

          這里是配置了MiniProfiler的路由基礎(chǔ)路徑,默認的路徑是/mini-profiler-resources

          按照當前配置,你可以使用"/profiler/results"來訪問分析報告


          第四步啟用該中間件

            public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)  {     app.UseMiniProfiler();  }

          第五步 配置監(jiān)控代碼 為了方便就用腳手架上自帶的Api進行分析

          MiniProfiler.Current.Step方法定義了分析的步驟,這個方法可以接受一個String類型的參數(shù),它會顯示在最終的報告中

          MiniProfiler.Current.CustomTiming方法是更細粒度的對報告內(nèi)容進行分類,以上代碼中定義了2種分類,一種是SQL, 一種是子方法

             using (MiniProfiler.Current.Step("整體測試"))            {



          using (MiniProfiler.Current.Step("第一個方法")) { using (MiniProfiler.Current.CustomTiming("SQL", "SELECT * FROM Table")) { Thread.Sleep(500); } } using (MiniProfiler.Current.Step("第二個方法")) { using (MiniProfiler.Current.CustomTiming("子方法1", "GET ")) { Thread.Sleep(700); }

          using (MiniProfiler.Current.CustomTiming("子方法2", "GET ")) { Thread.Sleep(800); } }





          }





          最后一步啟動程序查看我們接口的代碼的每一部分的耗時




          總結(jié)

          本篇博客描述了如何使用MiniProfiler來監(jiān)控分析你的Api。如何分析自己api的性能,

          如果覺得還不錯,請給個關(guān)注


          瀏覽 73
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  成人黄网站 免费视频 | 久久五月天AV | 亚洲欧洲在线观看高清 | 国产男女网站 | 精品无码一区二区三区在线 |