什么是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#

luaprofiler探索的更多相关文章

  1. 【探索】机器指令翻译成 JavaScript

    前言 前些时候研究脚本混淆时,打算先学一些「程序流程」相关的概念.为了不因太枯燥而放弃,决定想一个有趣的案例,可以边探索边学. 于是想了一个话题:尝试将机器指令 1:1 翻译 成 JavaScript ...

  2. 【探索】利用 canvas 实现数据压缩

    前言 HTTP 支持 GZip 压缩,可节省不少传输资源.但遗憾的是,只有下载才有,上传并不支持.如果上传也能压缩,那就完美了.特别适合大量文本提交的场合,比如博客园,就是很好的例子. 虽然标准不支持 ...

  3. 探索C#之6.0语法糖剖析

    阅读目录: 自动属性默认初始化 自动只读属性默认初始化 表达式为主体的函数 表达式为主体的属性(赋值) 静态类导入 Null条件运算符 字符串格式化 索引初始化 异常过滤器when catch和fin ...

  4. Mysql事务探索及其在Django中的实践(二)

    继上一篇<Mysql事务探索及其在Django中的实践(一)>交代完问题的背景和Mysql事务基础后,这一篇主要想介绍一下事务在Django中的使用以及实际应用给我们带来的效率提升. 首先 ...

  5. Linux学习之探索文件系统

    Linux,一起学习进步-    ls With it, we can see directory contents and determine a variety of important file ...

  6. 马里奥AI实现方式探索 ——神经网络+增强学习

    [TOC] 马里奥AI实现方式探索 --神经网络+增强学习 儿时我们都曾有过一个经典游戏的体验,就是马里奥(顶蘑菇^v^),这次里约奥运会闭幕式,日本作为2020年东京奥运会的东道主,安倍最后也已经典 ...

  7. C++随笔:.NET CoreCLR之GC探索(4)

    今天继续来 带大家讲解CoreCLR之GC,首先我们继续看这个GCSample,这篇文章是上一篇文章的继续,如果有不清楚的,还请翻到我写的上一篇随笔.下面我们继续: // Initialize fre ...

  8. C++随笔:.NET CoreCLR之GC探索(2)

    首先谢谢 @dudu 和 @张善友 这2位大神能订阅我,本来在写这个系列以前,我一直对写一些核心而且底层的知识持怀疑态度,我为什么持怀疑态度呢?因为一般写高层语言的人99%都不会碰底层,其实说句实话, ...

  9. 【腾讯优测干货分享】安卓专项测试之GPU测试探索

    本文来自于Dev Club 开发者社区,非经作者同意,请勿转载,原文地址:http://dev.qq.com/topic/57c7ffdc0569a1191bce8a63 作者:章未哲——腾讯SNG质 ...

随机推荐

  1. ubuntu 安装 Terminator

    sudo apt-get install terminator Ctrl-Shift-E: 垂直分割Ctrl-Shift-O: 水平分割Ctrl-Shift-P: 激活先前的窗口Ctrl-Shift- ...

  2. Codeforces Round #243 (Div. 2) B. Sereja and Mirroring

    #include <iostream> #include <vector> #include <algorithm> using namespace std; in ...

  3. 转自虫师:性能测试的 Check List

    原文地址:http://www.cnblogs.com/jackei/archive/2006/03/24/357372.html 1. 开发人员是否提交了测试申请? 2. 测试对象是否已经明确? 3 ...

  4. [深入浅出Windows 10]模拟实现微信的彩蛋动画

    9.7 模拟实现微信的彩蛋动画 大家在玩微信的时候有没有发现节日的时候发一些节日问候语句如“情人节快乐”,这时候会出现很多爱心形状从屏幕上面飘落下来,我们这小节就是要模拟实现这样的一种动画效果.可能微 ...

  5. 获取UILabel宽度的方法

    - (CGFloat)labelLength:(NSString *)str font:(CGFloat)font{ str = ISSTRING(str) ? str : @"" ...

  6. Cloudera Manager 5和CDH5离线安装

    CDH (Cloudera’s Distribution, including Apache Hadoop),是Hadoop众多分支中的一种,由Cloudera维护,基于稳定版本的Apache Had ...

  7. 关于Autoit上传文件的问题

    Autoit上传文件需要安装两个软件: 使用这个做文件上传时:在代码中需要添加的代码如下: Runtime.getRuntime().exec("d:/zhpg.exe"); D盘 ...

  8. Java横向、纵向合并图片

    进行图片对比时候想把两张有差异的图片放到一起,方便人工查看下,在网上搜了一些,有纵向合并的. 将纵向合并的自己调整了下,源码如下: import java.io.File; import java.a ...

  9. Java 多继承

    浅浅地上了几天 Java 的课程,然后怎么也想不明白:Java 不支持多继承有和接口到底是什么样的关系? 一只牛的故事. // 叫的抽象基类 abstract class call{ } // 跑的抽 ...

  10. Oracle求部门员工工资占总工资的比率

    --根据每个部门来统计部门工资总和 select deptid, sum(sal) 工资合计 from emp group by deptid; --根据每个部门来统计部门工资总和select dep ...