#include <unistd.h>
#include <cctype>
+#include <string_view>
#include "blink/log_private.hh"
constexpr const char kAulBlink[] = "AUL_BLINK";
constexpr const char kAulBlinkTimeout[] = "AUL_BLINK_TIMEOUT";
+constexpr const char kAulBlinkLevel[] = "AUL_BLINK_LEVEL";
+constexpr const char kAulBlinkOption[] = "AUL_BLINK_OPTION";
class Blink {
public:
if (timeout && isdigit(timeout[0]))
timeout_ = atoi(timeout);
+ const char* level = getenv(kAulBlinkLevel);
+ if (level) SetLevel(std::string_view(level));
+
+ const char* option = getenv(kAulBlinkOption);
+ if (option) SetOption(std::string_view(option));
+
Set();
}
}
~Blink() { Clear(); }
private:
+ void SetLevel(const std::string_view& level) {
+ if (level == "strong")
+ level_ = CPU_BOOSTING_LEVEL_STRONG;
+ else if (level == "medium")
+ level_ = CPU_BOOSTING_LEVEL_MEDIUM;
+ else if (level == "weak")
+ level_ = CPU_BOOSTING_LEVEL_WEAK;
+ else
+ _E("Unknown level=%s", level.data());
+ }
+
+ void SetOption(const std::string_view& option) {
+ if (option == "reset-on-fork")
+ option_ = CPU_BOOSTING_RESET_ON_FORK;
+ else if (option == "inherit-on-fork")
+ option_ = static_cast<cpu_boosting_flag_e>(0);
+ else
+ _E("Unknown option=%s", option.data());
+ }
+
void Set() {
pid_t pid = getpid();
resource_pid_t res_pid = {
.tid_count = 1,
};
- int ret =
- resource_set_cpu_boosting(res_pid, CPU_BOOSTING_LEVEL_STRONG,
- CPU_BOOSTING_RESET_ON_FORK, -1);
+ int ret = resource_set_cpu_boosting(res_pid, level_, option_, -1);
if (ret != 0) {
_E("resource_set_cpu_boosting() is failed. error=%d", ret);
return;
private:
bool enabled_ = false;
int timeout_ = 5000;
+ cpu_boosting_level_e level_ = CPU_BOOSTING_LEVEL_STRONG;
+ cpu_boosting_flag_e option_ = CPU_BOOSTING_RESET_ON_FORK;
guint source_ = 0;
};