From fc66d4866edf1c1625fd8aff757c22a776333fd9 Mon Sep 17 00:00:00 2001 From: wwwcg Date: Wed, 28 Jun 2023 17:02:08 +0800 Subject: [PATCH] feat(devtools): add rendererType and componentCount report (#3322) Co-authored-by: OpenHippy <124017524+open-hippy@users.noreply.github.com> --- .../hippy/devsupport/inspector/Inspector.java | 8 ++++++- .../mtt/hippy/modules/HippyModuleManager.java | 6 ++++++ .../hippy/modules/HippyModuleManagerImpl.java | 5 +++++ .../hippy/uimanager/ControllerManager.java | 4 ++++ .../hippy/uimanager/ControllerRegistry.java | 4 ++++ ios/sdk/debug/devtools/HippyDevManager.m | 21 ++++++++++++++++--- ios/sdk/module/dev/HippyDevMenu.mm | 4 ++-- 7 files changed, 46 insertions(+), 6 deletions(-) diff --git a/android/sdk/src/main/java/com/tencent/mtt/hippy/devsupport/inspector/Inspector.java b/android/sdk/src/main/java/com/tencent/mtt/hippy/devsupport/inspector/Inspector.java index ab28b0852d0..eade40f1b70 100644 --- a/android/sdk/src/main/java/com/tencent/mtt/hippy/devsupport/inspector/Inspector.java +++ b/android/sdk/src/main/java/com/tencent/mtt/hippy/devsupport/inspector/Inspector.java @@ -41,7 +41,7 @@ public class Inspector implements BatchListener { private static final String TAG = "Inspector"; - + private static final String RENDERER_TYPE = "Native"; private static final String CHROME_SOCKET_CLOSED = "chrome_socket_closed"; public static int CLOSE_DESTROY = 4003; @@ -174,6 +174,9 @@ public void updateContextName(String name) { contextObj.put("contextName", name); Context context = getContext().getGlobalConfigs().getContext(); + int moduleCount = getContext().getModuleManager().getNativeModuleCount(); + int viewCount = getContext().getRenderManager().getControllerManager().getControllerCount(); + String packageName = ""; String versionName = ""; if (context != null) { @@ -185,6 +188,9 @@ public void updateContextName(String name) { contextObj.put("bundleId", packageName); contextObj.put("hostVersion", versionName); contextObj.put("sdkVersion", BuildConfig.LIBRARY_VERSION); + contextObj.put("rendererType", RENDERER_TYPE); + contextObj.put("viewCount", viewCount); + contextObj.put("moduleCount", moduleCount); sendEventToFrontend(new InspectEvent("TDFRuntime.updateContextInfo", contextObj)); } catch (Exception e) { LogUtils.e(TAG, "updateContextName, exception:", e); diff --git a/android/sdk/src/main/java/com/tencent/mtt/hippy/modules/HippyModuleManager.java b/android/sdk/src/main/java/com/tencent/mtt/hippy/modules/HippyModuleManager.java index 4b49c645fab..6167fb0e6ea 100644 --- a/android/sdk/src/main/java/com/tencent/mtt/hippy/modules/HippyModuleManager.java +++ b/android/sdk/src/main/java/com/tencent/mtt/hippy/modules/HippyModuleManager.java @@ -47,4 +47,10 @@ public interface HippyModuleManager { * @param apiProviders API providers need to be added. */ void addModules(List apiProviders); + + /** + * Get the number of native module, use for data report + * @return native module count + */ + int getNativeModuleCount(); } diff --git a/android/sdk/src/main/java/com/tencent/mtt/hippy/modules/HippyModuleManagerImpl.java b/android/sdk/src/main/java/com/tencent/mtt/hippy/modules/HippyModuleManagerImpl.java index e151fe2bf41..db7eda792bb 100644 --- a/android/sdk/src/main/java/com/tencent/mtt/hippy/modules/HippyModuleManagerImpl.java +++ b/android/sdk/src/main/java/com/tencent/mtt/hippy/modules/HippyModuleManagerImpl.java @@ -225,6 +225,11 @@ public synchronized T getNativeModule(Class return null; } + @Override + public int getNativeModuleCount() { + return mNativeModuleInfo.size(); + } + @Nullable public HippyNativeModuleInfo getModuleInfo(@NonNull String moduleName) { return mNativeModuleInfo.get(moduleName); diff --git a/android/sdk/src/main/java/com/tencent/mtt/hippy/uimanager/ControllerManager.java b/android/sdk/src/main/java/com/tencent/mtt/hippy/uimanager/ControllerManager.java index 4b02b819e0f..f0cf200cc60 100644 --- a/android/sdk/src/main/java/com/tencent/mtt/hippy/uimanager/ControllerManager.java +++ b/android/sdk/src/main/java/com/tencent/mtt/hippy/uimanager/ControllerManager.java @@ -74,6 +74,10 @@ private void processControllers(List hippyPackages) { new ControllerHolder(new HippyViewGroupController(), false)); } + public int getControllerCount() { + return mControllerRegistry.getControllersCount(); + } + /** * Add view controllers defined in {@link HippyAPIProvider}. * diff --git a/android/sdk/src/main/java/com/tencent/mtt/hippy/uimanager/ControllerRegistry.java b/android/sdk/src/main/java/com/tencent/mtt/hippy/uimanager/ControllerRegistry.java index c5532272fc3..ae197a60205 100644 --- a/android/sdk/src/main/java/com/tencent/mtt/hippy/uimanager/ControllerRegistry.java +++ b/android/sdk/src/main/java/com/tencent/mtt/hippy/uimanager/ControllerRegistry.java @@ -48,6 +48,10 @@ public ControllerHolder getControllerHolder(String className) { return mControllers.get(className); } + public int getControllersCount() { + return mControllers.size(); + } + @SuppressWarnings({"rawtypes"}) public HippyViewController getViewController(String className) { try { diff --git a/ios/sdk/debug/devtools/HippyDevManager.m b/ios/sdk/debug/devtools/HippyDevManager.m index 3cedf3251dc..33257346542 100644 --- a/ios/sdk/debug/devtools/HippyDevManager.m +++ b/ios/sdk/debug/devtools/HippyDevManager.m @@ -28,9 +28,12 @@ #import "HippyBridge.h" #import "HippyUIManager.h" #import "HippyInspector.h" +#import "HippyBridge+Private.h" NSString *const HippyRuntimeDomainName = @"TDFRuntime"; NSString *const HippyRuntimeMethodUpdateContextInfo = @"updateContextInfo"; +NSString *const HippyRendererType = @"Native"; + @interface HippyDevManager () { HippyDevWebSocketClient *_devWSClient; @@ -65,15 +68,27 @@ - (void)updateContextInfoWithName:(NSString *)contextName { NSString *methodName = [NSString stringWithFormat:@"%@.%@", HippyRuntimeDomainName, HippyRuntimeMethodUpdateContextInfo]; NSString *bundleId = [[NSBundle mainBundle] bundleIdentifier]; NSString *hostVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]; + + // Get ViewManagers' number + NSArray* allModules = HippyGetModuleClasses(); + int viewManagerCount = 0; + for (Class module in allModules) { + if ([module isSubclassOfClass:HippyViewManager.class]) { + viewManagerCount ++; + } + } NSDictionary *params = @{ @"contextName": contextName ? : @"", @"bundleId": bundleId ? : @"Unknown", @"hostVersion": hostVersion ? : @"", - @"sdkVersion": _HippySDKVersion + @"sdkVersion": _HippySDKVersion, + @"rendererType": HippyRendererType, + @"viewCount": @(viewManagerCount), + @"moduleCount": @([allModules count] - viewManagerCount), }; - [_inspector sendDataToFrontendWithMethod:methodName - params:params]; + + [_inspector sendDataToFrontendWithMethod:methodName params:params]; } - (void)sendDataToFrontendWithData:(NSString *)dataString { diff --git a/ios/sdk/module/dev/HippyDevMenu.mm b/ios/sdk/module/dev/HippyDevMenu.mm index 3d7193a4577..68edbf939a7 100644 --- a/ios/sdk/module/dev/HippyDevMenu.mm +++ b/ios/sdk/module/dev/HippyDevMenu.mm @@ -228,13 +228,13 @@ - (void)addItem:(HippyDevMenuItem *)item { return; } - NSString *title = [NSString stringWithFormat:@"Hippy: Development (%@)", [_bridge class]]; + NSString *title = [NSString stringWithFormat:@"Hippy: Development (%@)", [_bridge moduleName]]; // On larger devices we don't have an anchor point for the action sheet UIAlertControllerStyle style = [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone ? UIAlertControllerStyleActionSheet : UIAlertControllerStyleAlert; _actionSheet = [UIAlertController alertControllerWithTitle:title - message:@"" + message:nil preferredStyle:style]; NSArray *items = [self menuItems];