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 #ifndef OHOS_WS_INTENTION_EVENT_ENTRANCE_LOG 17 #define OHOS_WS_INTENTION_EVENT_ENTRANCE_LOG 18 19 #include <cinttypes> 20 #include <functional> 21 #include <future> 22 #include <string> 23 #include <sstream> 24 25 #include "hilog/log.h" 26 27 #include "window_manager_hilog.h" 28 29 namespace OHOS { 30 namespace Rosen { 31 class InnerFunctionTracer { 32 public: 33 using HilogFunc = std::function<int(const char *)>; 34 35 public: InnerFunctionTracer(HilogFunc logfn,const char * tag,LogLevel level)36 InnerFunctionTracer(HilogFunc logfn, const char* tag, LogLevel level) 37 : logfn_ { logfn }, tag_ { tag }, level_ { level } 38 { 39 if (HiLogIsLoggable(OHOS::Rosen::HILOG_DOMAIN_WINDOW, tag_, level_)) { 40 if (logfn_ != nullptr) { 41 logfn_("enter"); 42 } 43 } 44 } ~InnerFunctionTracer()45 ~InnerFunctionTracer() 46 { 47 if (HiLogIsLoggable(OHOS::Rosen::HILOG_DOMAIN_WINDOW, tag_, level_)) { 48 if (logfn_ != nullptr) { 49 logfn_("leave"); 50 } 51 } 52 } 53 private: 54 HilogFunc logfn_ { nullptr }; 55 const char* tag_ { nullptr }; 56 LogLevel level_ { LOG_LEVEL_MIN }; 57 }; 58 59 #define CALL_DEBUG_ENTER OHOS::Rosen::InnerFunctionTracer ___innerFuncTracer_Debug___ \ 60 { std::bind(&OHOS::HiviewDFX::HiLog::Debug, LABEL, std::placeholders::_1, __FUNCTION__), LABEL.tag, LOG_DEBUG } 61 62 #define CALL_INFO_TRACE OHOS::Rosen::InnerFunctionTracer ___innerFuncTracer_Info___ \ 63 { std::bind(&OHOS::HiviewDFX::HiLog::Info, LABEL, std::placeholders::_1, __FUNCTION__), LABEL.tag, LOG_INFO } 64 65 #define CALL_TEST_DEBUG OHOS::Rosen::InnerFunctionTracer ___innerFuncTracer_Info___ \ 66 { std::bind(&OHOS::HiviewDFX::HiLog::Info, LABEL, std::placeholders::_1, \ 67 (test_info_ == nullptr ? "TestBody" : test_info_->name())), LABEL.tag, LOG_DEBUG } 68 69 } // namespace Rosen 70 } 71 #endif // OHOS_WS_INTENTION_EVENT_ENTRANCE_LOG 72