Skip to content

Commit

Permalink
libprocessgroup: Allow vendor profile attributes to override system ones
Browse files Browse the repository at this point in the history
In the current implementation vendor profile attributes do not override
system ones and instead generate a warning. Fix that by overriding existing
attribute if a new definition is found.

Bug: 160318642
Test: add vendor attributes and confirm no warnings
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Merged-In: I71a2ee4d4b3c585e7c9a01b791e973390d409cbc
Change-Id: I71a2ee4d4b3c585e7c9a01b791e973390d409cbc

Former-commit-id: d4bc3f2adb882c4d7858653ab38f6f5a0baf5171
  • Loading branch information
surenbaghdasaryan committed Jul 1, 2020
1 parent 59a2423 commit 2a3540a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
16 changes: 11 additions & 5 deletions libprocessgroup/task_profiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ using android::base::WriteStringToFile;
#define TASK_PROFILE_DB_FILE "/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 {
std::string subgroup;
if (!controller()->GetTaskGroup(tid, &subgroup)) {
Expand Down Expand Up @@ -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 file_attr = attr[i]["File"].asString();

if (attributes_.find(name) == attributes_.end()) {
auto controller = cg_map.FindController(controller_name);
if (controller.HasValue()) {
auto controller = cg_map.FindController(controller_name);
if (controller.HasValue()) {
auto iter = attributes_.find(name);
if (iter == attributes_.end()) {
attributes_[name] = std::make_unique<ProfileAttribute>(controller, file_attr);
} else {
LOG(WARNING) << "Controller " << controller_name << " is not found";
iter->second->Reset(controller, file_attr);
}
} else {
LOG(WARNING) << "Attribute " << name << " is already defined";
LOG(WARNING) << "Controller " << controller_name << " is not found";
}
}

Expand Down
1 change: 1 addition & 0 deletions libprocessgroup/task_profiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class ProfileAttribute {

const CgroupController* controller() const { return &controller_; }
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;

Expand Down

0 comments on commit 2a3540a

Please sign in to comment.