From 3963f6879323ebe756dbc5cc0d43d928c30b9fd9 Mon Sep 17 00:00:00 2001 From: ruifanyuan Date: Fri, 20 Oct 2023 15:39:22 +0800 Subject: [PATCH] fix(ios): remove highly frequent logs --- dom/src/dom/root_node.cc | 6 ----- driver/js/src/modules/scene_builder_module.cc | 22 ------------------- driver/js/src/napi/jsc/jsc_ctx.cc | 12 ---------- framework/ios/base/bridge/HippyBridge.mm | 8 ++++++- modules/footstone/include/footstone/logging.h | 11 ++-------- .../native/ios/renderer/HippyUIManager.mm | 5 ++--- .../ios/renderer/NativeRenderManager.mm | 4 +--- 7 files changed, 12 insertions(+), 56 deletions(-) diff --git a/dom/src/dom/root_node.cc b/dom/src/dom/root_node.cc index fc9dbcc4f41..5032eb5bdf7 100644 --- a/dom/src/dom/root_node.cc +++ b/dom/src/dom/root_node.cc @@ -67,12 +67,9 @@ void RootNode::RemoveEventListener(const std::string& name, uint64_t listener_id void RootNode::ReleaseResources() {} void RootNode::CreateDomNodes(std::vector>&& nodes) { - HP_PERF_LOG("CreateDomNodes Begin"); - for (const auto& interceptor : interceptors_) { interceptor->OnDomNodeCreate(nodes); } - HP_PERF_LOG("CreateDomNodes Interceptor callback done"); std::vector> nodes_to_create; for (const auto& node_info : nodes) { auto& node = node_info->dom_node; @@ -88,7 +85,6 @@ void RootNode::CreateDomNodes(std::vector>&& nodes) { node->HandleEvent(event); OnDomNodeCreated(node); } - HP_PERF_LOG("CreateDomNodes Nodes created and finished callback"); for (const auto& node : nodes_to_create) { node->SetRenderInfo({node->GetId(), node->GetPid(), node->GetSelfIndex()}); } @@ -98,7 +94,6 @@ void RootNode::CreateDomNodes(std::vector>&& nodes) { if (!nodes_to_create.empty()) { dom_operations_.push_back({DomOperation::Op::kOpCreate, nodes_to_create}); } - HP_PERF_LOG("CreateDomNodes End"); } void RootNode::UpdateDomNodes(std::vector>&& nodes) { @@ -438,7 +433,6 @@ void RootNode::DoAndFlushLayout(const std::shared_ptr& render_man void RootNode::FlushDomOperations(const std::shared_ptr& render_manager) { for (auto& dom_operation : dom_operations_) { - HP_PERF_LOG("RootNode::FlushDomOperations dom_operation.op cnt:%lld", dom_operation.nodes.size()); MarkLayoutNodeDirty(dom_operation.nodes); switch (dom_operation.op) { case DomOperation::Op::kOpCreate: diff --git a/driver/js/src/modules/scene_builder_module.cc b/driver/js/src/modules/scene_builder_module.cc index 51f5624122d..1167b3dd342 100644 --- a/driver/js/src/modules/scene_builder_module.cc +++ b/driver/js/src/modules/scene_builder_module.cc @@ -431,15 +431,12 @@ std::shared_ptr> RegisterSceneBuilder(const std::wea size_t argument_count, const std::shared_ptr arguments[], std::shared_ptr&) -> std::shared_ptr { - HP_PERF_LOG("SceneBuilder.create()"); auto scope = weak_scope.lock(); if (!scope) { - HP_PERF_LOG("SceneBuilder.create() exit with error"); return nullptr; } auto ret = HandleJsValue(scope->GetContext(), arguments[0], scope); SceneBuilder::Create(scope->GetDomManager(), scope->GetRootNode(), std::move(std::get<2>(ret))); - HP_PERF_LOG("SceneBuilder.create() End"); return nullptr; }; class_template.functions.emplace_back(std::move(create_func_def)); @@ -451,15 +448,12 @@ std::shared_ptr> RegisterSceneBuilder(const std::wea size_t argument_count, const std::shared_ptr arguments[], std::shared_ptr&) -> std::shared_ptr { - HP_PERF_LOG("SceneBuilder.update()"); auto scope = weak_scope.lock(); if (!scope) { - HP_PERF_LOG("SceneBuilder.update() exit with error"); return nullptr; } auto ret = HandleJsValue(scope->GetContext(), arguments[0], scope); SceneBuilder::Update(scope->GetDomManager(), scope->GetRootNode(), std::move(std::get<2>(ret))); - HP_PERF_LOG("SceneBuilder.update() End"); return nullptr; }; @@ -471,11 +465,8 @@ std::shared_ptr> RegisterSceneBuilder(const std::wea const std::shared_ptr arguments[], std::shared_ptr&) -> std::shared_ptr { - HP_PERF_LOG("SceneBuilder.move()"); - auto scope = weak_scope.lock(); if (!scope) { - HP_PERF_LOG("SceneBuilder.move() exit with error"); return nullptr; } auto weak_dom_manager = scope->GetDomManager(); @@ -491,13 +482,11 @@ std::shared_ptr> RegisterSceneBuilder(const std::wea auto node = context->CopyArrayElement(info, 0); auto id_tuple = GetNodeId(context, node); if (!std::get<0>(id_tuple)) { - HP_PERF_LOG("SceneBuilder.move() exit with error"); return nullptr; } auto pid_tuple = GetNodePid(context, node); if (!std::get<0>(pid_tuple)) { - HP_PERF_LOG("SceneBuilder.move() exit with error"); return nullptr; } if (length >= 2) { @@ -514,7 +503,6 @@ std::shared_ptr> RegisterSceneBuilder(const std::wea } } SceneBuilder::Move(weak_dom_manager, scope->GetRootNode(), std::move(dom_infos)); - HP_PERF_LOG("SceneBuilder.move() End"); return nullptr; }; class_template.functions.emplace_back(std::move(move_func_def)); @@ -526,11 +514,9 @@ std::shared_ptr> RegisterSceneBuilder(const std::wea size_t argument_count, const std::shared_ptr arguments[], std::shared_ptr&) -> std::shared_ptr { - HP_PERF_LOG("SceneBuilder.delete()"); auto scope = weak_scope.lock(); if (!scope) { - HP_PERF_LOG("SceneBuilder.delete() exit with error"); return nullptr; } auto nodes = arguments[0]; @@ -550,7 +536,6 @@ std::shared_ptr> RegisterSceneBuilder(const std::wea auto pid_tuple = GetNodePid(context, node); if (!std::get<0>(pid_tuple)) { - HP_PERF_LOG("SceneBuilder.delete() exit with error"); return nullptr; } @@ -563,7 +548,6 @@ std::shared_ptr> RegisterSceneBuilder(const std::wea } } SceneBuilder::Delete(scope->GetDomManager(), scope->GetRootNode(), std::move(dom_infos)); - HP_PERF_LOG("SceneBuilder.delete() End"); return nullptr; }; @@ -576,17 +560,14 @@ std::shared_ptr> RegisterSceneBuilder(const std::wea size_t argument_count, const std::shared_ptr arguments[], std::shared_ptr&) -> std::shared_ptr { - HP_PERF_LOG("SceneBuilder.addEventListener()"); auto scope = weak_scope.lock(); if (!scope) { - HP_PERF_LOG("SceneBuilder.addEventListener() exit with error"); return nullptr; } Scope::EventListenerInfo listener_info; HandleEventListenerInfo(scope->GetContext(), argument_count, arguments, listener_info); auto dom_listener_info = scope->AddListener(listener_info); SceneBuilder::AddEventListener(scope->GetDomManager(), scope->GetRootNode(), dom_listener_info); - HP_PERF_LOG("SceneBuilder.addEventListener() End"); return nullptr; }; class_template.functions.emplace_back(std::move(add_event_listener_def)); @@ -598,18 +579,15 @@ std::shared_ptr> RegisterSceneBuilder(const std::wea size_t argument_count, const std::shared_ptr arguments[], std::shared_ptr&) -> std::shared_ptr { - HP_PERF_LOG("SceneBuilder.removeEventListener()"); auto scope = weak_scope.lock(); if (!scope) { - HP_PERF_LOG("SceneBuilder.removeEventListener() exit with error"); return nullptr; } Scope::EventListenerInfo listener_info; HandleEventListenerInfo(scope->GetContext(), argument_count, arguments, listener_info); auto dom_listener_info = scope->RemoveListener(listener_info); SceneBuilder::RemoveEventListener(scope->GetDomManager(), scope->GetRootNode(), dom_listener_info); - HP_PERF_LOG("SceneBuilder.removeEventListener() End"); return nullptr; }; class_template.functions.emplace_back(std::move(remove_event_listener_def)); diff --git a/driver/js/src/napi/jsc/jsc_ctx.cc b/driver/js/src/napi/jsc/jsc_ctx.cc index 4d58c8a0482..6849b759a0a 100644 --- a/driver/js/src/napi/jsc/jsc_ctx.cc +++ b/driver/js/src/napi/jsc/jsc_ctx.cc @@ -893,11 +893,9 @@ std::shared_ptr JSCCtx::CallFunction(const std::shared_ptr& const std::shared_ptr argv[]) { auto function_value = std::static_pointer_cast(function); JSValueRef exception = nullptr; - HP_PERF_LOG("JSCCtx::CallFunction"); auto function_object = JSValueToObject(context_, function_value->value_, &exception); if (exception) { SetException(std::make_shared(context_, exception)); - HP_PERF_LOG("JSCCtx::CallFunction End with exception"); return nullptr; } @@ -906,7 +904,6 @@ std::shared_ptr JSCCtx::CallFunction(const std::shared_ptr& auto receiver_object = JSValueToObject(context_, receiver_value->value_, &exception); if (exception) { SetException(std::make_shared(context_, exception)); - HP_PERF_LOG("JSCCtx::CallFunction End with exception"); return nullptr; } @@ -914,10 +911,8 @@ std::shared_ptr JSCCtx::CallFunction(const std::shared_ptr& auto ret_value_ref = JSObjectCallAsFunction(context_, function_object, receiver_object, 0, nullptr, &exception); if (exception) { SetException(std::make_shared(context_, exception)); - HP_PERF_LOG("JSCCtx::CallFunction End with exception"); return nullptr; } - HP_PERF_LOG("JSCCtx::CallFunction End with exception"); return std::make_shared(context_, ret_value_ref); } @@ -930,15 +925,12 @@ std::shared_ptr JSCCtx::CallFunction(const std::shared_ptr& auto ret_value_ref = JSObjectCallAsFunction(context_, function_object, receiver_object, argc, values, &exception); if (exception) { SetException(std::make_shared(context_, exception)); - HP_PERF_LOG("JSCCtx::CallFunction End with exception"); return nullptr; } if (!ret_value_ref) { - HP_PERF_LOG("JSCCtx::CallFunction End with exception"); return nullptr; } - HP_PERF_LOG("JSCCtx::CallFunction End with exception"); return std::make_shared(context_, ret_value_ref); } @@ -1134,7 +1126,6 @@ std::shared_ptr JSCCtx::RunScript(const string_view& data, if (StringViewUtils::IsEmpty(data)) { return nullptr; } - HP_PERF_LOG("JSCCtx::RunScript"); JSStringRef js = JSCVM::CreateJSCString(data); JSValueRef exception = nullptr; @@ -1150,15 +1141,12 @@ std::shared_ptr JSCCtx::RunScript(const string_view& data, if (exception) { SetException(std::make_shared(context_, exception)); - HP_PERF_LOG("JSCCtx::RunScript Error"); return nullptr; } if (!value) { - HP_PERF_LOG("JSCCtx::RunScript Error"); return nullptr; } - HP_PERF_LOG("JSCCtx::RunScript End"); return std::make_shared(context_, value); } diff --git a/framework/ios/base/bridge/HippyBridge.mm b/framework/ios/base/bridge/HippyBridge.mm index eaa4c2433bc..3aaa0344685 100644 --- a/framework/ios/base/bridge/HippyBridge.mm +++ b/framework/ios/base/bridge/HippyBridge.mm @@ -191,6 +191,7 @@ - (instancetype)initWithDelegate:(id)delegate _valid = YES; _bundlesQueue = [[HippyBundleOperationQueue alloc] init]; _startTime = footstone::TimePoint::SystemNow(); + HP_PERF_LOG("HippyBridge init begin, self:%p", self); [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(rootViewContentDidAppear:) name:HippyContentDidAppearNotification object:nil]; HippyExecuteOnMainThread(^{ @@ -207,7 +208,7 @@ - (instancetype)initWithDelegate:(id)delegate [HippyBridge setCurrentBridge:self]; [self loadPendingVendorBundleURLIfNeeded]; - HippyLogInfo(@"[Hippy_OC_Log][Life_Circle],%@ Init %p", NSStringFromClass([self class]), self); + HP_PERF_LOG("HippyBridge init end, self:%p", self); } return self; } @@ -413,6 +414,7 @@ - (void)loadBundleURL:(NSURL *)bundleURL } return; } + HP_PERF_LOG("Begin loading bundle(%s) at %s", HP_CSTR_NOT_NULL(bundleURL.absoluteString.lastPathComponent.UTF8String), HP_CSTR_NOT_NULL(bundleURL.absoluteString.UTF8String)); [_bundleURLs addObject:bundleURL]; dispatch_async(HippyBridgeQueue(), ^{ [self beginLoadingBundle:bundleURL completion:completion]; @@ -450,6 +452,8 @@ - (void)beginLoadingBundle:(NSURL *)bundleURL return; } [strongSelf executeJSCode:script sourceURL:bundleURL onCompletion:^(id result, NSError *error) { + HP_PERF_LOG("End loading bundle(%s) at %s", HP_CSTR_NOT_NULL(bundleURL.absoluteString.lastPathComponent.UTF8String), HP_CSTR_NOT_NULL(bundleURL.absoluteString.UTF8String)); + if (completion) { completion(bundleURL, error); } @@ -505,6 +509,7 @@ - (void)loadInstanceForRootView:(NSNumber *)rootTag withProperties:(NSDictionary - (void)innerLoadInstanceForRootView:(NSNumber *)rootTag withProperties:(NSDictionary *)props { HippyAssert(_moduleName, @"module name must not be null"); HippyLogInfo(@"[Hippy_OC_Log][Life_Circle],Running application %@ (%@)", _moduleName, props); + HP_PERF_LOG("Begin loading instance for HippyBridge(%p)", self); NSDictionary *param = @{@"name": _moduleName, @"id": rootTag, @"params": props ?: @{}, @@ -512,6 +517,7 @@ - (void)innerLoadInstanceForRootView:(NSNumber *)rootTag withProperties:(NSDicti footstone::value::HippyValue value = [param toHippyValue]; std::shared_ptr domValue = std::make_shared(value); self.javaScriptExecutor.pScope->LoadInstance(domValue); + HP_PERF_LOG("End loading instance for HippyBridge(%p)", self); } - (void)rootViewSizeChangedEvent:(NSNumber *)tag params:(NSDictionary *)params { diff --git a/modules/footstone/include/footstone/logging.h b/modules/footstone/include/footstone/logging.h index e31c8f9ce08..91637a34282 100644 --- a/modules/footstone/include/footstone/logging.h +++ b/modules/footstone/include/footstone/logging.h @@ -213,16 +213,9 @@ bool ShouldCreateLogMessage(LogSeverity severity); #endif -inline void HPDoPerfLog( const char* file, int line, const char *format, ...){ - va_list args; - va_start(args, format); - footstone::LogMessage::LogWithFormat(file, line, format, args); - va_end(args); -} -void HPDoPerfLog( const char *, int, const char *format, ...); +#define HP_CSTR_NOT_NULL( p ) (p ? p : "") #define HP_PERF_LOG(format, ...) \ - HPDoPerfLog(__FILE_NAME__, __LINE__, "[HP PERF]" \ - " " format, \ +footstone::LogMessage::LogWithFormat(__FILE_NAME__, __LINE__, "[HP PERF] " format, \ ##__VA_ARGS__) diff --git a/renderer/native/ios/renderer/HippyUIManager.mm b/renderer/native/ios/renderer/HippyUIManager.mm index 9dae617ccfb..bd03fd09092 100644 --- a/renderer/native/ios/renderer/HippyUIManager.mm +++ b/renderer/native/ios/renderer/HippyUIManager.mm @@ -690,7 +690,6 @@ - (void)flushUIBlocksOnRootNode:(std::weak_ptr)rootNode { dispatch_async(dispatch_get_main_queue(), ^{ if (weakManager) { HP_PERF_LOG("flushUIBlocksOnRootNode on main thread(random id:%u)",rand); - int cnt = 0; HippyUIManager *strongSelf = weakManager; NSDictionary *viewReg = @@ -698,11 +697,11 @@ - (void)flushUIBlocksOnRootNode:(std::weak_ptr)rootNode { @try { for (HippyViewManagerUIBlock block in previousPendingUIBlocks) { block(strongSelf, viewReg); - ++cnt; } } @catch (NSException *exception) { } - HP_PERF_LOG("flushUIBlocksOnRootNode on main thread done, block count:%d(random id:%u)", cnt, rand); + HP_PERF_LOG("flushUIBlocksOnRootNode on main thread done, block count:%d(random id:%u)", previousPendingUIBlocks.count, rand); + } }); } diff --git a/renderer/native/ios/renderer/NativeRenderManager.mm b/renderer/native/ios/renderer/NativeRenderManager.mm index 45cf4231e05..914a2d20125 100644 --- a/renderer/native/ios/renderer/NativeRenderManager.mm +++ b/renderer/native/ios/renderer/NativeRenderManager.mm @@ -111,7 +111,7 @@ void NativeRenderManager::EndBatch(std::weak_ptr root_node) { @autoreleasepool { - HP_PERF_LOG("NativeRenderManager::EndBatch"); + HP_PERF_LOG("NativeRenderManager::EndBatch Begin"); HippyAssert(renderImpl_, @"renderImpl_ is null, did you forget to call Initialize()?"); [renderImpl_ batchOnRootNode:root_node]; HP_PERF_LOG("NativeRenderManager::EndBatch End"); @@ -120,11 +120,9 @@ } void NativeRenderManager::BeforeLayout(std::weak_ptr root_node) { - HP_PERF_LOG("NativeRenderManager::BeforeLayout"); } void NativeRenderManager::AfterLayout(std::weak_ptr root_node) { - HP_PERF_LOG("NativeRenderManager::AfterLayout"); } void NativeRenderManager::AddEventListener(std::weak_ptr root_node,