• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef XPERF_EVENT_BUILDER_H
16 #define XPERF_EVENT_BUILDER_H
17 
18 #include <string>
19 #include <vector>
20 #include "xperf_event.h"
21 
22 namespace OHOS {
23 namespace HiviewDFX {
24 
25 class XperfEventBuilder {
26 public:
27     explicit XperfEventBuilder();
28     ~XperfEventBuilder();
29 
30     XperfEventBuilder& EventName(const std::string& eventName);
31     XperfEventBuilder& EventType(const HiSysEventEventType& eventType);
32     XperfEventBuilder& Param(const char* name, bool value);
33     XperfEventBuilder& Param(const char* name, int8_t value);
34     XperfEventBuilder& Param(const char* name, uint8_t value);
35     XperfEventBuilder& Param(const char* name, int16_t value);
36     XperfEventBuilder& Param(const char* name, uint16_t value);
37     XperfEventBuilder& Param(const char* name, int32_t value);
38     XperfEventBuilder& Param(const char* name, uint32_t value);
39     XperfEventBuilder& Param(const char* name, int64_t value);
40     XperfEventBuilder& Param(const char* name, uint64_t value);
41     XperfEventBuilder& Param(const char* name, float value);
42     XperfEventBuilder& Param(const char* name, double value);
43     XperfEventBuilder& Param(const char* name, const std::string value);
44     XperfEventBuilder& Param(const char* name, char* value);
45     XperfEventBuilder& Param(const char* name, const std::vector<uint16_t>& value);
46     OHOS::HiviewDFX::XperfEvent Build();
47 
48 private:
49     std::string evtName;
50     HiSysEventEventType evtType{HISYSEVENT_BEHAVIOR};
51     std::vector<HiSysEventParam> paramList;
52 
53     bool Check();
54     void SetParamName(HiSysEventParam& param, const char* name);
55     void Release();
56 };
57 }
58 }
59 #endif //XPERF_EVENT_BUILDER_H