forked from enlightenment/efl
elua: benchmark module, plus return values for init/shutdown
This commit is contained in:
parent
4b5b051dfa
commit
bce656b93f
|
@ -0,0 +1,100 @@
|
|||
-- Elua benchmark module
|
||||
-- Dependencies: eina.counter, eina.log, util, cutil
|
||||
|
||||
local cutil = require("cutil")
|
||||
local util = require("util")
|
||||
local counter = require("eina.counter")
|
||||
local log = require("eina.log")
|
||||
|
||||
local Counter = counter.Counter
|
||||
|
||||
local M = {}
|
||||
|
||||
local dom
|
||||
|
||||
cutil.init_module(function()
|
||||
dom = log.Domain("elua_benchmark")
|
||||
if not dom:is_valid() then
|
||||
log.err("Could not register log domain: elua_benchmark")
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end, function()
|
||||
dom:unregister()
|
||||
dom = nil
|
||||
return true
|
||||
end)
|
||||
|
||||
local PLOT_MASK = "bench_%s_%s.gnuplot"
|
||||
local DATA_MASK = "bench_%s_%s.%s.data"
|
||||
|
||||
M.Benchmark = util.Object:clone {
|
||||
__ctor = function(self, name, run)
|
||||
self.name, self.run = name, run
|
||||
self.runs = {}
|
||||
end,
|
||||
|
||||
register = function(self, name, bench_cb, c_start, c_end, c_step)
|
||||
self.runs[#self.runs + 1] = {
|
||||
cb = bench_cb, name = name, c_start = c_start, c_end = c_end,
|
||||
c_step = c_step
|
||||
}
|
||||
return true
|
||||
end,
|
||||
|
||||
run = function(self, pmask, dmask)
|
||||
pmask, dmask = pmask or PLOT_MASK, dmask or DATA_MASK
|
||||
local fname = pmask:format(self.name, self.run)
|
||||
local plots = io.open(fname, "w")
|
||||
if not plots then
|
||||
return nil
|
||||
end
|
||||
local fnames = {}
|
||||
fnames[#fnames + 1] = fname
|
||||
plots:write(([[
|
||||
set autoscale # scale axes automatically
|
||||
unset log # remove any log-scaling
|
||||
unset label # remove any previous labels
|
||||
set xtic auto # set xtics automatically
|
||||
set ytic auto # set ytics automatically
|
||||
set terminal png size 1024,768
|
||||
set output "output_%s_%s.png"
|
||||
set title "%s %s"
|
||||
set xlabel "tests"
|
||||
set ylabel "time"
|
||||
plot ]]):format(self.name, self.run, self.name, self.run))
|
||||
local first = false
|
||||
for i, run in ipairs(self.runs) do
|
||||
local fname = dmask:format(self.name, self.run, run.name)
|
||||
local datas = io.open(fname, "w")
|
||||
if datas then
|
||||
fnames[#fnames + 1] = fname
|
||||
local cnt = Counter(run.name)
|
||||
for i = run.c_start, run.c_end, run.c_step do
|
||||
io.stderr:write("Run ", run.name, ": ", i, "\n")
|
||||
cnt:start()
|
||||
run.cb(i)
|
||||
cnt:stop(i)
|
||||
end
|
||||
local ret = cnt:dump()
|
||||
if ret then
|
||||
datas:write(ret)
|
||||
end
|
||||
cnt:free()
|
||||
datas:close()
|
||||
if not first then
|
||||
first = true
|
||||
else
|
||||
plots:write(", \\\n")
|
||||
end
|
||||
plots:write(("\"%s\" using 1:2 title \'%s\' with line")
|
||||
:format(fname, run.name))
|
||||
end
|
||||
end
|
||||
plots:write("\n")
|
||||
plots:close()
|
||||
return fnames
|
||||
end
|
||||
}
|
||||
|
||||
return M
|
|
@ -49,8 +49,10 @@ local smart_cb_wrapper = ffi.cast("Evas_Smart_Cb",
|
|||
cutil.init_module(function()
|
||||
elm, evas = ffi.load("elementary"), ffi.load("evas")
|
||||
elm.elm_init(0, nil)
|
||||
return true
|
||||
end, function()
|
||||
elm.elm_exit()
|
||||
return true
|
||||
end)
|
||||
|
||||
local Evas_Object = util.Object:clone {
|
||||
|
|
|
@ -24,10 +24,12 @@ local eina
|
|||
|
||||
local init = function()
|
||||
eina = util.lib_load("eina")
|
||||
return true
|
||||
end
|
||||
|
||||
local shutdown = function()
|
||||
util.lib_unload("eina")
|
||||
return true
|
||||
end
|
||||
|
||||
cutil.init_module(init, shutdown)
|
||||
|
|
|
@ -136,10 +136,12 @@ local eina
|
|||
|
||||
local init = function()
|
||||
eina = util.lib_load("eina")
|
||||
return true
|
||||
end
|
||||
|
||||
local shutdown = function()
|
||||
util.lib_unload("eina")
|
||||
return true
|
||||
end
|
||||
|
||||
cutil.init_module(init, shutdown)
|
||||
|
|
|
@ -16,10 +16,12 @@ local eina
|
|||
|
||||
local init = function()
|
||||
eina = util.lib_load("eina")
|
||||
return true
|
||||
end
|
||||
|
||||
local shutdown = function()
|
||||
util.lib_unload("eina")
|
||||
return true
|
||||
end
|
||||
|
||||
cutil.init_module(init, shutdown)
|
||||
|
|
|
@ -24,10 +24,12 @@ local eina
|
|||
|
||||
local init = function()
|
||||
eina = util.lib_load("eina")
|
||||
return true
|
||||
end
|
||||
|
||||
local shutdown = function()
|
||||
util.lib_unload("eina")
|
||||
return true
|
||||
end
|
||||
|
||||
ffi.metatype("Eina_Iterator", {
|
||||
|
|
|
@ -50,11 +50,13 @@ local init = function()
|
|||
eina = util.lib_load("eina")
|
||||
global_domain = ffi.new("Domain_Private", eina.EINA_LOG_DOMAIN_GLOBAL)
|
||||
default_domain = global_domain
|
||||
return true
|
||||
end
|
||||
|
||||
local shutdown = function()
|
||||
util.lib_unload("eina")
|
||||
default_domain, global_domain = nil, nil
|
||||
return true
|
||||
end
|
||||
|
||||
cutil.init_module(init, shutdown)
|
||||
|
@ -70,6 +72,7 @@ M.level = {
|
|||
}
|
||||
|
||||
M.color = {
|
||||
DEFAULT = "\x1B[36m",
|
||||
LIGHTRED = "\x1B[31;1m",
|
||||
RED = "\x1B[31m",
|
||||
LIGHTBLUE = "\x1B[34;1m",
|
||||
|
@ -122,7 +125,7 @@ local logfuncs = {
|
|||
}
|
||||
|
||||
for i, v in ipairs(logfuncs) do
|
||||
M["log_" .. v[1]] = function(msg)
|
||||
M[v[1]] = function(msg)
|
||||
if not default_domain then return end
|
||||
local info = getinfo(2, "nlSf")
|
||||
local dom = ffi.cast("Domain_Private*", default_domain).domain
|
||||
|
@ -152,6 +155,10 @@ M.Domain_Base = util.Object:clone {
|
|||
|
||||
log = function(self, level, msg, loff)
|
||||
log(self, level, msg, (loff or 0) + 1)
|
||||
end,
|
||||
|
||||
is_valid = function(self)
|
||||
return self:__get_domain() ~= nil
|
||||
end
|
||||
}
|
||||
|
||||
|
@ -173,8 +180,10 @@ M.default_domain = M.Domain_Default
|
|||
|
||||
M.Domain = M.Domain_Base:clone {
|
||||
__ctor = function(self, name, color)
|
||||
local dom = eina.eina_log_domain_register(name, color or "\x1B[36m")
|
||||
if dom < 0 then return end
|
||||
self.__domain = ffi.gc(ffi.cast("Domain*", ffi.new("Domain_Private",
|
||||
eina.eina_log_domain_register(name, color))), unregister_dom)
|
||||
dom)), unregister_dom)
|
||||
end,
|
||||
|
||||
unregister = function(self)
|
||||
|
@ -189,7 +198,9 @@ M.Domain = M.Domain_Base:clone {
|
|||
}
|
||||
|
||||
M.set_default_domain = function(dom)
|
||||
default_domain = dom:__get_domain()
|
||||
dom = dom:__get_domain()
|
||||
if not dom then return end
|
||||
default_domain = dom
|
||||
end
|
||||
|
||||
return M
|
|
@ -36,10 +36,12 @@ local eina
|
|||
|
||||
local init = function()
|
||||
eina = util.lib_load("eina")
|
||||
return true
|
||||
end
|
||||
|
||||
local shutdown = function()
|
||||
util.lib_unload("eina")
|
||||
return true
|
||||
end
|
||||
|
||||
cutil.init_module(init, shutdown)
|
||||
|
|
|
@ -52,10 +52,12 @@ local eina
|
|||
|
||||
local init = function()
|
||||
eina = util.lib_load("eina")
|
||||
return true
|
||||
end
|
||||
|
||||
local shutdown = function()
|
||||
util.lib_unload("eina")
|
||||
return true
|
||||
end
|
||||
|
||||
cutil.init_module(init, shutdown)
|
||||
|
|
|
@ -53,10 +53,12 @@ local eina
|
|||
|
||||
local init = function()
|
||||
eina = util.lib_load("eina")
|
||||
return true
|
||||
end
|
||||
|
||||
local shutdown = function()
|
||||
util.lib_unload("eina")
|
||||
return true
|
||||
end
|
||||
|
||||
cutil.init_module(init, shutdown)
|
||||
|
|
|
@ -11,7 +11,7 @@ log.log_err("test with default log domain")
|
|||
|
||||
local foo = function()
|
||||
for i = 1, 4 do
|
||||
log.log_err("testing: " .. i)
|
||||
log.err("testing: " .. i)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue