From f7a7765ba2dd91d73c82511850d24c20c24506dd Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 26 Mar 2024 13:06:08 +0530 Subject: [PATCH] Clean up debug rendering output --- glfw/wl_window.c | 2 +- kitty/child-monitor.c | 4 ++-- kitty/core_text.m | 2 +- kitty/data-types.c | 6 ++++++ kitty/fast_data_types.pyi | 1 + kitty/fonts.c | 2 +- kitty/gl.c | 2 +- kitty/screen.c | 1 - kitty/window.py | 8 +++++--- 9 files changed, 18 insertions(+), 10 deletions(-) diff --git a/glfw/wl_window.c b/glfw/wl_window.c index c8a375410..4b8a4c1f4 100644 --- a/glfw/wl_window.c +++ b/glfw/wl_window.c @@ -41,7 +41,7 @@ #include #include -#define debug(...) if (_glfw.hints.init.debugRendering) fprintf(stderr, __VA_ARGS__); +#define debug(...) if (_glfw.hints.init.debugRendering) { fprintf(stderr, "[%.3f] ", monotonic_t_to_s_double(monotonic())); fprintf(stderr, __VA_ARGS__); } static GLFWLayerShellConfig layer_shell_config_for_next_window = {0}; diff --git a/kitty/child-monitor.c b/kitty/child-monitor.c index 54ef85586..c81ce4c9b 100644 --- a/kitty/child-monitor.c +++ b/kitty/child-monitor.c @@ -819,9 +819,9 @@ no_render_frame_received_recently(OSWindow *w, monotonic_t now, monotonic_t max_ bool ans = now - w->last_render_frame_received_at > max_wait; if (ans && global_state.debug_rendering) { if (global_state.is_wayland) { - log_error("No render frame received in %.2f seconds", monotonic_t_to_s_double(max_wait)); + fprintf(stderr, "[%f] No render frame received in %.2f seconds", monotonic_t_to_s_double(now), monotonic_t_to_s_double(max_wait)); } else { - log_error("No render frame received in %.2f seconds, re-requesting at: %f", monotonic_t_to_s_double(max_wait), monotonic_t_to_s_double(now)); + fprintf(stderr, "[%f] No render frame received in %.2f seconds, re-requesting", monotonic_t_to_s_double(now), monotonic_t_to_s_double(max_wait)); } } return ans; diff --git a/kitty/core_text.m b/kitty/core_text.m index 0b82ba728..d9fda023d 100644 --- a/kitty/core_text.m +++ b/kitty/core_text.m @@ -21,7 +21,7 @@ #import #import -#define debug(...) if (global_state.debug_rendering) { fprintf(stderr, __VA_ARGS__); fflush(stderr); } +#define debug(...) if (global_state.debug_font_fallback) { fprintf(stderr, __VA_ARGS__); fflush(stderr); } typedef struct { PyObject_HEAD diff --git a/kitty/data-types.c b/kitty/data-types.c index b7b6a9809..fb868e18e 100644 --- a/kitty/data-types.c +++ b/kitty/data-types.c @@ -411,6 +411,11 @@ py_terminfo_data(PyObject *self UNUSED, PyObject *args UNUSED) { return PyBytes_FromStringAndSize((const char*)terminfo_data, arraysz(terminfo_data)); } +static PyObject* +py_monotonic(PyObject *self UNUSED, PyObject *args UNUSED) { + return PyFloat_FromDouble(monotonic_t_to_s_double(monotonic())); +} + static PyMethodDef module_methods[] = { METHODB(replace_c0_codes_except_nl_space_tab, METH_O), {"wcwidth", (PyCFunction)wcwidth_wrap, METH_O, ""}, @@ -433,6 +438,7 @@ static PyMethodDef module_methods[] = { {"shm_unlink", (PyCFunction)py_shm_unlink, METH_VARARGS, ""}, {"wrapped_kitten_names", (PyCFunction)wrapped_kittens, METH_NOARGS, ""}, {"terminfo_data", (PyCFunction)py_terminfo_data, METH_NOARGS, ""}, + {"monotonic", (PyCFunction)py_monotonic, METH_NOARGS, ""}, {"find_in_memoryview", (PyCFunction)find_in_memoryview, METH_VARARGS, ""}, #ifdef __APPLE__ METHODB(user_cache_dir, METH_NOARGS), diff --git a/kitty/fast_data_types.pyi b/kitty/fast_data_types.pyi index 932ffda2f..7002e3218 100644 --- a/kitty/fast_data_types.pyi +++ b/kitty/fast_data_types.pyi @@ -1575,3 +1575,4 @@ def replace_c0_codes_except_nl_space_tab(text: Union[bytes, memoryview, bytearra def terminfo_data() -> bytes:... def wayland_compositor_pid() -> int:... def window_fully_created(kitty_window_id: int) -> bool: ... +def monotonic() -> float: ... diff --git a/kitty/fonts.c b/kitty/fonts.c index 305a16f29..1bc9d4746 100644 --- a/kitty/fonts.c +++ b/kitty/fonts.c @@ -15,7 +15,7 @@ #define MISSING_GLYPH (NUM_UNDERLINE_STYLES + 2) #define MAX_NUM_EXTRA_GLYPHS_PUA 4u -#define debug(...) if (global_state.debug_rendering) { fprintf(stderr, __VA_ARGS__); fflush(stderr); } +#define debug(...) if (global_state.debug_font_fallback) { fprintf(stderr, __VA_ARGS__); fflush(stderr); } static PyObject *python_send_to_gpu_impl = NULL; #define current_send_sprite_to_gpu(...) (python_send_to_gpu_impl ? python_send_to_gpu(__VA_ARGS__) : send_sprite_to_gpu(__VA_ARGS__)) diff --git a/kitty/gl.c b/kitty/gl.c index 301700117..ce4a21e10 100644 --- a/kitty/gl.c +++ b/kitty/gl.c @@ -60,7 +60,7 @@ gl_init(void) { int gl_major = GLAD_VERSION_MAJOR(gl_version); int gl_minor = GLAD_VERSION_MINOR(gl_version); const char *gvs = (const char*)glGetString(GL_VERSION); - if (global_state.debug_rendering) printf("GL version string: '%s' Detected version: %d.%d\n", gvs, gl_major, gl_minor); + if (global_state.debug_rendering) printf("[%.3f] GL version string: '%s' Detected version: %d.%d\n", monotonic_t_to_s_double(monotonic()), gvs, gl_major, gl_minor); if (gl_major < OPENGL_REQUIRED_VERSION_MAJOR || (gl_major == OPENGL_REQUIRED_VERSION_MAJOR && gl_minor < OPENGL_REQUIRED_VERSION_MINOR)) { fatal("OpenGL version is %d.%d, version >= 3.3 required for kitty", gl_major, gl_minor); } diff --git a/kitty/screen.c b/kitty/screen.c index 373a4573d..6ccdea8c7 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -2301,7 +2301,6 @@ shell_prompt_marking(Screen *self, char *buf) { break; } } - if (global_state.debug_rendering) fprintf(stderr, "prompt_marking: x=%d y=%d op=%s\n", self->cursor->x, self->cursor->y, buf); } static bool diff --git a/kitty/window.py b/kitty/window.py index e65c1b36e..04e176241 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -12,7 +12,7 @@ from functools import lru_cache, partial from gettext import gettext as _ from itertools import chain -from time import monotonic, time_ns +from time import time_ns from typing import ( TYPE_CHECKING, Any, @@ -72,6 +72,7 @@ is_css_pointer_name_valid, last_focused_os_window_id, mark_os_window_dirty, + monotonic, mouse_selection, move_cursor_to_mouse_if_in_prompt, pointer_name_to_css_name, @@ -843,9 +844,10 @@ def set_geometry(self, new_geometry: WindowGeometry) -> None: self.child_is_launched = True update_ime_position = True if boss.args.debug_rendering: - print(f'Child launched {monotonic() - self.started_at:.2f} seconds after window creation') + now = monotonic() + print(f'[{now:.3f}] Child launched {now - self.started_at:.2f} seconds after window creation', file=sys.stderr) if boss.args.debug_rendering and self.child_is_launched: - print(f'SIGWINCH sent to child in window: {self.id} with size: {current_pty_size}', file=sys.stderr) + print(f'[{monotonic():.3f}] SIGWINCH sent to child in window: {self.id} with size: {current_pty_size}', file=sys.stderr) self.last_reported_pty_size = current_pty_size else: mark_os_window_dirty(self.os_window_id)