什么是luaprofiler?

http://luaprofiler.luaforge.net/manual.html

LuaProfiler is a time profiler designed to help finding bottlenecks on your Lua program.

If you use LuaProfiler into your program, it will generate a log of all your function calls and their respective running times. You can use this log to generate a summary of the functions your program uses, along with how long it stayed in each of them, or you can import the log into a spreadsheet for further analysis.

LuaProfiler is free software and uses the same license as Lua 5.1.

此工具是检测lua代码中, 对于lua执行速度有影响代码点, 即程序的效率瓶颈。

此工具会产生一个 函数调用的 log, 每个调用会产生响应的运行时间。

可以使用工具产生 总结性质的表, 此表能够统计各个函数调用的耗时, 并可以将此表导入 电子表格软件,然后进一步分析。

最重要的一点是, 此工具仅仅与lua5.1 兼容。

Status

Current version is 2.0.2. It was developed for Lua 5.1.

github网址:

https://github.com/luaforge/luaprofiler

软件下载:

release bin

http://files.luaforge.net/releases/luaprofiler/LuaProfilerbinaries/version1.1forlinux

code

http://files.luaforge.net/releases/luaprofiler/LuaProfiler/LuaProfiler2.0.2

luaprofiler构成

http://luaprofiler.luaforge.net/manual.html

For flexibility reasons, LuaProfiler is divided in 2 parts: the Lua code profiler, written in C to maximize the precision of timing, and the analyzer that generates information about the program execution, written in Lua to allow greater variance in the analysis process.

analyzer 中是 summary.lua

安装

The easies way to install LuaProfiler is through LuaRocks. Just do luarocks install luaprofiler and LuaRocks will download and install LuaProfiler on all major platforms.

If you want to install by hand, LuaProfiler source is distributed as a group of C files and some makefile templates. LuaProfiler follows the package model for Lua 5.1, therefore it should be "installed" in your package.path.

http://luaprofiler.luaforge.net/manual.html

luarocks install luaprofiler

luaprofiler使用

http://luaprofiler.luaforge.net/manual.html

Just require"profiler" in your script and this will define a profiler module with two functions:

start([filename])
Starts the profiler using the optional filename as the log file.
stop()
Stops the profiler.

You can restart the profiler after a stop with another call to start.

All you need now is to run your program and get the output generated by the profiler. The default log file is written to the working directory of the program, in a file like lprof_randomid.out where randomid is a random number. The log format uses a line for every function call in your program which may result in huge files, so be careful with disk space if your program runs for a long time, or use localized profiling wrapping the target section with a start()/stop() call sequence.

示例

在 replace.lua中添加 profiler检测代码:

local profiler = require("profiler")

profiler.start()

for _,file in ipairs(targetFiles) do
    print("handling file =".. file)
    handle_file(file)
end

profiler.stop()

------------------------------------------  handle file end ------------------------------------------

运行 replace.lua,发现确实产生一个 lprof_fileYLIo8z.out:

root@fqs:/home/share/luascript/replace# lua replace.lua
parse trans_table starting .....
line=    you  lucy
well formed line=    you  lucy
line=
parse trans_table ending .....
handling file =./replaceFiles/test.txt
you==>lucy
root@fqs:/home/share/luascript/replace# ls
config.lua  lprof_fileYLIo8z.out  replaceFiles  replace.lua

查看日志内容:

root@fqs:/home/share/luascript/replace# cat lprof_fileYLIo8z.out
stack_level    file_defined    function_name    line_defined    current_line    local_time    total_time
0    (C)    profiler_init    -1    -1    0.000010    0.000010
0    =[C]    ipairs    -1    232    0.000002    0.000002
0    =[C]    (for generator)    -1    232    0.000002    0.000001
1    =[C]    called from print    -1    -1    0.000003    0.000003
0    =[C]    print    -1    233    0.000024    0.000028
1    =[C]    open    -1    151    0.000010    0.000010
1    =[C]    assert    -1    151    0.000001    0.000001
1    =[C]    read    -1    152    0.000014    0.000014
1    =[C]    close    -1    153    0.000007    0.000008
1    =[C]    pairs    -1    155    0.000001    0.000002
1    =[C]    (for generator)    -1    155    0.000002    0.000002
2    =[C]    called from print    -1    -1    0.000003    0.000002
1    =[C]    print    -1    156    0.000012    0.000016
1    =[C]    gsub    -1    157    0.000003    0.000003
1    =[C]    (for generator)    -1    155    0.000001    0.000001
1    =[C]    open    -1    223    0.000033    0.000033
1    =[C]    assert    -1    223    0.000005    0.000004
1    =[C]    write    -1    224    0.000009    0.000008
1    =[C]    close    -1    225    0.000096    0.000096
0    @replace.lua    handle_file    147    234    0.000114    0.000300
0    =[C]    (for generator)    -1    232    0.000002    0.000002
0    =[C]    stop    -1    237    0.000001    0.000001
root@fqs:/home/share/luascript/replace#

使用summary统计下:

root@fqs:/home/share/luascript/replace# /usr/local/bin/summary.lua -v lprof_fileYLIo8z.out
Node name    Calls    Average per call    Total time    %Time
handle_file    1    0.000114    0.000114    32.112676056338
close    2    5.15e-05    0.000103    29.014084507042
open    2    2.15e-05    4.3e-05    12.112676056338
print    2    1.8e-05    3.6e-05    10.140845070423
read    1    1.4e-05    0.000014    3.943661971831
profiler_init    1    1e-05    0.000010    2.8169014084507
write    1    9e-06    0.000009    2.5352112676056
(for generator)    4    1.75e-06    7e-06    1.9718309859155
called from print    2    3e-06    6e-06    1.6901408450704
assert    2    3e-06    6e-06    1.6901408450704
gsub    1    3e-06    0.000003    0.84507042253521
ipairs    1    2e-06    0.000002    0.56338028169014
pairs    1    1e-06    0.000001    0.28169014084507
stop    1    1e-06    0.000001    0.28169014084507
root@fqs:/home/share/luascript/replace#

转载于:https://www.cnblogs.com/lightsong/p/5576100.html

luaprofiler探索相关推荐

  1. 探索 TVM 进行量化方法

    探索 TVM 进行量化方法 Relay框架 如上图所示,有两种不同的并行工作正在进行中 • 自动整数量化 - 采用 FP32 框架图,在 Relay 中自动转换为 Int8. • 接受预量化整数模型 ...

  2. 自主数据类型:在TVM中启用自定义数据类型探索

    自主数据类型:在TVM中启用自定义数据类型探索 介绍 在设计加速器时,一个重要的决定是如何在硬件中近似地表示实数.这个问题有一个长期的行业标准解决方案:IEEE 754浮点标准.1.然而,当试图通过构 ...

  3. 2021年大数据ELK(二十六):探索数据(Discovery)

    全网最详细的大数据ELK文章系列,强烈建议收藏加关注! 新文章都已经列出历史文章目录,帮助大家回顾前面的知识重点. 目录 探索数据(Discovery) 一.使用探索数据功能 二.导入更多的Apach ...

  4. Python数据挖掘:数据探索,数据清洗,异常值处理

    来源:天善智能韦玮老师 课堂笔记 作者:Dust 探索性数据分析Exploratory Data Analysis,EDA 数据探索的核心是︰ 1.数据质量分析(跟数据清洗密切联系) 2.数据特征分析 ...

  5. oracle无创建directory权限,【DIRECTORY】普通用户创建Oracle DIRECTORY数据库对象的权限需求及探索...

    可能遇到的报错信息如若在创建DIRECTORY之前普通用户sec未获得相应权限,将会收到最为常见的"ORA-01031: insufficient privileges"错误.模拟 ...

  6. sources root pycharm 怎么设置_使用python语言开发ROOT之搭建环境方法探索

    这里指的是使用python调用ROOT的模块,编写程序用来处理数据的环境搭建方法. 经过研究,一般有四种方案 环境变量法,主要依靠ROOT本身,环境变量是关键 预编译包,但是该方法没有证实成功搭建py ...

  7. 论计算机的创新性,论计算机专业教学创新探索

    1/4论计算机专业教学创新探索改革高校计算机专业实训课程教学方法的重要意义高校计算机专业实训课程是计算机专业的实践课程,在计算机专业课程体系中处于非常重要的位置,主要用于培养计算机专业学生实践应用能力 ...

  8. mysql 集群实践_MySQL Cluster集群探索与实践

    MySQL集群是一种在无共享架构(SNA,Share Nothing Architecture)系统里应用内存数据库集群的技术.这种无共享的架构可以使得系统使用低廉的硬件获取高的可扩展性. MySQL ...

  9. php内核探索方法与资源

    PHP内核探索 TIPI深入理解PHP内核 风雪之隅PHP源码分析 <php扩展开发及内核应用> 百度XLQ God's blog codinglabs PHP内核探索:从SAPI接口开始 ...

  10. 跨平台PHP调试器设计及使用方法——探索和设计

    在<跨平台PHP调试器设计及使用方法--立项>一文中,我确定了使用xdebug作为调试器插件部分的基础组件.xdebug提供了一个远程调试的功能(相关资料可以详见https://xdebu ...

最新文章

  1. Jetson TX2 开发记录
  2. Linux 技巧:让进程在后台可靠执行的几种方法
  3. Camel 2.11 –没有Spring的Camel Web应用程序
  4. php cookie防伪造,技术分享:Cookie 防伪造 防修改
  5. php验证码显示碎图片,我的验证码只显示破碎的小图片
  6. CF1093D Beautiful Graph
  7. cad画多段线时不显示轨迹_CAD画的线段显示不出来的解决方法
  8. IT之家精华:苹果iOS系统发布/固件下载/升级更新大全表~
  9. PT站的做种和魔力值是如何增加换算的?
  10. 查看漏洞库平台有哪些?
  11. 刚刚 Kubernetes 1.25 正式发布,所有变化都在这儿了
  12. 苹果软件扣费申请退款
  13. 帧中继网络与NBMA/P2MA
  14. nginx后端节点的健康检查
  15. 海思视频和QT的Colorkey显示模式
  16. def demo什么意思python_Python之Turtle库Demo案例
  17. 华为 java 校招经验_华为校招消费者管培生三面面试经历
  18. 2021.1.28课程摘要(逻辑教育-王劲胜)
  19. AOP机制之环绕通知的见解
  20. DAC中经常遇到的一些术语及含义

热门文章

  1. 在苹果Mac中巧用聚焦搜索Spotlight
  2. 如何使用 Mac 在 iPhone 上录制 FaceTime 通话?
  3. 苹果Mac定制化App开发神器:​​​​FileMaker
  4. 如何为Mac视频添加模糊效果?
  5. 6间企业获颁“首届粤港澳大湾区百强企业传承大奖”
  6. Logstash配置方法
  7. (转 留存)Windows环境下的NodeJS+NPM+GIT+Bower安装配置步骤
  8. POJ 3264 -----RMQ问题
  9. Oracle系列:(22)视图
  10. Ext JS 6应用程序Build后出现“c is not a constructor return new c(a[0])”的处理