.NET Memory Profiler 查看內存使用情況


1 簡介

.Net Memory Profiler(以下簡稱Profiler):專門針對於.NET程序,功能最全的內存分析工具,最大的特點是具有內存動態分析(Automatic Memory Analysis)功能。

2 安裝

http://memprofiler.com/download.aspx

下載好后 直接下一步下一步

3 使用方法

支持7種類型.NET程序

  • 啟動跟蹤(Profiler Application)

    選定對應的調試方式,如調試桌面程序,選中Profiler Application,然后選擇需要啟動的執行文件,Profiler將作為宿主程序啟動程序開始實時監控內存.

  • 附加進程(Attach Process)

    將Profiler附加到指定的進程上,此時不能實時監控內存情況,只能夠收集內存鏡像.

  • 導入內存鏡像(Import Memory Dump)

    可以選擇dmp為后綴的內存鏡像文件,比如Windbg以及DebugDiag導出的鏡像文件,此時不能實時監控內存情況,只能夠收集內存鏡像且不能跟蹤非托管資源.

 

4 軟件設置

  為了加快Profiler分析內存類型實例的速度,需要設置程序的符號路徑即(Symbol File Locations),進入菜單Tool->Options->Preferences->Symobl File Locations,得到彈出菜單如下圖.

 

5 操作 

 

  首先,選擇需要調試類型,選擇 Profiler Application,選擇好需要啟動的程序exe文件. 

 

選擇級別

 程序代碼

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Couchbase;
using Couchbase.Configuration;
using Enyim.Caching.Memcached;

namespace CentaNet.CouchbaseTest
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = 0;
            while (true)
            {
                Console.WriteLine("=============第{0}次================", ++n);

                string Bucket = System.Configuration.ConfigurationManager.AppSettings["bucket"];
                string BucketPassword = Bucket;
                var key = "cottrell_brewing-old_yankee_ale" + DateTime.Now.ToString();
                Test(Bucket, BucketPassword, "http://10.4.18.13:8091/pools/default", key); 
                Console.Write("\n"); 
            }
        }

        static void Test(string Bucket, string BucketPassword, string url, string key)
        {
            var clientConfiguration = new CouchbaseClientConfiguration();
            clientConfiguration.Bucket = Bucket;
            clientConfiguration.BucketPassword = BucketPassword;
            clientConfiguration.Urls.Add(new Uri(url));
            clientConfiguration.SocketPool.ReceiveTimeout = new TimeSpan(0, 0, 111);
            clientConfiguration.SocketPool.ConnectionTimeout = new TimeSpan(0, 0, 111);
            clientConfiguration.SocketPool.DeadTimeout = new TimeSpan(0, 0, 111);
            var client = new CouchbaseClient(clientConfiguration);
            var result = client.Store(StoreMode.Set, key, "test");

            if (result)
            {
                var savedBeer = client.Get(key);
                Console.WriteLine(clientConfiguration.Urls[0].AbsoluteUri + "   " + savedBeer.ToString());
            }
            else
            {
                Console.WriteLine(clientConfiguration.Urls[0].AbsoluteUri + "   失敗" );
            }

        }
    }
}

執行效果如下

可以看到占用Uri資源實例是最多的

存儲快照 分析原因

 

雙擊

可以看出造成URI實例原因是 couchbasepool 造成的,可以跟蹤程序代碼

 

Import Memory Dump

轉存需要分析的dmp文件

 

 

需要下載SDK支持

https://developer.microsoft.com/en-us/windows/hardware/windows-driver-kit

 

可以看到內存的使用情況 分析溢出

推薦其他4款超實用的.NET性能分析工具

1.JetBrains dotTrace

  JetBrains dotTrace是一款性能和內存分析工具,它可以幫助你優化應用程序性能指標,支持.NET 1.0版本到4.5,快速分析程序瓶頸,找出影響效率的代碼。官方網站上面有10天試用版,大家可以點擊下載使用。

2.ANTS Performance Profiler

  ANTS性能分析器是一種用於分析.NET框架支持的用任何語言編寫的應用程序的工具。ANTS性能分析器能分析所有.NET應用程序,包括ASP.NET網絡應用程序、Windows服務和COM+應用程序。ANTS性能分析器能在幾分鍾內識別性能瓶頸,運行非常快速,且響應時,對程序的執行具有最低影響。ANTS性能分析器可用作一種獨立工具,也可用作Red Gate .NET Developer Bundle的一部分。目前支持14天免費試用,大家可以去體驗體驗。

3.EQATEC Profiler

  另一個非常好的.NET分析器,它擁有多個版本,有免費版,標准版、專業版等。不僅使用方便,而且優化速度也相當快。

4.Telerik Just Trace

  Telerik Just Trace是一款幫你輕松找出內存泄漏的分析工具,並且可以輕松搞定許多性能問題。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM