Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

MethodCanary is tool to record method invocations

License

NotificationsYou must be signed in to change notification settings

Kyson/MethodCanary

Repository files navigation

中文

MethodCanary is tool to metric method cost.

Written forAndroidGodEye.

Build Status

Quick Start

Step0 Download

Root build.gradle

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

Module com.android.application

applyplugin:'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 conditioninstrumentationRuleFilePath && instrumentationRuleIncludeClassNamePrefix will be instrumented

You can change instrumentation rule

  1. Add class prefix list toinstrumentationRuleIncludeClassNamePrefix
  2. Put js fileAndroidGodEye-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 forisInclude
  3. ParamclassInfo has fields:int access,String name,String superName,String[] interfaces
  4. ParammethodInfo has fields:int access,String name,String desc
  5. WriteAndroidGodEye-MethodCanary.js by javascript language

Step2

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

About

MethodCanary is tool to record method invocations

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2026 Movatter.jp