1 /*
2  * Copyright (c) 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 "daudio_hitrace.h"
17 
18 #undef DH_LOG_TAG
19 #define DH_LOG_TAG "DAudioHitrace"
20 
21 namespace OHOS {
22 namespace DistributedHardware {
Count(const std::string & value,int64_t count,bool isEnable)23 void DAudioHitrace::Count(const std::string &value, int64_t count, bool isEnable)
24 {
25     CountTraceDebug(isEnable, HITRACE_TAG_ZAUDIO, value, count);
26 }
27 
DAudioHitrace(const std::string & value,bool isShowLog,bool isEnable)28 DAudioHitrace::DAudioHitrace(const std::string &value, bool isShowLog, bool isEnable)
29 {
30     value_ = value;
31     isShowLog_ = isShowLog;
32     isEnable_ = isEnable;
33     isFinished_ = false;
34     if (isShowLog) {
35         isShowLog_ = true;
36         DHLOGI("%{public}s start.", value_.c_str());
37     }
38     StartTraceDebug(isEnable_, HITRACE_TAG_ZAUDIO, value);
39 }
40 
End()41 void DAudioHitrace::End()
42 {
43     if (!isFinished_) {
44         FinishTraceDebug(isEnable_, HITRACE_TAG_ZAUDIO);
45         isFinished_ = true;
46         if (isShowLog_) {
47             DHLOGI("%{public}s end.", value_.c_str());
48         }
49     }
50 }
51 
~DAudioHitrace()52 DAudioHitrace::~DAudioHitrace()
53 {
54     End();
55 }
56 } // namespace DistributedHardware
57 } // namespace OHOS