mirror of
https://github.com/octoleo/lsyncd.git
synced 2024-12-14 06:58:29 +00:00
Add debug functions and timestamp2string helpers
This commit is contained in:
parent
4a03dab872
commit
1f79032c28
5
lsyncd.c
5
lsyncd.c
@ -2142,11 +2142,12 @@ l_jiffies_index(lua_State *L)
|
||||
clock_t a1 = ( *( clock_t * ) luaL_checkudata( L, 1, "Lsyncd.jiffies" ) );
|
||||
const char *a2 = luaL_checkstring(L, 2);
|
||||
|
||||
printf("in index %s %d\n", a2, a1);
|
||||
|
||||
if (!strcmp(a2, "seconds")) {
|
||||
lua_pushinteger( L, a1 / clocks_per_sec);
|
||||
return 1;
|
||||
} else if (!strcmp(a2, "string")) {
|
||||
lua_pushfstring (L, "%d", a1 / clocks_per_sec);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
33
lsyncd.lua
33
lsyncd.lua
@ -151,6 +151,13 @@ inheritKV =
|
||||
end
|
||||
end
|
||||
|
||||
function alarm2string(a)
|
||||
if type(a) == 'userdata' then
|
||||
return a.string
|
||||
end
|
||||
return tostring( a )
|
||||
end
|
||||
|
||||
--
|
||||
-- Coping globals to ensure userscripts cannot change this.
|
||||
--
|
||||
@ -849,6 +856,20 @@ local Delay = ( function
|
||||
self[ k_nt ].alarm = alarm
|
||||
end
|
||||
|
||||
--
|
||||
-- Returns a debug string of the delay
|
||||
--
|
||||
local function debug(self, deep)
|
||||
local rv = "<Delay "..self.status.." dpos:"..self.dpos.." type:"..self.etype.." alarm:"..alarm2string(self.alarm).." blocked:"..(self.blocks and #self.blocks or 0).." path:"..self.path
|
||||
if deep and self.blocks then
|
||||
for k,v in ipairs(self.blocks) do
|
||||
rv = rv.."\n blocked: "..v:debug(false)
|
||||
end
|
||||
end
|
||||
rv = rv..">"
|
||||
return rv
|
||||
end
|
||||
|
||||
--
|
||||
-- Creates a new delay.
|
||||
--
|
||||
@ -868,6 +889,7 @@ local Delay = ( function
|
||||
blockedBy = blockedBy,
|
||||
setActive = setActive,
|
||||
wait = wait,
|
||||
debug = debug,
|
||||
[ k_nt ] =
|
||||
{
|
||||
etype = etype,
|
||||
@ -3174,6 +3196,16 @@ local Sync = ( function
|
||||
f:write( '\n' )
|
||||
end
|
||||
|
||||
--
|
||||
-- Returns a debug string describing the Sync
|
||||
--
|
||||
local function debug
|
||||
(
|
||||
self
|
||||
)
|
||||
local rv = "<Sync "..self.config.name.." delays:"..self.delays:size( ).."> "
|
||||
return rv
|
||||
end
|
||||
--
|
||||
-- Returns substitude data for event
|
||||
--
|
||||
@ -3214,6 +3246,7 @@ local Sync = ( function
|
||||
collect = collect,
|
||||
concerns = concerns,
|
||||
delay = delay,
|
||||
debug = debug,
|
||||
getAlarm = getAlarm,
|
||||
getDelays = getDelays,
|
||||
getNextDelay = getNextDelay,
|
||||
|
Loading…
Reference in New Issue
Block a user