LCOV - code coverage report
Current view: top level - legacy/ascend950/unified_platform/external_system - orion_adapter_trace.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 87.0 % 23 20
Test Date: 2026-08-18 17:47:01 Functions: 100.0 % 4 4

            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              : #include "log.h"
      12              : #include "atrace_pub.h"
      13              : #include "orion_adapter_trace.h"
      14              : using namespace std;
      15              : namespace Hccl {
      16              : 
      17              : constexpr u32 MAX_LOG_TIMEOUT_MS = 1000;
      18              : std::chrono::steady_clock::time_point lastLogTimeTrace{};
      19              : 
      20              : // 抑制日志刷屏,同一类型日志超时前只打印一次
      21            9 : bool CheckLogTime(std::chrono::steady_clock::time_point& lastTime)
      22              : {
      23            9 :     auto nowTime = std::chrono::steady_clock::now();
      24            9 :     if (nowTime - lastTime <= std::chrono::milliseconds(MAX_LOG_TIMEOUT_MS)) {
      25            6 :         return false;
      26              :     }
      27            3 :     lastTime = nowTime;
      28            3 :     return true;
      29              : }
      30              : 
      31           43 : intptr_t TraceCreate(const char* objName)
      32              : {
      33           43 :     TraceAttr hcclAtraceAttr = {};
      34           43 :     hcclAtraceAttr.exitSave = true;
      35           43 :     hcclAtraceAttr.msgNum = DEFAULT_ATRACE_MSG_NUM;
      36           43 :     hcclAtraceAttr.msgSize = DEFAULT_ATRACE_MSG_SIZE;
      37              : 
      38           43 :     TraHandle traHandle = 0;
      39           43 :     traHandle = AtraceCreateWithAttr(TRACER_TYPE_SCHEDULE, objName, &hcclAtraceAttr);
      40           43 :     if (traHandle == TRACE_INVALID_HANDLE && CheckLogTime(lastLogTimeTrace)) {
      41            0 :         HCCL_ERROR(
      42              :             "[TraceCrate]errNo[0x%016llx] rt trace create failed. return[%d]",
      43              :             HCCL_ERROR_CODE(HcclResult::HCCL_E_INTERNAL), traHandle);
      44              :     }
      45           43 :     return traHandle;
      46              : }
      47              : 
      48            1 : bool TraceSubmit(intptr_t handle, const void* buffer, uint32_t bufSize)
      49              : {
      50            1 :     auto ret = AtraceSubmit(handle, buffer, bufSize);
      51            1 :     if (ret != 0) {
      52            0 :         HCCL_ERROR(
      53              :             "[TraceSubmit]errNo[0x%016llx] rt trace submit failed. return[%d]",
      54              :             HCCL_ERROR_CODE(HcclResult::HCCL_E_INTERNAL), ret);
      55            0 :         return false;
      56              :     }
      57            1 :     return true;
      58              : }
      59              : 
      60          253 : void TraceDestroy(intptr_t handle) { AtraceDestroy(handle); }
      61              : 
      62              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1