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: 88.0 % 25 22
Test Date: 2026-07-28 12:11:00 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 = {0};
      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("[TraceCrate]errNo[0x%016llx] rt trace create failed. return[%d]",
      42              :                    HCCL_ERROR_CODE(HcclResult::HCCL_E_INTERNAL), traHandle);
      43              :     }
      44           43 :     return traHandle;
      45              : }
      46              :  
      47            1 : bool TraceSubmit(intptr_t handle, const void *buffer, uint32_t bufSize)
      48              : {
      49            1 :     auto ret = AtraceSubmit(handle, buffer, bufSize);
      50            1 :     if (ret != 0) {
      51            0 :         HCCL_ERROR("[TraceSubmit]errNo[0x%016llx] rt trace submit failed. return[%d]",
      52              :                    HCCL_ERROR_CODE(HcclResult::HCCL_E_INTERNAL), ret);
      53            0 :         return false;
      54              :     }
      55            1 :     return true;
      56              : }
      57              :  
      58          252 : void TraceDestroy(intptr_t handle)
      59              : {
      60          252 :     AtraceDestroy(handle);
      61          252 : }
      62              : 
      63              : } //namespace Hccl
        

Generated by: LCOV version 2.0-1