!21128 Print erro info while file open failed

Merge pull request !21128 from zhangzhaoju/master_file_open_error
This commit is contained in:
i-robot 2021-08-04 03:41:54 +00:00 committed by Gitee
commit a3155d16ed
11 changed files with 32 additions and 17 deletions

View File

@ -596,7 +596,8 @@ void DumpIR(const std::string &filename, const FuncGraphPtr &graph, bool dump_fu
std::ofstream fout(realpath.value());
std::ostringstream buffer;
if (!fout.is_open()) {
MS_LOG(ERROR) << "Open dump file '" << realpath.value() << "' failed!";
MS_LOG(ERROR) << "Open dump file '" << realpath.value() << "' failed!"
<< " Errno:" << errno << " ErrInfo:" << strerror(errno);
return;
}
@ -638,7 +639,8 @@ void DumpIRForRDR(const std::string &filename, const FuncGraphPtr &graph, bool d
std::ofstream fout(realpath.value());
std::ostringstream buffer;
if (!fout.is_open()) {
MS_LOG(ERROR) << "Open dump file '" << realpath.value() << "' failed!";
MS_LOG(ERROR) << "Open dump file '" << realpath.value() << "' failed!"
<< " Errno:" << errno << " ErrInfo:" << strerror(errno);
return;
}

View File

@ -606,7 +606,8 @@ void AnfExporter::ExportFuncGraph(const std::string &filename, const FuncGraphPt
std::ofstream ofs(filename);
if (!ofs.is_open()) {
MS_LOG(ERROR) << "Open file '" << filename << "' failed!";
MS_LOG(ERROR) << "Open file '" << filename << "' failed!"
<< " Errno:" << errno << " ErrInfo:" << strerror(errno);
return;
}

View File

@ -274,7 +274,8 @@ bool Common::SaveStringToFile(const std::string filename, const std::string stri
ofs.open(real_path.value());
if (!ofs.is_open()) {
MS_LOG(ERROR) << "Open dump file '" << real_path.value() << "' failed!";
MS_LOG(ERROR) << "Open dump file '" << real_path.value() << "' failed!"
<< " Errno:" << errno << " ErrInfo:" << strerror(errno);
return false;
}
ofs << string_info << std::endl;

View File

@ -92,7 +92,8 @@ void DumpJsonParser::Parse() {
std::ifstream json_file(dump_config_file.value());
if (!json_file.is_open()) {
MS_LOG(EXCEPTION) << "Dump file:" << dump_config_file.value() << " open failed.";
MS_LOG(EXCEPTION) << "Dump file:" << dump_config_file.value() << " open failed."
<< " Errno:" << errno << " ErrInfo:" << strerror(errno);
}
nlohmann::json j;
@ -204,7 +205,8 @@ bool DumpJsonParser::DumpToFile(const std::string &filename, const void *data, s
ChangeFileMode(file_path, S_IWUSR);
std::ofstream fd(file_path, std::ios::out | std::ios::trunc | std::ios::binary);
if (!fd.is_open()) {
MS_LOG(ERROR) << "Open file " << file_path << " failed.";
MS_LOG(ERROR) << "Open file " << file_path << " failed."
<< " Errno:" << errno << " ErrInfo:" << strerror(errno);
return false;
}
std::string npy_header = GenerateNpyHeader(shape, type);

View File

@ -399,7 +399,8 @@ void DebugServices::ReadTensorFromNpy(const std::string &file_name, std::string
MS_LOG(INFO) << "Reading in file: " << file_path;
infile.open(file_path.c_str(), std::ios::ate | std::ios::binary | std::ios::in);
if (!infile.is_open()) {
MS_LOG(ERROR) << "Failed to open file (In ReadTensorFromNpy) " << file_path;
MS_LOG(ERROR) << "Failed to open file (In ReadTensorFromNpy) " << file_path << " Errno:" << errno
<< " ErrInfo:" << strerror(errno);
return;
}
uint64_t file_size = infile.tellg();
@ -1108,8 +1109,8 @@ bool DebugServices::CheckOpOverflow(std::string node_name_to_find, unsigned int
std::ifstream infile;
infile.open(file_path.c_str(), std::ios::ate | std::ios::binary | std::ios::in);
if (!infile.is_open()) {
MS_LOG(ERROR) << "Failed to open overflow bin file " << file_name;
MS_LOG(ERROR) << "Error: " << strerror(errno);
MS_LOG(ERROR) << "Failed to open overflow bin file " << file_name << " Errno:" << errno
<< " ErrInfo:" << strerror(errno);
continue;
}

View File

@ -573,7 +573,8 @@ void DumpIRProtoWithSrcInfo(const FuncGraphPtr &func_graph, const std::string &s
// write to pb file
std::ofstream ofs(realpath.value());
if (!ofs.is_open()) {
MS_LOG(ERROR) << "Open file '" << realpath.value() << "' failed!";
MS_LOG(ERROR) << "Open file '" << realpath.value() << "' failed!"
<< " Errno:" << errno << " ErrInfo:" << strerror(errno);
return;
}
ofs << graph_proto;

View File

@ -555,7 +555,8 @@ void DumpIRProto(const FuncGraphPtr &func_graph, const std::string &suffix) {
// write to pb file
std::ofstream ofs(file_path);
if (!ofs.is_open()) {
MS_LOG(ERROR) << "Open file '" << file_path << "' failed!";
MS_LOG(ERROR) << "Open file '" << file_path << "' failed!"
<< " Errno:" << errno << " ErrInfo:" << strerror(errno);
return;
}
ofs << GetFuncGraphProtoString(func_graph);

View File

@ -122,7 +122,8 @@ void EnvConfigParser::ParseFromFile() {
std::ifstream json_file(config_file_);
if (!json_file.is_open()) {
MS_LOG(WARNING) << "Env config file:" << config_file_ << " open failed."
<< " Please check the config file '" << config_file_ << "' set by 'env_config_path' in context.";
<< " Please check the config file '" << config_file_ << "' set by 'env_config_path' in context."
<< " Errno:" << errno << " ErrInfo:" << strerror(errno);
return;
}

View File

@ -348,7 +348,8 @@ bool AnalyzeFailExporter::ExportFuncGraph(const std::string &filename, const Tra
}
std::ofstream ofs(filename);
if (!ofs.is_open()) {
MS_LOG(ERROR) << "Open file '" << filename << "' failed!";
MS_LOG(ERROR) << "Open file '" << filename << "' failed!"
<< " Errno:" << errno << " ErrInfo:" << strerror(errno);
return false;
}

View File

@ -206,7 +206,8 @@ void CacheFuncGraph(const ResourcePtr &resource) {
ChangeFileMode(realpath.value(), S_IRWXU);
std::ofstream fout(realpath.value());
if (!fout.is_open()) {
MS_LOG(EXCEPTION) << "Open cache file '" << realpath.value() << "' failed!";
MS_LOG(EXCEPTION) << "Open cache file '" << realpath.value() << "' failed!"
<< " Errno:" << errno << " ErrInfo:" << strerror(errno);
}
FuncGraphPtr fg = resource->func_graph();
mind_ir::ModelProto fg_model = GetBinaryProto(fg, true);

View File

@ -78,7 +78,8 @@ class DfGraphConvertor {
void DrawComputeGraph(const std::string &name) {
std::ofstream fout(name);
if (!fout.is_open()) {
MS_LOG(ERROR) << "Open file '" << name << "' failed!";
MS_LOG(ERROR) << "Open file '" << name << "' failed!"
<< " Errno:" << errno << " ErrInfo:" << strerror(errno);
return;
}
fout << compute_sout_.str();
@ -87,7 +88,8 @@ class DfGraphConvertor {
void DrawInitGraph(const std::string &name) {
std::ofstream fout(name);
if (!fout.is_open()) {
MS_LOG(ERROR) << "Open file '" << name << "' failed!";
MS_LOG(ERROR) << "Open file '" << name << "' failed!"
<< " Errno:" << errno << " ErrInfo:" << strerror(errno);
return;
}
fout << init_sout_.str();
@ -96,7 +98,8 @@ class DfGraphConvertor {
void DrawSaveCheckpointGraph(const std::string &name) {
std::ofstream fout(name);
if (!fout.is_open()) {
MS_LOG(ERROR) << "Open file '" << name << "' failed!";
MS_LOG(ERROR) << "Open file '" << name << "' failed!"
<< " Errno:" << errno << " ErrInfo:" << strerror(errno);
return;
}
fout << checkpoint_sout_.str();