Esempio n. 1
0
        /// <summary>
        /// Returns the peak memory usage of a specific process
        /// </summary>
        /// <param name="handle">When calling from Windows the SafeProcessHandle is required</param>
        /// <param name="pid">On non-windows systems a process id has to be provided</param>
        public static ulong?GetActivePeakMemoryUsage(IntPtr handle, int pid)
        {
            switch (s_currentOS)
            {
            case OperatingSystem.MacOS:
            {
                ulong peakMemoryUsage = 0;
                if (MacOS.Memory.GetPeakWorkingSetSize(pid, ref peakMemoryUsage) == MACOS_INTEROP_SUCCESS)
                {
                    return(peakMemoryUsage);
                }

                return(null);
            }

            default:
            {
                Process.PROCESSMEMORYCOUNTERSEX processMemoryCounters = new Windows.Process.PROCESSMEMORYCOUNTERSEX();

                if (Process.GetProcessMemoryInfo(handle, processMemoryCounters, processMemoryCounters.cb))
                {
                    return(processMemoryCounters.PeakWorkingSetSize);
                }

                return(null);
            }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Get memory usage with all counters for Windows
        /// </summary>
        public static Process.PROCESSMEMORYCOUNTERSEX GetMemoryUsageCounters(IntPtr handle)
        {
            switch (s_currentOS)
            {
            case OperatingSystem.MacOS:
            {
                return(null);
            }

            default:
            {
                Process.PROCESSMEMORYCOUNTERSEX processMemoryCounters = new Windows.Process.PROCESSMEMORYCOUNTERSEX();

                if (Process.GetProcessMemoryInfo(handle, processMemoryCounters, processMemoryCounters.cb))
                {
                    return(processMemoryCounters);
                }

                return(null);
            }
            }
        }