This topic describes how to add performance logs for Mobile Analysis.
Performance logs for Mobile Analysis on Android include the following:
Startup time log
Lag log
Stuck log
You can Log in to the mPaaS console and choose Mobile Analysis Service > Basic analysis to view the startup duration; and log in to the mPaaS console and choose Mobile Analysis Service > Performance analysis to view lag and stuck reports.
Startup speed instrumentation
Application startup duration = Time when the method is called - Time when the application starts.
To instrument for startup speed, call the following method in the onCreate() method of the home page Activity.
MPLogger.reportLaunchTime(Context context);Stuttering instrumentation
Stuttering occurs when the Android main thread takes longer than 2.25 seconds to execute a method. The stuttering threshold varies depending on the APK package type:
If the APK is a debug package, the stuttering threshold is 0.75 seconds. This lets you quickly detect potential stuttering issues during debugging.
If the APK is a release package, the stuttering threshold is 2.25 seconds.
Enable stuttering monitoring
Method 1
To enable automatic stuttering monitoring, your interface must inherit from the BaseActivity, BaseFragmentActivity, or BaseAppCompatActivity class provided by mPaaS.
Method 2
This method is supported only in baseline 10.2.3.50 and later.
You can manually call the relevant APIs in the lifecycle methods of the Activity. For example:
import android.app.Activity;
import android.app.Application;
import android.os.Bundle;
import com.mpaas.mas.adapter.api.MPLogger;
public class MPLifecycle implements Application.ActivityLifecycleCallbacks {
private int mVisibleActivityCount = 0;
private boolean isBackground = false;
@Override
public void onActivityCreated(Activity activity, Bundle bundle) {
}
@Override
public void onActivityStarted(Activity activity) {
mVisibleActivityCount++;
if (isBackground) {
isBackground = false;
// Called when the application returns to the foreground.
MPLogger.monitorAppForeground();
}
}
@Override
public void onActivityResumed(Activity activity) {
// Update the Activity context.
MPLogger.monitorActivityResumed(activity);
}
@Override
public void onActivityPaused(Activity activity) {
}
@Override
public void onActivityStopped(Activity activity) {
mVisibleActivityCount--;
if (mVisibleActivityCount <= 0) {
isBackground = true;
// Called when the application is sent to the background.
MPLogger.monitorAppBackground();
}
}
@Override
public void onActivitySaveInstanceState(Activity activity, Bundle bundle) {
}
@Override
public void onActivityDestroyed(Activity activity) {
}
}Stuttering monitoring collects all data for debug APKs. For release APKs, monitoring is based on sampling with a sample rate of 10%.
ANR instrumentation
An ANR typically occurs when the main thread is unresponsive for more than 5 seconds.
To enable ANR monitoring, see Enable stuttering monitoring.