{"id":20745731,"url":"https://github.com/kyson/methodcanary","last_synced_at":"2025-04-24T06:47:10.220Z","repository":{"id":53950509,"uuid":"189734293","full_name":"Kyson/MethodCanary","owner":"Kyson","description":"MethodCanary is tool to record method invocations","archived":false,"fork":false,"pushed_at":"2021-03-11T03:39:31.000Z","size":1230,"stargazers_count":15,"open_issues_count":1,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-24T06:47:09.680Z","etag":null,"topics":["android","asm","gradle","invocation","methods","tools"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Kyson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-06-01T13:11:31.000Z","updated_at":"2024-07-24T00:40:46.000Z","dependencies_parsed_at":"2022-08-13T05:11:08.643Z","dependency_job_id":null,"html_url":"https://github.com/Kyson/MethodCanary","commit_stats":null,"previous_names":[],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kyson%2FMethodCanary","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kyson%2FMethodCanary/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kyson%2FMethodCanary/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kyson%2FMethodCanary/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kyson","download_url":"https://codeload.github.com/Kyson/MethodCanary/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250580709,"owners_count":21453531,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","asm","gradle","invocation","methods","tools"],"created_at":"2024-11-17T07:22:13.264Z","updated_at":"2025-04-24T06:47:10.200Z","avatar_url":"https://github.com/Kyson.png","language":"Java","readme":"# MethodCanary\n\n[中文](https://github.com/Kyson/MethodCanary/blob/master/README_zh.md)\n\nMethodCanary is tool to metric method cost.\n\nWritten for [AndroidGodEye](https://github.com/Kyson/AndroidGodEye).\n\n[![Build Status](https://travis-ci.org/Kyson/MethodCanary.svg?branch=master)](https://travis-ci.org/Kyson/MethodCanary)\n\n## Quick Start\n\n### Step0 Download\n\nRoot build.gradle\n\n```groovy\nbuildscript {\n    repositories {\n        jcenter()\n    }\n    dependencies {\n        classpath 'cn.hikyson.methodcanary:plugin:VERSION'\n    }\n}\n```\n\nModule com.android.application \n\n```groovy\napply plugin: 'cn.hikyson.methodcanary.plugin'\n\nimplementation 'cn.hikyson.methodcanary:lib:VERSION'\n```\n\n### Step1 Custom plugin\n\n`cn.hikyson.methodcanary.plugin` has some configurations.\n\n```groovy\nAndroidGodEye {\n        enableLifecycleTracer = true // Need lifecycle methods instrumentation, default true\n        enableMethodTracer = true // Need common methods instrumentation, default true\n        instrumentationRuleFilePath = \"app/AndroidGodEye-MethodCanary2.js\" // Default AndroidGodEye-MethodCanary.js\n        instrumentationRuleIncludeClassNamePrefix = [\"cn/hikyson/methodcanary/sample\"] // Default null\n    }\n```\n\n\u003e Methods Meet this condition `instrumentationRuleFilePath \u0026\u0026 instrumentationRuleIncludeClassNamePrefix` will be instrumented\n\nYou can change instrumentation rule\n\n1. Add class prefix list to `instrumentationRuleIncludeClassNamePrefix`\n2. Put js file `AndroidGodEye-MethodCanary.js` in project root, content sample:\n\n```\nfunction isInclude(classInfo,methodInfo){\n    if(classInfo.name.startsWith('cn/hikyson/methodcanary/samplelib/R$')\n            || classInfo.name === 'cn/hikyson/methodcanary/samplelib/BuildConfig'\n            || classInfo.name === 'cn/hikyson/methodcanary/samplelib/R'\n            || classInfo.name.startsWith('cn/hikyson/methodcanary/sample/R$')\n            || classInfo.name === 'cn/hikyson/methodcanary/sample/BuildConfig'\n            || classInfo.name === 'cn/hikyson/methodcanary/sample/R'){\n            return false\n    }\n    return true\n}\n```\n\n#### Note\n\n1. Can not change function name and desc: `function isInclude(classInfo,methodInfo)`\n2. Functions must return boolean type, default True for `isInclude`\n3. Param `classInfo` has fields: `int access`,`String name`,`String superName`,`String[] interfaces`\n4. Param `methodInfo` has fields: `int access`,`String name`,`String desc`\n5. Write `AndroidGodEye-MethodCanary.js` by javascript language\n\n### Step2\n\n```java\n// start recording\nMethodCanary.get().startMethodTracing(\"sessionName0\")\n// stop recording\nMethodCanary.get().stopMethodTracing(\n                    \"sessionName0\", MethodCanaryConfig(5)\n                ) { sessionTag, startMillis, stopMillis, methodEventMap -\u003e\n                    Logger.d(\"finish！！！\")\n                }\n// Observe page lifecycle method cost\nMethodCanary.get().addOnPageLifecycleEventCallback { lifecycleExitMethodEvent, page -\u003e\n            Logger.d(page.javaClass.simpleName + lifecycleExitMethodEvent)\n        }\nMethodCanary.get().removeOnPageLifecycleEventCallback()\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkyson%2Fmethodcanary","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkyson%2Fmethodcanary","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkyson%2Fmethodcanary/lists"}