Skip to content

Commit

Permalink
fix(perf): enable perflog output in debug mode only
Browse files Browse the repository at this point in the history
  • Loading branch information
ruifanyuan committed Oct 25, 2023
1 parent 61c41d8 commit cd628af
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
12 changes: 6 additions & 6 deletions framework/ios/base/bridge/HippyBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +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);
HippyLogInfo(@"HippyBridge init begin, self:%p", self);
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(rootViewContentDidAppear:)
name:HippyContentDidAppearNotification object:nil];
HippyExecuteOnMainThread(^{
Expand All @@ -208,7 +208,7 @@ - (instancetype)initWithDelegate:(id<HippyBridgeDelegate>)delegate
[HippyBridge setCurrentBridge:self];

[self loadPendingVendorBundleURLIfNeeded];
HP_PERF_LOG("HippyBridge init end, self:%p", self);
HippyLogInfo(@"HippyBridge init end, self:%p", self);
}
return self;
}
Expand Down Expand Up @@ -414,7 +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));
HippyLogInfo(@"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 @@ -452,7 +452,7 @@ - (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));
HippyLogInfo(@"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 @@ -509,15 +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);
HippyLogInfo(@"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);
HippyLogInfo(@"End loading instance for HippyBridge(%p)", self);
}

- (void)rootViewSizeChangedEvent:(NSNumber *)tag params:(NSDictionary *)params {
Expand Down
9 changes: 9 additions & 0 deletions modules/footstone/include/footstone/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,16 @@ bool ShouldCreateLogMessage(LogSeverity severity);


#define HP_CSTR_NOT_NULL( p ) (p ? p : "")

#ifdef DEBUG

// enable perf log output in debug mode only
#define HP_PERF_LOG(format, ...) \
footstone::LogMessage::LogWithFormat(__FILE_NAME__, __LINE__, "[HP PERF] " format, \
##__VA_ARGS__)

#else

#define HP_PERF_LOG(format, ...)

#endif

0 comments on commit cd628af

Please sign in to comment.