LCOV - code coverage report
Current view: top level - adump/host - adx_datadump_server.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 74.0 % 77 57
Test Date: 2026-07-28 10:54:24 Functions: 75.0 % 4 3

            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              : #include "adx_datadump_server.h"
      11              : #include "component/adx_server_manager.h"
      12              : #include "ascend_hal.h"
      13              : #include "adx_dump_receive.h"
      14              : #include "log/adx_log.h"
      15              : #include "adx_dump_record.h"
      16              : #include "create_func.h"
      17              : #include "sys_utils.h"
      18              : #include "adump_dsmi.h"
      19              : #include "config.h"
      20              : using namespace Adx;
      21              : namespace {
      22              : AdxServerManager g_manager;
      23            0 : IdeThreadArg AdxDataDumpServerProcess(const IdeThreadArg arg)
      24              : {
      25              :     UNUSED(arg);
      26            0 :     std::unique_ptr<AdxEpoll> epoll(CreateAdxEpoll(EpollType::EPOLL_HDC));
      27            0 :     IDE_CTRL_VALUE_FAILED(epoll != nullptr, return nullptr, "create epoll error");
      28            0 :     std::unique_ptr<AdxComponent> cpn(new (std::nothrow)AdxDumpReceive());
      29            0 :     IDE_CTRL_VALUE_FAILED(cpn != nullptr, return nullptr, "create component error");
      30            0 :     std::unique_ptr<AdxCommOpt> opt(CreateAdxCommOpt(OptType::COMM_HDC));
      31            0 :     IDE_CTRL_VALUE_FAILED(opt != nullptr, return nullptr, "create commopt error");
      32            0 :     bool ret = g_manager.RegisterEpoll(epoll);
      33            0 :     IDE_CTRL_VALUE_FAILED(ret, return nullptr, "register epoll error");
      34            0 :     ret = g_manager.RegisterCommOpt(opt, std::to_string(HDC_SERVICE_TYPE_DUMP));
      35            0 :     IDE_CTRL_VALUE_FAILED(ret, return nullptr, "register commopt error");
      36            0 :     ret = g_manager.ComponentAdd(cpn);
      37            0 :     IDE_CTRL_VALUE_FAILED(ret, return nullptr, "component add error");
      38            0 :     ret = g_manager.ComponentInit();
      39            0 :     IDE_CTRL_VALUE_FAILED(ret, return nullptr, "component Init error");
      40            0 :     g_manager.SetThreadName(std::string("adx_data_dump_thread"));
      41            0 :     g_manager.Start();
      42            0 :     (void)g_manager.Join();
      43            0 :     return nullptr;
      44            0 : }
      45              : 
      46          110 : static bool IsOnDeviceSide()
      47              : {
      48          110 :     uint32_t platformInfo = static_cast<uint32_t>(SysPlatformType::INVALID);
      49          110 :     bool ret = AdumpDsmi::DrvGetPlatformInfo(platformInfo);
      50          110 :     if (ret && (platformInfo == static_cast<uint32_t>(SysPlatformType::DEVICE))) {
      51           90 :         return true;
      52              :     }
      53           20 :     return false;
      54              : }
      55              : }
      56              : 
      57           55 : int32_t AdxDataDumpServerInit()
      58              : {
      59           55 :     if (AdxDumpRecord::Instance().HasStartedServer()) {
      60            2 :         IDE_LOGI("the data dump server has been started, not need to start again");
      61            2 :         AdxDumpRecord::Instance().UpdateDumpInitNum(true);
      62            2 :         return IDE_DAEMON_OK;
      63              :     }
      64           53 :     IDE_LOGI("start to do dump init");
      65              :     mmUserBlock_t funcBlock;
      66           53 :     mmThread tid = 0;
      67              :     // non-soc case, no need to pass host pid
      68          106 :     int32_t ret = AdxDumpRecord::Instance().Init("");
      69           53 :     if (ret != IDE_DAEMON_OK) {
      70            2 :         IDE_LOGE("AdxDumpRecord init failed.");
      71            2 :         return IDE_DAEMON_ERROR;
      72              :     }
      73           51 :     ret = AdxDumpRecord::Instance().StartRecord();
      74           51 :     if (ret != IDE_DAEMON_OK) {
      75            1 :         IDE_LOGE("start dump record thread failed.");
      76            1 :         return IDE_DAEMON_ERROR;
      77              :     }
      78              : 
      79           50 :     std::string hostPid;
      80           50 :     ADX_GET_ENV(MM_ENV_ASCEND_HOSTPID, hostPid);
      81           50 :     if (IsOnDeviceSide() && !hostPid.empty()) {
      82            4 :         AdxDumpRecord::Instance().UpdateDumpInitNum(true);
      83            4 :         IDE_LOGI("dump server not start on helper device");
      84            4 :         return IDE_DAEMON_OK;
      85              :     }
      86           46 :     funcBlock.procFunc = AdxDataDumpServerProcess;
      87           46 :     funcBlock.pulArg = nullptr;
      88           46 :     ret = Thread::CreateDetachTaskWithDefaultAttr(tid, funcBlock);
      89           46 :     (void)g_manager.WaitServerInitted();
      90           46 :     if (ret == EN_OK) {
      91           45 :         AdxDumpRecord::Instance().UpdateDumpInitNum(true);
      92              :     }
      93           46 :     return (ret != EN_OK) ? IDE_DAEMON_ERROR : IDE_DAEMON_OK;
      94           50 : }
      95              : 
      96           62 : int32_t AdxDataDumpServerUnInit()
      97              : {
      98           62 :     if (!AdxDumpRecord::Instance().CanShutdownServer()) {
      99            2 :         IDE_LOGI("still have init times, can not stop the data dump server");
     100            2 :         AdxDumpRecord::Instance().UpdateDumpInitNum(false);
     101            2 :         return IDE_DAEMON_OK;
     102              :     }
     103              : 
     104           60 :     IDE_LOGI("start to do dump uninit");
     105           60 :     std::string hostPid;
     106           60 :     ADX_GET_ENV(MM_ENV_ASCEND_HOSTPID, hostPid);
     107           60 :     int32_t ret = IDE_DAEMON_OK;
     108           60 :     bool isHelper = IsOnDeviceSide() && !hostPid.empty();
     109           60 :     if (!isHelper && g_manager.Exit() != IDE_DAEMON_OK) {
     110            1 :         IDE_LOGE("AdxServerManager Exit failed");
     111            1 :         ret = IDE_DAEMON_ERROR;
     112              :     }
     113           60 :     if (isHelper) {
     114            8 :         IDE_LOGI("dump server not start on helper device");
     115              :     }
     116              : 
     117           60 :     if (AdxDumpRecord::Instance().UnInit() != IDE_DAEMON_OK) {
     118            2 :         IDE_LOGE("dump record uninit failed");
     119            2 :         ret = IDE_DAEMON_ERROR;
     120              :     }
     121              : 
     122           60 :     if (ret == IDE_DAEMON_OK) {
     123           57 :         AdxDumpRecord::Instance().UpdateDumpInitNum(false);
     124              :     }
     125           60 :     return ret;
     126           60 : }
        

Generated by: LCOV version 2.0-1