Browse Source

!23522 fix log to file bug of Could not create logging file: No such file or directory/File exists

Merge pull request !23522 from huanghui/fix-log-to-file
tags/v1.5.0-rc1
i-robot Gitee 4 years ago
parent
commit
825897f15f
3 changed files with 7 additions and 15 deletions
  1. +1
    -2
      mindspore/ccsrc/common/duplex_pipe.cc
  2. +6
    -11
      mindspore/ccsrc/debug/common.cc
  3. +0
    -2
      mindspore/ccsrc/utils/file_utils.cc

+ 1
- 2
mindspore/ccsrc/common/duplex_pipe.cc View File

@@ -48,8 +48,7 @@ int DuplexPipe::Open(const std::initializer_list<std::string> &arg_list, bool ap
close(fd2_[1]);
DP_EXCEPTION << "fork failed, errno: " << errno;
} else if (pid_ == 0) { // Remote process
DP_INFO << "Remote process, id: " << getpid() << ", " << fd1_[0] << "/" << fd2_[1];
DP_INFO << "Execute: arg_list:" << arg_list;
// Here cannot record log before execvp called, because glog will warn "File Exist" if log to file.
remote_stdout_ = dup(STDOUT_FILENO);
remote_stdin_ = dup(STDIN_FILENO);
close(fd1_[1]);


+ 6
- 11
mindspore/ccsrc/debug/common.cc View File

@@ -369,6 +369,9 @@ struct GlogLogDirRegister {
if (logtostderr != nullptr && log_dir != nullptr) {
std::string logtostderr_str = std::string(logtostderr);
std::string log_dir_str = std::string(log_dir);
if (logtostderr_str != "0") {
return;
}
const char *rank_id = std::getenv("RANK_ID");
const char *gpu_rank_id = std::getenv("OMPI_COMM_WORLD_RANK");
std::string rank = "0";
@@ -381,19 +384,11 @@ struct GlogLogDirRegister {
rank = std::string(rank_id);
both_exist = true;
}
log_dir_str += "/rank_" + rank + "/logs";
auto real_log_dir_str = Common::CreatePrefixPath(log_dir_str);
log_dir_str += "/rank_" + rank + "/logs/";
auto real_log_dir_str = Common::CreatePrefixPath(log_dir_str, true);
// While 'GLOG_logtostderr' = 0, logs output to files. 'GLOG_log_dir' must be specified as the path of log files.
// Here can not throw exception and use python to catch, because the PYBIND11_MODULE is not yet been initialed.
if (logtostderr_str == "0" && real_log_dir_str.has_value()) {
if (!Common::IsPathValid(real_log_dir_str.value(), MAX_DIRECTORY_LENGTH, "")) {
MS_LOG(ERROR) << "The path of log files, which set by 'GLOG_log_dir', is invalid";
exit(EXIT_FAILURE);
} else if (!FileUtils::CreateNotExistDirs(real_log_dir_str.value())) {
MS_LOG(ERROR) << "Create the path of log files, which set by 'GLOG_log_dir', failed.";
exit(EXIT_FAILURE);
}
} else if (logtostderr_str == "0") {
if (!real_log_dir_str.has_value()) {
MS_LOG(ERROR) << "The path of log files, which set by 'GLOG_log_dir', is invalid.";
exit(EXIT_FAILURE);
}


+ 0
- 2
mindspore/ccsrc/utils/file_utils.cc View File

@@ -102,7 +102,6 @@ std::optional<std::string> FileUtils::CreateNotExistDirs(const std::string &path
temp_path[i] = '\0';
std::string path_handle(temp_path);
if (!fs->FileExist(path_handle)) {
MS_LOG(INFO) << "Dir " << path_handle << " does not exit, creating...";
if (!fs->CreateDir(path_handle)) {
MS_LOG(ERROR) << "Create " << path_handle << " dir error";
return std::nullopt;
@@ -114,7 +113,6 @@ std::optional<std::string> FileUtils::CreateNotExistDirs(const std::string &path
}

if (!fs->FileExist(path)) {
MS_LOG(INFO) << "Dir " << path << " does not exit, creating...";
if (!fs->CreateDir(path)) {
MS_LOG(ERROR) << "Create " << path << " dir error";
return std::nullopt;


Loading…
Cancel
Save