2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2023-07-20 13:54:03 +08:00
|
|
|
* Copyright (C) 2020-2023 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-06-08 22:19:52 +08:00
|
|
|
#include "shared/source/os_interface/debug_env_reader.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2023-08-20 12:31:48 +08:00
|
|
|
#include "shared/source/helpers/api_specific_config.h"
|
2020-06-08 22:19:52 +08:00
|
|
|
#include "shared/source/utilities/io_functions.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2023-08-20 12:31:48 +08:00
|
|
|
#include <vector>
|
|
|
|
|
2020-06-08 22:19:52 +08:00
|
|
|
namespace NEO {
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-10-10 22:02:19 +08:00
|
|
|
const char *EnvironmentVariableReader::appSpecificLocation(const std::string &name) {
|
|
|
|
return name.c_str();
|
|
|
|
}
|
|
|
|
|
2023-08-20 12:31:48 +08:00
|
|
|
bool EnvironmentVariableReader::getSetting(const char *settingName, bool defaultValue, DebugVarPrefix &type) {
|
|
|
|
return getSetting(settingName, static_cast<int64_t>(defaultValue), type) ? true : false;
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
bool EnvironmentVariableReader::getSetting(const char *settingName, bool defaultValue) {
|
2020-03-27 14:47:16 +08:00
|
|
|
return getSetting(settingName, static_cast<int64_t>(defaultValue)) ? true : false;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2023-08-20 12:31:48 +08:00
|
|
|
int32_t EnvironmentVariableReader::getSetting(const char *settingName, int32_t defaultValue, DebugVarPrefix &type) {
|
|
|
|
return static_cast<int32_t>(getSetting(settingName, static_cast<int64_t>(defaultValue), type));
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
int32_t EnvironmentVariableReader::getSetting(const char *settingName, int32_t defaultValue) {
|
2020-03-27 14:47:16 +08:00
|
|
|
return static_cast<int32_t>(getSetting(settingName, static_cast<int64_t>(defaultValue)));
|
|
|
|
}
|
|
|
|
|
2023-08-20 12:31:48 +08:00
|
|
|
int64_t EnvironmentVariableReader::getSetting(const char *settingName, int64_t defaultValue, DebugVarPrefix &type) {
|
|
|
|
int64_t value = defaultValue;
|
|
|
|
char *envValue;
|
|
|
|
|
2023-09-21 22:02:00 +08:00
|
|
|
auto prefixString = ApiSpecificConfig::getPrefixStrings();
|
|
|
|
auto prefixType = ApiSpecificConfig::getPrefixTypes();
|
2023-08-20 12:31:48 +08:00
|
|
|
uint32_t i = 0;
|
|
|
|
|
|
|
|
for (const auto &prefix : prefixString) {
|
2023-09-07 20:44:36 +08:00
|
|
|
std::string neoKey = prefix;
|
|
|
|
neoKey += settingName;
|
|
|
|
envValue = IoFunctions::getenvPtr(neoKey.c_str());
|
2023-08-20 12:31:48 +08:00
|
|
|
if (envValue) {
|
|
|
|
value = atoll(envValue);
|
|
|
|
type = prefixType[i];
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
2023-12-05 20:06:54 +08:00
|
|
|
type = DebugVarPrefix::none;
|
2023-08-20 12:31:48 +08:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2020-03-27 14:47:16 +08:00
|
|
|
int64_t EnvironmentVariableReader::getSetting(const char *settingName, int64_t defaultValue) {
|
|
|
|
int64_t value = defaultValue;
|
2017-12-21 07:45:38 +08:00
|
|
|
char *envValue;
|
|
|
|
|
2020-06-08 22:19:52 +08:00
|
|
|
envValue = IoFunctions::getenvPtr(settingName);
|
2017-12-21 07:45:38 +08:00
|
|
|
if (envValue) {
|
2022-09-09 21:19:21 +08:00
|
|
|
value = atoll(envValue);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2023-08-20 12:31:48 +08:00
|
|
|
std::string EnvironmentVariableReader::getSetting(const char *settingName, const std::string &value, DebugVarPrefix &type) {
|
|
|
|
char *envValue;
|
|
|
|
std::string keyValue;
|
|
|
|
keyValue.assign(value);
|
|
|
|
|
2023-09-21 22:02:00 +08:00
|
|
|
auto prefixString = ApiSpecificConfig::getPrefixStrings();
|
|
|
|
auto prefixType = ApiSpecificConfig::getPrefixTypes();
|
2023-08-20 12:31:48 +08:00
|
|
|
|
|
|
|
uint32_t i = 0;
|
|
|
|
for (const auto &prefix : prefixString) {
|
2023-09-07 20:44:36 +08:00
|
|
|
std::string neoKey = prefix;
|
|
|
|
neoKey += settingName;
|
|
|
|
envValue = IoFunctions::getenvPtr(neoKey.c_str());
|
2023-08-20 12:31:48 +08:00
|
|
|
if (envValue) {
|
|
|
|
keyValue.assign(envValue);
|
|
|
|
type = prefixType[i];
|
|
|
|
return keyValue;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
2023-12-05 20:06:54 +08:00
|
|
|
type = DebugVarPrefix::none;
|
2023-08-20 12:31:48 +08:00
|
|
|
return keyValue;
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
std::string EnvironmentVariableReader::getSetting(const char *settingName, const std::string &value) {
|
|
|
|
char *envValue;
|
|
|
|
std::string keyValue;
|
|
|
|
keyValue.assign(value);
|
|
|
|
|
2020-06-08 22:19:52 +08:00
|
|
|
envValue = IoFunctions::getenvPtr(settingName);
|
2017-12-21 07:45:38 +08:00
|
|
|
if (envValue) {
|
|
|
|
keyValue.assign(envValue);
|
|
|
|
}
|
|
|
|
return keyValue;
|
|
|
|
}
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|