{"id":21071596,"url":"https://github.com/esrrhs/wlua","last_synced_at":"2025-05-16T05:31:38.513Z","repository":{"id":87695696,"uuid":"346296281","full_name":"esrrhs/wLua","owner":"esrrhs","description":"监视lua状态机内部的工具。a tool that watch running lua state","archived":false,"fork":false,"pushed_at":"2023-02-23T11:32:37.000Z","size":304,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-03T20:51:14.312Z","etag":null,"topics":["lua","watching"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/esrrhs.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":"2021-03-10T09:10:28.000Z","updated_at":"2025-03-27T02:00:55.000Z","dependencies_parsed_at":null,"dependency_job_id":"8e41f424-dc49-4749-a1ad-5c972b7b7349","html_url":"https://github.com/esrrhs/wLua","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esrrhs%2FwLua","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esrrhs%2FwLua/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esrrhs%2FwLua/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esrrhs%2FwLua/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/esrrhs","download_url":"https://codeload.github.com/esrrhs/wLua/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254474266,"owners_count":22077247,"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","watching"],"created_at":"2024-11-19T18:53:42.073Z","updated_at":"2025-05-16T05:31:38.506Z","avatar_url":"https://github.com/esrrhs.png","language":"C","readme":"# wLua\r\n[\u003cimg src=\"https://img.shields.io/github/license/esrrhs/wLua\"\u003e](https://github.com/esrrhs/wLua)\r\n[\u003cimg src=\"https://img.shields.io/github/languages/top/esrrhs/wLua\"\u003e](https://github.com/esrrhs/wLua)\r\n[\u003cimg src=\"https://img.shields.io/github/actions/workflow/status/esrrhs/wLua/cmake.yml?branch=master\"\u003e](https://github.com/esrrhs/wLua/actions)\r\n\r\nwLua是监视Lua虚拟内部状态的工具。\r\n\r\n# 特性\r\n* C++编写，支持Linux平台\r\n* 通过附加到其他进程上，进行监视\r\n* 支持对table rehash冲突检查\r\n* 支持对table get set次数统计\r\n* 支持对gc数据统计\r\n* 支持对string数据统计\r\n\r\n# 编译\r\n* 运行```./build.sh```编译，生成libwlua.so\r\n* 下载编译[hookso](https://github.com/esrrhs/hookso)，生成```hookso```，```hookso```是注入工具\r\n* 将```./build.sh```、```hookso```放在同级目录即可使用\r\n\r\n# 示例\r\n运行test.lua，因为alloc_id函数不合理，导致全部hash冲突，会导致rehash的时间很长\r\n```\r\n# lua test.lua\r\n```\r\n然后运行监视程序，假定PID=1234\r\n```\r\n# ./start.sh 1234\r\n```\r\n然后查看当前目录下的wlua_check.log \r\n### table rehash 冲突\r\n```\r\n[2021.3.13,8:30:8]table hash collision max=64 total=64 at @test.lua:17\r\n[2021.3.13,8:30:8]table hash collision max=128 total=128 at @test.lua:17\r\n[2021.3.13,8:30:8]table hash collision max=256 total=256 at @test.lua:17\r\n[2021.3.13,8:30:8]table hash collision max=512 total=512 at @test.lua:17\r\n[2021.3.13,8:30:8]table hash collision max=1024 total=1024 at @test.lua:17\r\n[2021.3.13,8:30:8]table hash collision max=2048 total=2048 at @test.lua:17\r\n[2021.3.13,8:30:8]table hash collision max=4096 total=4096 at @test.lua:17\r\n[2021.3.13,8:30:9]table hash collision max=8192 total=8192 at @test.lua:17\r\n[2021.3.13,8:30:11]table hash collision max=16384 total=16384 at @test.lua:17\r\n```\r\nmax=hashtable里最大的冲突链表长度，total=hashtable总共的元素个数。当max \u003e= 20%*total会告警\r\n### table get set次数\r\n```\r\n[2021.3.24,7:58:8]table get=1023102 set=360613\r\n[2021.3.24,7:59:8]table get=1023766 set=360613\r\n[2021.3.24,8:0:8]table get=1022092 set=360613\r\n[2021.3.24,8:1:8]table get=1022588 set=360613\r\n[2021.3.24,8:2:8]table get=1019782 set=360613\r\n```\r\n### gc数据\r\n```\r\n[2021.3.24,7:58:8]gc fullgc=0 step=250 singlestep=4700 singlestep-freesize=9942KB marked-obj=83065 new-obj=331237 free-obj=300028\r\n[2021.3.24,7:59:8]gc fullgc=0 step=300 singlestep=5640 singlestep-freesize=11931KB marked-obj=99678 new-obj=331569 free-obj=360034\r\n[2021.3.24,8:0:8]gc fullgc=0 step=250 singlestep=4700 singlestep-freesize=9942KB marked-obj=83065 new-obj=330732 free-obj=300028\r\n[2021.3.24,8:1:8]gc fullgc=0 step=300 singlestep=5640 singlestep-freesize=11931KB marked-obj=99678 new-obj=330982 free-obj=360036\r\n```\r\nfullgc是全量gc次数，step是单步gc调用次数，singlestep是单次单步gc调用次数，singlestep-freesize是单步gc总共回收的内存大小，marked-obj是标记为黑色（使用中）的对象个数\r\nnew-obj是新建的对象个数，free-obj是释放的对象个数\r\n### string数据\r\n```\r\n[2021.3.24,8:38:22]string alloc=951539 cache=22 short=951517 short-reuse=634333 long=0 short-size=1806KB short-reuse-size=0KB long-size=0KB\r\n[2021.3.24,8:39:22]string alloc=1002332 cache=22 short=1002310 short-reuse=668194 long=0 short-size=1957KB short-reuse-size=0KB long-size=0KB\r\n[2021.3.24,8:40:22]string alloc=999446 cache=22 short=999424 short-reuse=666268 long=0 short-size=1982KB short-reuse-size=0KB long-size=0KB\r\n[2021.3.24,8:41:22]string alloc=993905 cache=22 short=993883 short-reuse=662576 long=0 short-size=2264KB short-reuse-size=0KB long-size=0KB\r\n[2021.3.24,8:42:22]string alloc=982166 cache=22 short=982144 short-reuse=654748 long=0 short-size=2237KB short-reuse-size=0KB long-size=0KB\r\n```\r\nalloc是分配字符串次数，cache是命中缓存次数，short是分配短字符串次数，short-reuse是命中短字符次数，long是分配长字符串次数，short-size、short-reuse-size、long-size分别是对应的字符串长度。\r\n注意这里short-reuse很大但是short-reuse-size为0，说明有很多分配空字符串的行为\r\n\r\n## 其他\r\n[lua全家桶](https://github.com/esrrhs/lua-family-bucket)\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fesrrhs%2Fwlua","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fesrrhs%2Fwlua","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fesrrhs%2Fwlua/lists"}