• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 "base/log/ace_scoring_log.h"
17 
18 #include <cinttypes>
19 #ifdef LINUX_PLATFORM
20 #include <mutex>
21 #endif
22 
23 #include "base/log/log.h"
24 #include "base/utils/system_properties.h"
25 #include "base/utils/time_util.h"
26 #include "core/common/ace_application_info.h"
27 
28 namespace OHOS::Ace {
29 
30 std::string AceScoringLog::procName_;
31 bool AceScoringLog::isDebuggingEnabled_ = false;
32 
AceScoringLog(const std::string & eventName)33 AceScoringLog::AceScoringLog(const std::string& eventName)
34 {
35     Init();
36     if (!AceScoringLog::isDebuggingEnabled_) {
37         return;
38     }
39     logInfo_ = eventName;
40 }
41 
AceScoringLog(const std::string & pageName,const std::string & componentType,const std::string & procType)42 AceScoringLog::AceScoringLog(const std::string& pageName, const std::string& componentType, const std::string& procType)
43 {
44     Init();
45     if (!AceScoringLog::isDebuggingEnabled_) {
46         return;
47     }
48     logInfo_ = pageName;
49     logInfo_.append(" ");
50     logInfo_.append(componentType);
51     logInfo_.append(" ");
52     logInfo_.append(procType);
53 }
54 
Init()55 void AceScoringLog::Init()
56 {
57     static std::once_flag onceFlag;
58     std::call_once(onceFlag, []() {
59         AceScoringLog::procName_ = AceApplicationInfo::GetInstance().GetProcessName().empty()
60                                        ? AceApplicationInfo::GetInstance().GetPackageName()
61                                        : AceApplicationInfo::GetInstance().GetProcessName();
62         AceScoringLog::isDebuggingEnabled_ = SystemProperties::IsScoringEnabled(AceScoringLog::procName_);
63         LOGI("AceScoringLog enabled");
64     });
65     startTime_ = GetSysTimestamp();
66 }
67 
~AceScoringLog()68 AceScoringLog::~AceScoringLog()
69 {
70     if (!AceScoringLog::isDebuggingEnabled_) {
71         return;
72     }
73     endTime_ = GetSysTimestamp();
74     LOGI("%{public}s %{public}s %{public}" PRIu64 " %{public}" PRIu64 "", procName_.c_str(), logInfo_.c_str(),
75         startTime_, endTime_);
76 }
77 
78 } // namespace OHOS::Ace
79