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 KERNEL_INFO_COLLECTOR_H
11 : #define KERNEL_INFO_COLLECTOR_H
12 : #include <memory>
13 : #include <string>
14 : #include <vector>
15 : #include <elf.h>
16 : #include "adump_pub.h"
17 : #include "runtime/rt.h"
18 :
19 : namespace Adx {
20 :
21 : class KernelInfoCollector {
22 : public:
23 276 : KernelInfoCollector()
24 276 : : kernelBinHandle_(nullptr),
25 276 : kernelBinSize_(0){};
26 276 : ~KernelInfoCollector() = default;
27 : void LoadKernelInfo(const rtExceptionArgsInfo &argsInfo);
28 : int32_t InitFromBinHandle(rtBinHandle BinHandle, const std::string &kernelName);
29 : int32_t LoadKernelBinBuffer();
30 : int32_t StartCollectKernel(const std::string &dumpPath) const;
31 : // 快速同步落 _host.o(纯内存 buffer 写),从 StartCollectKernel 拆出、供调用方单独同步调用。
32 : int32_t DumpHostKernelBin(const std::string &dumpPath) const;
33 : std::string GetProcessedKernelName() const;
34 : std::vector<std::string> GetSearchPath() const;
35 : std::string SearchJsonFiles(const std::string &rootPath, const std::string &targetString) const;
36 : private:
37 : bool ContainsString(const std::string &filePath, const std::string &targetString) const;
38 : std::string GetFirstItem(const std::string &curLine, size_t& curPlace) const;
39 : bool IsTargetLine(const std::string ¤tLine, const std::string &key, const std::string &value) const;
40 : int32_t CollectKernelFile(const std::string &kernelName, const std::string &dumpPath) const;
41 : std::vector<std::string> SplitString(const std::string &str, char delimiter) const;
42 : rtBinHandle kernelBinHandle_;
43 : std::string kernelBinData_;
44 : uint32_t kernelBinSize_;
45 : std::string kernelName_;
46 : };
47 : int32_t StartCollectKernelAsync(std::shared_ptr<KernelInfoCollector> collector, const std::string &dumpPath);
48 : } // namespace Adx
49 : #endif // KERNEL_INFO_COLLECTOR_H
|