diff options
-rw-r--r-- | src/compgen.c | 1 | ||||
-rw-r--r-- | src/log.c | 29 | ||||
-rw-r--r-- | src/log.h | 2 | ||||
-rw-r--r-- | src/main.c | 19 |
4 files changed, 46 insertions, 5 deletions
diff --git a/src/compgen.c b/src/compgen.c index f514d66..3ab228a 100644 --- a/src/compgen.c +++ b/src/compgen.c @@ -90,6 +90,5 @@ struct string_vec compgen(struct history *history) programs.buf[i] = xstrdup(to_add.buf[i]); } string_vec_destroy(&to_add); - log_debug("Done.\n"); return programs; } @@ -10,11 +10,33 @@ static struct timespec time_diff( struct timespec cur, struct timespec old); +static int indent = 0; + +static void print_indent(FILE *file) +{ + for (int i = 0; i < indent; i++) { + fprintf(file, "\t"); + } +} + +void log_indent(void) +{ + indent++; +} + +void log_unindent(void) +{ + if (indent > 0) { + indent--; + } +} + void log_error(const char *const fmt, ...) { va_list args; va_start(args, fmt); fprintf(stderr, "[ERROR]: "); + print_indent(stderr); vfprintf(stderr, fmt, args); va_end(args); } @@ -24,6 +46,7 @@ void log_warning(const char *const fmt, ...) va_list args; va_start(args, fmt); fprintf(stderr, "[WARNING]: "); + print_indent(stderr); vfprintf(stderr, fmt, args); va_end(args); } @@ -35,7 +58,7 @@ void log_debug(const char *const fmt, ...) #endif static struct timespec start_time; if (start_time.tv_nsec == 0) { - fprintf(stderr, "[ real, cpu, maxRSS]\n"); + fprintf(stderr, "[ real, cpu, maxRSS]\n"); clock_gettime(CLOCK_REALTIME, &start_time); } struct timespec real_time; @@ -51,13 +74,14 @@ void log_debug(const char *const fmt, ...) va_start(args, fmt); fprintf( stderr, - "[%ld.%03ld, %ld.%03ld, %ld KB][DEBUG]: ", + "[%ld.%03ld, %ld.%03ld, %5ld KB][DEBUG]: ", real_time.tv_sec, real_time.tv_nsec / 1000000, cpu_time.tv_sec, cpu_time.tv_nsec / 1000000, usage.ru_maxrss ); + print_indent(stderr); vfprintf(stderr, fmt, args); va_end(args); } @@ -67,6 +91,7 @@ void log_info(const char *const fmt, ...) va_list args; va_start(args, fmt); fprintf(stderr, "[INFO]: "); + print_indent(stderr); vfprintf(stderr, fmt, args); va_end(args); } @@ -1,6 +1,8 @@ #ifndef LOG_H #define LOG_H +void log_indent(void); +void log_unindent(void); void log_error(const char *const fmt, ...); void log_warning(const char *const fmt, ...); void log_debug(const char *const fmt, ...); @@ -508,7 +508,7 @@ static void surface_enter( struct wl_surface *wl_surface, struct wl_output *wl_output) { - log_debug("TODO: surface entered output.\n"); + log_debug("Surface entered output.\n"); } static void surface_leave( @@ -516,7 +516,7 @@ static void surface_leave( struct wl_surface *wl_surface, struct wl_output *wl_output) { - log_debug("TODO: surface left output.\n"); + /* Deliberately left blank */ } static const struct wl_surface_listener wl_surface_listener = { @@ -581,9 +581,13 @@ int main(int argc, char *argv[]) } }; + log_debug("Generating command list.\n"); + log_indent(); tofi.window.entry.history = history_load(); tofi.window.entry.commands = compgen(&tofi.window.entry.history); tofi.window.entry.results = string_vec_copy(&tofi.window.entry.commands); + log_unindent(); + log_debug("Command list generated.\n"); /* Option parsing with getopt. */ @@ -720,7 +724,9 @@ int main(int argc, char *argv[]) * various global object bindings. */ log_debug("First roundtrip start.\n"); + log_indent(); wl_display_roundtrip(tofi.wl_display); + log_unindent(); log_debug("First roundtrip done.\n"); /* @@ -729,7 +735,9 @@ int main(int argc, char *argv[]) * configured, telling us the scale factor. */ log_debug("Second roundtrip start.\n"); + log_indent(); wl_display_roundtrip(tofi.wl_display); + log_unindent(); log_debug("Second roundtrip done.\n"); /* @@ -782,7 +790,9 @@ int main(int argc, char *argv[]) * configured, after which we're ready to start drawing to the screen. */ log_debug("Third roundtrip start.\n"); + log_indent(); wl_display_roundtrip(tofi.wl_display); + log_unindent(); log_debug("Third roundtrip done.\n"); @@ -792,7 +802,10 @@ int main(int argc, char *argv[]) * drawing, and surface_init allocates the buffers we'll be drawing to. */ log_debug("Initialising window surface.\n"); + log_indent(); surface_init(&tofi.window.surface, tofi.wl_shm); + log_unindent(); + log_debug("Window surface initialised.\n"); /* * Initialise the structures for rendering the entry. @@ -804,6 +817,7 @@ int main(int argc, char *argv[]) * shouldn't be moving between outputs while running. */ log_debug("Initialising renderer.\n"); + log_indent(); entry_init( &tofi.window.entry, tofi.window.surface.shm_pool_data, @@ -811,6 +825,7 @@ int main(int argc, char *argv[]) tofi.window.surface.height, tofi.window.scale); entry_update(&tofi.window.entry); + log_unindent(); log_debug("Renderer initialised.\n"); /* Perform an initial render. */ |