| #pragma once |
|
|
| #include <c10/macros/Export.h> |
| #include <c10/util/Exception.h> |
|
|
| #include <memory> |
| #include <string> |
| #include <unordered_map> |
|
|
| namespace c10 { |
|
|
| enum class C10_API_ENUM DebugInfoKind : uint8_t { |
| PRODUCER_INFO = 0, |
| MOBILE_RUNTIME_INFO, |
| PROFILER_STATE, |
| INFERENCE_CONTEXT, |
| PARAM_COMMS_INFO, |
|
|
| TEST_INFO, |
| TEST_INFO_2, |
| }; |
|
|
| class C10_API DebugInfoBase { |
| public: |
| DebugInfoBase() {} |
| virtual ~DebugInfoBase() = default; |
| }; |
|
|
| |
| |
| |
| |
| |
| |
| class C10_API ThreadLocalDebugInfo { |
| public: |
| static DebugInfoBase* get(DebugInfoKind kind); |
|
|
| |
| static std::shared_ptr<ThreadLocalDebugInfo> current(); |
|
|
| |
| static void _forceCurrentDebugInfo( |
| const std::shared_ptr<ThreadLocalDebugInfo>& info); |
|
|
| |
| static void _push(DebugInfoKind kind, std::shared_ptr<DebugInfoBase> info); |
| |
| |
| static std::shared_ptr<DebugInfoBase> _pop(DebugInfoKind kind); |
| |
| |
| static std::shared_ptr<DebugInfoBase> _peek(DebugInfoKind kind); |
|
|
| private: |
| std::shared_ptr<DebugInfoBase> info_; |
| DebugInfoKind kind_; |
| std::shared_ptr<ThreadLocalDebugInfo> parent_info_; |
|
|
| friend class DebugInfoGuard; |
| }; |
|
|
| |
| |
| |
| |
| |
| |
| class C10_API DebugInfoGuard { |
| public: |
| DebugInfoGuard(DebugInfoKind kind, std::shared_ptr<DebugInfoBase> info); |
|
|
| explicit DebugInfoGuard(std::shared_ptr<ThreadLocalDebugInfo> info); |
|
|
| ~DebugInfoGuard(); |
|
|
| DebugInfoGuard(const DebugInfoGuard&) = delete; |
| DebugInfoGuard(DebugInfoGuard&&) = delete; |
|
|
| private: |
| bool active_ = false; |
| std::shared_ptr<ThreadLocalDebugInfo> prev_info_ = nullptr; |
| }; |
|
|
| } |
|
|