use ms logging instead of custom debugger logging

This commit is contained in:
John Tzanakakis 2021-09-29 23:13:55 -04:00
parent 6f2f35c3a1
commit 76c6af7722
8 changed files with 5 additions and 100 deletions

View File

@ -16,8 +16,8 @@ set(_DEBUG_SRC_LIST
set(_OFFLINE_SRC_LIST
"${CMAKE_CURRENT_SOURCE_DIR}/debug_services.cc"
"${CMAKE_CURRENT_SOURCE_DIR}/debugger/tensor_summary.cc"
"${CMAKE_CURRENT_SOURCE_DIR}/debugger/offline_debug/offline_logger.cc"
"${CMAKE_CURRENT_SOURCE_DIR}/debugger/offline_debug/dbg_services.cc"
"${CMAKE_SOURCE_DIR}/mindspore/core/utils/log_adapter.cc"
"${CMAKE_CURRENT_SOURCE_DIR}/debugger/offline_debug/mi_pybind_register.cc"
)
@ -68,6 +68,7 @@ if(ENABLE_DEBUGGER)
set_property(SOURCE ${_OFFLINE_SRC_LIST} PROPERTY COMPILE_DEFINITIONS
SUBMODULE_ID=mindspore::SubModuleId::SM_OFFLINE_DEBUG)
add_library(_mindspore_offline_debug SHARED ${_OFFLINE_SRC_LIST})
target_link_libraries(_mindspore_offline_debug PRIVATE mindspore::glog mindspore_gvar)
set_target_properties(_mindspore_offline_debug PROPERTIES
PREFIX "${PYTHON_MODULE_PREFIX}"
SUFFIX "${PYTHON_MODULE_EXTENSION}"

View File

@ -22,7 +22,6 @@
#ifdef OFFLINE_DBG_MODE
#include "base/float16.h"
#include "debugger/offline_debug/offline_logger.h"
#endif
#include <math.h>

View File

@ -18,14 +18,7 @@
#include <algorithm>
#include <chrono>
DbgServices::DbgServices(bool verbose) {
DbgLogger::verbose = verbose;
std::string dbg_log_path = common::GetEnv("OFFLINE_DBG_LOG");
if (!dbg_log_path.empty()) {
DbgLogger::verbose = true;
}
debug_services_ = new DebugServices();
}
DbgServices::DbgServices(bool verbose) { debug_services_ = new DebugServices(); }
DbgServices::DbgServices(const DbgServices &other) {
MS_LOG(INFO) << "cpp DbgServices object is created via copy";

View File

@ -1,19 +0,0 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "debugger/offline_debug/offline_logger.h"
bool DbgLogger::verbose = false;

View File

@ -1,63 +0,0 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OFFLINE_LOGGER_H_
#define OFFLINE_LOGGER_H_
#include <iostream>
#define PATH_MAX 4096
#define MS_LOG(level) MS_LOG_##level
#define MS_LOG_INFO static_cast<void>(0), !(DbgLogger::verbose) ? void(0) : DbgLogger(DbgLoggerLvl::INFO) < std::cout
#define MS_LOG_ERROR MS_LOG_INFO
#define MS_LOG_DEBUG MS_LOG_INFO
#define MS_LOG_WARNING MS_LOG_INFO
#define MS_LOG_EXCEPTION static_cast<void>(0), DbgLogger(DbgLoggerLvl::EXCEPTION) < std::cout
enum DbgLoggerLvl : int { DEBUG = 0, INFO, WARNING, ERROR, EXCEPTION };
class DbgLogger {
public:
explicit DbgLogger(DbgLoggerLvl lvl) : lvl_(lvl) {}
~DbgLogger() = default;
void operator<(std::ostream &os) const {
char *dbg_log_path = std::getenv("OFFLINE_DBG_LOG");
if (dbg_log_path != nullptr) {
char abspath[PATH_MAX];
if (sizeof(dbg_log_path) > PATH_MAX || NULL == realpath(dbg_log_path, abspath)) {
std::cout << "ERROR: DbgLogger could not create real path";
}
FILE *fp = freopen(abspath, "a", stdout);
if (fp == nullptr) {
std::cout << "ERROR: DbgLogger could not redirect all stdout to a file";
}
}
os << std::endl;
if (lvl_ == DbgLoggerLvl::EXCEPTION) {
throw lvl_;
}
}
static bool verbose;
private:
DbgLoggerLvl lvl_;
};
#endif // OFFLINE_LOGGER_H_

View File

@ -25,7 +25,6 @@
#ifdef OFFLINE_DBG_MODE
#include "base/float16.h"
#include "offline_debug/offline_logger.h"
#endif
#ifdef ONLINE_DBG_MODE

View File

@ -21,11 +21,9 @@
#include <string>
#include <cstring>
#include <iostream>
#ifdef OFFLINE_DBG_MODE
#include "debugger/offline_debug/offline_logger.h"
#else
#include "ir/tensor.h"
#include "mindspore/core/utils/log_adapter.h"
#ifdef ONLINE_DBG_MODE
#include "ir/tensor.h"
#endif
#ifdef ONLINE_DBG_MODE

View File

@ -25,9 +25,6 @@
#include <utility>
#include <deque>
#include <algorithm>
#ifdef OFFLINE_DBG_MODE
#include "debugger/offline_debug/offline_logger.h"
#endif
#include "debug/tensor_data.h"
#ifdef ONLINE_DBG_MODE
#include "debug/data_dump/dump_json_parser.h"