Loading libprocessgroup/task_profiles.cpp +4 −2 Original line number Original line Diff line number Diff line Loading @@ -477,6 +477,7 @@ void TaskProfile::MoveTo(TaskProfile* profile) { bool TaskProfile::ExecuteForProcess(uid_t uid, pid_t pid) const { bool TaskProfile::ExecuteForProcess(uid_t uid, pid_t pid) const { for (const auto& element : elements_) { for (const auto& element : elements_) { if (!element->ExecuteForProcess(uid, pid)) { if (!element->ExecuteForProcess(uid, pid)) { LOG(VERBOSE) << "Applying profile action " << element->Name() << " failed"; return false; return false; } } } } Loading @@ -489,6 +490,7 @@ bool TaskProfile::ExecuteForTask(int tid) const { } } for (const auto& element : elements_) { for (const auto& element : elements_) { if (!element->ExecuteForTask(tid)) { if (!element->ExecuteForTask(tid)) { LOG(VERBOSE) << "Applying profile action " << element->Name() << " failed"; return false; return false; } } } } Loading Loading @@ -600,7 +602,7 @@ bool TaskProfiles::Load(const CgroupMap& cg_map, const std::string& file_name) { std::string profile_name = profile_val["Name"].asString(); std::string profile_name = profile_val["Name"].asString(); const Json::Value& actions = profile_val["Actions"]; const Json::Value& actions = profile_val["Actions"]; auto profile = std::make_shared<TaskProfile>(); auto profile = std::make_shared<TaskProfile>(profile_name); for (Json::Value::ArrayIndex act_idx = 0; act_idx < actions.size(); ++act_idx) { for (Json::Value::ArrayIndex act_idx = 0; act_idx < actions.size(); ++act_idx) { const Json::Value& action_val = actions[act_idx]; const Json::Value& action_val = actions[act_idx]; Loading Loading @@ -710,7 +712,7 @@ bool TaskProfiles::Load(const CgroupMap& cg_map, const std::string& file_name) { } } } } if (ret) { if (ret) { auto profile = std::make_shared<TaskProfile>(); auto profile = std::make_shared<TaskProfile>(aggregateprofile_name); profile->Add(std::make_unique<ApplyProfileAction>(profiles)); profile->Add(std::make_unique<ApplyProfileAction>(profiles)); profiles_[aggregateprofile_name] = profile; profiles_[aggregateprofile_name] = profile; } } Loading libprocessgroup/task_profiles.h +11 −1 Original line number Original line Diff line number Diff line Loading @@ -59,6 +59,8 @@ class ProfileAction { virtual ~ProfileAction() {} virtual ~ProfileAction() {} virtual const char* Name() const = 0; // Default implementations will fail // Default implementations will fail virtual bool ExecuteForProcess(uid_t, pid_t) const { return false; }; virtual bool ExecuteForProcess(uid_t, pid_t) const { return false; }; virtual bool ExecuteForTask(int) const { return false; }; virtual bool ExecuteForTask(int) const { return false; }; Loading @@ -75,6 +77,7 @@ class SetClampsAction : public ProfileAction { public: public: SetClampsAction(int boost, int clamp) noexcept : boost_(boost), clamp_(clamp) {} SetClampsAction(int boost, int clamp) noexcept : boost_(boost), clamp_(clamp) {} const char* Name() const override { return "SetClamps"; } bool ExecuteForProcess(uid_t uid, pid_t pid) const override; bool ExecuteForProcess(uid_t uid, pid_t pid) const override; bool ExecuteForTask(int tid) const override; bool ExecuteForTask(int tid) const override; Loading @@ -87,6 +90,7 @@ class SetTimerSlackAction : public ProfileAction { public: public: SetTimerSlackAction(unsigned long slack) noexcept : slack_(slack) {} SetTimerSlackAction(unsigned long slack) noexcept : slack_(slack) {} const char* Name() const override { return "SetTimerSlack"; } bool ExecuteForTask(int tid) const override; bool ExecuteForTask(int tid) const override; private: private: Loading @@ -101,6 +105,7 @@ class SetAttributeAction : public ProfileAction { SetAttributeAction(const IProfileAttribute* attribute, const std::string& value) SetAttributeAction(const IProfileAttribute* attribute, const std::string& value) : attribute_(attribute), value_(value) {} : attribute_(attribute), value_(value) {} const char* Name() const override { return "SetAttribute"; } bool ExecuteForProcess(uid_t uid, pid_t pid) const override; bool ExecuteForProcess(uid_t uid, pid_t pid) const override; bool ExecuteForTask(int tid) const override; bool ExecuteForTask(int tid) const override; Loading @@ -114,6 +119,7 @@ class SetCgroupAction : public ProfileAction { public: public: SetCgroupAction(const CgroupController& c, const std::string& p); SetCgroupAction(const CgroupController& c, const std::string& p); const char* Name() const override { return "SetCgroup"; } bool ExecuteForProcess(uid_t uid, pid_t pid) const override; bool ExecuteForProcess(uid_t uid, pid_t pid) const override; bool ExecuteForTask(int tid) const override; bool ExecuteForTask(int tid) const override; void EnableResourceCaching(ResourceCacheType cache_type) override; void EnableResourceCaching(ResourceCacheType cache_type) override; Loading @@ -136,6 +142,7 @@ class WriteFileAction : public ProfileAction { public: public: WriteFileAction(const std::string& path, const std::string& value, bool logfailures); WriteFileAction(const std::string& path, const std::string& value, bool logfailures); const char* Name() const override { return "WriteFile"; } bool ExecuteForProcess(uid_t uid, pid_t pid) const override; bool ExecuteForProcess(uid_t uid, pid_t pid) const override; bool ExecuteForTask(int tid) const override; bool ExecuteForTask(int tid) const override; void EnableResourceCaching(ResourceCacheType cache_type) override; void EnableResourceCaching(ResourceCacheType cache_type) override; Loading @@ -154,8 +161,9 @@ class WriteFileAction : public ProfileAction { class TaskProfile { class TaskProfile { public: public: TaskProfile() : res_cached_(false) {} TaskProfile(const std::string& name) : name_(name), res_cached_(false) {} const std::string& Name() const { return name_; } void Add(std::unique_ptr<ProfileAction> e) { elements_.push_back(std::move(e)); } void Add(std::unique_ptr<ProfileAction> e) { elements_.push_back(std::move(e)); } void MoveTo(TaskProfile* profile); void MoveTo(TaskProfile* profile); Loading @@ -165,6 +173,7 @@ class TaskProfile { void DropResourceCaching(ProfileAction::ResourceCacheType cache_type); void DropResourceCaching(ProfileAction::ResourceCacheType cache_type); private: private: const std::string name_; bool res_cached_; bool res_cached_; std::vector<std::unique_ptr<ProfileAction>> elements_; std::vector<std::unique_ptr<ProfileAction>> elements_; }; }; Loading @@ -175,6 +184,7 @@ class ApplyProfileAction : public ProfileAction { ApplyProfileAction(const std::vector<std::shared_ptr<TaskProfile>>& profiles) ApplyProfileAction(const std::vector<std::shared_ptr<TaskProfile>>& profiles) : profiles_(profiles) {} : profiles_(profiles) {} const char* Name() const override { return "ApplyProfileAction"; } bool ExecuteForProcess(uid_t uid, pid_t pid) const override; bool ExecuteForProcess(uid_t uid, pid_t pid) const override; bool ExecuteForTask(int tid) const override; bool ExecuteForTask(int tid) const override; void EnableResourceCaching(ProfileAction::ResourceCacheType cache_type) override; void EnableResourceCaching(ProfileAction::ResourceCacheType cache_type) override; Loading Loading
libprocessgroup/task_profiles.cpp +4 −2 Original line number Original line Diff line number Diff line Loading @@ -477,6 +477,7 @@ void TaskProfile::MoveTo(TaskProfile* profile) { bool TaskProfile::ExecuteForProcess(uid_t uid, pid_t pid) const { bool TaskProfile::ExecuteForProcess(uid_t uid, pid_t pid) const { for (const auto& element : elements_) { for (const auto& element : elements_) { if (!element->ExecuteForProcess(uid, pid)) { if (!element->ExecuteForProcess(uid, pid)) { LOG(VERBOSE) << "Applying profile action " << element->Name() << " failed"; return false; return false; } } } } Loading @@ -489,6 +490,7 @@ bool TaskProfile::ExecuteForTask(int tid) const { } } for (const auto& element : elements_) { for (const auto& element : elements_) { if (!element->ExecuteForTask(tid)) { if (!element->ExecuteForTask(tid)) { LOG(VERBOSE) << "Applying profile action " << element->Name() << " failed"; return false; return false; } } } } Loading Loading @@ -600,7 +602,7 @@ bool TaskProfiles::Load(const CgroupMap& cg_map, const std::string& file_name) { std::string profile_name = profile_val["Name"].asString(); std::string profile_name = profile_val["Name"].asString(); const Json::Value& actions = profile_val["Actions"]; const Json::Value& actions = profile_val["Actions"]; auto profile = std::make_shared<TaskProfile>(); auto profile = std::make_shared<TaskProfile>(profile_name); for (Json::Value::ArrayIndex act_idx = 0; act_idx < actions.size(); ++act_idx) { for (Json::Value::ArrayIndex act_idx = 0; act_idx < actions.size(); ++act_idx) { const Json::Value& action_val = actions[act_idx]; const Json::Value& action_val = actions[act_idx]; Loading Loading @@ -710,7 +712,7 @@ bool TaskProfiles::Load(const CgroupMap& cg_map, const std::string& file_name) { } } } } if (ret) { if (ret) { auto profile = std::make_shared<TaskProfile>(); auto profile = std::make_shared<TaskProfile>(aggregateprofile_name); profile->Add(std::make_unique<ApplyProfileAction>(profiles)); profile->Add(std::make_unique<ApplyProfileAction>(profiles)); profiles_[aggregateprofile_name] = profile; profiles_[aggregateprofile_name] = profile; } } Loading
libprocessgroup/task_profiles.h +11 −1 Original line number Original line Diff line number Diff line Loading @@ -59,6 +59,8 @@ class ProfileAction { virtual ~ProfileAction() {} virtual ~ProfileAction() {} virtual const char* Name() const = 0; // Default implementations will fail // Default implementations will fail virtual bool ExecuteForProcess(uid_t, pid_t) const { return false; }; virtual bool ExecuteForProcess(uid_t, pid_t) const { return false; }; virtual bool ExecuteForTask(int) const { return false; }; virtual bool ExecuteForTask(int) const { return false; }; Loading @@ -75,6 +77,7 @@ class SetClampsAction : public ProfileAction { public: public: SetClampsAction(int boost, int clamp) noexcept : boost_(boost), clamp_(clamp) {} SetClampsAction(int boost, int clamp) noexcept : boost_(boost), clamp_(clamp) {} const char* Name() const override { return "SetClamps"; } bool ExecuteForProcess(uid_t uid, pid_t pid) const override; bool ExecuteForProcess(uid_t uid, pid_t pid) const override; bool ExecuteForTask(int tid) const override; bool ExecuteForTask(int tid) const override; Loading @@ -87,6 +90,7 @@ class SetTimerSlackAction : public ProfileAction { public: public: SetTimerSlackAction(unsigned long slack) noexcept : slack_(slack) {} SetTimerSlackAction(unsigned long slack) noexcept : slack_(slack) {} const char* Name() const override { return "SetTimerSlack"; } bool ExecuteForTask(int tid) const override; bool ExecuteForTask(int tid) const override; private: private: Loading @@ -101,6 +105,7 @@ class SetAttributeAction : public ProfileAction { SetAttributeAction(const IProfileAttribute* attribute, const std::string& value) SetAttributeAction(const IProfileAttribute* attribute, const std::string& value) : attribute_(attribute), value_(value) {} : attribute_(attribute), value_(value) {} const char* Name() const override { return "SetAttribute"; } bool ExecuteForProcess(uid_t uid, pid_t pid) const override; bool ExecuteForProcess(uid_t uid, pid_t pid) const override; bool ExecuteForTask(int tid) const override; bool ExecuteForTask(int tid) const override; Loading @@ -114,6 +119,7 @@ class SetCgroupAction : public ProfileAction { public: public: SetCgroupAction(const CgroupController& c, const std::string& p); SetCgroupAction(const CgroupController& c, const std::string& p); const char* Name() const override { return "SetCgroup"; } bool ExecuteForProcess(uid_t uid, pid_t pid) const override; bool ExecuteForProcess(uid_t uid, pid_t pid) const override; bool ExecuteForTask(int tid) const override; bool ExecuteForTask(int tid) const override; void EnableResourceCaching(ResourceCacheType cache_type) override; void EnableResourceCaching(ResourceCacheType cache_type) override; Loading @@ -136,6 +142,7 @@ class WriteFileAction : public ProfileAction { public: public: WriteFileAction(const std::string& path, const std::string& value, bool logfailures); WriteFileAction(const std::string& path, const std::string& value, bool logfailures); const char* Name() const override { return "WriteFile"; } bool ExecuteForProcess(uid_t uid, pid_t pid) const override; bool ExecuteForProcess(uid_t uid, pid_t pid) const override; bool ExecuteForTask(int tid) const override; bool ExecuteForTask(int tid) const override; void EnableResourceCaching(ResourceCacheType cache_type) override; void EnableResourceCaching(ResourceCacheType cache_type) override; Loading @@ -154,8 +161,9 @@ class WriteFileAction : public ProfileAction { class TaskProfile { class TaskProfile { public: public: TaskProfile() : res_cached_(false) {} TaskProfile(const std::string& name) : name_(name), res_cached_(false) {} const std::string& Name() const { return name_; } void Add(std::unique_ptr<ProfileAction> e) { elements_.push_back(std::move(e)); } void Add(std::unique_ptr<ProfileAction> e) { elements_.push_back(std::move(e)); } void MoveTo(TaskProfile* profile); void MoveTo(TaskProfile* profile); Loading @@ -165,6 +173,7 @@ class TaskProfile { void DropResourceCaching(ProfileAction::ResourceCacheType cache_type); void DropResourceCaching(ProfileAction::ResourceCacheType cache_type); private: private: const std::string name_; bool res_cached_; bool res_cached_; std::vector<std::unique_ptr<ProfileAction>> elements_; std::vector<std::unique_ptr<ProfileAction>> elements_; }; }; Loading @@ -175,6 +184,7 @@ class ApplyProfileAction : public ProfileAction { ApplyProfileAction(const std::vector<std::shared_ptr<TaskProfile>>& profiles) ApplyProfileAction(const std::vector<std::shared_ptr<TaskProfile>>& profiles) : profiles_(profiles) {} : profiles_(profiles) {} const char* Name() const override { return "ApplyProfileAction"; } bool ExecuteForProcess(uid_t uid, pid_t pid) const override; bool ExecuteForProcess(uid_t uid, pid_t pid) const override; bool ExecuteForTask(int tid) const override; bool ExecuteForTask(int tid) const override; void EnableResourceCaching(ProfileAction::ResourceCacheType cache_type) override; void EnableResourceCaching(ProfileAction::ResourceCacheType cache_type) override; Loading