LCOV - code coverage report
Current view: top level - adump/exception - dfx_args_parser.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 88.2 % 17 15
Test Date: 2026-08-31 10:09:28 Functions: 100.0 % 8 8

            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              : 
      11              : #ifndef DFX_ARGS_PARSER_H
      12              : #define DFX_ARGS_PARSER_H
      13              : 
      14              : #include <cstdint>
      15              : #include <vector>
      16              : #include <string>
      17              : #include "str_utils.h"
      18              : #include "adump_pub.h"
      19              : #include "dump_args.h"
      20              : #include "log/hdc_log.h"
      21              : 
      22              : namespace Adx {
      23              : 
      24              : class DfxArgsParser {
      25              : public:
      26           29 :     DfxArgsParser() = default;
      27              :     ~DfxArgsParser();
      28              :     DfxArgsParser(const DfxArgsParser&) = delete;
      29              :     DfxArgsParser& operator=(const DfxArgsParser&) = delete;
      30              :     DfxArgsParser(DfxArgsParser&&) = delete;
      31              :     DfxArgsParser& operator=(DfxArgsParser&&) = delete;
      32              : 
      33              :     int32_t Init(void* argAddr, uint64_t argSize, const uint8_t* dfxAddr, uint16_t dfxSize);
      34              : 
      35              :     int32_t InitTensorModeInfo();
      36              : 
      37              :     int32_t ParseAll();
      38              : 
      39            6 :     const std::vector<TensorBuffer>& GetTensors() const { return tensors_; }
      40            6 :     const std::vector<DumpWorkspace>& GetWorkspaces() const { return workspaces_; }
      41            6 :     const std::vector<DumpWorkspace>& GetMc2Space() const { return mc2Space_; }
      42            6 :     const std::vector<std::string>& GetLogRecords() const { return logRecords_; }
      43              :     bool IsDynamicMode() const { return dynamicModeFlag_; }
      44              :     const void** GetArgOnHost() const { return argOnHost_; }
      45              :     uint64_t GetMaxArgNum() const { return maxArgNum_; }
      46              : 
      47           22 :     void SetIsTik(bool isTik) { isTik_ = isTik; }
      48              :     bool GetIsTik() const { return isTik_; }
      49              : 
      50              : private:
      51              :     void* hostArgsData_{nullptr};
      52              :     const void** argOnHost_{nullptr};
      53              :     uint64_t maxArgNum_{0};
      54              :     void* argAddr_{nullptr};
      55              :     uint64_t argSize_{0};
      56              : 
      57              :     const uint8_t* dfxAddr_{nullptr};
      58              :     uint16_t dfxSize_{0};
      59              :     uint64_t currDfxSize_{0};
      60              : 
      61              :     bool dynamicModeFlag_{false};
      62              :     bool isTik_{false};
      63              :     uint64_t* shapeDataAddr_{nullptr};
      64              :     uint64_t* shapeDataMaxAddr_{nullptr};
      65              : 
      66              :     std::vector<TensorBuffer> tensors_;
      67              :     std::vector<DumpWorkspace> workspaces_;
      68              :     std::vector<DumpWorkspace> mc2Space_;
      69              :     std::vector<std::string> logRecords_;
      70              : 
      71              :     void RecordDumpLog(const std::string& log);
      72              :     void LogArgsInfo();
      73              : 
      74              :     template <typename T>
      75              :     static int32_t GetPointerValueByBigEndian(const uint8_t** ptr, T& value, uint64_t& currSize, uint16_t totalSize);
      76              : 
      77              :     static const char* GetTensorTypeName(DfxTensorType tensorType);
      78              :     static const char* GetPointerTypeName(DfxPointerType pointerType);
      79              : 
      80              :     static int32_t GetAddressBias(uint64_t& addrBias, const void* argAddr, void* baseAddr, uint64_t argsSize);
      81              : 
      82              :     static int32_t CheckAddressOverArgs(const uint64_t* address, const void** argOnHost, uint64_t maxArgNum);
      83              : 
      84              :     int32_t InitTensorModeInfoInner(uint32_t currArgsIndex, const uint8_t*& dfxAddr, uint64_t& currDfxSize);
      85              :     int32_t LoadDfxInfo(uint32_t& currArgsIndex);
      86              :     int32_t LoadDfxTensor(TensorBuffer& tensor, uint16_t argsInfoNum);
      87              :     int32_t LoadDfxL1PtrTensor(TensorBuffer& tensor);
      88              :     int32_t LoadDfxL2ShapePtrTensor(TensorBuffer& tensor);
      89              :     int32_t LoadDfxWorkspace(TensorBuffer& tensor);
      90              :     int32_t LoadDfxTilingData(TensorBuffer& tensor);
      91              :     void LoadDfxMc2(const TensorBuffer& tensor);
      92              :     int32_t LoadDfxShapeData();
      93              :     int32_t GetShapeData(uint64_t atomicIndex);
      94              :     int32_t CheckShapeDataAddress() const;
      95              :     bool CheckMagicMemory(const uint8_t* address) const;
      96              :     int32_t LoadTensorShapeAndSize(
      97              :         TensorBuffer& tensor, uint64_t* dynamicTensorAddr, void** tensorAddr, uint64_t shapeInfoCount);
      98              :     bool GetIsDataTypeSizeByte(bool& isDataTypeSizeByte) const;
      99              : };
     100              : 
     101              : template <typename T>
     102          496 : int32_t DfxArgsParser::GetPointerValueByBigEndian(const uint8_t** ptr, T& value, uint64_t& currSize, uint16_t totalSize)
     103              : {
     104          496 :     constexpr uint16_t bitOfByte = 8;
     105          496 :     value = 0;
     106              : 
     107         2736 :     for (size_t i = 0; i < sizeof(T); ++i) {
     108         2240 :         if (currSize >= totalSize) {
     109            0 :             IDE_LOGE("The dfx data size[%llu] is larger than the total dfx size[%u].", currSize, totalSize);
     110            0 :             return ADUMP_FAILED;
     111              :         }
     112         2240 :         value = value | (static_cast<uint64_t>(**ptr) << ((sizeof(T) - i - 1) * bitOfByte));
     113         2240 :         currSize++;
     114         2240 :         (*ptr)++;
     115              :     }
     116              : 
     117          496 :     return ADUMP_SUCCESS;
     118              : }
     119              : 
     120              : } // namespace Adx
     121              : 
     122              : #endif // DFX_ARGS_PARSER_H
        

Generated by: LCOV version 2.0-1