C#實現(xiàn)進程內(nèi)存信息獲取-創(chuàng)新互聯(lián)

usingSystem.Collections.Generic;
usingSystem.Runtime.InteropServices;
usingSystem;
usingSystem.Diagnostics;
staticclassNat
{
   [StructLayout(LayoutKind.Sequential]
   struct IO_COUNTERS
   {
       publiculongReadOperationCount;
       publiculongWriteOperationCount;
       publiculongOtherOperationCount;
       publiculongReadTransferCount;
       publiculongWriteTransferCount;
       publiculongOtherTransferCount;
   }
   [DllImport("kernel32.dll")]
   unsafestaticextern boolGetProcessIoCounters(IntPtrProcessHandle,out IO_COUNTERSIoCounters);

   [StructLayout(LayoutKind.Sequential,Size=40)]
   privatestruct PROCESS_MEMORY_COUNTERS
   {
       publicuint cb;
       publicuintPageFaultCount;
       publicuintPeakWorkingSetSize;
       publicuintWorkingSetSize;
       publicuintQuotaPeakPagedPoolUsage;
       publicuintQuotaPagedPoolUsage;
       publicuintQuotaPeakNonPagedPoolUsage;
       publicuintQuotaNonPagedPoolUsage;
       publicuintPagefileUsage;
       publicuintPeakPagefileUsage;
   }

   [DllImport("psapi.dll",SetLastError=true)]
   unsafestaticextern boolGetProcessMemoryInfo(IntPtr* hProcess,out PROCESS_MEMORY_COUNTERS*Memcounters,int size);

   publicstaticclass IO
   {
       unsafepublicstaticDictionary<string,ulong>GetALLIO(Process procToRtrivIO)
       {
           IO_COUNTERS counters;
           Dictionary<string,ulong> retCountIoDict=newDictionary<string,ulong>();
           IntPtr ptr=System.Diagnostics.Process.GetCurrentProcess().Handle;

           GetProcessIoCounters(ptr,out counters);
           retCountIoDict.Add("ReadOperationCount", counters.ReadOperationCount);
           retCountIoDict.Add("WriteOperationCount", counters.WriteOperationCount);
           retCountIoDict.Add("OtherOperationCount", counters.OtherOperationCount);
           retCountIoDict.Add("ReadTransferCount", counters.ReadTransferCount);
           retCountIoDict.Add("WriteTransferCount", counters.WriteTransferCount);
           retCountIoDict.Add("OtherTransferCount", counters.OtherTransferCount);
           return retCountIoDict;
           //return "This process has read " + ((counters.ReadTransferCount/1024)/1024).ToString("N0") +
           //   " Mb of data.";

       }
   }
   publicstaticclassMem
   {
       unsafepublicstaticDictionary<string,uint>GetAllMem(Process procToRtrivMem)
       {

           PROCESS_MEMORY_COUNTERS*MemCounters;
           Dictionary<string,uint> retCountMemDict=newDictionary<string,uint>();
           IntPtr ptr=System.Diagnostics.Process.GetCurrentProcess().Handle;

           GetProcessMemoryInfo(&ptr,outMemCounters,Marshal.SizeOf(typeof(PROCESS_MEMORY_COUNTERS)));//MemCounters.cb);
           retCountMemDict.Add("cb",MemCounters->cb);
           retCountMemDict.Add("PageFaultCount",MemCounters->PageFaultCount);
           retCountMemDict.Add("PeakWorkingSetSize",MemCounters->PeakWorkingSetSize);
           retCountMemDict.Add("WorkingSetSize",MemCounters->WorkingSetSize);
           retCountMemDict.Add("QuotaPeakPagedPoolUsage",MemCounters->QuotaPeakPagedPoolUsage);
           retCountMemDict.Add("QuotaPagedPoolUsage",MemCounters->QuotaPagedPoolUsage);

           retCountMemDict.Add("QuotaPeakNonPagedPoolUsage",MemCounters->QuotaPeakNonPagedPoolUsage);
           retCountMemDict.Add("QuotaNonPagedPoolUsage",MemCounters->QuotaNonPagedPoolUsage);
           retCountMemDict.Add("PagefileUsage",MemCounters->PagefileUsage);
           retCountMemDict.Add("PeakPagefileUsage",MemCounters->PeakPagefileUsage);

           return retCountMemDict;
           //return "This process has read " + ((counters.ReadTransferCount/1024)/1024).ToString("N0") +
           //   " Mb of data.";

       }
   }
}
C#實現(xiàn)進程內(nèi)存信息獲取

 參考:using unsafe code in C# asp.net  http://stackoverflow.com/questions/17207310/using-unsafe-code-in-c-sharp-asp-net

創(chuàng)新互聯(lián)公司從2013年成立,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項目網(wǎng)站設(shè)計制作、成都網(wǎng)站建設(shè)網(wǎng)站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元塔什庫爾干塔吉克做網(wǎng)站,已為上家服務(wù),為塔什庫爾干塔吉克各地企業(yè)和個人服務(wù),聯(lián)系電話:18980820575

collectiong memory usage information for a processhttp://msdn.microsoft.com/en-us/library/windows/desktop/ms682050(v=vs.85).aspx

在C#中調(diào)用psapi.dll內(nèi)置的GetProcessMemoryInfo函數(shù)http://social.microsoft.com/Forums/it-IT/650197e0-a21a-4f5e-a974-23f074f52a55/cpsapidllgetprocessmemoryinfo?forum=visualcshartzhchs

ASP.NET(C#)獲取當前計算機CPU內(nèi)存使用率等相關(guān)信息http://luzinwbing.blog.163.com/blog/static/113805840201031093415658/

 不安全代碼只會在使用/unsafe編譯情況下使用 http://lixiaorong223.blog.163.com/blog/static/44011629200993181241924/

wmi獲得進程的虛擬內(nèi)存與任務(wù)管理器中顯示的不一致 http://bbs.csdn.net/topics/260033107

文章標題:C#實現(xiàn)進程內(nèi)存信息獲取-創(chuàng)新互聯(lián)
文章鏈接:http://muchs.cn/article18/cddpdp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供全網(wǎng)營銷推廣、手機網(wǎng)站建設(shè)面包屑導航、App設(shè)計網(wǎng)站排名、關(guān)鍵詞優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都app開發(fā)公司