示例#1
0
        public bool IsWow64Process(SafeProcessHandle process)
        {
            IntPtr handle = process == null?GetCurrentProcess() : process.DangerousGetHandle();

            if (IO.Windows.FileSystemWin.StaticIsOSVersionGreaterOrEqual(IO.Windows.FileSystemWin.MinWindowsVersionThatSupportsWow64Processes))
            {
                return(ExternIsWow64Process(handle, out bool result) && result);
            }

            return(false);
        }
示例#2
0
        /// <inheritdoc />
        public ulong?GetActivePeakWorkingSet()
        {
            using (m_queryJobDataLock.AcquireReadLock())
            {
                var detouredProcess = m_detouredProcess;
                if (detouredProcess == null ||
                    !detouredProcess.HasStarted ||
                    detouredProcess.HasExited ||
                    m_disposeStarted)
                {
                    return(null);
                }

                ulong?currentPeakWorkingSet    = null;
                ulong?currentPeakPagefileUsage = null;

                var jobObject = detouredProcess.GetJobObject();
                if (jobObject == null || !jobObject.TryGetProcessIds(out uint[] childProcessIds) || childProcessIds.Length == 0)
                {
                    return(null);
                }

                foreach (uint processId in childProcessIds)
                {
                    using (SafeProcessHandle processHandle = ProcessUtilities.OpenProcess(
                               ProcessSecurityAndAccessRights.PROCESS_QUERY_INFORMATION,
                               false,
                               processId))
                    {
                        if (processHandle.IsInvalid)
                        {
                            // we are too late: could not open process
                            continue;
                        }

                        if (!jobObject.ContainsProcess(processHandle))
                        {
                            // we are too late: process id got reused by another process
                            continue;
                        }

                        int exitCode;
                        if (!ProcessUtilities.GetExitCodeProcess(processHandle, out exitCode))
                        {
                            // we are too late: process id got reused by another process
                            continue;
                        }

                        var memoryUsage = Interop.Dispatch.GetMemoryUsageCounters(processHandle.DangerousGetHandle());
                        if (memoryUsage != null)
                        {
                            currentPeakWorkingSet    = (currentPeakWorkingSet ?? 0) + memoryUsage.PeakWorkingSetSize;
                            currentPeakPagefileUsage = (currentPeakPagefileUsage ?? 0) + memoryUsage.PeakPagefileUsage;
                        }
                    }
                }

                m_peakWorkingSet.RegisterSample(currentPeakWorkingSet ?? 0);
                m_peakPagefileUsage.RegisterSample(currentPeakPagefileUsage ?? 0);

                return(currentPeakWorkingSet);
            }
        }