1 /* 2 * Copyright (c) 2021 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 #ifndef DDS_TRACE_H 17 #define DDS_TRACE_H 18 19 #include <string> 20 #include <atomic> 21 #include "visibility.h" 22 23 namespace OHOS { 24 namespace DistributedKv { 25 class DdsTrace { 26 public: 27 KVSTORE_API DdsTrace(const std::string &value, bool isSend = false); 28 KVSTORE_API ~DdsTrace(); 29 KVSTORE_API void SetMiddleTrace(const std::string &beforeValue, const std::string &afterValue); 30 31 private: 32 void Start(const std::string &value); 33 void Middle(const std::string &beforeValue, const std::string &afterValue); 34 void Finish(const std::string &value); 35 bool SetBytraceEnable(); 36 37 enum SwitchOption { 38 DEBUG_CLOSE = 0x00, 39 BYTRACE_ON = 0x01, 40 API_PERFORMANCE_TRACE_ON = 0x02, 41 }; 42 static std::atomic_uint switchOption; 43 static std::atomic_uint indexCount; 44 static std::atomic_bool isSetBytraceEnabled; 45 std::string traceValue{ }; 46 uint64_t lastTime{ 0 }; 47 uint32_t traceCount{ 0 }; 48 bool isSendToHiview{ false }; 49 }; 50 } // namespace OHOS 51 } // namespace DistributedKv 52 #endif 53