private string GetForPidDotNet(int pid)
 {
     if (dotNetCache.GetValue().TryGetValue(pid, out var instanceId))
     {
         return(instanceId);
     }
     ProcessUtility.EnsureProcessIsRunning(pid);
     return(null);
 }
 private string GetForPid(int pid)
 {
     if (globalCache.GetValue().TryGetValue(pid, out var instanceId))
     {
         return(instanceId);
     }
     ProcessUtility.EnsureProcessIsRunning(pid);
     globalCache.Evict();
     if (!globalCache.GetValue().TryGetValue(pid, out instanceId))
     {
         throw new InvalidOperationException($"Process with pid {pid} exists, but not found in cache");
     }
     return(instanceId);
 }
Beispiel #3
0
        /// <summary>
        /// Estimates memory consumption
        /// </summary>
        /// <exception cref="InvalidOperationException">Process has exited</exception>
        /// <returns></returns>
        public ProcessMemoryInfo GetMemoryInfo()
        {
            ProcessUtility.EnsureProcessIsRunning(handle, pid);

            if (!PsApi.GetProcessMemoryInfo(handle, out var counters))
            {
                Win32ExceptionUtility.Throw();
            }

            return(new ProcessMemoryInfo
            {
                // use PrivateUsage instead of PagefileUsage because PagefileUsage is always zero on Windows 7, Windows Server 2008 R2 and earlier systems
                PrivateBytes = (long)counters.PrivateUsage,
                WorkingSetBytes = (long)counters.WorkingSetSize,
            });
        }
Beispiel #4
0
            public int GetThreadsCount(int pid)
            {
                if (TryGetThreadsCount(pid, out var count))
                {
                    return(count);
                }

                ProcessUtility.EnsureProcessIsRunning(pid);
                threadsCountCache.Evict();

                if (TryGetThreadsCount(pid, out count))
                {
                    return(count);
                }

                throw new InvalidOperationException($"Unable to retrieve process metrics for process with id {pid}");
            }