Giter VIP home page Giter VIP logo

luaprofiler-1's Introduction

###LuaProfiler使用说明

LuaProfiler原自KeplerProject,原项目自2007.08之后停止更新了,所以我们把LuaProfiler源代码拿过来进行了一番修改,这里感谢作者。

目前LuaProfiler已经可以支持Lua 5.3版本,经过测试已支持Android和iOS。对于Lua脚本的分析结果会生成一个JSON文件,然后通过解析JSON文件得到分析数据。

####使用方法

  1. 将LuaProfiler源代码集成到你的项目中的Lua源代码中,最终编译成dll/lib/so。
  2. 在调用luaL_newstate()之后,调用LuaProfiler暴露出来的接口:profiler_open(L)
  3. Lua脚本中,在要开始分析的地方调用profiler_start(jsonFile),结束分析的地方调用profiler_stop()

####函数说明

int profiler_open(lua_State *L)
Type: C
Note: LuaProfiler初始化
Param1: L 指针类型,lua_State指针
Return: 1,成功

function profiler_start(jsonFilePath)
Type: Lua
Note: 开始分析
Param1: jsonFilePath 字符串,生成json文件的绝对路径
Return: bool, 是否成功

function profiler_stop()
Type: Lua
Note: 结束分析,生成结果JSON文件
Param1: 无
Return: bool, 是否成功

####分析结果
分析出来的结果是一个JSON数组,具体结果如下:

[
  {
    sub:
    [
      {}, 
      {}, 
      {
        sub:[{}, {}]
      }
    ]
  },
]

真实的数据如下:

[
  {
    "ln": 9,
    "cs": 0.675849,
    "lv": 1,
    "info": "Lua",
    "mod": "Prefab.lua",
    "fn": "CloneGo",
    "sub": [
       {
        "ln": 9,
        "cs": 0.666518,
        "lv": 2,
        "info": "C",
        "mod": "=[C]",
        "fn": "cs_func",
        "sub": []
       }
    ]
  }
]

ln: 函数所在文件的行号,如果为-1则表示无法跟踪。
cs: 函数耗时,单位毫秒(ms)。
lv: 在Lua栈的位置。
info: 调用类型,Lua或C。
mod: 模块,如果info是Lua的话,mod则是具体的Lua脚本文件。
sub: 子调用。

说明:

  1. 每个JSON文件最后会有:

    { "total_cs": 0.274, "total_call": 6 }

其中total_cs表示总耗时,total_call总调用次数。
2. 最终生成的JSON文件阅读性并不好,所以建议大家写一个工具解析成可读性比较好的格式。由于我是在Web上显示,所以我用了TableTree4J这个JS库去解析JSON文件。

luaprofiler-1's People

Contributors

shaoyuan1943 avatar

Watchers

jaafarshi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.