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 48 : 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(const std::string &fileName, const std::string &userTag,
41 : 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(const rtExceptionInfo &exception,
61 : std::vector<ExceptionDumpInfo> &dumpInfos,
62 : ExceptionDumpMode &finalMode);
63 : void DumpCallbackData(const rtExceptionInfo &exception,
64 : const std::vector<ExceptionDumpInfo> &dumpInfos,
65 : const std::string &dumpPath);
66 : int32_t DumpNormalException(const rtExceptionInfo &exception, const std::string &dumpPath);
67 : int32_t DumpDetailException(const rtExceptionInfo &exception, const std::string &dumpPath);
68 : // 在符号化(DumpErrorSymbols)之前,提前同步把 _host.o 落盘,供后续按错误 PC 解析源码行使用。best-effort。
69 : void DumpHostKernelBinBeforeSymbolize(const rtExceptionInfo &exception, const std::string &dumpPath) const;
70 : int32_t LoadTensorPluginLib();
71 : bool InitArgsExceptionMemory() const;
72 : std::string GetDumpSceneName() const;
73 : void Exit() const;
74 : bool coredumpStatus_{ false };
75 : bool coredumpEnableComplete_{ true };
76 : bool exceptionStatus_{ false };
77 : bool argsExceptionStatus_{ false };
78 : bool destructionFlag_{false};
79 : std::string dumpPath_;
80 : std::string extraDumpPath_;
81 : DumpSetting setting_;
82 : mutable std::mutex mutex_;
83 : std::deque<DumpOperator> agingOperators_;
84 : std::map<uint32_t, std::map<uint32_t, std::deque<DumpOperator>>> residentOperators_;
85 : std::vector<ExceptionDumpCallback> callbacks_;
86 : std::recursive_mutex callbackMutex_;
87 : };
88 :
89 7 : inline bool ExceptionDumper::GetExceptionStatus() const
90 : {
91 7 : return exceptionStatus_;
92 : }
93 :
94 40 : inline bool ExceptionDumper::GetArgsExceptionStatus() const
95 : {
96 40 : return argsExceptionStatus_;
97 : }
98 :
99 72 : inline bool ExceptionDumper::GetCoredumpStatus() const
100 : {
101 72 : return coredumpStatus_;
102 : }
103 : } // namespace Adx
104 : #endif // EXCEPTION_DUMPER_H
|