# UnityLuaPerfTest **Repository Path**: liyonghelpme/UnityLuaPerfTest ## Basic Information - **Project Name**: UnityLuaPerfTest - **Description**: Unity 中lua的性能测试,cpu性能和内存占用分析,IOS - **Primary Language**: C++ - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 1 - **Created**: 2016-10-19 - **Last Updated**: 2021-03-03 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README #编译Ulua 除了 lua虚拟机之外的代码,用于和luajit 2.1.0 beta2 版本协同工作 执行build.py, 将会生成 armv7 arm64 src目录下的 几个ulua代码和 pb cjson 库 #UnityLuaPerfTest 源码: http://git.oschina.net/liyonghelpme/UnityLuaPerfTest 博客: https://my.oschina.net/u/186074/blog/760949 lua有一个接口 lua_setallocf 可以hook 掉lua的内存分配,可以用来监控lua的内存分配malloc,内存释放free,以及内存大小调整 realloc. 通过这个函数可以统计当前lua已经分配了占用了多少内存 类似于之前的cpu性能测试,我们可以每一帧打印出这个内存占用,就可以观察程序的内存状态了 lua5.1 只支持整个内存统计,但是对于table,number string,闭包等各自占用多少内存并不知道 lua5.2以上版本,可以支持统计每种不同类型数据各自的内存 这里主要对IOS系统做了测试: 接入了Lumberjack 日志库,在IOS的cache目录下,Logs目录中产生内存占用日志 要将改代码嵌入到Unity项目中的Plugins/iOS目录中 1.主要拷贝Classes 目录中的日志库, 2.LuaP.mm LuaP.hpp 性能统计代码 3.src 目录下的lua头文件 在Unity中,需要修改 1.c#中需要在Lua状态机启动的时候,加载我们实现的luaprofiler 库 2.lua代码中,调用我们的luaprofiler库函数,setLogPath, start 启动性能统计工具 3.lua代码中,unity的update调用的lua函数中,调用writelog ,记录性能统计日志 游戏测试完成之后,将日志导出,使用python等进行分析