[Add] 增加APP启动时长计算

Signed-off-by: donghongyu <donghongyu@zhidaoauto.com>
This commit is contained in:
donghongyu
2021-11-27 00:18:27 +08:00
parent 82accd5dc6
commit 12ecc7cf0c
4 changed files with 97 additions and 0 deletions

View File

@@ -25,6 +25,7 @@ import com.mogo.commons.mvp.MvpActivity;
import com.mogo.commons.mvp.MvpFragment;
import com.mogo.eagle.core.data.constants.MoGoFragmentPaths;
import com.mogo.eagle.core.data.map.MogoLocation;
import com.mogo.eagle.core.utilcode.mogo.AppLaunchTimeUtils;
import com.mogo.eagle.core.utilcode.mogo.toast.ResourcesHelper;
import com.mogo.map.location.IMogoLocationListener;
import com.mogo.map.uicontroller.EnumMapUI;
@@ -154,6 +155,7 @@ public class MainActivity extends MvpActivity<MainView, MainPresenter> implement
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
calculateStartTime();
ContextHolderUtil.holdContext(this);
mPresenter.postLoadModuleMsg();
NetworkUtils.listenNetStrength(this);
@@ -163,6 +165,36 @@ public class MainActivity extends MvpActivity<MainView, MainPresenter> implement
mPresenter.checkPermission(this);
}
private void calculateStartTime() {
long coldStartTime = AppLaunchTimeUtils.getTimeCalculate(AppLaunchTimeUtils.COLD_START);
// 这里记录的TimeUtils.coldStartTime是指Application启动的时间最终的冷启动时间等于Application启动时间+热启动时间
AppLaunchTimeUtils.sColdStartTime = coldStartTime > 0 ? coldStartTime : 0;
AppLaunchTimeUtils.beginTimeCalculate(AppLaunchTimeUtils.HOT_START);
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
if (hasFocus) {
long hotStartTime = AppLaunchTimeUtils.getTimeCalculate(AppLaunchTimeUtils.HOT_START);
if (AppLaunchTimeUtils.sColdStartTime > 0 && hotStartTime > 0) {
// 真正的冷启动时间 = Application启动时间 + 热启动时间
long coldStartTime = AppLaunchTimeUtils.sColdStartTime + hotStartTime;
// 过滤掉异常启动时间
if (coldStartTime < 50000) {
// 上传冷启动时间coldStartTime
Logger.i(TAG, "coldStartTime:" + coldStartTime);
}
} else if (hotStartTime > 0) {
// 过滤掉异常启动时间
if (hotStartTime < 30000) {
// 上传热启动时间hotStartTime
Logger.i(TAG, "hotStartTime:" + hotStartTime);
}
}
}
}
private void init() {
if (mServiceApis == null) {
mServiceApis = MogoApisHandler.getInstance().getApis();