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-07-28 10:54:24 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,
      76              :                                                uint64_t &currSize, uint16_t totalSize);
      77              : 
      78              :     static const char* GetTensorTypeName(DfxTensorType tensorType);
      79              :     static const char* GetPointerTypeName(DfxPointerType pointerType);
      80              : 
      81              :     static int32_t GetAddressBias(uint64_t &addrBias, const void *argAddr,
      82              :                                   void *baseAddr, uint64_t argsSize);
      83              : 
      84              :     static int32_t CheckAddressOverArgs(const uint64_t *address,
      85              :                                         const void **argOnHost, uint64_t maxArgNum);
      86              : 
      87              :     int32_t InitTensorModeInfoInner(uint32_t currArgsIndex, const uint8_t *&dfxAddr, uint64_t &currDfxSize);
      88              :     int32_t LoadDfxInfo(uint32_t &currArgsIndex);
      89              :     int32_t LoadDfxTensor(TensorBuffer &tensor, uint16_t argsInfoNum);
      90              :     int32_t LoadDfxL1PtrTensor(TensorBuffer &tensor);
      91              :     int32_t LoadDfxL2ShapePtrTensor(TensorBuffer &tensor);
      92              :     int32_t LoadDfxWorkspace(TensorBuffer &tensor);
      93              :     int32_t LoadDfxTilingData(TensorBuffer &tensor);
      94              :     void LoadDfxMc2(const TensorBuffer &tensor);
      95              :     int32_t LoadDfxShapeData();
      96              :     int32_t GetShapeData(uint64_t atomicIndex);
      97              :     int32_t CheckShapeDataAddress() const;
      98              :     bool CheckMagicMemory(const uint8_t *address) const;
      99              :     int32_t LoadTensorShapeAndSize(TensorBuffer &tensor, uint64_t *dynamicTensorAddr,
     100              :                                    void **tensorAddr, uint64_t shapeInfoCount);
     101              :     bool GetIsDataTypeSizeByte(bool &isDataTypeSizeByte) const;
     102              : };
     103              : 
     104              : template <typename T>
     105          496 : int32_t DfxArgsParser::GetPointerValueByBigEndian(const uint8_t **ptr, T &value,
     106              :                                                   uint64_t &currSize, uint16_t totalSize)
     107              : {
     108          496 :     constexpr uint16_t bitOfByte = 8;
     109          496 :     value = 0;
     110              : 
     111         2736 :     for (size_t i = 0; i < sizeof(T); ++i) {
     112         2240 :         if (currSize >= totalSize) {
     113            0 :             IDE_LOGE("The dfx data size[%llu] is larger than the total dfx size[%u].", currSize, totalSize);
     114            0 :             return ADUMP_FAILED;
     115              :         }
     116         2240 :         value = value | (static_cast<uint64_t>(**ptr) << ((sizeof(T) - i - 1) * bitOfByte));
     117         2240 :         currSize++;
     118         2240 :         (*ptr)++;
     119              :     }
     120              : 
     121          496 :     return ADUMP_SUCCESS;
     122              : }
     123              : 
     124              : } // namespace Adx
     125              : 
     126              : #endif // DFX_ARGS_PARSER_H
        

Generated by: LCOV version 2.0-1