public ProcessInfoModel(ProcessDiagnosticInfo process) { ProcessCpuUsageReport cpuReport = process.CpuUsage.GetReport(); if (cpuReport != null) { TimeSpan cpuUsageTime = cpuReport.KernelTime + cpuReport.UserTime; CpuUsageTime = string.Format("{0:hh\\:mm\\:ss}", cpuUsageTime); } ProcessDiskUsageReport diskReport = process.DiskUsage.GetReport(); if (diskReport != null) { DiskBytesCount = diskReport.BytesReadCount + diskReport.BytesWrittenCount; } ProcessMemoryUsageReport memoryReport = process.MemoryUsage.GetReport(); if (memoryReport != null) { PageFileSize = memoryReport.PageFileSizeInBytes; WorkingSetSize = memoryReport.WorkingSetSizeInBytes; } ProcessId = process.ProcessId; ExeName = process.ExecutableFileName; }
private void DoMonitor(object state) { #if NETFX_CORE ProcessCpuUsageReport report = CurrentProcess.GetReport(); if (monitorProcessorTime) { ProcessorTime = report.KernelTime.Ticks / System.Environment.ProcessorCount; if (ProcessorTime > PeakProcessorTime) { PeakProcessorTime = ProcessorTime; } } if (monitorUserTime) { UserTime = report.UserTime.Ticks / System.Environment.ProcessorCount; if (UserTime > PeakUserTime) { PeakUserTime = UserTime; } } #else if (monitorPrivilegedTime) { PrivilegedTime = privilegedTimeCounter.NextValue() / System.Environment.ProcessorCount; if (PrivilegedTime > PeakPrivilegedTime) { PeakPrivilegedTime = PrivilegedTime; } } if (monitorProcessorTime) { ProcessorTime = processorTimeCounter.NextValue() / System.Environment.ProcessorCount; if (ProcessorTime > PeakProcessorTime) { PeakProcessorTime = ProcessorTime; } } if (monitorUserTime) { UserTime = userTimeCounter.NextValue() / System.Environment.ProcessorCount; if (UserTime > PeakUserTime) { PeakUserTime = UserTime; } } #endif }
public async static void Update() { if (processes != null) { foreach (ProcessDiagnosticInfo process in processes) { string exeName = process.ExecutableFileName; string pid = process.ProcessId.ToString(); ProcessCpuUsageReport cpuReport = process.CpuUsage.GetReport(); TimeSpan userCpu = cpuReport.UserTime; TimeSpan kernelCpu = cpuReport.KernelTime; ProcessMemoryUsageReport memReport = process.MemoryUsage.GetReport(); ulong npp = memReport.NonPagedPoolSizeInBytes; ulong pp = memReport.PagedPoolSizeInBytes; ulong peakNpp = memReport.PeakNonPagedPoolSizeInBytes; //...etc ProcessDiskUsageReport diskReport = process.DiskUsage.GetReport(); long bytesRead = diskReport.BytesReadCount; long bytesWritten = diskReport.BytesWrittenCount; //...etc if (process.IsPackaged) { IList <AppDiagnosticInfo> diagnosticInfos = process.GetAppDiagnosticInfos(); if (diagnosticInfos != null && diagnosticInfos.Count > 0) { AppDiagnosticInfo diagnosticInfo = diagnosticInfos.FirstOrDefault(); if (diagnosticInfo != null) { IList <AppResourceGroupInfo> groups = diagnosticInfo.GetResourceGroups(); if (groups != null && groups.Count > 0) { AppResourceGroupInfo group = groups.FirstOrDefault(); if (group != null) { string name = diagnosticInfo.AppInfo.DisplayInfo.DisplayName; string description = diagnosticInfo.AppInfo.DisplayInfo.Description; BitmapImage bitmapImage = await GetLogoAsync(diagnosticInfo); AppResourceGroupStateReport stateReport = group.GetStateReport(); if (stateReport != null) { string executionStatus = stateReport.ExecutionState.ToString(); string energyStatus = stateReport.EnergyQuotaState.ToString(); } AppResourceGroupMemoryReport memoryReport = group.GetMemoryReport(); if (memoryReport != null) { AppMemoryUsageLevel level = memoryReport.CommitUsageLevel; ulong limit = memoryReport.CommitUsageLimit; ulong totalCommit = memoryReport.TotalCommitUsage; ulong privateCommit = memoryReport.PrivateCommitUsage; ulong sharedCommit = totalCommit - privateCommit; } } } } } } } } }
private AppInfoDetails CreateDetailsFromDiagnostics(AppRowInfo ari) { Debug.WriteLine("CreateDetailsFromDiagnostics: aumid={0}, name={1}", ari.Adi.AppInfo.AppUserModelId, ari.Adi.AppInfo.DisplayInfo.DisplayName); AppInfoDetails appDetails = null; try { // Create an AppInfoDetails from this AppRowInfo.AppDiagnosticInfo. IList <GroupInfoDetails> groupDetails = new List <GroupInfoDetails>(); IList <AppResourceGroupInfo> groups = ari.Adi.GetResourceGroups(); if (groups != null && groups.Count > 0) { foreach (AppResourceGroupInfo group in groups) { Debug.WriteLine("group Id: {0}", group.InstanceId); IList <ProcessInfoDetails> pDetails = new List <ProcessInfoDetails>(); IList <ProcessDiagnosticInfo> pInfos = group.GetProcessDiagnosticInfos(); if (pInfos != null && pInfos.Count > 0) { foreach (ProcessDiagnosticInfo pInfo in pInfos) { TimeSpan kernel = TimeSpan.Zero; TimeSpan user = TimeSpan.Zero; ulong npp = 0; ulong pp = 0; ulong pFault = 0; ulong pFile = 0; ulong pNpp = 0; ulong pPP = 0; ulong ppFile = 0; ulong pVirt = 0; ulong pWSet = 0; ulong ppc = 0; ulong vm = 0; ulong ws = 0; long br = 0; long bw = 0; long ob = 0; long oo = 0; long ro = 0; long wo = 0; ProcessCpuUsageReport pcReport = pInfo.CpuUsage.GetReport(); if (pcReport != null) { kernel = pcReport.KernelTime; user = pcReport.UserTime; } ProcessMemoryUsageReport pmReport = pInfo.MemoryUsage.GetReport(); if (pmReport != null) { npp = pmReport.NonPagedPoolSizeInBytes; pp = pmReport.PagedPoolSizeInBytes; pFault = pmReport.PageFaultCount; pFile = pmReport.PageFileSizeInBytes; pNpp = pmReport.PeakNonPagedPoolSizeInBytes; pPP = pmReport.PeakPagedPoolSizeInBytes; ppFile = pmReport.PeakPageFileSizeInBytes; pVirt = pmReport.PeakVirtualMemorySizeInBytes; pWSet = pmReport.PeakWorkingSetSizeInBytes; ppc = pmReport.PrivatePageCount; vm = pmReport.VirtualMemorySizeInBytes; ws = pmReport.WorkingSetSizeInBytes; } ProcessDiskUsageReport pdReport = pInfo.DiskUsage.GetReport(); if (pdReport != null) { br = pdReport.BytesReadCount; bw = pdReport.BytesWrittenCount; ob = pdReport.OtherBytesCount; oo = pdReport.OtherOperationCount; ro = pdReport.ReadOperationCount; wo = pdReport.WriteOperationCount; } ProcessInfoDetails pDetail = new ProcessInfoDetails( pInfo.ProcessId, pInfo.ExecutableFileName, pInfo.ProcessStartTime, kernel, user, npp, pp, pFault, pFile, pNpp, pPP, ppFile, pVirt, pWSet, ppc, vm, ws, br, bw, ob, oo, ro, wo); pDetails.Add(pDetail); } } AppMemoryUsageLevel usageLevel = AppMemoryUsageLevel.Low; ulong commitLimit = 0; ulong privateCommit = 0; ulong totalCommit = 0; AppResourceGroupExecutionState ex = AppResourceGroupExecutionState.Unknown; AppResourceGroupEnergyQuotaState eq = AppResourceGroupEnergyQuotaState.Unknown; AppResourceGroupMemoryReport mReport = group.GetMemoryReport(); AppResourceGroupStateReport sReport = group.GetStateReport(); IList <AppResourceGroupBackgroundTaskReport> bgReports = new List <AppResourceGroupBackgroundTaskReport>(); bgReports = group.GetBackgroundTaskReports(); if (mReport != null) { usageLevel = mReport.CommitUsageLevel; commitLimit = mReport.CommitUsageLimit; privateCommit = mReport.PrivateCommitUsage; totalCommit = mReport.TotalCommitUsage; } if (sReport != null) { ex = sReport.ExecutionState; eq = sReport.EnergyQuotaState; } GroupInfoDetails groupDetail = new GroupInfoDetails( group.InstanceId, group.IsShared, usageLevel, commitLimit, privateCommit, totalCommit, ex, eq, bgReports, pDetails); groupDetails.Add(groupDetail); } // We'll save time and get the cached Logo from the ARI, and get the rest of the data from the ADI. appDetails = new AppInfoDetails( ari.Logo, ari.Adi.AppInfo.AppUserModelId, ari.Adi.AppInfo.Id, ari.Adi.AppInfo.PackageFamilyName, ari.Adi.AppInfo.DisplayInfo.DisplayName, ari.Adi.AppInfo.DisplayInfo.Description, groupDetails); } } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } return(appDetails); }