예제 #1
0
        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 RowAggregateData(
     ulong limit, ulong total, ulong priv, int bg, ExecutionStateEx exState, EnergyQuotaStateEx enState)
 {
     CommitLimit    = limit;
     TotalCommit    = total;
     PrivateCommit  = priv;
     BgTaskCount    = bg;
     ExecutionState = exState;
     EnergyState    = enState;
 }
예제 #3
0
 public void Update(
     ulong limit, ulong total, ulong commit,
     ExecutionStateEx exState, EnergyQuotaStateEx enState, int bgCount)
 {
     CommitLimit         = limit;
     TotalCommit         = total;
     PrivateCommit       = commit;
     ExecutionState      = exState;
     EnergyQuotaState    = enState;
     BackgroundTaskCount = bgCount;
 }
예제 #4
0
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            if (value == null)
            {
                return(null);
            }

            string             returnValue = string.Empty;
            EnergyQuotaStateEx energyState = (EnergyQuotaStateEx)value;

            if (energyState != EnergyQuotaStateEx.NotApplicable)
            {
                returnValue = energyState.ToString();
            }
            return(returnValue);
        }
예제 #5
0
        public AppRowInfo(
            AppDiagnosticInfo a,
            string id,
            BitmapImage logo, string name,
            ulong limit, ulong totCommit, ulong prvCommit,
            ExecutionStateEx exState, EnergyQuotaStateEx eqState, int taskCount)
        {
            Adi  = a;
            Id   = id;
            Logo = logo;
            Name = name;

            commitLimit         = limit;
            totalCommit         = totCommit;
            privateCommit       = prvCommit;
            executionState      = exState;
            energyQuotaState    = eqState;
            backgroundTaskCount = taskCount;
        }
예제 #6
0
        public bool Update()
        {
            bool result = false;

            // If we don't lock the collection, there's a race where databinding could end up with
            // additional spurious instances, especially if the polling interval is only 1-2 sec.
            lock (lockObject)
            {
                // Get a list of running apps (filtered by permission level).
                IAsyncOperation <IList <AppDiagnosticInfo> > infoOperation = AppDiagnosticInfo.RequestInfoAsync();
                Task <IList <AppDiagnosticInfo> >            infoTask      = infoOperation.AsTask();
                infoTask.Wait();
                IList <AppDiagnosticInfo> runningApps = infoTask.Result;

                // We don't recreate the list each time: instead, we remove dead rows and update existing ones,
                // only adding new rows for new apps that appear. This is slow, but typically we'd only have a small
                // number of UWP apps running (say 5-20), so it's not noticeable.
                if (runningApps != null)
                {
                    // First, remove from the list any apps that are no longer in memory.
                    RemoveDeadRows(runningApps);

                    // Find key data from the bottom-up (process and group level) for roll-up purposes.
                    foreach (AppDiagnosticInfo app in runningApps)
                    {
                        ulong              appCommitLimit    = 0;
                        ulong              appTotalCommit    = 0;
                        ulong              appPrivateCommit  = 0;
                        ExecutionStateEx   appExecutionState = ExecutionStateEx.Unknown;
                        EnergyQuotaStateEx appEnergyState    = EnergyQuotaStateEx.Unknown;
                        int appBgTaskCount = 0;

                        // Get the roll-up data from group and process level.
                        IList <AppResourceGroupInfo> groups = app.GetResourceGroups();
                        if (groups != null)
                        {
                            foreach (AppResourceGroupInfo group in groups)
                            {
                                Debug.WriteLine("app: {0}, group Id: {1}", app.AppInfo.DisplayInfo.DisplayName, group.InstanceId);

                                // Get the total private commit usage of all processes for this app.
                                ulong totalProcessPrivateCommit         = 0;
                                IList <ProcessDiagnosticInfo> processes = group.GetProcessDiagnosticInfos();
                                if (processes != null)
                                {
                                    foreach (ProcessDiagnosticInfo process in processes)
                                    {
                                        totalProcessPrivateCommit += GetProcessPrivateCommit(process);
                                    }
                                }

                                // Accumulate the aggregated totals for all resource groups for this app.
                                // We pass down the private commit for all processes for this group for comparison only.
                                RowAggregateData groupData = GetGroupAggregateData(
                                    app.AppInfo.DisplayInfo.DisplayName, group, totalProcessPrivateCommit);

                                appCommitLimit   += groupData.CommitLimit;
                                appTotalCommit   += groupData.TotalCommit;
                                appPrivateCommit += groupData.PrivateCommit;
                                appBgTaskCount   += groupData.BgTaskCount;

                                if (appExecutionState != groupData.ExecutionState)
                                {
                                    if (appExecutionState == ExecutionStateEx.Unknown)
                                    {
                                        appExecutionState = groupData.ExecutionState;
                                    }
                                    else
                                    {
                                        appExecutionState = ExecutionStateEx.Multiple;
                                    }
                                }
                                if (appEnergyState != groupData.EnergyState)
                                {
                                    if (appEnergyState == EnergyQuotaStateEx.Unknown)
                                    {
                                        appEnergyState = groupData.EnergyState;
                                    }
                                    else
                                    {
                                        appEnergyState = EnergyQuotaStateEx.Multiple;
                                    }
                                }
                            }
                        }

                        RowAggregateData appData = new RowAggregateData(
                            appCommitLimit, appTotalCommit, appPrivateCommit, appBgTaskCount, appExecutionState, appEnergyState);

                        // Now add or update the rows.
                        bool isAppAdded = AddOrUpdateApp(app, appData, appExecutionState);
                        if (isAppAdded)
                        {
                            // If any row update resulted in adding an app, we set the return value to true.
                            result = true;
                        }
                    }
                }
            }
            return(result);
        }