• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 "hitrace_adapter_impl.h"
17 
18 #include "hitrace_meter.h"
19 #include "nweb_log.h"
20 #include "parameters.h"
21 
22 namespace OHOS::NWeb {
GetInstance()23 HiTraceAdapterImpl& HiTraceAdapterImpl::GetInstance()
24 {
25     static HiTraceAdapterImpl instance;
26     return instance;
27 }
28 
StartTrace(const std::string & value,float limit)29 void HiTraceAdapterImpl::StartTrace(const std::string& value, float limit)
30 {
31     ::StartTrace(HITRACE_TAG_NWEB, value, limit);
32 }
33 
FinishTrace()34 void HiTraceAdapterImpl::FinishTrace()
35 {
36     ::FinishTrace(HITRACE_TAG_NWEB);
37 }
38 
StartAsyncTrace(const std::string & value,int32_t taskId,float limit)39 void HiTraceAdapterImpl::StartAsyncTrace(const std::string& value, int32_t taskId, float limit)
40 {
41     ::StartAsyncTrace(HITRACE_TAG_NWEB, value, taskId, limit);
42 }
43 
FinishAsyncTrace(const std::string & value,int32_t taskId)44 void HiTraceAdapterImpl::FinishAsyncTrace(const std::string& value, int32_t taskId)
45 {
46     ::FinishAsyncTrace(HITRACE_TAG_NWEB, value, taskId);
47 }
48 
CountTrace(const std::string & name,int64_t count)49 void HiTraceAdapterImpl::CountTrace(const std::string& name, int64_t count)
50 {
51     ::CountTrace(HITRACE_TAG_NWEB, name, count);
52 }
53 
IsHiTraceEnable()54 bool HiTraceAdapterImpl::IsHiTraceEnable()
55 {
56     const std::string KEY_TRACE_TAG = "debug.hitrace.tags.enableflags";
57 
58     uint64_t tags = OHOS::system::GetUintParameter<uint64_t>(KEY_TRACE_TAG, 0);
59     if (tags == 0) {
60         WVLOG_E("HiTraceAdapterImpl GetUintParameter %s error.", KEY_TRACE_TAG.c_str());
61         return false;
62     }
63     return (tags & HITRACE_TAG_NWEB);
64 }
65 } // namespace OHOS::NWeb
66