Common log optimize

pull/1328/head
liyihan2@huawei.com 4 years ago
parent 7b25976593
commit 14744209b9

@ -33,8 +33,8 @@ const int kFileOpSuccess = 0;
namespace ge {
Status FileSaver::OpenFile(int32_t &fd, const std::string &file_path) {
if (CheckPath(file_path) != SUCCESS) {
GELOGE(FAILED, "[Open][File]Check output file failed, file_path:%s.", file_path.c_str());
REPORT_INNER_ERROR("E19999", "Check output file failed, file_path:%s.", file_path.c_str());
GELOGE(FAILED, "[Check][FilePath]Check output file failed, file_path:%s.", file_path.c_str());
REPORT_CALL_ERROR("E19999", "Check output file failed, file_path:%s.", file_path.c_str());
return FAILED;
}
@ -91,7 +91,7 @@ Status FileSaver::WriteData(const void *data, uint32_t size, int32_t fd) {
Status FileSaver::SaveWithFileHeader(const std::string &file_path, const ModelFileHeader &file_header, const void *data,
int len) {
if (data == nullptr || len <= 0) {
GELOGE(FAILED, "[Save][File]Failed, model_data is null or the length[%d] is less than 1.", len);
GELOGE(FAILED, "[Check][Param]Failed, model_data is null or the length[%d] is less than 1.", len);
REPORT_INNER_ERROR("E19999", "Save file failed, model_data is null or the length:%d is less than 1.", len);
return FAILED;
}
@ -111,7 +111,8 @@ Status FileSaver::SaveWithFileHeader(const std::string &file_path, const ModelFi
} while (0);
// Close file
if (mmClose(fd) != 0) { // mmClose 0: success
GELOGE(FAILED, "[Save][File]Failed, error_code:%u.", ret);
GELOGE(FAILED, "[Close][File]Failed, error_code:%u.", ret);
REPORT_INNER_ERROR("E19999", "Close file failed, error_code:%u.", ret);
ret = FAILED;
}
return ret;
@ -332,7 +333,7 @@ Status FileSaver::SaveWithFileHeader(const std::string &file_path, const ModelFi
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status FileSaver::SaveToFile(const string &file_path, const void *data,
int len) {
if (data == nullptr || len <= 0) {
GELOGE(FAILED, "[Save][File]Failed, model_data is null or the length[%d] is less than 1.", len);
GELOGE(FAILED, "[Check][Param]Failed, model_data is null or the length[%d] is less than 1.", len);
REPORT_INNER_ERROR("E19999", "Save file failed, the model_data is null or its length:%d is less than 1.", len);
return FAILED;
}
@ -348,7 +349,8 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status FileSaver::SaveToFile(co
// Close file
if (mmClose(fd) != 0) { // mmClose 0: success
GELOGE(FAILED, "[Save][File]Failed, error_code:%u.", ret);
GELOGE(FAILED, "[Close][File]Failed, error_code:%u.", ret);
REPORT_INNER_ERROR("E19999", "Close file failed, error_code:%u.", ret);
ret = FAILED;
}
return ret;

@ -113,11 +113,11 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool ReadProtoFromArray(const v
// Get file length
long GetFileLength(const std::string &input_file) {
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(input_file.empty(), return -1, "input_file path is null.");
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(input_file.empty(), return -1, "input_file path is null");
std::string real_path = RealPath(input_file.c_str());
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(real_path.empty(), return -1, "input_file path '%s' not valid", input_file.c_str());
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(real_path.empty(), return -1, "input_file path '%s' not valid.", input_file.c_str());
unsigned long long file_length = 0;
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(
mmGetFileSize(input_file.c_str(), &file_length) != EN_OK,
@ -318,7 +318,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY uint64_t GetCurrentTimestamp()
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY uint32_t GetCurrentSecondTimestap() {
mmTimeval tv{};
int ret = mmGetTimeOfDay(&tv, nullptr);
GE_LOGE_IF(ret != EN_OK, "Func gettimeofday may failed: ret=%d", ret);
GE_LOGE_IF(ret != EN_OK, "Func gettimeofday may failed: ret=%d.", ret);
auto total_use_time = tv.tv_sec; // seconds
return static_cast<uint32_t>(total_use_time);
}
@ -349,7 +349,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool CheckInt64MulOverflow(int6
}
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY std::string RealPath(const char *path) {
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(path == nullptr, return "", "path pointer is NULL.");
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(path == nullptr, return "", "path pointer is NULL");
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(strlen(path) >= MMPA_MAX_PATH,
ErrorManager::GetInstance().ATCReportErrMessage("E19002", {"filepath", "size"},
{path, std::to_string(MMPA_MAX_PATH)});

Loading…
Cancel
Save