Skip to content

Commit

Permalink
fix(ios, android): performance records inaccurate issues
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwcg committed Aug 2, 2024
1 parent 64f94ae commit 1083ed3
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 103 deletions.
5 changes: 1 addition & 4 deletions driver/js/src/scope.cc
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ void Scope::LoadInstance(const std::shared_ptr<HippyValue>& value) {
auto cb = [WEAK_THIS, weak_context, value]() mutable {
#endif
DEFINE_AND_CHECK_SELF(Scope)
// perfromance start time
// perfromance - RunApplication start time (end at DomStart)
auto entry = self->GetPerformance()->PerformanceNavigation(kPerfNavigationHippyInit);
entry->SetHippyRunApplicationStart(footstone::TimePoint::SystemNow());

Expand Down Expand Up @@ -561,9 +561,6 @@ void Scope::LoadInstance(const std::shared_ptr<HippyValue>& value) {
context->ThrowException("Application entry not found");
}
}

// perfromance end time
entry->SetHippyRunApplicationEnd(footstone::TimePoint::SystemNow());
};
auto runner = GetTaskRunner();
if (footstone::Worker::IsTaskRunning() && runner == footstone::runner::TaskRunner::GetCurrentTaskRunner()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ void OnFirstPaintEnd(JNIEnv* j_env, jobject j_object, jint j_scope_id, jlong tim
return;
}
auto entry = scope->GetPerformance()->PerformanceNavigation("hippyInit");
entry->SetHippyRunApplicationEnd(dom_manager->GetDomStartTimePoint());
entry->SetHippyDomStart(dom_manager->GetDomStartTimePoint());
entry->SetHippyDomEnd(dom_manager->GetDomEndTimePoint());
entry->SetHippyFirstFrameStart(dom_manager->GetDomEndTimePoint());
Expand Down
11 changes: 11 additions & 0 deletions framework/ios/base/bridge/HippyBridge+PerformanceAPI.mm
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#import "HippyBridge+PerformanceAPI.h"
#import "HippyJSExecutor.h"
#import "HippyLog.h"
#import "driver/scope.h"

@implementation HippyBridge (PerformanceAPI)
Expand All @@ -38,10 +39,20 @@ - (void)updatePerfRecordsOnRootContentDidAppear {
if (!entry) {
return;
}
entry->SetHippyRunApplicationEnd(domManager->GetDomStartTimePoint());
entry->SetHippyDomStart(domManager->GetDomStartTimePoint());
entry->SetHippyDomEnd(domManager->GetDomEndTimePoint());
entry->SetHippyFirstFrameStart(domManager->GetDomEndTimePoint());
entry->SetHippyFirstFrameEnd(footstone::TimePoint::SystemNow());

#if HIPPY_DEBUG
int64_t totalFPTime = (entry->GetHippyFirstFrameEnd() - entry->GetHippyNativeInitStart()).ToMilliseconds();
auto nativeInit = (entry->GetHippyNativeInitEnd() - entry->GetHippyNativeInitStart()).ToMilliseconds();
auto runApplication = (entry->GetHippyRunApplicationEnd() - entry->GetHippyRunApplicationStart()).ToMilliseconds();
auto domCreate = (entry->GetHippyDomEnd() - entry->GetHippyDomStart()).ToMilliseconds();
auto firstFrame = (entry->GetHippyFirstFrameEnd() - entry->GetHippyFirstFrameStart()).ToMilliseconds();
HippyLogTrace(@"Hippy FP=%lld, detail: %lld, %lld, %lld, %lld", totalFPTime, nativeInit, runApplication, domCreate, firstFrame);
#endif /* HIPPY_DEBUG */
}
}

Expand Down
4 changes: 4 additions & 0 deletions framework/ios/base/bridge/HippyBridge+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#define HippyBridge_Private_h

#import "HippyBridge.h"
#import "footstone/time_point.h"
#include <memory>

class VFSUriLoader;
Expand All @@ -46,6 +47,9 @@ class RenderManager;
/// URI Loader
@property (nonatomic, assign) std::weak_ptr<VFSUriLoader> vfsUriLoader;

/// Start time of hippyBridge, for performance api.
@property (nonatomic, assign) footstone::TimePoint startTime;

@end


Expand Down
24 changes: 8 additions & 16 deletions framework/ios/base/bridge/HippyBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,24 @@
#import "TypeConverter.h"
#import "VFSUriLoader.h"
#import "HippyBase64DataHandler.h"

#include <objc/runtime.h>
#include <sys/utsname.h>
#include <string>
#import "NativeRenderManager.h"
#import "HippyRootView.h"
#import "UIView+Hippy.h"
#import "UIView+MountEvent.h"

#include "dom/animation/animation_manager.h"
#include "dom/dom_manager.h"
#include "dom/scene.h"
#include "dom/render_manager.h"
#include "driver/scope.h"
#include "driver/performance/performance.h"
#include "footstone/worker_manager.h"
#include "vfs/uri_loader.h"
#include "VFSUriHandler.h"
#include "footstone/logging.h"

#import "NativeRenderManager.h"
#import "HippyRootView.h"
#import "UIView+Hippy.h"
#import "UIView+MountEvent.h"

#include <objc/runtime.h>
#include <sys/utsname.h>
#include <string>

#ifdef ENABLE_INSPECTOR
#include "devtools/vfs/devtools_handler.h"
Expand Down Expand Up @@ -155,8 +152,6 @@ @interface HippyBridge() {
NSMutableArray<NSURL *> *_bundleURLs;
NSURL *_sandboxDirectory;

footstone::TimePoint _startTime;

std::shared_ptr<VFSUriLoader> _uriLoader;
std::shared_ptr<hippy::RootNode> _rootNode;

Expand Down Expand Up @@ -187,6 +182,7 @@ @implementation HippyBridge
@synthesize renderManager = _renderManager;
@synthesize imageLoader = _imageLoader;
@synthesize imageProviders = _imageProviders;
@synthesize startTime = _startTime;

dispatch_queue_t HippyJSThread;

Expand Down Expand Up @@ -439,10 +435,6 @@ - (void)setUp {
HippyBridge *strongSelf = weakSelf;
if (strongSelf) {
dispatch_semaphore_signal(strongSelf.moduleSemaphore);
footstone::TimePoint endTime = footstone::TimePoint::SystemNow();
auto enty = strongSelf.javaScriptExecutor.pScope->GetPerformance()->PerformanceNavigation(hippy::kPerfNavigationHippyInit);
enty->SetHippyNativeInitStart(strongSelf->_startTime);
enty->SetHippyNativeInitEnd(endTime);
}
}];

Expand Down
39 changes: 26 additions & 13 deletions framework/ios/base/executors/HippyJSExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,49 +55,59 @@ class UriLoader;

typedef void (^HippyContextCreatedBlock)(id<HippyContextWrapper>);

/**
* Default name for the JS thread
*/
HIPPY_EXTERN NSString *const HippyJSCThreadName;

/**
* Uses a JavaScriptCore context as the execution engine.
*/
@interface HippyJSExecutor : NSObject<HippyInvalidating>

@property (nonatomic, strong) HippyBridge *bridge;
/// HippyBridge instance
@property (nonatomic, weak) HippyBridge *bridge;

/**
* Whether the executor has been invalidated
*/
@property (nonatomic, readonly, getter=isValid) BOOL valid;

/// EngineKey
@property (nonatomic, copy) NSString *enginekey;
/*
*hippy-core js engine
*/

/// hippy scope
@property (atomic, assign) std::shared_ptr<hippy::Scope> pScope;

/// context created block
@property(nonatomic, copy) HippyContextCreatedBlock contextCreatedBlock;

/// Init method
/// - Parameters:
/// - engineKey: NSString
/// - bridge: HippyBridge instance
- (instancetype)initWithEngineKey:(NSString *)engineKey bridge:(HippyBridge *)bridge;

/**
* Used to set up the executor after the bridge has been fully initialized.
* Do any expensive setup in this method instead of `-init`.
*/
/// Used to set up the executor after bridge has been fully initialized.
- (void)setup;

/// Set sandbox directory for Hippy
/// - Parameter directory: NSString
- (void)setSandboxDirectory:(NSString *)directory;

/// Set context name
/// - Parameter contextName: NSString
- (void)setContextName:(NSString *)contextName;

/// Set whether js engine is inspectable
/// - Parameter inspectable: BOOL
- (void)setInspecable:(BOOL)inspectable;

/// Set Uri loader
/// - Parameter uriLoader: vfs::UriLoader
- (void)setUriLoader:(std::weak_ptr<hippy::vfs::UriLoader>)uriLoader;

/// Get turbo object
/// - Parameter name: NSString
- (std::shared_ptr<hippy::napi::CtxValue>)JSTurboObjectWithName:(NSString *)name;

// TODO: 疑似已废弃
/**
* Executes BatchedBridge.flushedQueue on JS thread and calls the given callback
* with JSValue, containing the next queue, and JSContext.
Expand All @@ -109,7 +119,10 @@ HIPPY_EXTERN NSString *const HippyJSCThreadName;
* method name and optional additional arguments on the JS thread and calls the
* given callback with JSValue, containing the next queue, and JSContext.
*/
- (void)callFunctionOnModule:(NSString *)module method:(NSString *)method arguments:(NSArray *)args callback:(HippyJavaScriptCallback)onComplete;
- (void)callFunctionOnModule:(NSString *)moduleName
method:(NSString *)method
arguments:(NSArray *)args
callback:(HippyJavaScriptCallback)onComplete;

/**
* Executes BatchedBridge.invokeCallbackAndReturnFlushedQueue with the cbID,
Expand Down
Loading

0 comments on commit 1083ed3

Please sign in to comment.