geoffleyland / luatrace Goto Github PK
View Code? Open in Web Editor NEWA tool for tracing Lua script execution and analysing time profiles and coverage
License: MIT License
A tool for tracing Lua script execution and analysing time profiles and coverage
License: MIT License
On Mac OS X with lua (and luajit) installed via Homebrew, I have luajit embedded in my 3d graphics engine. I'm then writing the vast majority of the game in lua, which is why I'm interested in the profiler.
Near the top of my main lua file I use:
Luatrace = require("luatrace")
Then when I want to profile a section, I use:
Luatrace.tron({trace_file_name="cms_trace.txt"})
Then I finish it with:
Luatrace.troff()
That does create a cms_trace.txt file that's 56k in size. So I try to run luatrace.profile and it crashes with an access to a nil local value:
tbogdala$ luatrace.profile cms_trace.txt
lua: /usr/local/share/lua/5.1/luatrace/profile.lua:125: attempt to index local 'thread' (a nil value)
stack traceback:
/usr/local/share/lua/5.1/luatrace/profile.lua:125: in function 'call_on_thread'
/usr/local/share/lua/5.1/luatrace/profile.lua:213: in function 'record'
/usr/local/share/lua/5.1/luatrace/trace_file.lua:133: in function 'read'
/usr/local/share/lua/5.1/luatrace/profile.lua:463: in function 'go'
(command line):1: in main chunk
Can this be used to write a profiling report for embedded luajit2?
If so, can you add an example to the README.md? I see the example calling tron() and troff() but where are the results?
Hello, I get a slew of errors when I try to profile LuLPeg:
https://gist.github.com/pygy/b23ac1c81c6d3fffa387
Luatrace gets lost after 62 milliseconds, and the parsing itself takes 5+ secondson my machine.
Any suggestion?
To reproduce:
lua -e'require"strict" lt=require"luatrace" lt.tron()'
Output
lua: /usr/share/lua/5.1/luatrace.lua:305: assign to undeclared variable 'luatrace_exit_trick_file'
stack traceback:
[C]: in function 'error'
/usr/share/lua/5.1/strict.lua:23: in function '__newindex'
/usr/share/lua/5.1/luatrace.lua:305: in function 'luatrace_exit_trick'
/usr/share/lua/5.1/luatrace.lua:343: in function 'tron'
(command line):1: in main chunk
[C]: at 0x004f8b54
To fix just add a
local luatrace_exit_trick_file
before
local function luatrace_exit_trick()
Ubuntu (and other Debian distros) puts Lua stuff to "alternative" locations:
LUA_SHAREDIR=/usr/share/lua/5.1
LUA_LIBDIR=/usr/lib/lua/5.1
LUA_INCDIR=/usr/include/lua5.1/
I got my trace-out.txt with this:
25 154.304
3 0.25
6 0.221
9 0.183
12 0.175
15 0.172
25 0.213
26 0.165
26 279.552
25 640.975
2 0.246
4 0.045
What should I do next?
How can I tell which part of my code is slow?
Thanks!
would you provide build/install instructions for msvc? Thanks!
The following code makes the luatrace.profile
script to fail sometimes.
require "luarocks.require"
require "json"
local luatrace = require "luatrace"
luatrace.tron()
local t = json.decode[[
{
"friends": [],
"blah": {},
}
]]
luatrace.troff()
It gives the following error:
ERROR ( 1, line 147): counted execution of 0.5 microseconds at line 1 of a function defined at C:\LuaRocks/rocks//json4lua/git-1/lua/json.lua:633-650
lua: ...Rocks/rocks//luatrace/scm-2/lua/luatrace\profile.lua:266: attempt to index local 'top' (a nil value)
stack traceback:
...Rocks/rocks//luatrace/scm-2/lua/luatrace\profile.lua:266: in function 'record'
...ks/rocks//luatrace/scm-2/lua/luatrace\trace_file.lua:142: in function 'read'
...Rocks/rocks//luatrace/scm-2/lua/luatrace\profile.lua:459: in function 'go'
(command line):1: in main chunk
[C]: ?
The strange thing is that sometimes it works fine.
C:\>lua -lluarocks.require -e "require('luatrace.profile').go()"
Total time 103.50 microseconds
Times in microseconds
Top 20 lines by total time
File:line Hits Total Self Child | Line
test_json.lua:7 1 102.50 1.00 101.50 | local t = json.decode[[
C:\LuaRocks/rocks//json4lua/git-1/lua/json.lua:650 1 93.50 1.00 92.50 | end
C:\LuaRocks/rocks//json4lua/git-1/lua/json.lua:628 3 92.50 2.50 90.00 | local t = next_token(tt_object_value)
C:\LuaRocks/rocks//json4lua/git-1/lua/json.lua:575 2 90.00 1.50 88.50 | if t == tt_object_key then return read_object_key({}) end
C:\LuaRocks/rocks//json4lua/git-1/lua/json.lua:640 2 69.50 1.00 68.50 | if t == tt_object_key then return read_object_key(o) end
C:\LuaRocks/rocks//json4lua/git-1/lua/json.lua:635 5 32.50 2.50 30.00 | local t = next_token(tt_object_key)
C:\LuaRocks/rocks//json4lua/git-1/lua/json.lua:486 25 19.00 19.00 0.00 | local b = js_string:byte(pos)
C:\LuaRocks/rocks//json4lua/git-1/lua/json.lua:504 1 18.00 0.50 17.50 | local t = next_token(tok)
C:\LuaRocks/rocks//json4lua/git-1/lua/json.lua:524 2 16.50 16.50 0.00 | return (loadstring("return " .. stringValue ) ())
C:\LuaRocks/rocks//json4lua/git-1/lua/json.lua:485 14 12.50 12.50 0.00 | while pos <= #js_string do
C:\LuaRocks/rocks//json4lua/git-1/lua/json.lua:487 19 9.50 9.50 0.00 | local t = tok[b]
C:\LuaRocks/rocks//json4lua/git-1/lua/json.lua:643 1 9.00 0.50 8.50 | if next_token(tt_object_colon) == tt_comment_start then
C:\LuaRocks/rocks//json4lua/git-1/lua/json.lua:501 2 8.50 1.50 7.00 | local start = pos
C:\LuaRocks/rocks//json4lua/git-1/lua/json.lua:641 2 8.00 1.00 7.00 | local k = read_string(t)
C:\LuaRocks/rocks//json4lua/git-1/lua/json.lua:493 12 6.00 6.00 0.00 | pos = pos + 1
C:\LuaRocks/rocks//json4lua/git-1/lua/json.lua:636 3 6.00 1.50 4.50 | if t == tt_comment_start then
C:\LuaRocks/rocks//json4lua/git-1/lua/json.lua:494 9 4.50 4.50 0.00 | if t~=tt_ignore then return t end
C:\LuaRocks/rocks//json4lua/git-1/lua/json.lua:488 6 3.00 3.00 0.00 | if not t then
C:\LuaRocks/rocks//json4lua/git-1/lua/json.lua:513 2 2.50 2.50 0.00 | stringValue = string.gsub(stringValue, "([\\]+)u(%x%x)(%x%x)", function(escape, hex_value_high, hex_value_low)
C:\LuaRocks/rocks//json4lua/git-1/lua/json.lua:512 2 2.00 2.00 0.00 | local stringValue = js_string:sub(start-1, pos-1)
Top 20 functions by self time
File:lines Hits Total Self Child | Line
C:\LuaRocks/rocks//json4lua/git-1/lua/json.lua:484-497 14 54.50 54.50 0.00 | local function next_token (tok)
C:\LuaRocks/rocks//json4lua/git-1/lua/json.lua:500-536 2 48.50 24.00 24.50 | local function read_string (tok)
C:\LuaRocks/rocks//json4lua/git-1/lua/json.lua:633-650 4 89.50 9.50 80.00 | function read_object_key (o)
C:\LuaRocks/rocks//json4lua/git-1/lua/json.lua:458-660 1 101.50 9.00 92.50 | function decode (js_string)
C:\LuaRocks/rocks//json4lua/git-1/lua/json.lua:627-630 3 92.50 2.50 90.00 | function read_object_value (o)
test_json.lua:0-0 1 2.00 2.00 0.00 | -
C:\LuaRocks/rocks//json4lua/git-1/lua/json.lua:574-584 3 90.00 1.50 88.50 | function read_value (t,fromt)
C:\LuaRocks/rocks//json4lua/git-1/lua/json.lua:603-624 1 4.00 0.50 3.50 | function read_array (o,i)
C:\LuaRocks/rocks//luatrace/scm-2/lua/luatrace.lua:350-358 1 0.00 0.00 0.00 | -
To reproduce, install json4lua with luarocks and run the provided script. The script, a trace that succeeds and a trace that fail are available here.
Here is the error:
luatrace-master$ make
dirname: missing operand
Try 'dirname --help' for more information.
dirname: missing operand
Try 'dirname --help' for more information.
find: ‘/include’: No such file or directory
dirname: missing operand
Try 'dirname --help' for more information.
/usr/bin/cc -O3 -Wall -Wextra -pedantic -fPIC -shared c/c_hook.c -o lua/luatrace/c_hook.so -lrt -I
cc: error: missing path after ‘-I’
makefile:45: recipe for target 'lua/luatrace/c_hook.so' failed
make: *** [lua/luatrace/c_hook.so] Error 1
As subject says.
Trying to compile db7fb4e
$ make
/usr/bin/cc -O3 -Wall -Wextra -std=c89 -pedantic -fPIC -shared c/c_hook.c -o lua/luatrace/c_hook.so -lrt -I/usr/include
c/c_hook.c: In function ‘lclock’:
c/c_hook.c:51:19: error: storage size of ‘tp’ isn’t known
c/c_hook.c:52:3: warning: implicit declaration of function ‘clock_gettime’ [-Wimplicit-function-declaration]
c/c_hook.c:52:17: error: ‘CLOCK_MONOTONIC’ undeclared (first use in this function)
c/c_hook.c:52:17: note: each undeclared identifier is reported only once for each function it appears in
c/c_hook.c:51:19: warning: unused variable ‘tp’ [-Wunused-variable]
c/c_hook.c:54:1: warning: control reaches end of non-void function [-Wreturn-type]
make: *** [lua/luatrace/c_hook.so] Error 1
$ uname -a
Linux vm-arch 3.2.9-1-ARCH #1 SMP PREEMPT Thu Mar 1 09:31:13 CET 2012 x86_64 Intel(R) Core(TM) i5 CPU U 470 @ 1.33GHz GenuineIntel GNU/Linux
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.3/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /build/src/gcc-4.6.3/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --enable-libstdcxx-time --enable-gnu-unique-object --enable-linker-build-id --with-ppl --enable-cloog-backend=isl --enable-lto --enable-gold --enable-ld=default --enable-plugin --with-plugin-ld=ld.gold --enable-multilib --disable-libssp --enable-checking=release --with-fpmath=sse
Thread model: posix
gcc version 4.6.3 (GCC)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.