BlockCollect是一个兼具卡顿监测和远程收集日志的工具.
-
卡顿监测利用Android系统每隔16.6ms发出VSYNC信号,来通知界面进行重绘、渲染的原理.
-
远程收集日志利用Bugly这趟顺风车.
本地日志:
远程日志:
1、去Bugly官网创建应用获取AppId
2、填写Bugly所需要的权限
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_LOGS" />
3、添加依赖
dependencies {
compile 'com.tencent.bugly:crashreport:latest.release'
compile 'com.yph:blockcollect:1.0.1'
}
4、初始化
public class App extends Application{
@Override
public void onCreate() {
super.onCreate();
CrashReport.initCrashReport(this, "你的AppId", false);
BlockDetect.start(true);//是否开车
// BlockDetect.start(true,800,6);//1是否开车,2阈值,3采样
}
}
其中布尔值代表是否push到bugly,第二个参数为阈值,默认800ms,第三个采样频次,默认6次
卡顿监测之真正轻量级的卡顿监测工具BlockDetectUtil(仅一个类)
Copyright [2018] [yph]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.