• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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_adapter.h"
17 #include "accesstoken_common_log.h"
18 #include "hisysevent.h"
19 #include "time_util.h"
20 
21 namespace OHOS {
22 namespace Security {
23 namespace AccessToken {
24 namespace {
25 static const std::string ACCESSTOKEN_PROCESS_NAME = "accesstoken_service";
26 static constexpr char ADD_DOMAIN[] = "PERFORMANCE";
27 }
28 
ReportSysEventPerformance()29 void ReportSysEventPerformance()
30 {
31     // accesstoken_service add CPU_SCENE_ENTRY system event in OnStart, avoid CPU statistics
32     long id = 1 << 0; // first scene
33     int64_t time = AccessToken::TimeUtil::GetCurrentTimestamp();
34 
35     int32_t ret = HiSysEventWrite(ADD_DOMAIN, "CPU_SCENE_ENTRY", HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
36         "PACKAGE_NAME", ACCESSTOKEN_PROCESS_NAME, "SCENE_ID", std::to_string(id).c_str(), "HAPPEN_TIME", time);
37     if (ret != 0) {
38         LOGE(ATM_DOMAIN, ATM_TAG, "Failed to report performance, ret %{public}d.", ret);
39     }
40 }
41 
ReportSysEventServiceStart(int32_t pid,uint32_t hapSize,uint32_t nativeSize,uint32_t permDefSize)42 void ReportSysEventServiceStart(int32_t pid, uint32_t hapSize, uint32_t nativeSize, uint32_t permDefSize)
43 {
44     int32_t ret = HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::ACCESS_TOKEN, "ACCESSTOKEN_SERVICE_START",
45         HiviewDFX::HiSysEvent::EventType::STATISTIC,
46         "PID", pid, "HAP_SIZE", hapSize, "NATIVE_SIZE", nativeSize, "PERM_DEFINITION_SIZE", permDefSize);
47     if (ret != 0) {
48         LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write hisysevent write, ret %{public}d.", ret);
49     }
50 }
51 
ReportSysEventServiceStartError(SceneCode scene,const std::string & errMsg,int32_t errCode)52 void ReportSysEventServiceStartError(SceneCode scene, const std::string& errMsg, int32_t errCode)
53 {
54     int32_t ret = HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::ACCESS_TOKEN, "ACCESSTOKEN_SERVICE_START_ERROR",
55         HiviewDFX::HiSysEvent::EventType::FAULT, "SCENE_CODE", scene, "ERROR_CODE", errCode, "ERROR_MSG", errMsg);
56     if (ret != 0) {
57         LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write hisysevent write, ret %{public}d.", ret);
58     }
59 }
60 } // namespace AccessToken
61 } // namespace Security
62 } // namespace OHOS