Giter VIP home page Giter VIP logo

methodcanary's Introduction

MethodCanary

中文

MethodCanary is tool to metric method cost.

Written for AndroidGodEye.

Build Status

Quick Start

Step0 Download

Root build.gradle

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'cn.hikyson.methodcanary:plugin:VERSION'
    }
}

Module com.android.application

apply plugin: 'cn.hikyson.methodcanary.plugin'

implementation 'cn.hikyson.methodcanary:lib:VERSION'

Step1 Custom plugin

cn.hikyson.methodcanary.plugin has some configurations.

AndroidGodEye {
        enableLifecycleTracer = true // Need lifecycle methods instrumentation, default true
        enableMethodTracer = true // Need common methods instrumentation, default true
        instrumentationRuleFilePath = "app/AndroidGodEye-MethodCanary2.js" // Default AndroidGodEye-MethodCanary.js
        instrumentationRuleIncludeClassNamePrefix = ["cn/hikyson/methodcanary/sample"] // Default null
    }

Methods Meet this condition instrumentationRuleFilePath && instrumentationRuleIncludeClassNamePrefix will be instrumented

You can change instrumentation rule

  1. Add class prefix list to instrumentationRuleIncludeClassNamePrefix
  2. Put js file AndroidGodEye-MethodCanary.js in project root, content sample:
function isInclude(classInfo,methodInfo){
    if(classInfo.name.startsWith('cn/hikyson/methodcanary/samplelib/R$')
            || classInfo.name === 'cn/hikyson/methodcanary/samplelib/BuildConfig'
            || classInfo.name === 'cn/hikyson/methodcanary/samplelib/R'
            || classInfo.name.startsWith('cn/hikyson/methodcanary/sample/R$')
            || classInfo.name === 'cn/hikyson/methodcanary/sample/BuildConfig'
            || classInfo.name === 'cn/hikyson/methodcanary/sample/R'){
            return false
    }
    return true
}

Note

  1. Can not change function name and desc: function isInclude(classInfo,methodInfo)
  2. Functions must return boolean type, default True for isInclude
  3. Param classInfo has fields: int access,String name,String superName,String[] interfaces
  4. Param methodInfo has fields: int access,String name,String desc
  5. Write AndroidGodEye-MethodCanary.js by javascript language

Step2

// start recording
MethodCanary.get().startMethodTracing("sessionName0")
// stop recording
MethodCanary.get().stopMethodTracing(
                    "sessionName0", MethodCanaryConfig(5)
                ) { sessionTag, startMillis, stopMillis, methodEventMap ->
                    Logger.d("finish!!!")
                }
// Observe page lifecycle method cost
MethodCanary.get().addOnPageLifecycleEventCallback { lifecycleExitMethodEvent, page ->
            Logger.d(page.javaClass.simpleName + lifecycleExitMethodEvent)
        }
MethodCanary.get().removeOnPageLifecycleEventCallback()

methodcanary's People

Contributors

kyson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

methodcanary's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.