luaprofiler探索

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

[email protected]:/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
[email protected]:/home/share/luascript/replace# ls
config.lua  lprof_fileYLIo8z.out  replaceFiles  replace.lua

查看日志内容:

[email protected]:/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
[email protected]:/home/share/luascript/replace#

使用summary统计下:

[email protected]:/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
[email protected]:/home/share/luascript/replace#

时间: 2024-08-07 13:44:01

luaprofiler探索的相关文章

GLSProv WebUI Framework 探索阶段成果所得(1)

作为我的处子随笔,我就凭着我所想到的记录一下这段时间探索我所做的这个Feature的历程以及所学,所感. 先说一下背景,Provisiong一直是我们COM组项目里比较重要的配置环节,诞生10来年,一直是Java Swing作为主要的GUI界面,配合后台的OMCP Server 与网元以及数据库打交道.自从COM web 化以来,Swing Gui 从纯Java 演变为了WEB Swing, 但是本质上并没有什么变化, 较差的客户体验一直让老美不爽,所以经"董事会"们开会研究,先拿规模

使用Visual Studio快速开发STM32F4-Discovery探索板入门

本本将主要介绍如何使用Visual Studio创建一个基于STM32F4-Discovery探索板的简单工程. 本文使用以下硬件和软件: ●      Microsoft Visual Studio ●      VisualGDB ●      STM32F4-Discovery探索板 我们将创建一个简单的“LED闪烁”的工程,然后进行构建,并使用调试器进行单步调试. 1.    启动Visual Studio.选择File-> New-> Project. 2.    选择VisualG

数据探索

一.查看数据 首先,我们查看iris数据集的大小和结构,其维度和名称分别使用函数dim()和names()获取. 函数str()和attributes()返回数据的结构和属性 二.单变量分析 > head(iris) Sepal.Length Sepal.Width Petal.Length Petal.Width Species1 5.1 3.5 1.4 0.2 setosa2 4.9 3.0 1.4 0.2 setosa3 4.7 3.2 1.3 0.2 setosa4 4.6 3.1 1.

地统计分析笔记——探索数据

来自:http://blog.csdn.net/kikitamoon/article/details/49925147 在执行地统计分析之前,浏览.熟悉.检查自己的数据是至关重要的.绘制和检查数据是地统计分析过程中的必要阶段,我们可以从这些工作中获得一些先验知识,指导后续的工作. Stage 1 绘制数据 通过ArcMap的图层渲染方案绘制数据,我们可以获得对数据的第一印象. 例如,使用单一符号渲染了解采样点的疏密分布,通过分类渲染了解采样点高值低值的分布,等等. Stage 2 检查数据 绘制

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

首先谢谢 @dudu 和 @张善友 这2位大神能订阅我,本来在写这个系列以前,我一直对写一些核心而且底层的知识持怀疑态度,我为什么持怀疑态度呢?因为一般写高层语言的人99%都不会碰底层,其实说句实话,我以前也不看这些东西,只是因为自己觉得对C++感兴趣,索性乱写点东西,如果有写得不好的地方,还请上面2位大神指出. 其实我现在虽然写的是C++,但是我打算在后面把C++和.NET的一些基础类库融合起来,我发现写CLR的文章特别少,不知道什么原因.反正,废话不多,开始今天的写作吧,今天依然是把重点集中

探索Oracle之数据库升级二 11.2.0.3升级到11.2.0.4完整步骤

探索Oracle之数据库升级二  11.2.0.3升级到11.2.0.4完整步骤 说明:         这篇文章主要是记录下单实例环境下Oracle 11.2.0.1升级到11.2.0.3的过程,当然RAC的升级是会有所不同.但是他们每个版本之间升级步骤都是差不多的,先升级Database Software,再升级Oracle Instance. Oracle 11.2.0.4的Patchset No:19852360下载需要有Oracle Support才可以.  Patchset包含有7个

[ 测试思维 ] 探索式软件测试

非常不错的关于探索式软件测试的学习资料 1.探索式测试简析 作者:微软 史亮 http://pan.baidu.com/s/1c2D4tAo 2.探索式测试白皮书 作者:淘宝 季哥 http://pan.baidu.com/s/1qYFNG3y

探索 ConcurrentHashMap 高并发性的实现机制

简介 ConcurrentHashMap 是 util.concurrent 包的重要成员.本文将结合 Java 内存模型,分析 JDK 源代码,探索 ConcurrentHashMap 高并发的具体实现机制. 由于 ConcurrentHashMap 的源代码实现依赖于 Java 内存模型,所以阅读本文需要读者了解 Java 内存模型.同时,ConcurrentHashMap 的源代码会涉及到散列算法和链表数据结构,所以,读者需要对散列算法和基于链表的数据结构有所了解. Java 内存模型 由

JVM中class文件探索与解析(一)

一直想成为一名优秀的架构师的我,转眼已经工作快两年了,对于java内核了解甚少,闲来时间,看看JVM,吧自己的一些研究写下来供大家参考,有不对的地方请指正. 废话不多说,一起来看看JVM中类文件是如何加载和运行的. (1)首先,编写简单代码,对其编译生成的class文件进行研究,其java代码如下: 1 public class test { 2 private static int count = 0; 3 public static void recursion(){ 4 count++;