timing: rename time_end() -> time_finish()
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* Add time_end() that, just like time_begin(), returns a malloc:ed timespec * time_finish() now take an optional 'stop' argument (i.e. from time_end()). If NULL, time_finish() itself will calculate the stop time itself This allows us to separate the stop call from logging it.
authored by Daniel Eklöf · committed by Daniel Eklöf · parent 0221d35 · Browse files · 5 files·+62 added−47 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+62 added−47 removed
- other:+62 added−47 removed
Provenance
- Commit
d226f7f- Tree
980e7f9- Author
Daniel Eklöf <daniel@ekloef.se>- Committer
Daniel Eklöf <daniel@ekloef.se>- Parent
0221d35
5 files changed+62 added−47 removed
modified:main.c+21 added-31 removed
65 unmodified lines66 int dmenu_abort_fd;67 68 struct {69 struct {70- struct timeval start;71- struct timeval stop;72- struct timeval diff;70+ struct timespec *start;71+ struct timespec *stop;72 } apps;73 struct {75- struct timeval start;76- struct timeval stop;77- struct timeval diff;74+ struct timespec *start;75+ struct timespec *stop;76 } icons_theme;77 struct {80- struct timeval start;81- struct timeval stop;82- struct timeval diff;78+ struct timespec *start;79+ struct timespec *stop;80 } icons;81 } timing;82 };83 503 unmodified lines587 free(xdg_current_desktop);588 }589 }590 591+ ctx->timing.apps.start = time_begin();592+593 if (dmenu_enabled) {594 if (!conf->prompt_only) {595 dmenu_load_entries(596 apps, dmenu_delim, dmenu_with_nth_format, dmenu_nth_delim,597 ctx->event_fd, ctx->dmenu_abort_fd);598 read_cache(cache_path, apps, true);599 }600 } else {602- gettimeofday(&ctx->timing.apps.start, NULL);601 xdg_find_programs(terminal, actions_enabled, filter_desktop, &desktops, apps);602 if (list_exec_in_path)603 path_find_programs(apps);604 read_cache(cache_path, apps, false);607- gettimeofday(&ctx->timing.apps.stop, NULL);608- timersub(&ctx->timing.apps.stop, &ctx->timing.apps.start, &ctx->timing.apps.diff);605 }606 tll_free_and_free(desktops, free);607 608+ ctx->timing.apps.stop = time_end();609+610 int r = send_event(ctx->event_fd, EVENT_APPS_ALL_LOADED);611 if (r != 0)612 return r;613 614 if (icons_enabled) {617- gettimeofday(&ctx->timing.icons_theme.start, NULL);615+ ctx->timing.icons_theme.start = time_begin();616 icon_theme_list_t icon_themes = icon_load_theme(icon_theme, !dmenu_enabled);617 if (tll_length(icon_themes) > 0)618 LOG_INFO("theme: %s", tll_front(icon_themes).name);619 else620 LOG_WARN("%s: icon theme not found", icon_theme);623- gettimeofday(&ctx->timing.icons_theme.stop, NULL);624- timersub(&ctx->timing.icons_theme.stop, &ctx->timing.icons_theme.start, &ctx->timing.icons_theme.diff);621+ ctx->timing.icons_theme.stop = time_end();622 626- gettimeofday(&ctx->timing.icons.start, NULL);623+ ctx->timing.icons.start = time_begin();624 mtx_lock(ctx->icon_lock);625 {626 *ctx->themes = icon_themes;627 if (ctx->icon_size > 0) {5 unmodified lines633 }634 }635 }636 mtx_unlock(ctx->icon_lock);640- gettimeofday(&ctx->timing.icons.stop, NULL);641- timersub(&ctx->timing.icons.stop, &ctx->timing.icons.start, &ctx->timing.icons.diff);637+ ctx->timing.icons.stop = time_end();638 639 r = send_event(ctx->event_fd, EVENT_ICONS_LOADED);640 if (r != 0)641 return r;14 unmodified lines656 657 switch (event) {658 case EVENT_APPS_SOME_LOADED:659 case EVENT_APPS_ALL_LOADED: {664- if (event == EVENT_APPS_ALL_LOADED && conf->print_timing_info) {665- LOG_WARN("apps loaded in %llus %lluµs",666- (unsigned long long)ctx->timing.apps.diff.tv_sec,667- (unsigned long long)ctx->timing.apps.diff.tv_usec);660+ if (event == EVENT_APPS_ALL_LOADED) {661+ time_finish(662+ ctx->timing.apps.start, ctx->timing.apps.stop, "apps loaded");663 }664 /* Update matches list, then refresh the GUI */665 matches_set_applications(matches, apps);666 57 unmodified lines724 }725 726 case EVENT_ICONS_LOADED:727 /* Just need to refresh the GUI */733- if (conf->print_timing_info) {734- LOG_WARN("icon themes loaded in %llus %lluµs",735- (unsigned long long)ctx->timing.icons_theme.diff.tv_sec,736- (unsigned long long)ctx->timing.icons_theme.diff.tv_usec);737- LOG_WARN("icon paths resolved in %llus %lluµs",738- (unsigned long long)ctx->timing.icons.diff.tv_sec,739- (unsigned long long)ctx->timing.icons.diff.tv_usec);740- }728+ time_finish(ctx->timing.icons_theme.start, ctx->timing.icons_theme.stop,729+ "icon themes loaded");730+ time_finish(ctx->timing.icons.start, ctx->timing.icons.stop,731+ "icon paths resolved");732 matches_icons_loaded(matches);733 break;734 735 default:1513 unmodified lines2249 2250 if (!fdm_add(fdm, event_pipe[0], EPOLLIN, &fdm_apps_populated, &ctx))2251 goto out;2252 2262- gettimeofday(&ctx.timing.apps.start, NULL);2253 if (thrd_create(&app_thread_id, &populate_apps, &ctx) != thrd_success) {2254 LOG_ERR("failed to create thread");2255 goto out;2256 }93 unmodified linesmodified:render.c+4 added-4 removed
1183 unmodified lines1184 free(start_load);1185 return;1186 }1187 1188- time_end(start_load, "%s loaded", icon->path);1188+ time_finish(start_load, NULL, "%s loaded", icon->path);1189 LOG_DBG("%s", icon->path);1190 }1191 1192 struct timespec *render_start = time_begin();5 unmodified lines1198 #elif defined(FUZZEL_ENABLE_SVG_RESVG)1199 render_svg_resvg(icon, x, y, size, pix, cairo, gamma_correct);1200 #endif1201 1202- time_end(render_start, "%s rendered", icon->path);1202+ time_finish(render_start, NULL, "%s rendered", icon->path);1203 }1204 1205 #if defined(FUZZEL_ENABLE_PNG_LIBPNG)1206 static void171 unmodified lines1378 free(start_load);1379 return;1380 }1381 1382- time_end(start_load, "%s loaded", icon->path);1382+ time_finish(start_load, NULL, "%s loaded", icon->path);1383 LOG_DBG("%s", icon->path);1384 }1385 1386 struct timespec *start_render = time_begin();1 unmodified line1388 #if defined(FUZZEL_ENABLE_PNG_LIBPNG)1389 render_png_libpng(icon, x, y, size, pix, cairo, scaling_filter);1390 #endif1391 1392- time_end(start_render, "%s rendered", icon->path);1392+ time_finish(start_render, NULL, "%s rendered", icon->path);1393 }1394 1395 static int1396 first_row_y(const struct render *render)582 unmodified linesmodified:timing.c+32 added-9 removed
65 unmodified lines66 67 LOG_WARN("%s: %lds %ldµs since bootup", msg, diff.tv_sec, diff.tv_nsec / 1000);68 }69 70-struct timespec *71-time_begin(void)70+static struct timespec *71+time_stamp(void)72 {73 if (!enabled)74 return NULL;75 4 unmodified lines80 clock_gettime(CLOCK_MONOTONIC, ret);81 return ret;82 }83 84-void85-time_end(struct timespec *start, const char *fmt, ...)84+struct timespec *85+time_begin(void)86 {87- if (start == NULL)88- return;87+ return time_stamp();88+}89 90+struct timespec *91+time_end(void)92+{93+ return time_stamp();94+}95+96+void97+time_finish(struct timespec *start, struct timespec *stop, const char *fmt, ...)98+{99 if (!enabled) {100 free(start);101+ free(stop);102 return;103 }104 95- struct timespec stop;96- clock_gettime(CLOCK_MONOTONIC, &stop);105+ if (start == NULL)106+ return;107 108+ if (stop == NULL) {109+ stop = malloc(sizeof(*stop));110+111+ if (stop == NULL) {112+ free(start);113+ free(stop);114+ return;115+ }116+117+ clock_gettime(CLOCK_MONOTONIC, stop);118+ }119+120 struct timespec diff;99- timespec_sub(&stop, start, &diff);121+ timespec_sub(stop, start, &diff);122 123 va_list va1, va2;124 va_start(va1, fmt);125 va_copy(va2, va1);7 unmodified lines133 134 LOG_WARN("%s in %lds %ldµs", msg, diff.tv_sec, diff.tv_nsec / 1000);135 136 free(start);137+ free(stop);138 }modified:timing.h+2 added-1 removed
6 unmodified lines7 8 void time_since_boot(const char *fmt, ...) __attribute__((format(printf, 1, 2)));9 10 struct timespec *time_begin(void);11-void time_end(struct timespec *start, const char *fmt, ...) __attribute__((format(printf, 2, 3)));11+struct timespec *time_end(void);12+void time_finish(struct timespec *start, struct timespec *stop, const char *fmt, ...) __attribute__((format(printf, 3, 4)));modified:wayland.c+3 added-2 removed
2595 unmodified lines2596 /* No pending frames - render immediately */2597 assert(!wayl->need_refresh);2598 commit_buffer(wayl, buf);2599 done:2600+2600- time_end(2601- start_frame, "%sframe rendered",2601+ time_finish(2602+ start_frame, NULL, "%sframe rendered",2603 wayl->render_first_frame_transparent ? "transparent " : "");2604 }2605 2606 void552 unmodified lines