Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(devtools): add rendererType and componentCount report #3322

Merged
merged 2 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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