Skip to content

Commit 264e7a9

Browse files
committed
接入DoraemonKit进行性能监控
1 parent 46a5156 commit 264e7a9

File tree

8 files changed

+126
-3
lines changed

8 files changed

+126
-3
lines changed

app/build.gradle

+46
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ apply plugin: 'kotlin-android'
33
apply plugin: 'kotlin-android-extensions'
44
apply plugin: 'kotlin-kapt'
55
apply plugin: 'android-aspectjx'
6+
apply plugin: 'com.didi.dokit'
67
apply from: '../channel.gradle'
78
apply from: '../protect.gradle'
89
apply from: '../uploadpgy.gradle'
@@ -58,6 +59,47 @@ android {
5859
}
5960
}
6061

62+
dokitExt {
63+
//通用设置
64+
comm {
65+
//地图经纬度开关
66+
gpsSwitch true
67+
//网络开关
68+
networkSwitch true
69+
//大图开关
70+
bigImgSwitch true
71+
//webView js 抓包
72+
webViewSwitch true
73+
}
74+
75+
slowMethod {
76+
//0:默认模式 打印函数调用栈 需添加指定入口 默认为application onCreate 和attachBaseContext
77+
//1:普通模式 运行时打印某个函数的耗时 全局业务代码函数插入
78+
strategy 0
79+
//函数功能开关
80+
methodSwitch true
81+
82+
//调用栈模式配置
83+
stackMethod {
84+
//默认值为 5ms 小于该值的函数在调用栈中不显示
85+
thresholdTime 10
86+
//调用栈函数入口
87+
enterMethods = ["com.didichuxing.doraemondemo.MainDebugActivity.test1"]
88+
//黑名单 粒度最小到类 暂不支持到方法
89+
methodBlacklist = ["com.facebook.drawee.backends.pipeline.Fresco"]
90+
}
91+
//普通模式配置
92+
normalMethod {
93+
//默认值为 500ms 小于该值的函数在运行时不会在控制台中被打印
94+
thresholdTime 500
95+
//需要针对函数插装的包名
96+
packageNames = ["com.didichuxing.doraemondemo"]
97+
//不需要针对函数插装的包名&类名
98+
methodBlacklist = ["com.didichuxing.doraemondemo.dokit"]
99+
}
100+
}
101+
}
102+
61103
dependencies {
62104
implementation fileTree(dir: 'libs', include: ['*.jar'])
63105
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
@@ -134,6 +176,10 @@ dependencies {
134176
//aspectj
135177
implementation 'org.aspectj:aspectjrt:1.9.5'//需要使用aspectJ能力的模块
136178

179+
//DoKit
180+
debugImplementation 'com.didichuxing.doraemonkit:dokitx:3.3.5'
181+
releaseImplementation 'com.didichuxing.doraemonkit:dokitx-no-op:3.3.5'
182+
137183
//flutter
138184
implementation project(':flutter')
139185

app/src/main/java/com/fmt/github/App.kt

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class App : Application() {
1818
TaskDispatcher.createInstance()
1919
.addTask(InitBuGlyTask())
2020
.addTask(InitKoInTask())
21+
.addTask(InitDoKitTask())
2122
.addTask(InitImageLoaderTask())
2223
.addTask(InitSmartRefreshLayoutTask())
2324
.start()

app/src/main/java/com/fmt/github/base/fragment/BaseListMVFragment.kt

+25
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@ package com.fmt.github.base.fragment
22

33
import androidx.databinding.ObservableArrayList
44
import androidx.lifecycle.Observer
5+
import androidx.recyclerview.widget.RecyclerView
6+
import com.bumptech.glide.Glide
57
import com.fmt.github.R
68
import com.fmt.github.ext.otherwise
79
import com.fmt.github.ext.yes
810
import com.kennyc.view.MultiStateView
911
import com.scwang.smartrefresh.layout.api.RefreshLayout
1012
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener
1113
import com.scwang.smartrefresh.layout.listener.OnRefreshListener
14+
import kotlinx.android.synthetic.main.common_recyclerview.*
1215
import kotlinx.android.synthetic.main.common_refresh_recyclerview.*
16+
import kotlinx.android.synthetic.main.common_refresh_recyclerview.mRecyclerView
1317

1418
/**
1519
* 分页列表页面封装
@@ -21,13 +25,34 @@ abstract class BaseListMVFragment<M> : BaseVMFragment(), OnRefreshListener,
2125

2226
protected var mPage = 1
2327

28+
private var mIsScrolling = false
29+
2430
override fun getLayoutRes(): Int = R.layout.common_refresh_recyclerview
2531

2632
override fun initView() {
2733
initRefreshLayout()
34+
initScrollListener()
2835
initRecyclerView()
2936
}
3037

38+
//RecyclerView 滑动时图片加载的优化
39+
private fun initScrollListener() {
40+
mRecyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
41+
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
42+
super.onScrollStateChanged(recyclerView, newState)
43+
if (newState == RecyclerView.SCROLL_STATE_DRAGGING || newState == RecyclerView.SCROLL_STATE_SETTLING) {
44+
mIsScrolling = true
45+
Glide.with(this@BaseListMVFragment).pauseRequests()
46+
} else if (newState == RecyclerView.SCROLL_STATE_IDLE) {
47+
if (mIsScrolling) {
48+
Glide.with(this@BaseListMVFragment).resumeRequests()
49+
}
50+
mIsScrolling = false
51+
}
52+
}
53+
})
54+
}
55+
3156
private fun initRefreshLayout() {
3257
mRefreshLayout.run {
3358
setOnRefreshListener(this@BaseListMVFragment)

app/src/main/java/com/fmt/github/base/fragment/BasePagingVMFragment.kt

+19-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import androidx.paging.LoadState
44
import androidx.paging.PagingDataAdapter
55
import androidx.recyclerview.widget.LinearLayoutManager
66
import androidx.recyclerview.widget.RecyclerView
7+
import com.bumptech.glide.Glide
78
import com.fmt.github.R
89
import com.fmt.github.base.viewmodel.BaseLPagingViewModel
910
import com.fmt.github.home.adapter.PostsLoadStateAdapter
@@ -19,15 +20,32 @@ abstract class BasePagingVMFragment<M : Any, VM : BaseLPagingViewModel<M>, VH :
1920

2021
lateinit var mViewModel: VM
2122

23+
private var mIsScrolling = false
24+
2225
override fun getLayoutRes(): Int = R.layout.common_recyclerview
2326

2427
override fun initView() {
2528
mSwipeRefreshLayout.setOnRefreshListener {
2629
mAdapter.refresh()
2730
}
31+
mRecyclerView.layoutManager = LinearLayoutManager(mActivity)
32+
mRecyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
33+
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
34+
super.onScrollStateChanged(recyclerView, newState)
35+
if (newState == RecyclerView.SCROLL_STATE_DRAGGING || newState == RecyclerView.SCROLL_STATE_SETTLING) {
36+
mIsScrolling = true
37+
Glide.with(this@BasePagingVMFragment).pauseRequests()
38+
} else if (newState == RecyclerView.SCROLL_STATE_IDLE) {
39+
if (mIsScrolling) {
40+
Glide.with(this@BasePagingVMFragment).resumeRequests()
41+
}
42+
mIsScrolling = false
43+
}
44+
}
45+
})
2846
mRecyclerView.adapter =
2947
mAdapter.withLoadStateFooter(PostsLoadStateAdapter { mAdapter.retry() })
30-
mRecyclerView.layoutManager = LinearLayoutManager(mActivity)
48+
//监听Paging页面刷新时的状态
3149
mAdapter.addLoadStateListener {
3250
when (it.refresh) {
3351
is LoadState.Loading -> mSwipeRefreshLayout.isRefreshing = true

app/src/main/java/com/fmt/github/home/adapter/PostsLoadStateAdapter.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import com.fmt.github.R
1010
import kotlinx.android.synthetic.main.layout_network_state.view.*
1111

1212
/**
13-
* 设置底部加载进度或者加载出错时候的布局
13+
* 为Paging底部设置的加载进度、加载出错时候的多状态布局
1414
*/
1515
class PostsLoadStateAdapter(
1616
private val retryCallback: () -> Unit
@@ -32,7 +32,6 @@ class NetworkStateItemViewHolder(
3232
) : RecyclerView.ViewHolder(
3333
LayoutInflater.from(parent.context).inflate(R.layout.layout_network_state, parent, false)
3434
) {
35-
3635
init {
3736
itemView.mRetryLL.setOnClickListener {
3837
retryCallback.invoke()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.fmt.github.tasks
2+
3+
import com.didichuxing.doraemonkit.DoraemonKit
4+
import com.fmt.github.mApplication
5+
import com.fmt.launch.starter.task.MainTask
6+
7+
class InitDoKitTask : MainTask() {
8+
9+
override fun run() {
10+
//因为滴滴平台暂时注册不了,productId后续会替换,暂时使用不了平台工具
11+
DoraemonKit.install(mApplication,"")
12+
}
13+
}

build.gradle

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ apply from: './config.gradle'
44
buildscript {
55
ext.kotlin_version = '1.5.10'
66
repositories {
7+
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
8+
maven { url 'https://maven.aliyun.com/repository/google' }
79
google()
810
jcenter()
911
}
@@ -12,11 +14,14 @@ buildscript {
1214
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1315
classpath 'com.leon.channel:plugin:2.0.3'
1416
classpath 'com.hujiang.aspectjx:gradle-android-plugin-aspectjx:2.0.10'
17+
classpath 'com.didichuxing.doraemonkit:dokitx-plugin:3.3.5'
1518
}
1619
}
1720

1821
allprojects {
1922
repositories {
23+
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
24+
maven { url 'https://maven.aliyun.com/repository/google' }
2025
google()
2126
jcenter()
2227
maven { url "https://jitpack.io" }

gradle.properties

+16
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,19 @@ kapt.incremental.apt = false
2424

2525
#是否开启多渠道打包
2626
BUILD_MULTI_FLAVOR=true
27+
28+
## 插件开关
29+
DOKIT_PLUGIN_SWITCH=true
30+
## DOKIT读取三方库会和booster冲突 如果你的项目中也集成了booster 建议将开关改成false
31+
DOKIT_THIRD_LIB_SWITCH=true
32+
## 插件日志
33+
DOKIT_LOG_SWITCH=true
34+
## webview 的全限定名
35+
DOKIT_WEBVIEW_CLASS_NAME=com/didichuxing/doraemonkit/widget/webview/MyWebView
36+
## dokit 慢函数开关
37+
DOKIT_METHOD_SWITCH=true
38+
## dokit 函数调用栈层级
39+
DOKIT_METHOD_STACK_LEVEL=2
40+
## 0:调用栈模式 打印函数调用栈 需添加指定入口 默认为application onCreate 和attachBaseContext
41+
## 1:普通模式 运行时打印某个函数的耗时 全局业务代码函数插入
42+
DOKIT_METHOD_STRATEGY=0

0 commit comments

Comments
 (0)