• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 #define LOG_TAG "MiscPasteboardDfx"
17 
18 #include "pasteboard_trace.h"
19 
20 #include "hitrace_meter.h"
21 #include "pasteboard_hilog.h"
22 
23 namespace OHOS {
24 namespace MiscServices {
25 static constexpr uint64_t BYTRACE_LABEL = HITRACE_TAG_MISC;
26 using namespace MiscServices;
27 
28 std::atomic_bool PasteboardTrace::isSetBytraceEnabled_ = false;
29 
PasteboardTrace(const std::string & value)30 PasteboardTrace::PasteboardTrace(const std::string &value)
31 {
32     SetBytraceEnable();
33     StartTrace(BYTRACE_LABEL, value);
34 }
35 
~PasteboardTrace()36 PasteboardTrace::~PasteboardTrace()
37 {
38     FinishTrace(BYTRACE_LABEL);
39 }
40 
SetBytraceEnable() const41 bool PasteboardTrace::SetBytraceEnable() const
42 {
43     if (isSetBytraceEnabled_.exchange(true)) {
44         return true;
45     }
46     UpdateTraceLabel();
47     PASTEBOARD_HILOGD(PASTEBOARD_MODULE_SERVICE, "success, current tag is true");
48     return true;
49 }
50 } // namespace MiscServices
51 } // namespace OHOS
52