A gradle plugin to show time costs of methods on main-thread
.
Just several lines.
dependencies {
classpath 'com.xiaobo.plugin:method-time-cost:1.1.3'
...
}
dependencies {
compile 'com.xiaobo.plugin:method-time-cost_runtime:1.1.1'
...
}
apply plugin: 'com.xiaobo.method_time_cost'
method_time_cost {
enable = true // optional, default is true.
costBiggerThan = 20 // optional, default is 0. ==> show log of methods cost time >= 0
tag = "xiaobo" // optional, default is MethodTimeCost
}
gradlew assembleDebug
class Test {
public int add (int a, int b) {
int result = a + b;
return result;
}
}
will change into
class Test {
static LinkedList<Long> __time_list = new LinkedList<Long>();
public int add (int a, int b) {
__time_list.push(System.currentTimeMillis());
int result = a + b;
Log.d(TAG, "" + System.currentTimeMillis() - __time_list.pop());
return result;
}
}
The code is inserted by Java Assist.
Just use the plugin under debug mode. For it will insert code into your source class files, which will increases the size of your apk.
- A few methods can not be monitored since the exception from Java Assist.
- You can use
AspectJ
instead. But you will write more code and it will generatetoo many
classes.