Skip to content

Commit a0443cb

Browse files
committed
fix(android): add MonitorGroup for HippyEngineMonitorAdapter
1 parent da8d1c2 commit a0443cb

File tree

5 files changed

+39
-26
lines changed

5 files changed

+39
-26
lines changed

framework/android/src/main/java/com/tencent/mtt/hippy/HippyEngineManagerImpl.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ public void onFirstPaint(int rootId) {
240240
mEngineContext.getJsDriver().recordFirstPaintEndTime(System.currentTimeMillis(), rootId);
241241
mEngineContext.getMonitor().addPoint(TimeMonitor.MONITOR_GROUP_PAINT,
242242
TimeMonitor.MONITOR_POINT_FIRST_CONTENTFUL_PAINT);
243-
mGlobalConfigs.getEngineMonitorAdapter().onFirstPaintCompleted(mEngineContext.getComponentName());
243+
mGlobalConfigs.getEngineMonitorAdapter().onFirstPaintCompleted(mEngineContext.getComponentName(),
244+
mMonitor.getGroup(TimeMonitor.MONITOR_GROUP_PAINT));
244245
if (mModuleListener != null) {
245246
mModuleListener.onFirstViewAdded();
246247
}
@@ -250,7 +251,8 @@ public void onFirstPaint(int rootId) {
250251
public void onFirstContentfulPaint() {
251252
mEngineContext.getJsDriver().recordFirstContentfulPaintEndTime(System.currentTimeMillis());
252253
mEngineContext.getMonitor().endGroup(TimeMonitor.MONITOR_GROUP_PAINT);
253-
mGlobalConfigs.getEngineMonitorAdapter().onFirstContentfulPaintCompleted(mEngineContext.getComponentName());
254+
mGlobalConfigs.getEngineMonitorAdapter().onFirstContentfulPaintCompleted(mEngineContext.getComponentName(),
255+
mMonitor.getGroup(TimeMonitor.MONITOR_GROUP_PAINT));
254256
if (mModuleListener != null) {
255257
mModuleListener.onFirstContentfulPaint();
256258
}
@@ -453,7 +455,8 @@ public void getScreenshotBitmapForView(@Nullable Context context, @NonNull View
453455
throw new IllegalArgumentException("context is not activity");
454456
}
455457
}
456-
// Above Android O, use PixelCopy, because another way view.draw will cause Software rendering doesn't support hardware bitmaps
458+
// Above Android O, use PixelCopy, because another way view.draw will cause Software rendering
459+
// doesn't support hardware bitmaps
457460
int[] location = new int[2];
458461
view.getLocationInWindow(location);
459462
Window window = getViewWindow((Activity) context, view);
@@ -699,7 +702,8 @@ void notifyEngineInitialized(final EngineInitStatus statusCode, final Throwable
699702
}
700703

701704
private void onEngineInitialized(EngineInitStatus statusCode, Throwable error) {
702-
mGlobalConfigs.getEngineMonitorAdapter().onEngineInitialized(statusCode);
705+
mGlobalConfigs.getEngineMonitorAdapter()
706+
.onEngineInitialized(statusCode, mMonitor.getGroup(TimeMonitor.MONITOR_GROUP_INIT_ENGINE));
703707
for (EngineListener listener : mEventListeners) {
704708
listener.onInitialized(statusCode, error == null ? null : error.toString());
705709
}
@@ -1159,7 +1163,8 @@ public void run() {
11591163
public void onLoadModuleCompleted(ModuleLoadStatus statusCode, @Nullable String msg) {
11601164
notifyModuleLoaded(statusCode, msg);
11611165
mGlobalConfigs.getEngineMonitorAdapter()
1162-
.onLoadModuleCompleted(statusCode, mEngineContext.getComponentName());
1166+
.onLoadModuleCompleted(statusCode, mEngineContext.getComponentName(),
1167+
mMonitor.getGroup(TimeMonitor.MONITOR_GROUP_RUN_BUNDLE));
11631168
}
11641169

11651170
@Override

framework/android/src/main/java/com/tencent/mtt/hippy/adapter/monitor/DefaultEngineMonitorAdapter.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,31 @@
2323
import com.tencent.mtt.hippy.HippyEngine.ModuleLoadStatus;
2424
import com.tencent.mtt.hippy.bridge.HippyCallNativeParams;
2525
import com.tencent.mtt.hippy.utils.LogUtils;
26+
import com.tencent.mtt.hippy.utils.TimeMonitor.MonitorGroup;
2627

2728
public class DefaultEngineMonitorAdapter implements HippyEngineMonitorAdapter {
2829

2930
private static final String TAG = "DefaultEngineMonitorAdapter";
3031

3132
@Override
32-
public void onEngineInitialized(EngineInitStatus statusCode) {
33+
public void onEngineInitialized(EngineInitStatus statusCode, @Nullable MonitorGroup group) {
3334
LogUtils.i(TAG, "engine initialization completed with result: " + statusCode);
3435
}
3536

3637
@Override
37-
public void onLoadModuleCompleted(ModuleLoadStatus statusCode, @NonNull String componentName) {
38-
LogUtils.i(TAG,
39-
componentName + " load module completed with result: " + statusCode);
38+
public void onLoadModuleCompleted(ModuleLoadStatus statusCode, @NonNull String componentName,
39+
@Nullable MonitorGroup group) {
40+
LogUtils.i(TAG, componentName + " load module completed with result: " + statusCode);
4041
}
4142

4243
@Override
43-
public void onFirstPaintCompleted(@NonNull String componentName) {
44-
LogUtils.i(TAG,
45-
componentName + " first paint completed with first view added");
44+
public void onFirstPaintCompleted(@NonNull String componentName, @Nullable MonitorGroup group) {
45+
LogUtils.i(TAG, componentName + " first paint completed with first view added");
4646
}
4747

4848
@Override
49-
public void onFirstContentfulPaintCompleted(@NonNull String componentName) {
50-
LogUtils.i(TAG,
51-
componentName + " first contentful paint completed last content view added");
49+
public void onFirstContentfulPaintCompleted(@NonNull String componentName, @Nullable MonitorGroup group) {
50+
LogUtils.i(TAG, componentName + " first contentful paint completed last content view added");
5251
}
5352

5453
@Override

framework/android/src/main/java/com/tencent/mtt/hippy/adapter/monitor/HippyEngineMonitorAdapter.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,17 @@
2222
import com.tencent.mtt.hippy.HippyEngine.EngineInitStatus;
2323
import com.tencent.mtt.hippy.HippyEngine.ModuleLoadStatus;
2424
import com.tencent.mtt.hippy.bridge.HippyCallNativeParams;
25+
import com.tencent.mtt.hippy.utils.TimeMonitor.MonitorGroup;
2526

2627
public interface HippyEngineMonitorAdapter {
2728

28-
void onEngineInitialized(EngineInitStatus statusCode);
29+
void onEngineInitialized(EngineInitStatus statusCode, @Nullable MonitorGroup group);
2930

30-
void onLoadModuleCompleted(ModuleLoadStatus statusCode, @NonNull String componentName);
31+
void onLoadModuleCompleted(ModuleLoadStatus statusCode, @NonNull String componentName, @Nullable MonitorGroup group);
3132

32-
void onFirstPaintCompleted(@NonNull String componentName);
33+
void onFirstPaintCompleted(@NonNull String componentName, @Nullable MonitorGroup group);
3334

34-
void onFirstContentfulPaintCompleted(@NonNull String componentName);
35+
void onFirstContentfulPaintCompleted(@NonNull String componentName, @Nullable MonitorGroup group);
3536

3637
boolean onInterceptCallNative(@NonNull String componentName, @NonNull HippyCallNativeParams params);
3738

framework/android/src/main/java/com/tencent/mtt/hippy/bridge/HippyBridgeManagerImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@ public void Call(long result, Message message,
279279
"load coreJsBundle failed, check your core jsBundle:"
280280
+ reason);
281281
}
282-
callback.callback((result == 0), exception);
283282
timeMonitor.endGroup(TimeMonitor.MONITOR_GROUP_INIT_ENGINE);
283+
callback.callback((result == 0), exception);
284284
}
285285
});
286286
} else {
@@ -324,6 +324,9 @@ public void Call(long result, Message message,
324324
@Override
325325
public void Call(long result, Message message, String action,
326326
String reason) {
327+
timeMonitor.endGroup(TimeMonitor.MONITOR_GROUP_RUN_BUNDLE);
328+
timeMonitor.beginGroup(TimeMonitor.MONITOR_GROUP_PAINT);
329+
timeMonitor.addPoint(TimeMonitor.MONITOR_GROUP_PAINT, TimeMonitor.MONITOR_POINT_FIRST_PAINT);
327330
if (result == 0) {
328331
if (contextWeakRef.get() != null) {
329332
contextWeakRef.get().onLoadModuleCompleted(ModuleLoadStatus.STATUS_OK,
@@ -336,9 +339,6 @@ public void Call(long result, Message message, String action,
336339
"load module error. loader.load failed. check the file!!");
337340
}
338341
}
339-
timeMonitor.endGroup(TimeMonitor.MONITOR_GROUP_RUN_BUNDLE);
340-
timeMonitor.beginGroup(TimeMonitor.MONITOR_GROUP_PAINT);
341-
timeMonitor.addPoint(TimeMonitor.MONITOR_GROUP_PAINT, TimeMonitor.MONITOR_POINT_FIRST_PAINT);
342342
}
343343
});
344344
} else {

modules/android/hippy_support/src/main/java/com/tencent/mtt/hippy/utils/TimeMonitor.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class TimeMonitor {
3535
public static final String MONITOR_POINT_LOAD_MAIN_JS = "loadMainJs";
3636
public static final String MONITOR_POINT_FIRST_PAINT = "firstPaint";
3737
public static final String MONITOR_POINT_FIRST_CONTENTFUL_PAINT = "firstContentfulPaint";
38-
private int mEngineId;
38+
private final int mEngineId;
3939
@Nullable
4040
HashMap<String, MonitorGroup> mMonitorGroups;
4141

@@ -86,13 +86,21 @@ public synchronized void printGroup(@NonNull String groupName) {
8686
}
8787
}
8888

89-
private static class MonitorGroup {
89+
@Nullable
90+
public synchronized MonitorGroup getGroup(@NonNull String groupName) {
91+
if (mMonitorGroups != null) {
92+
return mMonitorGroups.get(groupName);
93+
}
94+
return null;
95+
}
96+
97+
public static class MonitorGroup {
9098

9199
public final String name;
92100
public long beginTime = -1;
93101
public long totalTime = -1;
94102
public boolean isActive = true;
95-
public int engineId = -1;
103+
public int engineId;
96104
@Nullable
97105
private ArrayList<MonitorPoint> mMonitorPoints;
98106
@Nullable

0 commit comments

Comments
 (0)