Skip to content
Myr

timing: new minimal timing framework

Before adoption: this commit came in with the history the project adopted, so no landing records it.

To make it easier to add timestamps and timing information for --print-timing-info.

authored by Daniel Eklöf · committed by Daniel Eklöf · parent 82b0558 · Browse files · 6 files+155 added−55 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

6 files+155 added−55 removed

  • other:+155 added−55 removed

6 files+155 added−55 removed

modified:main.c+8 added
40 unmodified lines
41#include "xdg.h"42#include "xmalloc.h"43#include "xsnprintf.h"4445#include "timing.h"4647#define max(x, y) ((x) > (y) ? (x) : (y))48#define min(x, y) ((x) < (y) ? (x) : (y))4950struct context {
754 unmodified lines
805806int807main(int argc, char *const *argv)808{809 time_init();810811 #define OPT_LETTER_SPACING 256812 #define OPT_LAUNCH_PREFIX 257813 #define OPT_SHOW_ACTIONS 258814 #define OPT_MATCH_MODE 259
1101 unmodified lines
1916 return EXIT_FAILURE;1917 }1918 }191919201921 log_init(log_colorize, log_syslog, LOG_FACILITY_USER, log_level);1922 LOG_INFO("%s", version_and_features());19231924 int ret = EXIT_FAILURE;
211 unmodified lines
2136 close(STDIN_FILENO); /* To catch reads */2137 }2138 }21392140 if (conf.print_timing_info)2141 time_enable();21422143 _Static_assert((int)LOG_CLASS_ERROR == (int)FCFT_LOG_CLASS_ERROR,2144 "fcft log level enum offset");2145 _Static_assert((int)LOG_COLORIZE_ALWAYS == (int)FCFT_LOG_COLORIZE_ALWAYS,2146 "fcft colorize enum mismatch");
213 unmodified lines
modified:meson.build+1 added
211 unmodified lines
212 'wayland.c', 'wayland.h',213 'xdg.c', 'xdg.h',214 'xmalloc.c', 'xmalloc.h',215 'xsnprintf.c', 'xsnprintf.h',216 'timing.c', 'timing.h',217 wl_proto_src + wl_proto_headers, version, srgb_funcs,218 dependencies: [math,219 threads,220 pixman,
56 unmodified lines
modified:render.c+14 added-44 removed
11 unmodified lines
12#include <sys/time.h>1314#include "column.h"15#include "macros.h"16#include "timing.h"1718#if HAS_INCLUDE(<pthread_np.h>)19#include <pthread_np.h>20#define pthread_setname_np(thread, name) (pthread_set_name_np(thread, name), 0)21#elif defined(__NetBSD__)
1155 unmodified lines
1177{1178 assert(icon->type == ICON_SVG);11791180 if (icon->svg == NULL) {1179 struct timeval start, stop, diff;1180 gettimeofday(&start, NULL);1181 struct timespec *start_load = time_begin();11821182 if (!icon_from_svg(icon, icon->path))1183 if (!icon_from_svg(icon, icon->path)) {1184 free(start_load);1185 return;11841185 if (print_timing_info) {1186 gettimeofday(&stop, NULL);1187 timersub(&stop, &start, &diff);11881189 LOG_WARN("%s loaded in %llus %lluµs",1190 icon->path,1191 (unsigned long long)diff.tv_sec,1192 (unsigned long long)diff.tv_usec);1186 }11871188 time_end(start_load, "%s loaded", icon->path);1189 LOG_DBG("%s", icon->path);1190 }11911198 struct timeval start, stop, diff;1199 gettimeofday(&start, NULL);1192 struct timespec *render_start = time_begin();11931194#if defined(FUZZEL_ENABLE_SVG_LIBRSVG)1195 render_svg_librsvg(icon, x, y, size, cairo);1196#elif defined(FUZZEL_ENABLE_SVG_NANOSVG)
1 unmodified line
1198#elif defined(FUZZEL_ENABLE_SVG_RESVG)1199 render_svg_resvg(icon, x, y, size, pix, cairo, gamma_correct);1200#endif12011209 if (print_timing_info) {1210 gettimeofday(&stop, NULL);1211 timersub(&stop, &start, &diff);12121213 LOG_WARN("%s rendered in %llus %lluµs",1214 icon->path,1215 (unsigned long long)diff.tv_sec,1216 (unsigned long long)diff.tv_usec);1217 }1202 time_end(render_start, "%s rendered", icon->path);1203}12041205#if defined(FUZZEL_ENABLE_PNG_LIBPNG)1206static void
164 unmodified lines
1371{1372 assert(icon->type == ICON_PNG);13731374 if (icon->png == NULL) {1390 struct timeval start, stop, diff;1391 gettimeofday(&start, NULL);1375 struct timespec *start_load = time_begin();13761393 if (!icon_from_png(icon, icon->path, gamma_correct))1377 if (!icon_from_png(icon, icon->path, gamma_correct)) {1378 free(start_load);1379 return;13951396 if (print_timing_info) {1397 gettimeofday(&stop, NULL);1398 timersub(&stop, &start, &diff);1399 LOG_WARN("%s loaded in %llus %lluµs",1400 icon->path,1401 (unsigned long long)diff.tv_sec,1402 (unsigned long long)diff.tv_usec);1380 }13811382 time_end(start_load, "%s loaded", icon->path);1383 LOG_DBG("%s", icon->path);1384 }13851408 struct timeval start, stop, diff;1409 gettimeofday(&start, NULL);1386 struct timespec *start_render = time_begin();13871388#if defined(FUZZEL_ENABLE_PNG_LIBPNG)1389 render_png_libpng(icon, x, y, size, pix, cairo, scaling_filter);1390#endif13911415 if (print_timing_info) {1416 gettimeofday(&stop, NULL);1417 timersub(&stop, &start, &diff);1418 LOG_WARN("%s rendered in %llus %lluµs",1419 icon->path,1420 (unsigned long long)diff.tv_sec,1421 (unsigned long long)diff.tv_usec);1422 }1392 time_end(start_render, "%s rendered", icon->path);1393}13941395static int1396first_row_y(const struct render *render)
582 unmodified lines
added:timing.c+115 added
1#include "timing.h"23#include <stdarg.h>4#include <stdio.h>5#include <stdlib.h>67#define LOG_MODULE "timing"8#define LOG_ENABLE_DBG 09#include "log.h"10#include "xsnprintf.h"1112static struct timespec bootup = {0};13static bool enabled = false;1415void16time_init(void)17{18 clock_gettime(CLOCK_MONOTONIC, &bootup);19}2021void22time_enable(void)23{24 enabled = true;25}2627static void28timespec_sub(const struct timespec *a, const struct timespec *b,29 struct timespec *res)30{31 const long one_sec_in_ns = 1000000000;3233 res->tv_sec = a->tv_sec - b->tv_sec;34 res->tv_nsec = a->tv_nsec - b->tv_nsec;3536 /* tv_nsec may be negative */37 if (res->tv_nsec < 0) {38 res->tv_sec--;39 res->tv_nsec += one_sec_in_ns;40 }41}4243void44time_since_boot(const char *fmt, ...)45{46 if (!enabled)47 return;4849 struct timespec stop;50 clock_gettime(CLOCK_MONOTONIC, &stop);5152 struct timespec diff;53 timespec_sub(&stop, &bootup, &diff);5455 va_list va1, va2;56 va_start(va1, fmt);57 va_copy(va2, va1);5859 int len = vsnprintf(NULL, 0, fmt, va1);60 va_end(va1);6162 char msg[len + 1];63 xvsnprintf(msg, len + 1, fmt, va2);64 va_end(va2);656667 LOG_WARN("%s: %lds %ldµs since bootup", msg, diff.tv_sec, diff.tv_nsec / 1000);68}6970struct timespec *71time_begin(void)72{73 if (!enabled)74 return NULL;7576 struct timespec *ret = malloc(sizeof(*ret));77 if (ret == NULL)78 return NULL;7980 clock_gettime(CLOCK_MONOTONIC, ret);81 return ret;82}8384void85time_end(struct timespec *start, const char *fmt, ...)86{87 if (start == NULL)88 return;8990 if (!enabled) {91 free(start);92 return;93 }9495 struct timespec stop;96 clock_gettime(CLOCK_MONOTONIC, &stop);9798 struct timespec diff;99 timespec_sub(&stop, start, &diff);100101 va_list va1, va2;102 va_start(va1, fmt);103 va_copy(va2, va1);104105 int len = vsnprintf(NULL, 0, fmt, va1);106 va_end(va1);107108 char msg[len + 1];109 xvsnprintf(msg, len + 1, fmt, va2);110 va_end(va2);111112 LOG_WARN("%s in %lds %ldµs", msg, diff.tv_sec, diff.tv_nsec / 1000);113114 free(start);115}
added:timing.h+11 added
1#pragma once23#include <time.h>45void time_init(void);6void time_enable(void);78void time_since_boot(const char *fmt, ...) __attribute__((format(printf, 1, 2)));910struct timespec *time_begin(void);11void time_end(struct timespec *start, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
modified:wayland.c+6 added-11 removed
49 unmodified lines
50#include "shm.h"51#include "xmalloc.h"52#include "xsnprintf.h"5354#include "timing.h"5556#define min(x, y) ((x) < (y) ? (x) : (y))5758struct font_spec {59 char *pattern;
2446 unmodified lines
2506 wayl->need_refresh = true;2507 return;2508 }25092508 struct timeval start, stop, diff;2509 gettimeofday(&start, NULL);2510 struct timespec *start_frame = time_begin();25112512 if (wayl->chain == NULL) {2513 wayl->chain =2514 shm_chain_new(
80 unmodified lines
2595commit:2596 /* No pending frames - render immediately */2597 assert(!wayl->need_refresh);2598 commit_buffer(wayl, buf);25982599done:2600 if (wayl->conf->print_timing_info) {2601 gettimeofday(&stop, NULL);2602 timersub(&stop, &start, &diff);2603 LOG_WARN("%sframe rendered in %llus %lluµs",2604 wayl->render_first_frame_transparent ? "transparent " : "",2605 (unsigned long long)diff.tv_sec,2606 (unsigned long long)diff.tv_usec);2607 }2600 time_end(2601 start_frame, "%sframe rendered",2602 wayl->render_first_frame_transparent ? "transparent " : "");2603}26042605void2606wayl_ready_to_display(struct wayland *wayl)
551 unmodified lines