Line data Source code
1 : /**
2 : * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 : #ifndef EXCEPTION_DUMPER_H
11 : #define EXCEPTION_DUMPER_H
12 : #include <string>
13 : #include <mutex>
14 : #include <deque>
15 : #include "runtime/rt.h"
16 : #include "adump_pub.h"
17 : #include "dump_operator.h"
18 : #include "dump_setting.h"
19 : #include "adump_api.h"
20 : #include "path.h"
21 :
22 : namespace Adx {
23 : class ExceptionDumper {
24 : public:
25 58 : ExceptionDumper() = default;
26 : ~ExceptionDumper();
27 : int32_t ExceptionDumperInit(DumpType dumpType, const DumpConfig& dumpConfig);
28 : inline bool GetExceptionStatus() const;
29 : inline bool GetArgsExceptionStatus() const;
30 : inline bool GetCoredumpStatus() const;
31 : void SetDumpPath(const std::string& dumpPath);
32 : std::string CreateExtraDumpPath();
33 : std::string CreateDeviceDumpPath(uint32_t deviceId) const;
34 : const char* GetExtraDumpCPath() const;
35 : void AddDumpOperator(const OperatorInfo& opInfo);
36 : void AddDumpOperatorV2(const OperatorInfoV2& opInfo);
37 : int32_t DelDumpOperator(uint32_t deviceId, uint32_t streamId);
38 : int32_t DumpException(const rtExceptionInfo& exception);
39 : int32_t GetExceptionDumpPath(std::string& path);
40 : int32_t SaveExceptionInfo(
41 : const std::string& fileName, const std::string& userTag, const std::vector<TensorInfo>& tensors);
42 : void ExceptionModeDowngrade();
43 : bool IsRepeatEnableException(DumpType type, const DumpConfig& dumpConfig);
44 : bool IsEnabledExceptionDump() const;
45 : int32_t RegisterExceptionDumpCallback(ExceptionDumpCallback callback);
46 : int32_t UnregisterExceptionDumpCallback(ExceptionDumpCallback callback);
47 :
48 : #ifdef __ADUMP_LLT
49 : void Reset();
50 : #endif
51 :
52 : private:
53 : std::string CreateDumpPath(Path& dumpPath) const;
54 : bool FindExceptionOperator(const rtExceptionInfo& exception, DumpOperator& excOp);
55 : int32_t DumpArgsException(const rtExceptionInfo& exception, const std::string& dumpPath);
56 : int32_t DumpArgsExceptionInner(const rtExceptionInfo& exception, const std::string& dumpPath);
57 : int32_t DumpArgsExceptionDefault(const rtExceptionInfo& exception, const std::string& dumpPath);
58 : int32_t DumpArgsExceptionFastRecovery(const rtExceptionInfo& exception) const;
59 :
60 : int32_t InvokeCallbacks(
61 : const rtExceptionInfo& exception, std::vector<ExceptionDumpInfo>& dumpInfos, ExceptionDumpMode& finalMode);
62 : void DumpCallbackData(
63 : const rtExceptionInfo& exception, const std::vector<ExceptionDumpInfo>& dumpInfos, const std::string& dumpPath);
64 : int32_t DumpNormalException(const rtExceptionInfo& exception, const std::string& dumpPath);
65 : int32_t DumpNormalExceptionDefault(const rtExceptionInfo& exception, const std::string& dumpPath);
66 : int32_t DumpDetailException(const rtExceptionInfo& exception, const std::string& dumpPath);
67 : int32_t DumpExceptionWithCallbacks(
68 : const rtExceptionInfo& exception, const std::string& dumpPath,
69 : int32_t (ExceptionDumper::*defaultDump)(const rtExceptionInfo&, const std::string&));
70 : // 在符号化(DumpErrorSymbols)之前,提前同步把 _host.o 落盘,供后续按错误 PC 解析源码行使用。best-effort。
71 : void DumpHostKernelBinBeforeSymbolize(const rtExceptionInfo& exception, const std::string& dumpPath) const;
72 : int32_t LoadTensorPluginLib();
73 : bool InitArgsExceptionMemory() const;
74 : std::string GetDumpSceneName() const;
75 : void Exit() const;
76 : bool coredumpStatus_{false};
77 : bool coredumpEnableComplete_{true};
78 : bool exceptionStatus_{false};
79 : bool argsExceptionStatus_{false};
80 : bool destructionFlag_{false};
81 : std::string dumpPath_;
82 : std::string extraDumpPath_;
83 : DumpSetting setting_;
84 : mutable std::mutex mutex_;
85 : std::deque<DumpOperator> agingOperators_;
86 : std::map<uint32_t, std::map<uint32_t, std::deque<DumpOperator>>> residentOperators_;
87 : std::vector<ExceptionDumpCallback> callbacks_;
88 : std::recursive_mutex callbackMutex_;
89 : };
90 :
91 8 : inline bool ExceptionDumper::GetExceptionStatus() const { return exceptionStatus_; }
92 :
93 40 : inline bool ExceptionDumper::GetArgsExceptionStatus() const { return argsExceptionStatus_; }
94 :
95 72 : inline bool ExceptionDumper::GetCoredumpStatus() const { return coredumpStatus_; }
96 : } // namespace Adx
97 : #endif // EXCEPTION_DUMPER_H
|