1 /** 2 * Copyright 2021 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #include "debug/rdr/base_recorder.h" 17 #include <sys/stat.h> 18 #include <fstream> 19 #include "debug/common.h" 20 #include "utils/utils.h" 21 #include "utils/ms_context.h" 22 #include "utils/comm_manager.h" 23 24 namespace mindspore { GetFileRealPath(const std::string & suffix) const25std::optional<std::string> BaseRecorder::GetFileRealPath(const std::string &suffix) const { 26 std::string filename; 27 if (filename_.empty()) { 28 filename = module_ + delimiter_ + name_; 29 if (!suffix.empty()) { 30 filename += delimiter_ + suffix; 31 } 32 filename += delimiter_ + timestamp_; 33 } else { 34 filename = filename_; 35 if (!suffix.empty()) { 36 filename = filename_ + delimiter_ + suffix; 37 } 38 } 39 std::string file_path = directory_ + filename; 40 auto context = MsContext::GetInstance(); 41 MS_EXCEPTION_IF_NULL(context); 42 auto config_file = context->get_param<std::string>(MS_CTX_ENV_CONFIG_PATH); 43 if (config_file.empty()) { 44 file_path = directory_ + "rank_" + std::to_string(GetRank()) + "/rdr/" + filename; 45 } 46 auto realpath = Common::CreatePrefixPath(file_path); 47 if (!realpath.has_value()) { 48 MS_LOG(ERROR) << "Get real path failed. " 49 << "Info: module=" << module_ << ", name=" << name_ << ", " 50 << "path=" << file_path << "."; 51 } 52 53 return realpath; 54 } 55 } // namespace mindspore 56