Browse Source

!3822 Decouple infer trace from LogWriter

Merge pull request !3822 from hewei/decouple_debug_trace
tags/v0.7.0-beta
mindspore-ci-bot Gitee 5 years ago
parent
commit
1091cdeedf
3 changed files with 19 additions and 7 deletions
  1. +13
    -0
      mindspore/ccsrc/debug/trace.cc
  2. +3
    -7
      mindspore/core/utils/log_adapter.cc
  3. +3
    -0
      mindspore/core/utils/log_adapter.h

+ 13
- 0
mindspore/ccsrc/debug/trace.cc View File

@@ -33,6 +33,7 @@
#include "ir/tensor.h" #include "ir/tensor.h"
#include "debug/anf_ir_utils.h" #include "debug/anf_ir_utils.h"
#include "pipeline/jit/static_analysis/evaluator.h" #include "pipeline/jit/static_analysis/evaluator.h"
#include "utils/log_adapter.h"


namespace mindspore { namespace mindspore {
// namespace to support debug trace infomation // namespace to support debug trace infomation
@@ -495,5 +496,17 @@ void ClearTraceStack() {
} }
cnode_debug_stack.clear(); cnode_debug_stack.clear();
} }

// Register trace provider to LogWriter.
struct TraceProviderRegister {
TraceProviderRegister() {
LogWriter::set_trace_provider([](std::ostringstream &oss) {
TraceGraphEval();
GetEvalStackInfo(oss);
});
}
~TraceProviderRegister() = default;
} trace_provider_regsiter;

} // namespace trace } // namespace trace
} // namespace mindspore } // namespace mindspore

+ 3
- 7
mindspore/core/utils/log_adapter.cc View File

@@ -19,9 +19,6 @@
#include <unistd.h> #include <unistd.h>
#include <sys/time.h> #include <sys/time.h>
#include <map> #include <map>
#ifndef USE_ANDROID_LOG
#include "debug/trace.h"
#endif


// namespace to support utils module definition // namespace to support utils module definition
namespace mindspore { namespace mindspore {
@@ -244,10 +241,9 @@ void LogWriter::operator^(const LogStream &stream) const {
} }
oss << msg.str(); oss << msg.str();


#ifndef USE_ANDROID_LOG
trace::TraceGraphEval();
trace::GetEvalStackInfo(oss);
#endif
if (trace_provider_ != nullptr) {
trace_provider_(oss);
}


if (exception_handler_ != nullptr) { if (exception_handler_ != nullptr) {
exception_handler_(exception_type_, oss.str()); exception_handler_(exception_type_, oss.str());


+ 3
- 0
mindspore/core/utils/log_adapter.h View File

@@ -142,6 +142,7 @@ extern int g_ms_submodule_log_levels[] __attribute__((visibility("default")));
class LogWriter { class LogWriter {
public: public:
using ExceptionHandler = std::function<void(ExceptionType, const std::string &msg)>; using ExceptionHandler = std::function<void(ExceptionType, const std::string &msg)>;
using TraceProvider = std::function<void(std::ostringstream &oss)>;


LogWriter(const LocationInfo &location, MsLogLevel log_level, SubModuleId submodule, LogWriter(const LocationInfo &location, MsLogLevel log_level, SubModuleId submodule,
ExceptionType excp_type = NoExceptionType) ExceptionType excp_type = NoExceptionType)
@@ -152,6 +153,7 @@ class LogWriter {
void operator^(const LogStream &stream) const __attribute__((noreturn, visibility("default"))); void operator^(const LogStream &stream) const __attribute__((noreturn, visibility("default")));


static void set_exception_handler(ExceptionHandler exception_handler) { exception_handler_ = exception_handler; } static void set_exception_handler(ExceptionHandler exception_handler) { exception_handler_ = exception_handler; }
static void set_trace_provider(TraceProvider trace_provider) { trace_provider_ = trace_provider; }


private: private:
void OutputLog(const std::ostringstream &msg) const; void OutputLog(const std::ostringstream &msg) const;
@@ -162,6 +164,7 @@ class LogWriter {
ExceptionType exception_type_; ExceptionType exception_type_;


inline static ExceptionHandler exception_handler_ = nullptr; inline static ExceptionHandler exception_handler_ = nullptr;
inline static TraceProvider trace_provider_ = nullptr;
}; };


#define MSLOG_IF(level, condition, excp_type) \ #define MSLOG_IF(level, condition, excp_type) \


Loading…
Cancel
Save