Merge "libprocessgroup: Allow vendor profile attributes to override system ones"

This commit is contained in:
Treehugger Robot 2020-07-01 22:35:04 +00:00 committed by Gerrit Code Review
commit bf95cc25e3
2 changed files with 12 additions and 5 deletions

View file

@ -44,6 +44,11 @@ using android::base::WriteStringToFile;
#define TASK_PROFILE_DB_FILE "/etc/task_profiles.json" #define TASK_PROFILE_DB_FILE "/etc/task_profiles.json"
#define TASK_PROFILE_DB_VENDOR_FILE "/vendor/etc/task_profiles.json" #define TASK_PROFILE_DB_VENDOR_FILE "/vendor/etc/task_profiles.json"
void ProfileAttribute::Reset(const CgroupController& controller, const std::string& file_name) {
controller_ = controller;
file_name_ = file_name;
}
bool ProfileAttribute::GetPathForTask(int tid, std::string* path) const { bool ProfileAttribute::GetPathForTask(int tid, std::string* path) const {
std::string subgroup; std::string subgroup;
if (!controller()->GetTaskGroup(tid, &subgroup)) { if (!controller()->GetTaskGroup(tid, &subgroup)) {
@ -380,15 +385,16 @@ bool TaskProfiles::Load(const CgroupMap& cg_map, const std::string& file_name) {
std::string controller_name = attr[i]["Controller"].asString(); std::string controller_name = attr[i]["Controller"].asString();
std::string file_attr = attr[i]["File"].asString(); std::string file_attr = attr[i]["File"].asString();
if (attributes_.find(name) == attributes_.end()) { auto controller = cg_map.FindController(controller_name);
auto controller = cg_map.FindController(controller_name); if (controller.HasValue()) {
if (controller.HasValue()) { auto iter = attributes_.find(name);
if (iter == attributes_.end()) {
attributes_[name] = std::make_unique<ProfileAttribute>(controller, file_attr); attributes_[name] = std::make_unique<ProfileAttribute>(controller, file_attr);
} else { } else {
LOG(WARNING) << "Controller " << controller_name << " is not found"; iter->second->Reset(controller, file_attr);
} }
} else { } else {
LOG(WARNING) << "Attribute " << name << " is already defined"; LOG(WARNING) << "Controller " << controller_name << " is not found";
} }
} }

View file

@ -33,6 +33,7 @@ class ProfileAttribute {
const CgroupController* controller() const { return &controller_; } const CgroupController* controller() const { return &controller_; }
const std::string& file_name() const { return file_name_; } const std::string& file_name() const { return file_name_; }
void Reset(const CgroupController& controller, const std::string& file_name);
bool GetPathForTask(int tid, std::string* path) const; bool GetPathForTask(int tid, std::string* path) const;