Add performance logging to your Android app to monitor startup time, stuttering, and ANR events with Mobile Analysis.
Mobile Analysis on Android tracks three categories of performance data:
Startup time log
Lag log
Stuck log
After instrumentation, view startup duration under Mobile Analysis Service > Basic analysis in the mPaaS console. View lag and stuck reports under Mobile Analysis Service > Performance analysis.
Startup speed instrumentation
Startup duration is the elapsed time from when the application process starts to when the home page onCreate() method is called. Call the following method inside Activity onCreate() to report this duration to Mobile Analysis.
MPLogger.reportLaunchTime(Context context);
Stuttering instrumentation
A stutter event is recorded when the Android main thread takes longer than the threshold to execute a method. The threshold differs by build type:
Debug APK: 0.75 seconds — a lower threshold to surface potential issues early during development.
Release APK: 2.25 seconds.
Enable stuttering monitoring
Method 1
Inherit from the BaseActivity, BaseFragmentActivity, or BaseAppCompatActivity class provided by mPaaS. Stuttering monitoring is enabled automatically — no additional code is required.
Method 2
This method is supported only in baseline 10.2.3.50 and later.
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) {
}
}
Data collection differs by build type:
|
Build type |
Data collected |
|
Debug APK |
All stutter events (100% sampling) |
|
Release APK |
Sampled at 10% |
ANR instrumentation
An Application Not Responding (ANR) event occurs when the main thread is unresponsive for more than 5 seconds.
ANR monitoring uses the same configuration as stuttering monitoring. To enable it, see Enable stuttering monitoring.