This article describes how to add performance logs for Mobile Analysis Service.
The performance logs that Mobile Analysis Service accesses to Android include:
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 time tracking
Application startup time = the time when this method is called - the time when the application starts.
It is recommended to call the following method in the onCreate()
method of the home page Activity
to track the startup speed.
MPLogger.reportLaunchTime(Context context);
Lag tracking
A lag is defined as the Android main thread taking more than 2.25 seconds to complete a method. The lag threshold varies depending on the APK package type:
When the APK package is a debug package, the lag threshold is 0.75 seconds, so that you can find the potential lagging issues during debugging.
When the APK package is a release package, the lag threshold is 2.25 seconds.
Enable lag monitoring
Method 1
The interface needs to inherit the BaseActivity
, BaseFragmentActivity
or BaseAppCompatActivity
class provided by mPaaS. All interfaces that inherit these classes will automatically monitor lag.
Method 2
This method is supported only in baseline 10.2.3.50 and later versions.
Manually call the relevant interface in the life cycle method of 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;
// Call it when the application returns to the foreground
MPLogger.monitorAppForeground();
}
}
@Override
public void onActivityResumed(Activity activity) {
// Update Activity Context
MPLogger.monitorActivityResumed(activity);
}
@Override
public void onActivityPaused(Activity activity) {
}
@Override
public void onActivityStopped(Activity activity) {
mVisibleActivityCount--;
if (mVisibleActivityCount <= 0) {
isBackground = true;
// Call it when the application returns to the background
MPLogger.monitorAppBackground();
}
}
@Override
public void onActivitySaveInstanceState(Activity activity, Bundle bundle) {
}
@Override
public void onActivityDestroyed(Activity activity) {
}
}
When the APK is a debug package, the lag monitoring is full statistics; when the APK is a release package, the lag monitoring is sampling statistics with a sampling rate of 10%.
Stuck tracking
A stuck is ANR in the Android system, which usually means that the main thread is unresponsive for more than 5 seconds.
To enable stuck monitoring, please refer to the above article for details: Enable lag monitoring.