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 : const char* GetExtraDumpCPath() const;
34 : void AddDumpOperator(const OperatorInfo &opInfo);
35 : void AddDumpOperatorV2(const OperatorInfoV2 &opInfo);
36 : int32_t DelDumpOperator(uint32_t deviceId, uint32_t streamId);
37 : int32_t DumpException(const rtExceptionInfo &exception);
38 : void ExceptionModeDowngrade();
39 : bool IsRepeatEnableException(DumpType type, const DumpConfig &dumpConfig);
40 :
41 : int32_t RegisterExceptionDumpCallback(ExceptionDumpCallback callback);
42 : int32_t UnregisterExceptionDumpCallback(ExceptionDumpCallback callback);
43 :
44 : #ifdef __ADUMP_LLT
45 : void Reset();
46 : #endif
47 :
48 : private:
49 : std::string CreateDumpPath(Path &dumpPath) const;
50 : std::string CreateDeviceDumpPath(uint32_t deviceId) const;
51 : bool FindExceptionOperator(const rtExceptionInfo &exception, DumpOperator &excOp);
52 : int32_t DumpArgsException(const rtExceptionInfo &exception, const std::string &dumpPath);
53 : int32_t DumpArgsExceptionInner(const rtExceptionInfo &exception, const std::string &dumpPath);
54 : int32_t DumpArgsExceptionDefault(const rtExceptionInfo &exception, const std::string &dumpPath);
55 : int32_t DumpArgsExceptionFastRecovery(const rtExceptionInfo &exception) const;
56 :
57 : int32_t InvokeCallbacks(const rtExceptionInfo &exception,
58 : std::vector<ExceptionDumpInfo> &dumpInfos,
59 : ExceptionDumpMode &finalMode);
60 : void DumpCallbackData(const rtExceptionInfo &exception,
61 : const std::vector<ExceptionDumpInfo> &dumpInfos,
62 : const std::string &dumpPath);
63 : int32_t DumpNormalException(const rtExceptionInfo &exception, const std::string &dumpPath);
64 : int32_t DumpDetailException(const rtExceptionInfo &exception, const std::string &dumpPath);
65 : int32_t LoadTensorPluginLib();
66 : bool InitArgsExceptionMemory() const;
67 : std::string GetDumpSceneName() const;
68 : void Exit() const;
69 : bool coredumpStatus_{ false };
70 : bool coredumpEnableComplete_{ true };
71 : bool exceptionStatus_{ false };
72 : bool argsExceptionStatus_{ false };
73 : bool destructionFlag_{false};
74 : std::string dumpPath_;
75 : std::string extraDumpPath_;
76 : DumpSetting setting_;
77 : std::mutex mutex_;
78 : std::deque<DumpOperator> agingOperators_;
79 : std::map<uint32_t, std::map<uint32_t, std::deque<DumpOperator>>> residentOperators_;
80 : std::vector<ExceptionDumpCallback> callbacks_;
81 : std::recursive_mutex callbackMutex_;
82 : };
83 :
84 52 : inline bool ExceptionDumper::GetExceptionStatus() const
85 : {
86 52 : return exceptionStatus_;
87 : }
88 :
89 84 : inline bool ExceptionDumper::GetArgsExceptionStatus() const
90 : {
91 84 : return argsExceptionStatus_;
92 : }
93 :
94 117 : inline bool ExceptionDumper::GetCoredumpStatus() const
95 : {
96 117 : return coredumpStatus_;
97 : }
98 : } // namespace Adx
99 : #endif // EXCEPTION_DUMPER_H
|