Skip to content

Commit

Permalink
feat(android): support fcp monitor (#3796)
Browse files Browse the repository at this point in the history
* feat(android): support fcp monitor

* fix(android): rename to PAINT_TYPE_KEY

---------

Co-authored-by: maxli <[email protected]>
  • Loading branch information
siguangli and siguangli2018 authored Mar 27, 2024
1 parent e887127 commit b38e990
Show file tree
Hide file tree
Showing 18 changed files with 208 additions and 131 deletions.
1 change: 1 addition & 0 deletions driver/js/examples/hippy-react-demo/src/pages/gallery.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ export class Gallery extends Component {
renderRow={this.renderRow}
getRowType={this.getRowType}
getRowKey={this.getRowKey}
paintType="fcp"
/>
);
}
Expand Down
2 changes: 1 addition & 1 deletion driver/js/examples/hippy-vue-demo/src/pages/menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</router-link>
</li>
<li v-if="nativeFeatureList.length">
<p class="feature-title">
<p class="feature-title" paintType="fcp">
终端组件 Demos
</p>
</li>
Expand Down
2 changes: 1 addition & 1 deletion driver/js/examples/hippy-vue-next-demo/src/pages/menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</router-link>
</li>
<li v-if="nativeFeatureList.length">
<p class="feature-title">
<p class="feature-title" paintType="fcp">
终端组件 Demos
</p>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class PerformanceNavigationTiming : public PerformanceEntry {
DEFINE_SET_AND_GET_METHOD(HippyDomEnd, TimePoint, hippy_dom_end_)
DEFINE_SET_AND_GET_METHOD(HippyFirstFrameStart, TimePoint, hippy_first_frame_start_)
DEFINE_SET_AND_GET_METHOD(HippyFirstFrameEnd, TimePoint, hippy_first_frame_end_)
DEFINE_SET_AND_GET_METHOD(HippyFirstContentfulPaintEnd, TimePoint, hippy_first_contentful_paint_end_)

#undef DEFINE_SET_AND_GET_METHOD

inline const std::vector<BundleInfo>& GetBundleInfoArray() const {
Expand All @@ -86,6 +88,7 @@ class PerformanceNavigationTiming : public PerformanceEntry {
TimePoint hippy_dom_end_;
TimePoint hippy_first_frame_start_;
TimePoint hippy_first_frame_end_;
TimePoint hippy_first_contentful_paint_end_;
};

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ std::shared_ptr<ClassTemplate<PerformanceNavigationTiming>> RegisterPerformanceN
ADD_PROPERTY(hippy_dom_end, "hippyDomEnd", GetHippyDomEnd)
ADD_PROPERTY(hippy_first_frame_start, "hippyFirstFrameStart", GetHippyFirstFrameStart)
ADD_PROPERTY(hippy_first_frame_end, "hippyFirstFrameEnd", GetHippyFirstFrameEnd)
ADD_PROPERTY(hippy_first_contentful_paint_end, "hippyFirstContentfulPaintEnd", GetHippyFirstContentfulPaintEnd)
#undef ADD_PROPERTY

PropertyDefine<PerformanceNavigationTiming> bundle_info;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ void SetDomManager(JNIEnv* j_env,

void OnNativeInitEnd(JNIEnv* j_env, jobject j_object, jint j_scope_id, jlong startTime, jlong endTime);

void OnFirstFrameEnd(JNIEnv* j_env, jobject j_object, jint j_scope_id, jlong time);
void OnFirstPaintEnd(JNIEnv* j_env, jobject j_object, jint j_scope_id, jlong time);

void OnFirstContentfulPaintEnd(JNIEnv* j_env, jobject j_object, jint j_scope_id, jlong time);

void OnResourceLoadEnd(JNIEnv* j_env, jobject j_object, jint j_scope_id, jstring j_uri, jlong j_start_time, jlong j_end_time, jlong j_ret_code, jstring j_error_msg);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,14 @@ REGISTER_JNI("com/openhippy/connector/JsDriver", // NOLINT(cert-err58-cpp)
OnNativeInitEnd)

REGISTER_JNI("com/openhippy/connector/JsDriver", // NOLINT(cert-err58-cpp)
"onFirstFrameEnd",
"onFirstPaintEnd",
"(IJ)V",
OnFirstFrameEnd)
OnFirstPaintEnd)

REGISTER_JNI("com/openhippy/connector/JsDriver", // NOLINT(cert-err58-cpp)
"onFirstContentfulPaintEnd",
"(IJ)V",
OnFirstContentfulPaintEnd)

REGISTER_JNI("com/openhippy/connector/JsDriver", // NOLINT(cert-err58-cpp)
"onResourceLoadEnd",
Expand Down Expand Up @@ -180,7 +185,7 @@ void OnNativeInitEnd(JNIEnv* j_env, jobject j_object, jint j_scope_id, jlong sta
}
}

void OnFirstFrameEnd(JNIEnv* j_env, jobject j_object, jint j_scope_id, jlong time) {
void OnFirstPaintEnd(JNIEnv* j_env, jobject j_object, jint j_scope_id, jlong time) {
auto scope = GetScope(j_scope_id);
auto runner = scope->GetEngine().lock()->GetJsTaskRunner();
if (runner) {
Expand All @@ -204,6 +209,23 @@ void OnFirstFrameEnd(JNIEnv* j_env, jobject j_object, jint j_scope_id, jlong tim
}
}

void OnFirstContentfulPaintEnd(JNIEnv* j_env, jobject j_object, jint j_scope_id, jlong time) {
auto scope = GetScope(j_scope_id);
auto runner = scope->GetEngine().lock()->GetJsTaskRunner();
if (runner) {
std::weak_ptr<Scope> weak_scope = scope;
auto task = [weak_scope, time]() {
auto scope = weak_scope.lock();
if (!scope) {
return;
}
auto entry = scope->GetPerformance()->PerformanceNavigation("hippyInit");
entry->SetHippyFirstContentfulPaintEnd(footstone::TimePoint::FromEpochDelta(footstone::TimeDelta::FromMilliseconds(time)));
};
runner->PostTask(std::move(task));
}
}

void OnResourceLoadEnd(JNIEnv* j_env, jobject j_object, jint j_scope_id, jstring j_uri,
jlong j_start_time, jlong j_end_time, jlong j_ret_code, jstring j_error_msg) {
if (!j_uri) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,12 @@ public void recordNativeInitEndTime(long startTime, long endTime) {
onNativeInitEnd(mInstanceId, startTime, endTime);
}

public void recordFirstFrameEndTime(long time) {
onFirstFrameEnd(mInstanceId, time);
public void recordFirstPaintEndTime(long time) {
onFirstPaintEnd(mInstanceId, time);
}

public void recordFirstContentfulPaintEndTime(long time) {
onFirstContentfulPaintEnd(mInstanceId, time);
}

public void doRecordResourceLoadResult(@NonNull String uri, long startTime, long endTime,
Expand Down Expand Up @@ -166,7 +170,9 @@ private native void callFunction(int instanceId, String action, NativeCallback c

private native void onNativeInitEnd(int instanceId, long startTime, long endTime);

private native void onFirstFrameEnd(int instanceId, long time);
private native void onFirstPaintEnd(int instanceId, long time);

private native void onFirstContentfulPaintEnd(int instanceId, long time);

private native void onResourceLoadEnd(int instanceId, String uri, long startTime, long endTime,
long retCode, String errorMsg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@
import com.tencent.mtt.hippy.utils.LogUtils;
import com.tencent.mtt.hippy.utils.PixelUtil;
import com.tencent.mtt.hippy.utils.TimeMonitor;
import com.tencent.mtt.hippy.utils.TimeMonitor.MonitorGroup;
import com.tencent.mtt.hippy.utils.TimeMonitor.MonitorGroupType;
import com.tencent.mtt.hippy.utils.UIThreadUtils;
import com.tencent.renderer.FrameworkProxy;
import com.tencent.renderer.component.image.ImageDecoderAdapter;
Expand Down Expand Up @@ -219,19 +217,23 @@ protected void onDestroyEngine() {
}

@Override
public void onFirstViewAdded() {
mEngineContext.getJsDriver().recordFirstFrameEndTime(System.currentTimeMillis());
MonitorGroup monitorGroup = mEngineContext.getMonitor()
.endGroup(MonitorGroupType.LOAD_INSTANCE);
if (monitorGroup != null) {
mGlobalConfigs.getEngineMonitorAdapter()
.onLoadInstanceCompleted(mEngineContext.getComponentName(), monitorGroup);
}
public void onFirstPaint() {
mEngineContext.getJsDriver().recordFirstPaintEndTime(System.currentTimeMillis());
mEngineContext.getMonitor().addPoint(TimeMonitor.MONITOR_GROUP_PAINT,
TimeMonitor.MONITOR_POINT_FIRST_CONTENTFUL_PAINT);
mGlobalConfigs.getEngineMonitorAdapter().onFirstPaintCompleted(mEngineContext.getComponentName());
if (mModuleListener != null) {
mModuleListener.onFirstViewAdded();
}
}

@Override
public void onFirstContentfulPaint() {
mEngineContext.getJsDriver().recordFirstContentfulPaintEndTime(System.currentTimeMillis());
mEngineContext.getMonitor().endGroup(TimeMonitor.MONITOR_GROUP_PAINT);
mGlobalConfigs.getEngineMonitorAdapter().onFirstContentfulPaintCompleted(mEngineContext.getComponentName());
}

@Override
public void onSizeChanged(int rootId, int w, int h, int ow, int oh) {
if (mEngineContext != null) {
Expand Down Expand Up @@ -582,21 +584,16 @@ void notifyEngineInitialized(final EngineInitStatus statusCode, final Throwable

private void onEngineInitialized(EngineInitStatus statusCode, Throwable error) {
mEngineContext.getJsDriver().recordNativeInitEndTime(mInitStartTime, System.currentTimeMillis());
MonitorGroup monitorGroup = mEngineContext.getMonitor()
.endGroup(MonitorGroupType.ENGINE_INITIALIZE);
if (monitorGroup != null) {
mGlobalConfigs.getEngineMonitorAdapter()
.onEngineInitialized(statusCode, monitorGroup);
}
mGlobalConfigs.getEngineMonitorAdapter().onEngineInitialized(statusCode);
for (EngineListener listener : mEventListeners) {
listener.onInitialized(statusCode, error == null ? null : error.toString());
}
mEventListeners.clear();
}

private synchronized void restartEngineInBackground(boolean onReLoad) {
mMonitor.startPoint(MonitorGroupType.ENGINE_INITIALIZE,
TimeMonitor.MONITOR_POINT_INIT_NATIVE_ENGINE);
mMonitor.beginGroup(TimeMonitor.MONITOR_GROUP_INIT_ENGINE);
mMonitor.addPoint(TimeMonitor.MONITOR_GROUP_INIT_ENGINE, TimeMonitor.MONITOR_POINT_INIT_NATIVE_ENGINE);
if (mCurrentState == EngineState.DESTROYED) {
String errorMsg =
"restartEngineInBackground... error STATUS_WRONG_STATE, state=" + mCurrentState;
Expand Down Expand Up @@ -1041,19 +1038,13 @@ public void run() {
@Override
public void onLoadModuleCompleted(ModuleLoadStatus statusCode, @Nullable String msg) {
notifyModuleLoaded(statusCode, msg);
MonitorGroup monitorGroup = mEngineContext.getMonitor()
.endGroup(MonitorGroupType.RUN_JS_BUNDLE);
if (monitorGroup != null) {
mGlobalConfigs.getEngineMonitorAdapter()
.onLoadModuleCompleted(statusCode, mEngineContext.getComponentName(),
monitorGroup);
}
mGlobalConfigs.getEngineMonitorAdapter()
.onLoadModuleCompleted(statusCode, mEngineContext.getComponentName());
}

@Override
public void onLoadInstanceCompleted(long result, String reason) {
mEngineContext.getMonitor().startPoint(MonitorGroupType.LOAD_INSTANCE,
TimeMonitor.MONITOR_POINT_FIRST_FRAME);

}

public void destroyBridge(boolean isReload) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,46 +23,32 @@
import com.tencent.mtt.hippy.HippyEngine.ModuleLoadStatus;
import com.tencent.mtt.hippy.bridge.HippyCallNativeParams;
import com.tencent.mtt.hippy.utils.LogUtils;
import com.tencent.mtt.hippy.utils.TimeMonitor.MonitorGroup;
import com.tencent.mtt.hippy.utils.TimeMonitor.MonitorPoint;
import java.util.ArrayList;

public class DefaultEngineMonitorAdapter implements HippyEngineMonitorAdapter {

private static final String TAG = "DefaultEngineMonitorAdapter";

protected void printGroupTime(@NonNull MonitorGroup monitorGroup) {
ArrayList<MonitorPoint> monitorPoints = monitorGroup.getMonitorPoints();
if (monitorPoints != null) {
for (MonitorPoint monitorPoint : monitorPoints) {
LogUtils.i(TAG,
monitorPoint.key + ": " + (monitorPoint.endTime - monitorPoint.startTime)
+ "ms");
}
}
LogUtils.i(TAG, "total time: " + monitorGroup.totalTime);
}

@Override
public void onEngineInitialized(EngineInitStatus statusCode, @NonNull MonitorGroup monitorGroup) {
public void onEngineInitialized(EngineInitStatus statusCode) {
LogUtils.i(TAG, "engine initialization completed with result: " + statusCode);
printGroupTime(monitorGroup);
}

@Override
public void onLoadModuleCompleted(ModuleLoadStatus statusCode, @NonNull String componentName,
@NonNull MonitorGroup monitorGroup) {
public void onLoadModuleCompleted(ModuleLoadStatus statusCode, @NonNull String componentName) {
LogUtils.i(TAG,
componentName + " load module completed with result: " + statusCode);
printGroupTime(monitorGroup);
}

@Override
public void onLoadInstanceCompleted(@NonNull String componentName,
@NonNull MonitorGroup monitorGroup) {
public void onFirstPaintCompleted(@NonNull String componentName) {
LogUtils.i(TAG,
componentName + " first paint completed with first view added");
}

@Override
public void onFirstContentfulPaintCompleted(@NonNull String componentName) {
LogUtils.i(TAG,
componentName + " load instance completed with first view added");
printGroupTime(monitorGroup);
componentName + " first contentful paint completed last content view added");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,18 @@
import com.tencent.mtt.hippy.HippyEngine.EngineInitStatus;
import com.tencent.mtt.hippy.HippyEngine.ModuleLoadStatus;
import com.tencent.mtt.hippy.bridge.HippyCallNativeParams;
import com.tencent.mtt.hippy.utils.TimeMonitor.MonitorGroup;

public interface HippyEngineMonitorAdapter {

void onEngineInitialized(EngineInitStatus statusCode, @NonNull MonitorGroup monitorGroup);
void onEngineInitialized(EngineInitStatus statusCode);

void onLoadModuleCompleted(ModuleLoadStatus statusCode, @NonNull String componentName,
@NonNull MonitorGroup monitorGroup);
void onLoadModuleCompleted(ModuleLoadStatus statusCode, @NonNull String componentName);

void onLoadInstanceCompleted(@NonNull String componentName, @NonNull MonitorGroup monitorGroup);
void onFirstPaintCompleted(@NonNull String componentName);

boolean onInterceptCallNative(@NonNull String componentName,
@NonNull HippyCallNativeParams params);
void onFirstContentfulPaintCompleted(@NonNull String componentName);

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

void onCallNativeFinished(@NonNull String componentName, @NonNull HippyCallNativeParams params);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
import com.openhippy.connector.JsDriver.V8InitParams;
import com.tencent.mtt.hippy.HippyEngineContext;
import com.tencent.mtt.hippy.devsupport.DevSupportManager;
import com.tencent.mtt.hippy.utils.TimeMonitor;
import com.tencent.mtt.hippy.utils.TimeMonitor.MonitorGroupType;
import com.tencent.mtt.hippy.utils.UIThreadUtils;

import com.tencent.vfs.ResourceDataHolder;
Expand Down Expand Up @@ -99,7 +97,6 @@ public void initJSBridge(String globalConfig, NativeCallback callback, final int
}

private void initJSEngine(int groupId, NativeCallback callback) {
mContext.getMonitor().startPoint(MonitorGroupType.ENGINE_INITIALIZE, TimeMonitor.MONITOR_POINT_INIT_JS_ENGINE);
synchronized (HippyBridgeImpl.class) {
try {
String localCachePath = mContext.getGlobalConfigs().getContext().getCacheDir()
Expand Down
Loading

0 comments on commit b38e990

Please sign in to comment.