コード例 #1
0
        internal static PROCESS_MEMORY_COUNTERS_EX GetCounters(IntPtr hProcess)
        {
            PROCESS_MEMORY_COUNTERS_EX counters = new PROCESS_MEMORY_COUNTERS_EX();

            counters.cb = Marshal.SizeOf(counters);
            if (NativeMemoryMethods.GetProcessMemoryInfo(hProcess, out counters, Marshal.SizeOf(counters)) == 0)
            {
                throw new Win32Exception();
            }

            return(counters);
        }
コード例 #2
0
        internal static long GetPrivateWorkingSet(Process process)
        {
            SYSTEM_INFO sysinfo = new SYSTEM_INFO();

            NativeMemoryMethods.GetSystemInfo(ref sysinfo);

            int wsInfoLength = (int)(Marshal.SizeOf(new PSAPI_WORKING_SET_INFORMATION()) +
                                     Marshal.SizeOf(new PSAPI_WORKING_SET_BLOCK()) * (process.WorkingSet64 / (sysinfo.dwPageSize)));
            IntPtr workingSetPointer = Marshal.AllocHGlobal(wsInfoLength);

            if (NativeMemoryMethods.QueryWorkingSet(process.Handle, workingSetPointer, wsInfoLength) == 0)
            {
                throw new Win32Exception();
            }

            PSAPI_WORKING_SET_INFORMATION workingSet = GenerateWorkingSetArray(workingSetPointer);

            Marshal.FreeHGlobal(workingSetPointer);

            return(CalculatePrivatePages(workingSet) * sysinfo.dwPageSize);
        }
コード例 #3
0
        private Dictionary <string, long> GenerateOracle(int processId)
        {
            Process testProcess = Process.GetProcessById(processId);
            PROCESS_MEMORY_COUNTERS_EX counters = GetCounters(testProcess.Handle);

            // Create oracle with correct data to verify against.
            Dictionary <string, long> oracle = new Dictionary <string, long>();

            oracle.Add("GdiObjectCount", NativeMemoryMethods.GetGuiResources(testProcess.Handle, NativeMemoryMethods.GR_GDIOBJECTS));
            oracle.Add("HandleCount", testProcess.HandleCount);
            oracle.Add("PageFileBytes", counters.PagefileUsage.ToInt64());
            oracle.Add("PageFilePeakBytes", counters.PeakPagefileUsage.ToInt64());
            oracle.Add("PoolNonpagedBytes", counters.QuotaNonPagedPoolUsage.ToInt64());
            oracle.Add("PoolPagedBytes", counters.QuotaPagedPoolUsage.ToInt64());
            oracle.Add("ThreadCount", testProcess.Threads.Count);
            oracle.Add("UserObjectCount", NativeMemoryMethods.GetGuiResources(testProcess.Handle, NativeMemoryMethods.GR_USEROBJECTS));
            oracle.Add("VirtualMemoryBytes", testProcess.VirtualMemorySize64);
            oracle.Add("VirtualMemoryPrivateBytes", counters.PrivateUsage.ToInt64());
            oracle.Add("WorkingSetBytes", testProcess.WorkingSet64);
            oracle.Add("WorkingSetPeakBytes", testProcess.PeakWorkingSet64);
            oracle.Add("WorkingSetPrivateBytes", GetPrivateWorkingSet(testProcess));

            return(oracle);
        }