forked from mindspore-Ecosystem/mindspore
fix pclint & codecheck warnings
This commit is contained in:
parent
ad1ea03779
commit
6f82ec5fc9
|
@ -172,8 +172,8 @@ std::optional<std::string> Common::GetEnvConfigFile() {
|
|||
return config_file;
|
||||
}
|
||||
|
||||
bool Common::IsStrLengthValid(const std::string &str, const int &length_limit, const std::string &error_message) {
|
||||
const int len_str = str.length();
|
||||
bool Common::IsStrLengthValid(const std::string &str, size_t length_limit, const std::string &error_message) {
|
||||
auto len_str = str.length();
|
||||
if (len_str > length_limit) {
|
||||
MS_LOG(WARNING) << error_message << "The length is " << str.length() << ", exceeding the limit of " << length_limit
|
||||
<< ".";
|
||||
|
@ -182,17 +182,17 @@ bool Common::IsStrLengthValid(const std::string &str, const int &length_limit, c
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Common::IsEveryFilenameValid(const std::string &path, const int &length_limit, const std::string &error_message) {
|
||||
int left_pos = 0;
|
||||
bool Common::IsEveryFilenameValid(const std::string &path, size_t length_limit, const std::string &error_message) {
|
||||
if (path.empty()) {
|
||||
MS_LOG(WARNING) << error_message << "The path is empty.";
|
||||
return false;
|
||||
}
|
||||
int len_path = path.length();
|
||||
for (int i = 0; i < len_path; i++) {
|
||||
size_t len_path = path.length();
|
||||
size_t left_pos = 0;
|
||||
for (size_t i = 0; i < len_path; i++) {
|
||||
if (i != 0) {
|
||||
if (path[i] == '\\' || path[i] == '/') {
|
||||
int cur_len = i - left_pos;
|
||||
auto cur_len = i - left_pos;
|
||||
if (cur_len > length_limit) {
|
||||
MS_LOG(WARNING) << error_message << "The name length of '" << path.substr(left_pos, cur_len) << "' is "
|
||||
<< cur_len << ". It is out of the limit which is " << length_limit << ".";
|
||||
|
@ -203,7 +203,7 @@ bool Common::IsEveryFilenameValid(const std::string &path, const int &length_lim
|
|||
}
|
||||
}
|
||||
if (!(path[len_path - 1] == '\\' || path[len_path - 1] == '/')) {
|
||||
int cur_len = len_path - left_pos;
|
||||
auto cur_len = len_path - left_pos;
|
||||
if (cur_len > length_limit) {
|
||||
MS_LOG(WARNING) << error_message << "The name length of '" << path.substr(left_pos, cur_len) << "' is " << cur_len
|
||||
<< ". It is out of the limit which is " << length_limit << ".";
|
||||
|
@ -213,7 +213,7 @@ bool Common::IsEveryFilenameValid(const std::string &path, const int &length_lim
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Common::IsPathValid(const std::string &path, const int &length_limit, const std::string &error_message) {
|
||||
bool Common::IsPathValid(const std::string &path, size_t length_limit, const std::string &error_message) {
|
||||
std::string err_msg = "Detail: ";
|
||||
if (!error_message.empty()) {
|
||||
err_msg = error_message + " " + err_msg;
|
||||
|
@ -245,7 +245,7 @@ bool Common::IsPathValid(const std::string &path, const int &length_limit, const
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Common::IsFilenameValid(const std::string &filename, const int &length_limit, const std::string &error_message) {
|
||||
bool Common::IsFilenameValid(const std::string &filename, size_t length_limit, const std::string &error_message) {
|
||||
std::string err_msg = "Detail: ";
|
||||
if (!error_message.empty()) {
|
||||
err_msg = error_message + " " + err_msg;
|
||||
|
|
|
@ -32,16 +32,15 @@ class Common {
|
|||
static std::optional<std::string> GetRealPath(const std::string &input_path);
|
||||
static std::optional<std::string> GetConfigFile(const std::string &env);
|
||||
static std::optional<std::string> GetEnvConfigFile();
|
||||
static bool IsStrLengthValid(const std::string &str, const int &length_limit, const std::string &error_message = "");
|
||||
static bool IsPathValid(const std::string &path, const int &length_limit, const std::string &error_message = "");
|
||||
static bool IsFilenameValid(const std::string &filename, const int &length_limit,
|
||||
const std::string &error_message = "");
|
||||
static bool IsStrLengthValid(const std::string &str, size_t length_limit, const std::string &error_message = "");
|
||||
static bool IsPathValid(const std::string &path, size_t length_limit, const std::string &error_message = "");
|
||||
static bool IsFilenameValid(const std::string &filename, size_t length_limit, const std::string &error_message = "");
|
||||
static bool CreateNotExistDirs(const std::string &path);
|
||||
|
||||
static std::string AddId(const std::string &filename, const std::string &suffix);
|
||||
|
||||
private:
|
||||
static bool IsEveryFilenameValid(const std::string &path, const int &length_limit, const std::string &error_message);
|
||||
static bool IsEveryFilenameValid(const std::string &path, size_t length_limit, const std::string &error_message);
|
||||
};
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_CCSRC_DEBUG_COMMON_H_
|
||||
|
|
|
@ -35,9 +35,8 @@ constexpr auto KEY_MEM_REUSE = "mem_reuse";
|
|||
namespace mindspore {
|
||||
std::optional<bool> GetRdrEnableFromEnv() {
|
||||
// get environment variable to configure RDR
|
||||
const char *env_enable_char = std::getenv(ENV_RDR_ENABLE);
|
||||
if (env_enable_char != nullptr) {
|
||||
std::string env_enable_str = std::string(env_enable_char);
|
||||
std::string env_enable_str = common::GetEnv(ENV_RDR_ENABLE);
|
||||
if (!env_enable_str.empty()) {
|
||||
(void)std::transform(env_enable_str.begin(), env_enable_str.end(), env_enable_str.begin(), ::tolower);
|
||||
if (env_enable_str != "0" && env_enable_str != "1") {
|
||||
MS_LOG(WARNING) << "The environment variable '" << ENV_RDR_ENABLE << "' should be 0 or 1.";
|
||||
|
@ -52,11 +51,10 @@ std::optional<bool> GetRdrEnableFromEnv() {
|
|||
|
||||
std::optional<std::string> GetRdrPathFromEnv() {
|
||||
// get environment variable to configure RDR
|
||||
const char *path_char = std::getenv(ENV_RDR_PATH);
|
||||
if (path_char != nullptr) {
|
||||
std::string path = common::GetEnv(ENV_RDR_PATH);
|
||||
if (!path.empty()) {
|
||||
std::string err_msg = "RDR path parse from environment variable failed. Please check the settings about '" +
|
||||
std::string(ENV_RDR_PATH) + "' in environment variables.";
|
||||
std::string path = std::string(path_char);
|
||||
if (!Common::IsPathValid(path, MAX_DIRECTORY_LENGTH, err_msg)) {
|
||||
return std::string("");
|
||||
}
|
||||
|
@ -238,7 +236,8 @@ void EnvConfigParser::ConfigToString() {
|
|||
cur_config.append("After parsed, rdr path: ");
|
||||
cur_config.append(rdr_path_);
|
||||
cur_config.append(", rdr_enable: ");
|
||||
cur_config.append(std::to_string(rdr_enabled_));
|
||||
std::string rdr_enable_flag = rdr_enabled_ ? "1" : "0";
|
||||
cur_config.append(rdr_enable_flag);
|
||||
MS_LOG(INFO) << cur_config;
|
||||
}
|
||||
} // namespace mindspore
|
||||
|
|
|
@ -42,16 +42,14 @@ class BaseRecorder {
|
|||
if (!filename_.empty() && !Common::IsFilenameValid(filename_, MAX_FILENAME_LENGTH, err_msg)) {
|
||||
filename_ = "";
|
||||
}
|
||||
|
||||
auto sys_time = std::chrono::system_clock::now();
|
||||
auto t_time = std::chrono::system_clock::to_time_t(sys_time);
|
||||
std::tm *l_time = std::localtime(&t_time);
|
||||
if (l_time == nullptr) {
|
||||
timestamp_ = "";
|
||||
} else {
|
||||
std::stringstream ss;
|
||||
ss << std::put_time(l_time, "%Y%m%d%H%M%S");
|
||||
timestamp_ = ss.str();
|
||||
auto sys_time = GetTimeString();
|
||||
for (auto ch : sys_time) {
|
||||
if (ch == '.') {
|
||||
break;
|
||||
}
|
||||
if (ch != '-' && ch != ':') {
|
||||
timestamp_.push_back(ch);
|
||||
}
|
||||
}
|
||||
}
|
||||
~BaseRecorder() {}
|
||||
|
|
|
@ -45,13 +45,12 @@ void DumpIRProto(const std::string &real_path, const FuncGraphPtr &func_graph) {
|
|||
}
|
||||
#else
|
||||
void DumpIRProto(const std::string &, const FuncGraphPtr &) {
|
||||
static bool already_printed = false;
|
||||
if (already_printed) {
|
||||
return;
|
||||
static bool is_printed = false;
|
||||
if (!is_printed) {
|
||||
is_printed = true;
|
||||
MS_LOG(WARNING) << "The functionality of dumping function graph IR in protobuf format is disabled, "
|
||||
<< "please recompile source to enable it. See help of building script.";
|
||||
}
|
||||
already_printed = true;
|
||||
MS_LOG(WARNING) << "The functionality of dumping function graph IR in protobuf format is disabled, "
|
||||
<< "please recompile source to enable it. See help of building script.";
|
||||
}
|
||||
#endif
|
||||
} // namespace protobuf
|
||||
|
|
Loading…
Reference in New Issue