libprocessgroup: add support to set aggregate profiles
To support setting multiple profiles with one call. The json format
is as below example.
"AggregateProfiles": [
...
{
"Name": "SCHED_SP_BACKGROUND",
"Profiles": [ "HighEnergySaving", "LowIoPriority", "TimerSlackHigh" ]
},
...
}
Bug: 139521784
Test: SetProfile works as expected
Change-Id: Ibe14ed57d5169cafcbcbbdb054df3ed171a2f6a2
diff --git a/libprocessgroup/processgroup.cpp b/libprocessgroup/processgroup.cpp
index 7c191be..7b6dde2 100644
--- a/libprocessgroup/processgroup.cpp
+++ b/libprocessgroup/processgroup.cpp
@@ -117,43 +117,11 @@
bool SetProcessProfiles(uid_t uid, pid_t pid, const std::vector<std::string>& profiles,
bool use_fd_cache) {
- const TaskProfiles& tp = TaskProfiles::GetInstance();
-
- for (const auto& name : profiles) {
- TaskProfile* profile = tp.GetProfile(name);
- if (profile != nullptr) {
- if (use_fd_cache) {
- profile->EnableResourceCaching();
- }
- if (!profile->ExecuteForProcess(uid, pid)) {
- PLOG(WARNING) << "Failed to apply " << name << " process profile";
- }
- } else {
- PLOG(WARNING) << "Failed to find " << name << "process profile";
- }
- }
-
- return true;
+ return TaskProfiles::GetInstance().SetProcessProfiles(uid, pid, profiles, use_fd_cache);
}
bool SetTaskProfiles(int tid, const std::vector<std::string>& profiles, bool use_fd_cache) {
- const TaskProfiles& tp = TaskProfiles::GetInstance();
-
- for (const auto& name : profiles) {
- TaskProfile* profile = tp.GetProfile(name);
- if (profile != nullptr) {
- if (use_fd_cache) {
- profile->EnableResourceCaching();
- }
- if (!profile->ExecuteForTask(tid)) {
- PLOG(WARNING) << "Failed to apply " << name << " task profile";
- }
- } else {
- PLOG(WARNING) << "Failed to find " << name << "task profile";
- }
- }
-
- return true;
+ return TaskProfiles::GetInstance().SetTaskProfiles(tid, profiles, use_fd_cache);
}
static std::string ConvertUidToPath(const char* cgroup, uid_t uid) {