public ProcessTracker(Process p, QpcTimeStamp getTimeStamp) { activePTSetIndex = -1; touchedTimeStamp = getTimeStamp; process = p; pid = p.Id; name = Utils.ExtensionMethods.TryGet(() => p.ProcessName); basePriority = Utils.ExtensionMethods.TryGet(() => p.BasePriority); mainModule = Utils.ExtensionMethods.TryGet(() => p.MainModule); if (mainModule != null) { mainModuleFilePath = Utils.ExtensionMethods.TryGet(() => mainModule.FileName); mainModuleFileVersion = Utils.ExtensionMethods.TryGet(() => mainModule.FileVersionInfo); } availableItemsToTrack = TrackedValues.TestAvailableItems(p); prevTrackedValues = default(TrackedValues); trackedValues = TrackedValues.TryGetFrom(p, getTimeStamp, availableItemsToTrack, prevTrackedValues); }
public static TrackedValues TryGetFrom(Process p, QpcTimeStamp getTimeStamp, TrackItemSelect trackItemsSelect, TrackedValues prevTrackedValues) { TrackedValues result = default(TrackedValues); result.timeStamp = getTimeStamp; if ((trackItemsSelect & TrackItemSelect.Affinity) != 0) { result.affinity = Utils.ExtensionMethods.TryGet(() => unchecked ((UInt64)p.ProcessorAffinity.ToInt64())); } if ((trackItemsSelect & TrackItemSelect.HandleCount) != 0) { result.handleCount = Utils.ExtensionMethods.TryGet(() => p.HandleCount); } if ((trackItemsSelect & TrackItemSelect.VMSize) != 0) { result.virtualMemorySize = Utils.ExtensionMethods.TryGet(() => unchecked ((UInt64)p.VirtualMemorySize64)); result.peakVirtualMemorySize = Utils.ExtensionMethods.TryGet(() => unchecked ((UInt64)p.PeakVirtualMemorySize64)); } if ((trackItemsSelect & TrackItemSelect.WSSize) != 0) { result.workingSetSize = Utils.ExtensionMethods.TryGet(() => unchecked ((UInt64)p.WorkingSet64)); result.peakWorkingSetSize = Utils.ExtensionMethods.TryGet(() => unchecked ((UInt64)p.PeakWorkingSet64)); } if ((trackItemsSelect & TrackItemSelect.ProcTime) != 0) { result.cpuTime = Utils.ExtensionMethods.TryGet(() => p.TotalProcessorTime); result.userCpuTime = Utils.ExtensionMethods.TryGet(() => p.UserProcessorTime); double totalElapsedTime = (getTimeStamp - prevTrackedValues.timeStamp).TotalSeconds; double oneOverTotalElapsedTime = (totalElapsedTime > 0.0) ? (1.0 / totalElapsedTime) : 0.0; double incrementalTotalCPUUsed = (result.cpuTime - prevTrackedValues.cpuTime).TotalSeconds; double incrementalUserCPUUsed = (result.userCpuTime - prevTrackedValues.userCpuTime).TotalSeconds; result.cpuPerEst = (float)(incrementalTotalCPUUsed * oneOverTotalElapsedTime * 100.0); result.userCpuPerEst = (float)(incrementalUserCPUUsed * oneOverTotalElapsedTime * 100.0); } return(result); }
public void UpdateFrom(Process p, QpcTimeStamp getTimeStamp) { touchedTimeStamp = getTimeStamp; prevTrackedValues = trackedValues; trackedValues = TrackedValues.TryGetFrom(p, getTimeStamp, availableItemsToTrack, prevTrackedValues); }