{"id":13677907,"url":"https://github.com/leinlin/Miku-LuaProfiler","last_synced_at":"2025-04-29T12:32:39.441Z","repository":{"id":37339694,"uuid":"158198602","full_name":"leinlin/Miku-LuaProfiler","owner":"leinlin","description":null,"archived":false,"fork":false,"pushed_at":"2024-06-06T09:41:16.000Z","size":32327,"stargazers_count":1910,"open_issues_count":28,"forks_count":439,"subscribers_count":81,"default_branch":"master","last_synced_at":"2024-11-11T15:12:01.411Z","etag":null,"topics":["lua","profiler","unity","xlua"],"latest_commit_sha":null,"homepage":null,"language":"C#","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/leinlin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-11-19T09:54:04.000Z","updated_at":"2024-11-11T03:59:50.000Z","dependencies_parsed_at":"2024-01-14T15:21:25.629Z","dependency_job_id":"f49d1503-93af-4ace-8c95-613b11a72ddc","html_url":"https://github.com/leinlin/Miku-LuaProfiler","commit_stats":null,"previous_names":["elpsycongree/luaprofiler-for-unity"],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leinlin%2FMiku-LuaProfiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leinlin%2FMiku-LuaProfiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leinlin%2FMiku-LuaProfiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leinlin%2FMiku-LuaProfiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leinlin","download_url":"https://codeload.github.com/leinlin/Miku-LuaProfiler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224173351,"owners_count":17268101,"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":["lua","profiler","unity","xlua"],"created_at":"2024-08-02T13:00:48.411Z","updated_at":"2024-11-11T20:30:43.383Z","avatar_url":"https://github.com/leinlin.png","language":"C#","readme":"## Lua Profiler For Unity\n\n![](doc~/logo.png)\n\n### 支持情况\n| 系统                  | 支持情况|\n| ----------------------- | ------------ |\n| `windows`| ✔  |\n| `android`| ✔  |\n| `MAC`| 支持中  |\n| `IOS`| 支持中  |\n\n![](doc~/use.gif)\n\n### 部署和安装\n1. 推荐安装Unity2019可以直接用PackageManager 用add by git路径添加,国内网络不好可以使用gitee代理\n![](doc~/package_clone.png)\n\u003ehttps://github.com/leinlin/Miku-LuaProfiler.git\n\n2. Unity5.6以上版本建议把代码clone下来，然后把LuaProfiler目录copy到Assets中\n\n3. 看到这个菜单说明安装成功了\n![](doc~/install_success.png)\n\n### 如何使用\n- 编辑器使用推荐使用local模式，打开DeepLua开关即可\n![](doc~/2022-12-14-21-50-20.png)\n\n- 真机目前只支持android系统，打包的时候加上宏 `USE_LUA_PROFILER`\n- 打包后，使用四根手指同时连续敲击屏幕5下以上后，就会出现以下菜单\n![](doc~/2022-12-14-21-58-59.png)\n\n- 点击 `Open Lua Profiler`就会打上标记，下一次启动游戏就会出现一个黑屏\n\n编辑器中点击local mode 按钮就可以切换remote mode,输入手机ip就可以查看数据了\n\n![](doc~/2022-12-14-22-04-21.png)\n如果公司网络不允许你直接访问手机ip，那么可以用USB数据线连接手机和电脑输入以下指令\n```\nadb forward tcp:2333 tcp:2333\n```\n之后直接在ip栏中输入`127.0.0.1`即可\n\n### 数据说明\n| Name                    | Descriptions                                                                                              |\n| ----------------------- | -------------------------------------------------------------------------------------------------------   |\n| `Overview`              | 函数名称                                                                                                  |\n| `totalLuaMemory`        | 此函数生成的所有Lua GC的总和                                                                              |\n| `self`                  | 函数本身产生的GC量                                                                                        |\n| `totalMonoMemory`       | 此函数生成的所有Mono GC的总和                                                                             |\n| `self`                  | 函数本身产生的GC量                                                                                        |\n| `currentTime`           | 函数在当前帧中运行所需的时间                                                                              |\n| `averageTime`           | 计算在函数上花费的时间的平均值                                                                            |\n| `totalTime`             | 此功能消耗的所有时间                                                                                      |\n| `LuaGC`                 | 由当前帧生成的Lua GC                                                                                      |\n| `MonoGC`                | 由当前帧生成的Mono GC                                                                                     |\n| `totalCalls`            | 游戏开始后此功能的运行次数                                                                                |\n| `Calls`                 | 函数当前帧的执行次数                                                                                      |\n\n### FAQ\n\n有的Unity版本不支持 `[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]`这个属性的时候，你可以在lua虚拟机启动之前调用代码\n```\nMikuLuaProfiler.HookLuaSetup.OnStartGame();\n```\n\n打开DeepLua之后会有很多空异常报错\n\u003e 有的项目组会使用debug.getupvalue去获取变量并进行修改，但是MikuLuaProfiler会在所有代码执行之前添加一个Upvalue函数进行BeginSample和EndSample。这个会导致原先的upvalue表混乱，解决办法就是遍历Upvalue表，然后根据upvalue的命名获取到相应的变量，如下代码：\n```\nfunction debug.getupvalue_byname(func, name)\n    local i = 1\n    while true do\n        local n, v = debug.getupvalue(func, i)\n        if not n then break end\n        if n == name then return v end\n        i = i + 1\n    end\nend\n\nfunction debug.setupvalue_byname(func, name, value)\n    local i = 1\n    while true do\n        local n, v = debug.getupvalue(func, i)\n        if not n then break end\n        if n == name then\n            debug.setupvalue(func, i, value)\n            break\n        end\n        i = i + 1\n    end\nend\n```\n\n真机数据只有resume或者协程数据\n\u003e 不要用luac加密代码，请直接使用明码字符串\n\n\n运行了性能调试之后，用代码调用luaGC无效\n\u003e 为了防止lua的GC导致内存统计出现负数，本项目直接用hook技术接管了lua的GC函数，让用户的自动促发无效，GC会根据内存是否增长到上次GC的1.2倍左右就触发，如果项目的Update GC优化的较好，内存曲线是基本一致的。\n\n\n关于XLua demo跑不起来的问题\n\u003e 把Demo里面LuaBehaviour 中 internal static LuaEnv luaEnv = new LuaEnv()的赋值改到Awake里面\n\n关于自定义profiler点\n```\nlocal LuaProfiler = MikuLuaProfiler.LuaProfiler\nLuaProfiler.BeginSampleCustom(\"profiler name\")\n-- your code\nLuaProfiler.EndSampleCustom()\n```\n\n\nMarkStaticRecord、MarkLuaRecord、DiffRecord、ClearDiff有什么用\n\u003e这一组功能是查泄漏使用的。举一个例子，你可以在打开UI前MarkStaticRecord，进行一次内存快照，然后打开UI后MarkLuaRecord，记录第二次快照，最后你在调用UI释放的函数这里DiffRecord。如果打开UI前不持有，而打开UI后\n与释放UI后都持有的对象为泄漏。\n函数API为：\n```\nfunction miku_do_record(val, prefix, key, record, history, null_list, staticRecord)\n\nfunction miku_diff(record, staticRecord)\n```\n\n运行起来后totalLuaMemory为负数\n\u003e底层统计lua内存申请采用记录lua虚拟机总量来记录对应的GC，如果函数运行的中间发生了GC就会导致内存差值为负数，你可以把自动GC关闭掉后进行统计。\n\n如何对Lua函数进行各种数据排序\n\u003e在搜索框中输入：[lua],然后点击右上角的merge按钮,最后点击各个数据标签进行排序\n![](doc~/sort.png)\n\n如何定位Lua函数内存暴涨的点\n\u003e使用Record模式启动游戏，在想采样的地方点击StartRecord,截取完记录后，找一段明显内存上涨的地方，采样出来分析函数即可.（鼠标点击上去，然后按键盘的左右键）\n![](doc~/record.png)\n\nref的function代表什么\n\u003e这里存储的一般都是C#这里持有的回调函数，你可以每一次打开UI前先clear数据，然后进入UI后记录数据，释放UI后如果 还持有不少委托，就代表说泄漏了。\n\n\u003cspan id=\"contact_zh\"\u003e\u003c/span\u003e\n### [联系](#zh)\n如果您发现任何错误或有任何建议加入QQ群：[882425563](https://jq.qq.com/?_wv=1027\u0026k=5QkOBSc) 与我们联系\n\n\u003cspan id=\"contact_zh\"\u003e\u003c/span\u003e\n## 投食\n![](doc~/zfb.png)\n\n##\n![](doc~/meizi.gif)\n\n","funding_links":[],"categories":["Open Source Repositories","C# #"],"sub_categories":["Lua Utilities"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleinlin%2FMiku-LuaProfiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleinlin%2FMiku-LuaProfiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleinlin%2FMiku-LuaProfiler/lists"}