Added LuaJIT profiling support (lulip), better cmdline option handling.

This commit is contained in:
Paulo Matias
2013-08-06 11:53:44 -03:00
parent 68af46f495
commit cc9f9cce4d
4 changed files with 228 additions and 9 deletions

View File

@@ -12,6 +12,7 @@ require "settings"
require "dbg"
require "gettext"
Profiler = nil
HomeMenu = InputContainer:new{
item_table = {},
@@ -33,6 +34,11 @@ HomeMenu = InputContainer:new{
}
function exitReader()
if Profiler ~= nil then
Profiler:stop()
Profiler:dump("./profile.html")
end
G_reader_settings:close()
input.closeAll()
@@ -189,6 +195,7 @@ end
-- option parsing:
longopts = {
debug = "d",
profile = "p",
help = "h",
}
@@ -197,6 +204,7 @@ function showusage()
print(_("Read all the books on your E-Ink reader"))
print("")
print(_("-d start in debug mode"))
print(_("-p [rows] enable Lua code profiling"))
print(_("-h show this usage help"))
print("")
print(_("If you give the name of a directory instead of a file path, a file"))
@@ -209,16 +217,37 @@ function showusage()
return
end
if ARGV[1] == "-h" then
return showusage()
end
DEBUG = function() end
local argidx = 1
if ARGV[1] == "-d" then
Dbg:turnOn()
while argidx <= #ARGV do
local arg = ARGV[argidx]
argidx = argidx + 1
else
DEBUG = function() end
if arg == "--" then break end
-- parse longopts
if arg:sub(1,2) == "--" then
local opt = longopts[arg:sub(3)]
if opt ~= nil then arg = "-"..opt end
end
-- code for each option
if arg == "-h" then
return showusage()
elseif arg == "-d" then
Dbg:turnOn()
elseif arg == "-p" then
require "lulip"
Profiler = lulip:new()
pcall(function()
-- set maxrows only if the optional arg is numeric
Profiler:maxrows(ARGV[argidx] + 0)
argidx = argidx + 1
end)
Profiler:start()
else
-- not a recognized option, should be a filename
argidx = argidx - 1
break
end
end
if Device:hasNoKeyboard() then