Codebergdnkl

foot

master
ply5 git calls543 ms31 KiB3 cachedprotocol v2
441 lines11 KiBRaw
1#include <stdlib.h>
2#include <stdio.h>
3#include <string.h>
4#include <unistd.h>
5#include <errno.h>
7#include <sys/types.h>
8#include <sys/stat.h>
9#include <sys/epoll.h>
10#include <sys/timerfd.h>
11#include <sys/mman.h>
12#include <fcntl.h>
14#include "async.h"
15#include "config.h"
16#include "key-binding.h"
17#include "reaper.h"
18#include "sixel.h"
19#include "user-notification.h"
20#include "vt.h"
22extern bool fdm_ptmx(struct fdm *fdm, int fd, int events, void *data);
24static void
25usage(const char *prog_name)
27 printf(
28 "Usage: %s stimuli-file1 stimuli-file2 ... stimuli-fileN\n",
29 prog_name);
32enum async_write_status
33async_write(int fd, const void *data, size_t len, size_t *idx)
35 return ASYNC_WRITE_DONE;
38bool
39fdm_add(struct fdm *fdm, int fd, int events, fdm_fd_handler_t handler, void *data)
41 return true;
44bool
45fdm_del(struct fdm *fdm, int fd)
47 return true;
50bool
51fdm_event_add(struct fdm *fdm, int fd, int events)
53 return true;
56bool
57fdm_event_del(struct fdm *fdm, int fd, int events)
59 return true;
62bool
63render_resize(
64 struct terminal *term, int width, int height, uint8_t resize_options)
66 return true;
69void render_refresh(struct terminal *term) {}
70void render_refresh_csd(struct terminal *term) {}
71void render_refresh_title(struct terminal *term) {}
72void render_refresh_app_id(struct terminal *term) {}
73void render_refresh_icon(struct terminal *term) {}
75void render_overlay(struct terminal *term) {}
77void render_buffer_release_callback(struct buffer *buf, void *data) {}
79bool
80render_xcursor_is_valid(const struct seat *seat, const char *cursor)
82 return true;
85bool
86render_xcursor_set(struct seat *seat, struct terminal *term, enum cursor_shape shape)
88 return true;
91enum cursor_shape
92xcursor_for_csd_border(struct terminal *term, int x, int y)
94 return CURSOR_SHAPE_LEFT_PTR;
97struct wl_window *
98wayl_win_init(struct terminal *term, const char *token)
100 return NULL;
103void wayl_win_destroy(struct wl_window *win) {}
104void wayl_win_alpha_changed(struct wl_window *win) {}
105bool wayl_win_set_urgent(struct wl_window *win) { return true; }
106bool wayl_win_ring_bell(const struct wl_window *win) { return true; }
107bool wayl_fractional_scaling(const struct wayland *wayl) { return true; }
109pid_t
110spawn(struct reaper *reaper, const char *cwd, char *const argv[],
111 int stdin_fd, int stdout_fd, int stderr_fd,
112 reaper_cb cb, void *cb_data, const char *xdg_activation_token)
114 return 2;
117pid_t
118slave_spawn(
119 int ptmx, int argc, const char *cwd, char *const *argv, char *const *envp,
120 const env_var_list_t *extra_env_vars, const char *term_env,
121 const char *conf_shell, bool login_shell,
122 const user_notifications_t *notifications)
124 return 0;
127int
128render_worker_thread(void *_ctx)
130 return 0;
133bool
134wayl_do_linear_blending(const struct wayland *wayl, const struct config *conf)
136 return false;
139struct extraction_context *
140extract_begin(enum selection_kind kind, bool strip_trailing_empty)
142 return NULL;
145bool
146extract_one(
147 const struct terminal *term, const struct row *row, const struct cell *cell,
148 int col, void *context)
150 return true;
153bool
154extract_finish(struct extraction_context *context, char **text, size_t *len)
156 return true;
159void cmd_scrollback_up(struct terminal *term, int rows) {}
160void cmd_scrollback_down(struct terminal *term, int rows) {}
162void ime_enable(struct seat *seat) {}
163void ime_disable(struct seat *seat) {}
164void ime_reset_preedit(struct seat *seat) {}
166bool
167notify_notify(struct terminal *term, struct notification *notif)
169 return true;
172void
173notify_close(struct terminal *term, const char *id)
177void
178notify_free(struct terminal *term, struct notification *notif)
182void
183notify_icon_add(struct terminal *term, const char *id,
184 const char *symbolic_name, const uint8_t *data,
185 size_t data_sz)
189void
190notify_icon_del(struct terminal *term, const char *id)
194void
195notify_icon_free(struct notification_icon *icon)
199void reaper_add(struct reaper *reaper, pid_t pid, reaper_cb cb, void *cb_data) {}
200void reaper_del(struct reaper *reaper, pid_t pid) {}
202void urls_reset(struct terminal *term) {}
204void shm_unref(struct buffer *buf) {}
205void shm_chain_free(struct buffer_chain *chain) {}
206enum shm_bit_depth shm_chain_bit_depth(const struct buffer_chain *chain) { return SHM_BITS_8; }
208struct buffer_chain *
209shm_chain_new(
210 struct wayland *wayl, bool scrollable, size_t pix_instances,
211 enum shm_bit_depth desired_bit_depth,
212 void (*release_cb)(struct buffer *buf, void *data), void *cb_data)
214 return NULL;
218void search_selection_cancelled(struct terminal *term) {}
220void get_current_modifiers(const struct seat *seat,
221 xkb_mod_mask_t *effective,
222 xkb_mod_mask_t *consumed, uint32_t key,
223 bool filter_locked) {}
225static struct key_binding_set kbd;
226static bool kbd_initialized = false;
228struct key_binding_set *
229key_binding_for(
230 struct key_binding_manager *mgr, const struct config *conf,
231 const struct seat *seat)
233 return &kbd;
236void
237key_binding_new_for_conf(
238 struct key_binding_manager *mgr, const struct wayland *wayl,
239 const struct config *conf)
241 if (!kbd_initialized) {
242 kbd_initialized = true;
243 kbd = (struct key_binding_set){
244 .key = tll_init(),
245 .search = tll_init(),
246 .url = tll_init(),
247 .mouse = tll_init(),
248 .selection_overrides = 0,
249 };
250 }
253void
254key_binding_unref(struct key_binding_manager *mgr, const struct config *conf)
258int
259main(int argc, const char *const *argv)
261 if (argc < 2) {
262 usage(argv[0]);
263 return EXIT_FAILURE;
264 }
266 const int row_count = 67;
267 const int col_count = 135;
268 const int grid_row_count = 16384;
270 int lower_fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK);
271 if (lower_fd < 0)
272 return EXIT_FAILURE;
274 int upper_fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK);
275 if (upper_fd < 0) {
276 close(lower_fd);
277 return EXIT_FAILURE;
278 }
280 struct row **normal_rows = calloc(grid_row_count, sizeof(normal_rows[0]));
281 struct row **alt_rows = calloc(grid_row_count, sizeof(alt_rows[0]));
283 for (int i = 0; i < grid_row_count; i++) {
284 normal_rows[i] = calloc(1, sizeof(*normal_rows[i]));
285 normal_rows[i]->cells = calloc(col_count, sizeof(normal_rows[i]->cells[0]));
286 alt_rows[i] = calloc(1, sizeof(*alt_rows[i]));
287 alt_rows[i]->cells = calloc(col_count, sizeof(alt_rows[i]->cells[0]));
288 }
290 struct config conf = {
291 .tweak = {
292 .delayed_render_lower_ns = 500000, /* 0.5ms */
293 .delayed_render_upper_ns = 16666666 / 2, /* half a frame period (60Hz) */
294 },
295 };
297 struct wayland wayl = {
298 .seats = tll_init(),
299 .monitors = tll_init(),
300 .terms = tll_init(),
301 };
303 struct terminal term = {
304 .conf = &conf,
305 .wl = &wayl,
306 .grid = &term.normal,
307 .normal = {
308 .num_rows = grid_row_count,
309 .num_cols = col_count,
310 .rows = normal_rows,
311 .cur_row = normal_rows[0],
312 },
313 .alt = {
314 .num_rows = grid_row_count,
315 .num_cols = col_count,
316 .rows = alt_rows,
317 .cur_row = alt_rows[0],
318 },
319 .scale = 1,
320 .width = col_count * 8,
321 .height = row_count * 15,
322 .cols = col_count,
323 .rows = row_count,
324 .cell_width = 8,
325 .cell_height = 15,
326 .scroll_region = {
327 .start = 0,
328 .end = row_count,
329 },
330 .selection = {
331 .coords = {
332 .start = {-1, -1},
333 .end = {-1, -1},
334 },
335 },
336 .delayed_render_timer = {
337 .lower_fd = lower_fd,
338 .upper_fd = upper_fd
339 },
340 .sixel = {
341 .palette_size = SIXEL_MAX_COLORS,
342 .max_width = SIXEL_MAX_WIDTH,
343 .max_height = SIXEL_MAX_HEIGHT,
344 },
345 };
347 tll_push_back(wayl.terms, &term);
349 int ret = EXIT_FAILURE;
351 for (int i = 1; i < argc; i++) {
352 struct stat st;
353 if (stat(argv[i], &st) < 0) {
354 fprintf(stderr, "error: %s: failed to stat: %s\n",
355 argv[i], strerror(errno));
356 goto out;
357 }
359 uint8_t *data = malloc(st.st_size);
360 if (data == NULL) {
361 fprintf(stderr, "error: %s: failed to allocate buffer: %s\n",
362 argv[i], strerror(errno));
363 goto out;
364 }
366 int fd = open(argv[1], O_RDONLY);
367 if (fd < 0) {
368 fprintf(stderr, "error: %s: failed to open: %s\n",
369 argv[i], strerror(errno));
370 goto out;
371 }
373 ssize_t amount = read(fd, data, st.st_size);
374 if (amount != st.st_size) {
375 fprintf(stderr, "error: %s: failed to read: %s\n",
376 argv[i], strerror(errno));
377 goto out;
378 }
380 close(fd);
382#if defined(MEMFD_CREATE)
383 int mem_fd = memfd_create("foot-pgo-ptmx", MFD_CLOEXEC);
384#elif defined(__FreeBSD__)
385 // memfd_create on FreeBSD 13 is SHM_ANON without sealing support
386 int mem_fd = shm_open(SHM_ANON, O_RDWR | O_CLOEXEC, 0600);
387#else
388 char name[] = "/tmp/foot-pgo-ptmx-XXXXXX";
389 int mem_fd = mkostemp(name, O_CLOEXEC);
390 unlink(name);
391#endif
392 if (mem_fd < 0) {
393 fprintf(stderr, "error: failed to create memory FD\n");
394 goto out;
395 }
397 if (write(mem_fd, data, st.st_size) < 0) {
398 fprintf(stderr, "error: failed to write memory FD\n");
399 close(mem_fd);
400 goto out;
401 }
403 free(data);
405 term.ptmx = mem_fd;
406 lseek(mem_fd, 0, SEEK_SET);
408 printf("Feeding VT parser with %s (%lld bytes)\n",
409 argv[i], (long long)st.st_size);
411 while (lseek(mem_fd, 0, SEEK_CUR) < st.st_size) {
412 if (!fdm_ptmx(NULL, -1, EPOLLIN, &term)) {
413 fprintf(stderr, "error: fdm_ptmx() failed\n");
414 close(mem_fd);
415 goto out;
416 }
417 }
418 close(mem_fd);
419 }
421 ret = EXIT_SUCCESS;
423out:
424 tll_free(wayl.terms);
426 for (int i = 0; i < grid_row_count; i++) {
427 if (normal_rows[i] != NULL)
428 free(normal_rows[i]->cells);
429 free(normal_rows[i]);
431 if (alt_rows[i] != NULL)
432 free(alt_rows[i]->cells);
433 free(alt_rows[i]);
434 }
436 free(normal_rows);
437 free(alt_rows);
438 close(lower_fd);
439 close(upper_fd);
440 return ret;
Diagnostics5 git calls · 543 ms
CallStatusSizeTime0543 ms
discover200178 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=178
git.server.agent=git/2.56.1-Linux
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch server-option object-format
git.server.fetch=shallow wait-for-done filter
git.protocol.version=2
git.pkt.frames=9
git.pkt.data=7
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=178
git.pkt.payload.max=35
ls-refs20010 KiB513 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=513
git.response.bytes=10322
git.response.cache=EXPIRED
git.response.duration_ms=513
git.protocol.version=2
git.pkt.frames=108
git.pkt.data=107
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=10322
git.pkt.payload.max=106
git.ls_refs.count=107
git.ls_refs.head=refs/heads/master
fetchcombine:blob:none+tree:2 · deepen 12008.6 KiB · hit4 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=4
git.response.bytes=8830
git.response.cache=HIT
git.response.duration_ms=4
git.fetch.filter=combine:blob:none+tree:2
git.fetch.wants=c0d2c3e95d74cb60526ff28aec9f34ee3df545e0
git.fetch.haves.count=0
git.fetch.deepen=1
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=7
git.pkt.data=5
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=8830
git.pkt.payload.max=8730
git.sideband.band1.bytes=8730
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=14
git.pack.bytes=8730
git.fetch.wide.objects=14
git.fetch.wide.extra_bytes=9909
git.fetch.wide.blobs=0
fetchtree:0 · deepen 102009.3 KiB · hit4 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=4
git.response.bytes=9489
git.response.cache=HIT
git.response.duration_ms=4
git.fetch.filter=tree:0
git.fetch.wants=c0d2c3e95d74cb60526ff28aec9f34ee3df545e0
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=7
git.pkt.data=5
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=9489
git.pkt.payload.max=9389
git.sideband.band1.bytes=9389
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=10
git.pack.bytes=9389
git.pack.ofs_delta=0
git.pack.ref_delta=0
git.pack.chain.max=0
git.pack.trailer=de930681b6073ba5b599a0f956bfbd114762ad5a
git.pack.full=10
Open pack map
fetch2003.0 KiB · hit26 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=26
git.response.bytes=3041
git.response.cache=HIT
git.response.duration_ms=26
git.fetch.wants=4ff4111c523ebf74f5c5f168c65f351427357f98
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=3041
git.pkt.payload.max=3014
git.sideband.band1.bytes=3014
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://codeberg.org/dnkl/foot
Ref
refs/heads/master
Commit
c0d2c3e95d74cb60526ff28aec9f34ee3df545e0
cf-ray
a5e2fb629f67cf81
Request
5d369662…
Protocol
v2 · sha1
Agent
git/2.56.1-Linux
Filter
advertised
Fetch
shallow wait-for-done filter
Capabilities
agent ls-refs fetch server-option object-format