Add extra logging to debug the event loop

This should make tracking down the root cause of the
event loop pauses on X11 easier. And the infrastructure
should come in handy in the future as well.
This commit is contained in:
Kovid Goyal
2019-04-24 16:16:40 +05:30
parent 099510f4d1
commit 0987a536b1
6 changed files with 46 additions and 4 deletions

14
glfw/init.c vendored
View File

@@ -193,6 +193,20 @@ void _glfwInputError(int code, const char* format, ...)
_glfwErrorCallback(code, description);
}
void
_glfwDebug(const char *format, ...) {
if (format)
{
va_list vl;
fprintf(stderr, "[%.4f] ", glfwGetTime());
va_start(vl, format);
vfprintf(stderr, format, vl);
va_end(vl);
fprintf(stderr, "\n");
}
}
//////////////////////////////////////////////////////////////////////////
////// GLFW public API //////

10
glfw/internal.h vendored
View File

@@ -743,13 +743,21 @@ void _glfwInputJoystickHat(_GLFWjoystick* js, int hat, char value);
void _glfwInputMonitor(_GLFWmonitor* monitor, int action, int placement);
void _glfwInputMonitorWindow(_GLFWmonitor* monitor, _GLFWwindow* window);
#if defined(__GNUC__)
#if defined(__GNUC__) || defined(__clang__)
void _glfwInputError(int code, const char* format, ...)
__attribute__((format(printf, 2, 3)));
void _glfwDebug(const char* format, ...)
__attribute__((format(printf, 1, 2)));
#else
void _glfwInputError(int code, const char* format, ...);
void _glfwDebug(const char* format, ...);
#endif
#ifdef DEBUG_EVENT_LOOP
#define EVDBG(...) _glfwDebug(__VA_ARGS__)
#else
#define EVDBG(...)
#endif
//////////////////////////////////////////////////////////////////////////
////// GLFW internal API //////

1
glfw/main_loop.h vendored
View File

@@ -29,6 +29,7 @@ void _glfwPlatformRunMainLoop(GLFWtickcallback callback, void* data) {
keep_going = GLFW_TRUE;
tick_callback_requested = GLFW_FALSE;
while(keep_going) {
EVDBG("tick_callback_requested: %d", tick_callback_requested);
while (tick_callback_requested) {
tick_callback_requested = GLFW_FALSE;
callback(data);

8
glfw/x11_window.c vendored
View File

@@ -59,10 +59,16 @@ GLFWbool _glfwDispatchX11Events(void);
static void
handleEvents(double timeout) {
EVDBG("starting handleEvents(%.2f)", timeout);
int display_read_ok = pollForEvents(&_glfw.x11.eventLoopData, timeout);
if (display_read_ok) _glfwDispatchX11Events();
EVDBG("display_read_ok: %d", display_read_ok);
if (display_read_ok) {
_glfwDispatchX11Events();
EVDBG("_glfwDispatchX11Events() done");
}
glfw_ibus_dispatch(&_glfw.x11.xkb.ibus);
glfw_dbus_session_bus_dispatch();
EVDBG("other dispatch done");
}
static GLFWbool