Skip to content

Commit

Permalink
feat(devtools): add rendererType and componentCount report (#3322)
Browse files Browse the repository at this point in the history
Co-authored-by: OpenHippy <124017524+open-hippy@users.noreply.github.com>
  • Loading branch information
2 people authored and zealotchen0 committed Aug 7, 2023
1 parent 1da3eb7 commit fc66d48
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,10 @@ public interface HippyModuleManager {
* @param apiProviders API providers need to be added.
*/
void addModules(List<HippyAPIProvider> apiProviders);

/**
* Get the number of native module, use for data report
* @return native module count
*/
int getNativeModuleCount();
}
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ public synchronized <T extends HippyNativeModuleBase> T getNativeModule(Class<T>
return null;
}

@Override
public int getNativeModuleCount() {
return mNativeModuleInfo.size();
}

@Nullable
public HippyNativeModuleInfo getModuleInfo(@NonNull String moduleName) {
return mNativeModuleInfo.get(moduleName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ private void processControllers(List<HippyAPIProvider> hippyPackages) {
new ControllerHolder(new HippyViewGroupController(), false));
}

public int getControllerCount() {
return mControllerRegistry.getControllersCount();
}

/**
* Add view controllers defined in {@link HippyAPIProvider}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
21 changes: 18 additions & 3 deletions ios/sdk/debug/devtools/HippyDevManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()<HippyDevClientProtocol> {
HippyDevWebSocketClient *_devWSClient;
Expand Down Expand Up @@ -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<Class>* 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 {
Expand Down
4 changes: 2 additions & 2 deletions ios/sdk/module/dev/HippyDevMenu.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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<HippyDevMenuItem *> *items = [self menuItems];
Expand Down

0 comments on commit fc66d48

Please sign in to comment.