debug: add a --print-timing-info command line option
Before adoption: this commit came in with the history the project adopted, so no landing records it.
When used, log timing information of various operations (on the warning level). This is useful when debugging performance issues.
authored by Daniel Eklöf · committed by Daniel Eklöf · parent 7835e25 · Browse files · 8 files·+137 added−6 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
8 files+137 added−6 removed
- other:+137 added−6 removed
Provenance
- Commit
1ea01b1- Tree
01f7fb3- Author
Daniel Eklöf <daniel@ekloef.se>- Committer
Daniel Eklöf <daniel@ekloef.se>- Parent
7835e25
8 files changed+137 added−6 removed
modified:completions/fish/fuzzel.fish+1 added
78 unmodified lines79 complete -c fuzzel -x -s d -l log-level -a "info warning error none" -d "log-level (warning)"80 complete -c fuzzel -x -s l -l log-colorize -a "always never auto" -d "enable or disable colorization of log output on stderr"81 complete -c fuzzel -s S -l log-no-syslog -d "disable syslog logging"82 complete -c fuzzel -s v -l version -d "show the version number and quit"83+complete -c fuzzel -l print-timing-info -d "print timing information, to help debug performance issues"84 complete -c fuzzel -s h -l help -d "show help message and quit"modified:completions/zsh/_fuzzel+2 added-1 removed
68 unmodified lines69 '--accept-nth[output the N:th column (tab separated) of each input line (dmenu mode only)]:with-nth:()' \70 '(-R --no-run-if-empty)'{-R,--no-run-if-empty}'[exit immediately without showing the UI if stdin is empty (dmenu mode only)]' \71 '--log-level[log level (warning)]:loglevel:(info warning error none)' \72 '--log-colorize[enable or disable colorization of log output on stderr]:logcolor:(never always auto)' \73- '--log-no-syslog[disable syslog logging]'73+ '--log-no-syslog[disable syslog logging]' \74+ '--print-timing-info[print timing information, to help debug performance issues]'75 76 case "${state}" in77 fonts)78 if command -v fc-list > /dev/null; then16 unmodified linesmodified:doc/fuzzel.1.scd+3 added
472 unmodified lines473 474 *--log-no-syslog*475 Disables syslog logging. Logging is only done on stderr.476 477+*--print-timing-info*478+ Print timing information, to help debug performance issues.479+480 *-v*,*--version*481 Show the version number and quit482 483 # CONFIGURATION57 unmodified linesmodified:config.c+1 added
1669 unmodified lines1670 .keyboard_focus = ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE,1671 .exit_on_kb_focus_loss = true,1672 .list_executables_in_path = false,1673 .cache_path = NULL,1674+ .print_timing_info = false,1675 };1676 1677 add_default_key_bindings(conf);1678 77 unmodified linesmodified:config.h+2 added
202 unmodified lines203 bool exit_on_kb_focus_loss;204 205 bool list_executables_in_path;206 char *cache_path;207+208+ bool print_timing_info;209 };210 211 typedef tll(char *) config_override_t;212 6 unmodified linesmodified:main.c+54 added
13 unmodified lines14 #include <sys/stat.h>15 #include <sys/file.h>16 #include <sys/epoll.h>17 #include <sys/eventfd.h>18+#include <sys/time.h>19 #include <fcntl.h>20 #include <dirent.h>21 22 #include <tllist.h>37 unmodified lines60 const size_t select_initial_idx;61 62 int event_fd;63 int dmenu_abort_fd;64+65+ struct {66+ struct {67+ struct timeval start;68+ struct timeval stop;69+ struct timeval diff;70+ } apps;71+ struct {72+ struct timeval start;73+ struct timeval stop;74+ struct timeval diff;75+ } icons_theme;76+ struct {77+ struct timeval start;78+ struct timeval stop;79+ struct timeval diff;80+ } icons;81+ } timing;82 };83 84 struct cache_entry {85 char *id;351 unmodified lines437 " --log-colorize=[never|always|auto]\n"438 " enable/disable colorization of log output on\n"439 " stderr\n"440 " --log-no-syslog disable syslog logging\n"441+ " --print-timing-info print timing information, to help debug\n"442+ " performance issues\n"443 " -v,--version show the version number and quit\n");444 printf("\n");445 printf("All colors are RGBA - i.e. 8-digit hex values, without prefix.\n");446 }131 unmodified lines578 ctx->event_fd, ctx->dmenu_abort_fd);579 read_cache(cache_path, apps, true);580 }581 } else {582+ gettimeofday(&ctx->timing.apps.start, NULL);583 xdg_find_programs(terminal, actions_enabled, filter_desktop, &desktops, apps);584 if (list_exec_in_path)585 path_find_programs(apps);586 read_cache(cache_path, apps, false);587+ gettimeofday(&ctx->timing.apps.stop, NULL);588+ timersub(&ctx->timing.apps.stop, &ctx->timing.apps.start, &ctx->timing.apps.diff);589 }590 tll_free_and_free(desktops, free);591 592 int r = send_event(ctx->event_fd, EVENT_APPS_ALL_LOADED);593 if (r != 0)594 return r;595 596 if (icons_enabled) {597+ gettimeofday(&ctx->timing.icons_theme.start, NULL);598 icon_theme_list_t icon_themes = icon_load_theme(icon_theme);599 if (tll_length(icon_themes) > 0)600 LOG_INFO("theme: %s", tll_front(icon_themes).name);601 else602 LOG_WARN("%s: icon theme not found", icon_theme);603+ gettimeofday(&ctx->timing.icons_theme.stop, NULL);604+ timersub(&ctx->timing.icons_theme.stop, &ctx->timing.icons_theme.start, &ctx->timing.icons_theme.diff);605 606+ gettimeofday(&ctx->timing.icons.start, NULL);607 mtx_lock(ctx->icon_lock);608 {609 *ctx->themes = icon_themes;610 if (ctx->icon_size > 0) {5 unmodified lines616 }617 }618 }619 mtx_unlock(ctx->icon_lock);620+ gettimeofday(&ctx->timing.icons.stop, NULL);621+ timersub(&ctx->timing.icons.stop, &ctx->timing.icons.start, &ctx->timing.icons.diff);622 623 r = send_event(ctx->event_fd, EVENT_ICONS_LOADED);624 if (r != 0)625 return r;14 unmodified lines640 641 switch (event) {642 case EVENT_APPS_SOME_LOADED:643 case EVENT_APPS_ALL_LOADED: {644+ if (event == EVENT_APPS_ALL_LOADED && conf->print_timing_info) {645+ LOG_WARN("apps loaded in %llus %lluµs",646+ (unsigned long long)ctx->timing.apps.diff.tv_sec,647+ (unsigned long long)ctx->timing.apps.diff.tv_usec);648+ }649 /* Update matches list, then refresh the GUI */650 matches_set_applications(matches, apps);651 652 if (event == EVENT_APPS_ALL_LOADED) {29 unmodified lines682 }683 684 case EVENT_ICONS_LOADED:685 /* Just need to refresh the GUI */686+ if (conf->print_timing_info) {687+ LOG_WARN("icon themes loaded in %llus %lluµs",688+ (unsigned long long)ctx->timing.icons_theme.diff.tv_sec,689+ (unsigned long long)ctx->timing.icons_theme.diff.tv_usec);690+ LOG_WARN("icon paths resolved in %llus %lluµs",691+ (unsigned long long)ctx->timing.icons.diff.tv_sec,692+ (unsigned long long)ctx->timing.icons.diff.tv_usec);693+ }694 matches_icons_loaded(matches);695 break;696 697 default:101 unmodified lines799 #define OPT_HIDE_WHEN_PROMPT_EMPTY 297800 #define OPT_DMENU_WITH_NTH 298801 #define OPT_DMENU_ACCEPT_NTH 299802 #define OPT_GAMMA_CORRECT 300803+ #define OPT_PRINT_TIMINGS 301804 805 static const struct option longopts[] = {806 {"config", required_argument, 0, OPT_CONFIG},807 {"check-config", no_argument, 0, OPT_CHECK_CONFIG},70 unmodified lines878 {"log-level", required_argument, 0, OPT_LOG_LEVEL},879 {"log-colorize", optional_argument, 0, OPT_LOG_COLORIZE},880 {"log-no-syslog", no_argument, 0, OPT_LOG_NO_SYSLOG},881 {"version", no_argument, 0, 'v'},882+ {"print-timing-info", no_argument, 0, OPT_PRINT_TIMINGS},883 {"help", no_argument, 0, 'h'},884 {NULL, no_argument, 0, 0},885 };886 59 unmodified lines946 bool delayed_filter_ms_set:1;947 bool delayed_filter_limit_set:1;948 bool placeholder_color_set:1;949 bool counter_set:1;950+ bool print_timing_info_set:1;951 } cmdline_overrides = {{0}};952 953 setlocale(LC_CTYPE, "");954 setlocale(LC_MESSAGES, "");782 unmodified lines1737 }1738 cmdline_overrides.delayed_filter_limit_set = true;1739 break;1740 1741+ case OPT_PRINT_TIMINGS:1742+ cmdline_overrides.conf.print_timing_info = true;1743+ cmdline_overrides.print_timing_info_set = true;1744+ break;1745+1746 case 'v':1747 printf("fuzzel %s\n", version_and_features());1748 return EXIT_SUCCESS;1749 188 unmodified lines1938 if (cmdline_overrides.conf.cache_path != NULL) {1939 free(conf.cache_path);1940 conf.cache_path = xstrdup(cmdline_overrides.conf.cache_path);1941 }1942+ if (cmdline_overrides.print_timing_info_set)1943+ conf.print_timing_info = cmdline_overrides.conf.print_timing_info;1944 1945 if (conf.dmenu.enabled) {1946 /* We don't have any meta data in dmenu mode */1947 conf.match_fields = MATCH_NAME;124 unmodified lines2072 2073 if (!fdm_add(fdm, event_pipe[0], EPOLLIN, &fdm_apps_populated, &ctx))2074 goto out;2075 2076+ gettimeofday(&ctx.timing.apps.start, NULL);2077 if (thrd_create(&app_thread_id, &populate_apps, &ctx) != thrd_success) {2078 LOG_ERR("failed to create thread");2079 goto out;2080 }75 unmodified linesmodified:render.c+62 added-5 removed
7 unmodified lines8 #include <stdlib.h>9 #include <string.h>10 #include <threads.h>11 #include <uchar.h>12+#include <sys/time.h>13 14 #include "column.h"15 #include "macros.h"16 #if HAS_INCLUDE(<pthread_np.h>)849 unmodified lines866 #endif /* FUZZEL_ENABLE_SVG_NANOSVG */867 868 static void869 render_svg(struct icon *icon, int x, int y, int size,869- pixman_image_t *pix, cairo_t *cairo, bool gamma_correct)870+ pixman_image_t *pix, cairo_t *cairo, bool gamma_correct,871+ bool print_timing_info)872 {873 assert(icon->type == ICON_SVG);874 875 if (icon->svg == NULL) {876+ struct timeval start, stop, diff;877+ gettimeofday(&start, NULL);878+879 if (!icon_from_svg(icon, icon->path))880 return;881+882+ if (print_timing_info) {883+ gettimeofday(&stop, NULL);884+ timersub(&stop, &start, &diff);885+886+ LOG_WARN("%s loaded in %llus %lluµs",887+ icon->path,888+ (unsigned long long)diff.tv_sec,889+ (unsigned long long)diff.tv_usec);890+ }891+892 LOG_DBG("%s", icon->path);893 }894 895+ struct timeval start, stop, diff;896+ gettimeofday(&start, NULL);897+898 #if defined(FUZZEL_ENABLE_SVG_LIBRSVG)899 render_svg_librsvg(icon, x, y, size, cairo);900 #elif defined(FUZZEL_ENABLE_SVG_NANOSVG)901 render_svg_nanosvg(icon, x, y, size, pix, cairo, gamma_correct);902 #endif903+904+ if (print_timing_info) {905+ gettimeofday(&stop, NULL);906+ timersub(&stop, &start, &diff);907+908+ LOG_WARN("%s rendered in %llus %lluµs",909+ icon->path,910+ (unsigned long long)diff.tv_sec,911+ (unsigned long long)diff.tv_usec);912+ }913 }914 915 #if defined(FUZZEL_ENABLE_PNG_LIBPNG)916 static void80 unmodified lines997 #endif /* FUZZEL_ENABLE_PNG_LIBPNG */998 999 static void1000 render_png(struct icon *icon, int x, int y, int size, pixman_image_t *pix,972- cairo_t *cairo, bool gamma_correct)1001+ cairo_t *cairo, bool gamma_correct, bool print_timing_info)1002 {1003 assert(icon->type == ICON_PNG);1004 1005 if (icon->png == NULL) {1006+ struct timeval start, stop, diff;1007+ gettimeofday(&start, NULL);1008+1009 if (!icon_from_png(icon, icon->path, gamma_correct))1010 return;1011+1012+ if (print_timing_info) {1013+ gettimeofday(&stop, NULL);1014+ timersub(&stop, &start, &diff);1015+ LOG_WARN("%s loaded in %llus %lluµs",1016+ icon->path,1017+ (unsigned long long)diff.tv_sec,1018+ (unsigned long long)diff.tv_usec);1019+ }1020+1021 LOG_DBG("%s", icon->path);1022 }1023 1024+ struct timeval start, stop, diff;1025+ gettimeofday(&start, NULL);1026+1027 #if defined(FUZZEL_ENABLE_PNG_LIBPNG)1028 render_png_libpng(icon, x, y, size, pix, cairo);1029 #endif1030+1031+ if (print_timing_info) {1032+ gettimeofday(&stop, NULL);1033+ timersub(&stop, &start, &diff);1034+ LOG_WARN("%s rendered in %llus %lluµs",1035+ icon->path,1036+ (unsigned long long)diff.tv_sec,1037+ (unsigned long long)diff.tv_usec);1038+ }1039 }1040 1041 static int1042 first_row_y(const struct render *render)81 unmodified lines1124 if (render_icons &&1125 match->application->icon.type == ICON_SVG &&1126 img_y > list_end + render->row_height)1127 {1074- render_svg(&match->application->icon, img_x, img_y, size, pix, cairo, render->gamma_correct);1128+ render_svg(&match->application->icon, img_x, img_y, size, pix, cairo,1129+ render->gamma_correct, render->conf->print_timing_info);1130 }1131 }1132 1133 if (render_icons) {6 unmodified lines1140 case ICON_NONE:1141 break;1142 1143 case ICON_PNG:1089- render_png(icon, img_x, img_y, size, pix, cairo, render->gamma_correct);1144+ render_png(icon, img_x, img_y, size, pix, cairo,1145+ render->gamma_correct, render->conf->print_timing_info);1146 break;1147 1148 case ICON_SVG:1093- render_svg(icon, img_x, img_y, size, pix, cairo, render->gamma_correct);1149+ render_svg(icon, img_x, img_y, size, pix, cairo,1150+ render->gamma_correct, render->conf->print_timing_info);1151 break;1152 }1153 }1154 430 unmodified linesmodified:wayland.c+12 added
10 unmodified lines11 12 #include <sys/mman.h>13 #include <sys/epoll.h>14 #include <sys/timerfd.h>15+#include <sys/time.h>16 17 #include <wayland-client.h>18 #include <wayland-cursor.h>19 #include <wayland-util.h>2148 unmodified lines2168 wayl->need_refresh = true;2169 return;2170 }2171 2172+ struct timeval start, stop, diff;2173+ gettimeofday(&start, NULL);2174+2175 if (wayl->chain == NULL) {2176 wayl->chain =2177 shm_chain_new(2178 wayl->shm, false, 1 + wayl->conf->render_worker_count,51 unmodified lines2230 commit:2231 /* No pending frames - render immediately */2232 assert(!wayl->need_refresh);2233 commit_buffer(wayl, buf);2234+2235+ if (wayl->conf->print_timing_info) {2236+ gettimeofday(&stop, NULL);2237+ timersub(&stop, &start, &diff);2238+ LOG_WARN("frame rendered in %llus %lluµs",2239+ (unsigned long long)diff.tv_sec,2240+ (unsigned long long)diff.tv_usec);2241+ }2242 }2243 2244 static bool2245 fdm_handler(struct fdm *fdm, int fd, int events, void *data)540 unmodified lines