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