• 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 
16 #include <hisysevent_c.h>
17 #include <hisysevent.h>
18 
19 #include "work_sched_utils.h"
20 #include "work_sched_hisysevent_report.h"
21 
22 using namespace OHOS;
23 
24 namespace OHOS {
25 namespace WorkScheduler {
26 namespace WorkSchedUtil {
HiSysEventStateChanged(const ServiceState state)27 void HiSysEventStateChanged(const ServiceState state)
28 {
29     char* events[] = { const_cast<char *>(state.eventName.c_str()) };
30     int32_t states[] = { state.state };
31     int64_t timestamps[] = { WorkSchedUtils::GetCurrentTimeMs() };
32     struct HiSysEventParam params[] = {
33         {
34             .name = "EVENT",
35             .t = HISYSEVENT_STRING_ARRAY,
36             .v = { .array = events },
37             .arraySize = sizeof(events) / sizeof(events[0])
38         },
39         {
40             .name = "STATE",
41             .t = HISYSEVENT_INT32_ARRAY,
42             .v = { .array = states },
43             .arraySize = sizeof(states) / sizeof(states[0])
44         },
45         {
46             .name = "TIMESTAMP",
47             .t = HISYSEVENT_INT64_ARRAY,
48             .v = { .array = timestamps },
49             .arraySize = sizeof(timestamps) / sizeof(timestamps[0])
50         }
51     };
52 
53     OH_HiSysEvent_Write(
54         HiviewDFX::HiSysEvent::Domain::WORK_SCHEDULER,
55         "SERVICE_STATE_CHANGE",
56         HISYSEVENT_STATISTIC,
57         params,
58         sizeof(params) / sizeof(params[0]));
59 }
60 
HiSysEventSystemPolicyLimit(const WorkSchedSystemPolicy & systemPolicy)61 void HiSysEventSystemPolicyLimit(const WorkSchedSystemPolicy& systemPolicy)
62 {
63     HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::WORK_SCHEDULER,
64         "SYSTEM_POLICY_LIMIT", HiviewDFX::HiSysEvent::EventType::STATISTIC, "POLICY", systemPolicy.GetInfo());
65 }
66 
HiSysEventException(int32_t errCode,const std::string & exceptionInfo)67 void HiSysEventException(int32_t errCode, const std::string& exceptionInfo)
68 {
69     struct HiSysEventParam params[] = {
70         {
71             .name = "ERR_CODE",
72             .t = HISYSEVENT_INT32,
73             .v = { .i32 = errCode },
74             .arraySize = 0
75         },
76         {
77             .name = "EXCEPTION_INFO",
78             .t = HISYSEVENT_STRING,
79             .v = { .s = const_cast<char *>(exceptionInfo.c_str()) },
80             .arraySize = 0
81         },
82     };
83 
84     OH_HiSysEvent_Write(
85         HiviewDFX::HiSysEvent::Domain::WORK_SCHEDULER,
86         "WORK_SCHEDULER_RTE",
87         HISYSEVENT_STATISTIC,
88         params,
89         sizeof(params) / sizeof(params[0]));
90 }
91 } // namespace WorkSchedUtil
92 } // namespace WorkScheduler
93 } // namespace OHOS