anycost-gradle-plugin

全局耗时计算器,可以在任何地方计算耗时

License

License

MIT
Categories

Categories

Gradle Build Tools
GroupId

GroupId

in.xiandan
ArtifactId

ArtifactId

anycost-gradle-plugin
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

pom.sha512
Description

Description

anycost-gradle-plugin
全局耗时计算器,可以在任何地方计算耗时
Project URL

Project URL

https://github.com/xiandanin/AnyCost
Source Code Management

Source Code Management

https://github.com/xiandanin/AnyCost

Download anycost-gradle-plugin

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

安装

implementation 'in.xiandan:anycost:1.0.5'

使用

开始计时

AnyCost.begin(key)

结束计时

long end = AnyCost.end(key)

启用或禁用

AnyCost.getInstance().enable(BuildConfig.DEBUG)

计时监听

// 添加监听
AnyCost.getInstance().addOnTimingListener(new OnTimingListener() {
    @Override
    public void onTimingBegin(String key, String threadName) {
        
    }

    @Override
    public void onTimingEnd(String key, String threadName, long time, Object extras) {
        
    }
});

//移除监听
AnyCost.getInstance().removeOnTimingEndListener(listener)

//移除所有监听
AnyCost.getInstance().removeOnTimingEndListener()

注解计时

如果需要通过注解自动计时,还需要启用插件

buildscript {
    dependencies {
        classpath 'in.xiandan:anycost-gradle-plugin:1.0.1'
    }
}

app-build.gradle

plugins {
    id 'anycost'
}

在需要计算耗时的方法加上AnyCostMark注解

@AnyCostMark(key = "test")
private void test() {
}

Kotlin扩展

计算代码块耗时

cost(key) {
    // 自动计算此代码块所耗的时间
}

添加计时结束监听

AnyCost.getInstance().addOnTimingListener { key, threadName, time, extras ->

}

Versions

Version
1.0.1
1.0.0