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 QUEUE_SCHEDULE_MSPROF_MANAGER_H
12 : #define QUEUE_SCHEDULE_MSPROF_MANAGER_H
13 :
14 : #include <atomic>
15 : #include <cstdint>
16 : #include <string>
17 : #include "common/bqs_log.h"
18 : #include "msprof_api_adapter.h"
19 :
20 : namespace bqs {
21 : enum class DgwProfInfoType : int32_t {
22 : HCCL_TRANS_DATA = 0x020000, // MSPROF_REPORT_MODEL_AICPU_BASE_TYPE
23 : ALLOC_MBUF,
24 : ENQUEUE_DATA,
25 : PROF_INFO_TYPE_BUTT
26 : };
27 :
28 12 : inline uint64_t GetTimeStamp() { return BqsMsprofApiAdapter::GetInstance().MsprofSysCycleTime(); }
29 :
30 : struct ProfInfo {
31 : uint32_t type;
32 : uint64_t itemId;
33 : uint64_t timeStamp;
34 : };
35 :
36 : class BqsMsprofManager {
37 : public:
38 : static BqsMsprofManager& GetInstance();
39 :
40 : void InitBqsMsprofManager(const bool initFlag, const std::string& cfgData);
41 : void ReportApiPerf(const ProfInfo& profData) const;
42 : void ReportEventPerf(const ProfInfo& profData);
43 :
44 30 : inline bool IsStartProfling() const { return isRun_; }
45 :
46 : private:
47 10 : BqsMsprofManager() : isInitMsprof_(false), isRun_(false), agingFlag_(true), requestId_(0U){};
48 10 : ~BqsMsprofManager()
49 9 : {
50 10 : if (!isInitMsprof_) {
51 1 : return;
52 : }
53 :
54 9 : BQS_LOG_RUN_INFO("[Prof]Start finalize msprof.");
55 : try {
56 9 : (void)BqsMsprofApiAdapter::GetInstance().MsprofFinalize();
57 0 : } catch (std::exception& e) {
58 : // pass
59 0 : }
60 :
61 9 : isInitMsprof_ = false;
62 10 : };
63 :
64 : BqsMsprofManager(const BqsMsprofManager&) = delete;
65 : BqsMsprofManager& operator=(const BqsMsprofManager&) = delete;
66 : BqsMsprofManager(BqsMsprofManager&&) = delete;
67 : BqsMsprofManager& operator=(BqsMsprofManager&&) = delete;
68 :
69 : ProfStatus InitProf(const std::string& cfgData);
70 : ProfStatus RegProfCallback() const;
71 : ProfStatus RegProfType() const;
72 : static int32_t ProfCallback(uint32_t type, void* data, uint32_t dataLen);
73 : ProfStatus HandleCtrlSwitch(const MsprofCommandHandle& profCmdHandle);
74 : ProfStatus HandelCtrlReporter(const MsprofCommandHandle& profCmdHandle) const;
75 : ProfStatus HandleCtrlStepInfo(const MsprofCommandHandle& profCmdHandle) const;
76 :
77 : bool isInitMsprof_;
78 : bool isRun_;
79 : bool agingFlag_; // qs data is always need againg
80 : std::atomic<uint32_t> requestId_;
81 : };
82 : } // namespace bqs
83 :
84 : #endif // QUEUE_SCHEDULE_MSPROF_MANAGER_H
|