private RowAggregateData GetGroupAggregateData(string appName, AppResourceGroupInfo group, ulong totalProcessPrivateCommit) { Debug.WriteLine("GetGroupAggregateData: app: {0}, group: {1}", appName, group.InstanceId); ulong commitLimit = 0; ulong totalCommit = 0; ulong privateCommit = 0; ExecutionStateEx executionState = ExecutionStateEx.Unknown; EnergyQuotaStateEx energyState = EnergyQuotaStateEx.Unknown; int bgTaskCount = 0; try { AppResourceGroupMemoryReport mReport = group.GetMemoryReport(); if (mReport != null) { commitLimit = mReport.CommitUsageLimit; totalCommit = mReport.TotalCommitUsage; privateCommit = mReport.PrivateCommitUsage; } } catch (Exception ex) { Debug.WriteLine("GetMemoryReport: " + ex.ToString()); } // The resource group Private Commit should always be the same (or almost the same) as the PDI Private Commit. Debug.WriteLine("Private Commit: ResourceGroup={0:N0} bytes ~= Total PDI={1:N0} bytes", privateCommit, totalProcessPrivateCommit); try { AppResourceGroupStateReport sReport = group.GetStateReport(); if (sReport != null) { executionState = (ExecutionStateEx)sReport.ExecutionState; energyState = (EnergyQuotaStateEx)sReport.EnergyQuotaState; } } catch (Exception ex) { Debug.WriteLine("GetStateReport: " + ex.ToString()); } try { IList <AppResourceGroupBackgroundTaskReport> bgReports = group.GetBackgroundTaskReports(); if (bgReports != null) { bgTaskCount = bgReports.Count; } } catch (Exception ex) { Debug.WriteLine("GetBackgroundTaskReports: " + ex.ToString()); } RowAggregateData groupData = new RowAggregateData( commitLimit, totalCommit, privateCommit, bgTaskCount, executionState, energyState); return(groupData); }
public static async Task SuspendAppAsync() { AppResourceGroupInfo appResourceGroupInfo = null; // for Windows v1803 aka build 17134 and above, we can minimize by suspending // cannot minimize a full screen window, so take the app out of full screen ApplicationView view = ApplicationView.GetForCurrentView(); if (view.IsFullScreenMode) { view.ExitFullScreenMode(); } // figure out if we can suspend and can get the references we need if (ConfigurationService.DoesOSBuildSupportSuspend()) { // get app diagnostic information IList <AppDiagnosticInfo> diagnosticInformations = await AppDiagnosticInfo.RequestInfoForAppAsync(); // if we got them if ((null != diagnosticInformations) && (diagnosticInformations.Count > 0)) { // loop through the informations foreach (AppDiagnosticInfo diagnosticInformation in diagnosticInformations) { // if we find one with Id = "App" if (0 == String.Compare(diagnosticInformation.AppInfo.Id, "App", true)) { // get the resource groups from that diagnostic information IList <AppResourceGroupInfo> resourceGroups = diagnosticInformation.GetResourceGroups(); // if we got them if ((null != resourceGroups) && (resourceGroups.Count > 0)) { // take the first resource group appResourceGroupInfo = resourceGroups[0]; } } } } } // if we got a suspendable object, use it if (null != appResourceGroupInfo) { // we can suspend and got an resource info object to use AppExecutionStateChangeResult result = await appResourceGroupInfo.StartSuspendAsync(); } else { // we can't suspend, so must exit App.Current.Exit(); } }
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; } } } } } } } } }