Skip to content

Commit

Permalink
fix(ios): remove highly frequent logs
Browse files Browse the repository at this point in the history
  • Loading branch information
ruifanyuan authored and hippy-actions[bot] committed Oct 23, 2023
1 parent 7b088a7 commit 3963f68
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 56 deletions.
6 changes: 0 additions & 6 deletions dom/src/dom/root_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,9 @@ void RootNode::RemoveEventListener(const std::string& name, uint64_t listener_id
void RootNode::ReleaseResources() {}

void RootNode::CreateDomNodes(std::vector<std::shared_ptr<DomInfo>>&& nodes) {
HP_PERF_LOG("CreateDomNodes Begin");

for (const auto& interceptor : interceptors_) {
interceptor->OnDomNodeCreate(nodes);
}
HP_PERF_LOG("CreateDomNodes Interceptor callback done");
std::vector<std::shared_ptr<DomNode>> nodes_to_create;
for (const auto& node_info : nodes) {
auto& node = node_info->dom_node;
Expand All @@ -88,7 +85,6 @@ void RootNode::CreateDomNodes(std::vector<std::shared_ptr<DomInfo>>&& 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()});
}
Expand All @@ -98,7 +94,6 @@ void RootNode::CreateDomNodes(std::vector<std::shared_ptr<DomInfo>>&& 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<std::shared_ptr<DomInfo>>&& nodes) {
Expand Down Expand Up @@ -438,7 +433,6 @@ void RootNode::DoAndFlushLayout(const std::shared_ptr<RenderManager>& render_man

void RootNode::FlushDomOperations(const std::shared_ptr<RenderManager>& 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:
Expand Down
22 changes: 0 additions & 22 deletions driver/js/src/modules/scene_builder_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -431,15 +431,12 @@ std::shared_ptr<ClassTemplate<SceneBuilder>> RegisterSceneBuilder(const std::wea
size_t argument_count,
const std::shared_ptr<CtxValue> arguments[],
std::shared_ptr<CtxValue>&) -> std::shared_ptr<CtxValue> {
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));
Expand All @@ -451,15 +448,12 @@ std::shared_ptr<ClassTemplate<SceneBuilder>> RegisterSceneBuilder(const std::wea
size_t argument_count,
const std::shared_ptr<CtxValue> arguments[],
std::shared_ptr<CtxValue>&) -> std::shared_ptr<CtxValue> {
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;
};
Expand All @@ -471,11 +465,8 @@ std::shared_ptr<ClassTemplate<SceneBuilder>> RegisterSceneBuilder(const std::wea
const std::shared_ptr<CtxValue> arguments[],
std::shared_ptr<CtxValue>&)
-> std::shared_ptr<CtxValue> {
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();
Expand All @@ -491,13 +482,11 @@ std::shared_ptr<ClassTemplate<SceneBuilder>> 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) {
Expand All @@ -514,7 +503,6 @@ std::shared_ptr<ClassTemplate<SceneBuilder>> 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));
Expand All @@ -526,11 +514,9 @@ std::shared_ptr<ClassTemplate<SceneBuilder>> RegisterSceneBuilder(const std::wea
size_t argument_count,
const std::shared_ptr<CtxValue> arguments[],
std::shared_ptr<CtxValue>&) -> std::shared_ptr<CtxValue> {
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];
Expand All @@ -550,7 +536,6 @@ std::shared_ptr<ClassTemplate<SceneBuilder>> 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;
}
Expand All @@ -563,7 +548,6 @@ std::shared_ptr<ClassTemplate<SceneBuilder>> RegisterSceneBuilder(const std::wea
}
}
SceneBuilder::Delete(scope->GetDomManager(), scope->GetRootNode(), std::move(dom_infos));
HP_PERF_LOG("SceneBuilder.delete() End");

return nullptr;
};
Expand All @@ -576,17 +560,14 @@ std::shared_ptr<ClassTemplate<SceneBuilder>> RegisterSceneBuilder(const std::wea
size_t argument_count,
const std::shared_ptr<CtxValue> arguments[],
std::shared_ptr<CtxValue>&) -> std::shared_ptr<CtxValue> {
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));
Expand All @@ -598,18 +579,15 @@ std::shared_ptr<ClassTemplate<SceneBuilder>> RegisterSceneBuilder(const std::wea
size_t argument_count,
const std::shared_ptr<CtxValue> arguments[],
std::shared_ptr<CtxValue>&) -> std::shared_ptr<CtxValue> {
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));
Expand Down
12 changes: 0 additions & 12 deletions driver/js/src/napi/jsc/jsc_ctx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -893,11 +893,9 @@ std::shared_ptr<CtxValue> JSCCtx::CallFunction(const std::shared_ptr<CtxValue>&
const std::shared_ptr<CtxValue> argv[]) {
auto function_value = std::static_pointer_cast<JSCCtxValue>(function);
JSValueRef exception = nullptr;
HP_PERF_LOG("JSCCtx::CallFunction");
auto function_object = JSValueToObject(context_, function_value->value_, &exception);
if (exception) {
SetException(std::make_shared<JSCCtxValue>(context_, exception));
HP_PERF_LOG("JSCCtx::CallFunction End with exception");

return nullptr;
}
Expand All @@ -906,18 +904,15 @@ std::shared_ptr<CtxValue> JSCCtx::CallFunction(const std::shared_ptr<CtxValue>&
auto receiver_object = JSValueToObject(context_, receiver_value->value_, &exception);
if (exception) {
SetException(std::make_shared<JSCCtxValue>(context_, exception));
HP_PERF_LOG("JSCCtx::CallFunction End with exception");
return nullptr;
}

if (argc <= 0) {
auto ret_value_ref = JSObjectCallAsFunction(context_, function_object, receiver_object, 0, nullptr, &exception);
if (exception) {
SetException(std::make_shared<JSCCtxValue>(context_, exception));
HP_PERF_LOG("JSCCtx::CallFunction End with exception");
return nullptr;
}
HP_PERF_LOG("JSCCtx::CallFunction End with exception");
return std::make_shared<JSCCtxValue>(context_, ret_value_ref);
}

Expand All @@ -930,15 +925,12 @@ std::shared_ptr<CtxValue> JSCCtx::CallFunction(const std::shared_ptr<CtxValue>&
auto ret_value_ref = JSObjectCallAsFunction(context_, function_object, receiver_object, argc, values, &exception);
if (exception) {
SetException(std::make_shared<JSCCtxValue>(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<JSCCtxValue>(context_, ret_value_ref);
}
Expand Down Expand Up @@ -1134,7 +1126,6 @@ std::shared_ptr<CtxValue> 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;
Expand All @@ -1150,15 +1141,12 @@ std::shared_ptr<CtxValue> JSCCtx::RunScript(const string_view& data,

if (exception) {
SetException(std::make_shared<JSCCtxValue>(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<JSCCtxValue>(context_, value);
}

Expand Down
8 changes: 7 additions & 1 deletion framework/ios/base/bridge/HippyBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ - (instancetype)initWithDelegate:(id<HippyBridgeDelegate>)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(^{
Expand All @@ -207,7 +208,7 @@ - (instancetype)initWithDelegate:(id<HippyBridgeDelegate>)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;
}
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -505,13 +509,15 @@ - (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 ?: @{},
@"version": HippySDKVersion};
footstone::value::HippyValue value = [param toHippyValue];
std::shared_ptr<footstone::value::HippyValue> domValue = std::make_shared<footstone::value::HippyValue>(value);
self.javaScriptExecutor.pScope->LoadInstance(domValue);
HP_PERF_LOG("End loading instance for HippyBridge(%p)", self);
}

- (void)rootViewSizeChangedEvent:(NSNumber *)tag params:(NSDictionary *)params {
Expand Down
11 changes: 2 additions & 9 deletions modules/footstone/include/footstone/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

5 changes: 2 additions & 3 deletions renderer/native/ios/renderer/HippyUIManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -690,19 +690,18 @@ - (void)flushUIBlocksOnRootNode:(std::weak_ptr<RootNode>)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<NSNumber *, UIView *> *viewReg =
[strongSelf->_viewRegistry componentsForRootTag:@(rootTag)];
@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);
}
});
}
Expand Down
4 changes: 1 addition & 3 deletions renderer/native/ios/renderer/NativeRenderManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@

void NativeRenderManager::EndBatch(std::weak_ptr<hippy::RootNode> 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");
Expand All @@ -120,11 +120,9 @@
}

void NativeRenderManager::BeforeLayout(std::weak_ptr<hippy::RootNode> root_node) {
HP_PERF_LOG("NativeRenderManager::BeforeLayout");
}

void NativeRenderManager::AfterLayout(std::weak_ptr<hippy::RootNode> root_node) {
HP_PERF_LOG("NativeRenderManager::AfterLayout");
}

void NativeRenderManager::AddEventListener(std::weak_ptr<hippy::RootNode> root_node,
Expand Down

0 comments on commit 3963f68

Please sign in to comment.