event-dispatcher: log event and hook names and chains

- Add a new variable "name" in WpEventHook and use it to log all the
  hooks(by name) picked up in _push_event(). This gives a clear picture
  if hook is registered for a given event.
- Form a name for an event and a chain of events for an event run, log
  both of them. This gives a clear picture of the events executed and
  order in which they are dispatched.
- Similarly build hooks chain and print it in _source_dispatch(), this
  gives a clear picture of the hooks picked and the order in which they
  are dispatched.
- Log only the dispatchable(with hooks) events, this de-clutters
  the log messages.
This commit is contained in:
Ashok Sidipotu
2022-06-30 10:03:18 +05:30
committed by Julian Bouzas
parent a6b3f1c1fb
commit ff833b138d
11 changed files with 192 additions and 67 deletions

View File

@@ -1774,12 +1774,19 @@ simple_event_hook_new (lua_State *L)
{
WpEventHook *hook = NULL;
gint priority = 0;
const gchar *name;
WpEventHookExecType type = 0;
GClosure *closure = NULL;
/* validate arguments */
luaL_checktype (L, 1, LUA_TTABLE);
lua_pushliteral (L, "name");
if (lua_gettable (L, 1) != LUA_TSTRING)
luaL_error (L, "AsyncEventHook: expected 'name' as string");
name = lua_tostring (L, -1);
lua_pop (L, 1);
lua_pushliteral (L, "priority");
if (lua_gettable (L, 1) == LUA_TNUMBER)
priority = lua_tointeger (L, -1);
@@ -1801,7 +1808,7 @@ simple_event_hook_new (lua_State *L)
luaL_error (L, "SimpleEventHook: expected 'execute' as function");
lua_pop (L, 1);
hook = wp_simple_event_hook_new (priority, type, closure);
hook = wp_simple_event_hook_new (name, priority, type, closure);
wplua_pushobject (L, hook);
lua_pushliteral (L, "interests");
@@ -1946,6 +1953,7 @@ static int
async_event_hook_new (lua_State *L)
{
WpEventHook *hook = NULL;
const gchar *name;
gint priority = 0;
WpEventHookExecType type = 0;
GClosure *get_next_step = NULL;
@@ -1954,6 +1962,12 @@ async_event_hook_new (lua_State *L)
/* validate arguments */
luaL_checktype (L, 1, LUA_TTABLE);
lua_pushliteral (L, "name");
if (lua_gettable (L, 1) != LUA_TSTRING)
luaL_error (L, "AsyncEventHook: expected 'name' as string");
name = lua_tostring (L, -1);
lua_pop (L, 1);
lua_pushliteral (L, "priority");
if (lua_gettable (L, 1) != LUA_TNUMBER)
luaL_error (L, "AsyncEventHook: expected 'priority' as number");
@@ -1981,7 +1995,8 @@ async_event_hook_new (lua_State *L)
execute_step = wplua_function_to_closure (L, -1);
lua_pop (L, 1);
hook = wp_async_event_hook_new (priority, type, get_next_step, execute_step);
hook = wp_async_event_hook_new (name, priority, type, get_next_step,
execute_step);
wplua_pushobject (L, hook);
lua_pushliteral (L, "interests");