Commit: c0aeb541f3ff1298c808165ff98b51986fcf23d9
Parent: a9781ad8f2a0d97c0685ffc9c871c2ee638f1e29
Author: Randy Palamar
Date: Sat, 19 Oct 2024 20:50:50 -0600
more debug timers
Diffstat:
M | main.c | | | 2 | -- |
M | terminal.c | | | 50 | +++++++++++++++++++++++++++++++++++++++++++------- |
M | vtgl.c | | | 27 | +++++++++------------------ |
3 files changed, 52 insertions(+), 27 deletions(-)
diff --git a/main.c b/main.c
@@ -1,7 +1,5 @@
/* See LICENSE for copyright details */
#define GL_GLEXT_PROTOTYPES 1
-#include <GL/glcorearb.h>
-#include <GL/glext.h>
#include <GLFW/glfw3.h>
#include "util.h"
diff --git a/terminal.c b/terminal.c
@@ -152,6 +152,7 @@ is_selected(Selection *s, i32 x, i32 y)
static void
fb_clear_region(Term *t, u32 r1, u32 r2, u32 c1, u32 c2)
{
+ BEGIN_TIMED_BLOCK();
u32 tmp;
if (r1 > r2) {
tmp = r1;
@@ -177,6 +178,7 @@ fb_clear_region(Term *t, u32 r1, u32 r2, u32 c1, u32 c2)
selection_clear(&t->selection);
}
}
+ END_TIMED_BLOCK();
}
static void
@@ -456,6 +458,7 @@ clear_term_tab(Term *t, i32 arg)
static void
set_mode(Term *t, CSI *csi, b32 set)
{
+ BEGIN_TIMED_BLOCK();
i32 alt = t->view_idx;
#define PRIV(a) ((1 << 30) | (a))
for (i32 i = 0; i < csi->argc; i++) {
@@ -524,6 +527,7 @@ set_mode(Term *t, CSI *csi, b32 set)
}
}
#undef PRIV
+ END_TIMED_BLOCK();
}
/* NOTE: adapted from the perl script 256colres.pl in xterm src */
@@ -598,6 +602,7 @@ direct_colour(i32 *argv, i32 argc, i32 *idx)
static void
set_colours(Term *t, CSI *csi)
{
+ BEGIN_TIMED_BLOCK();
CellStyle *cs = &t->cursor.style;
struct conversion_result dcr;
for (i32 i = 0; i < csi->argc; i++) {
@@ -657,6 +662,7 @@ set_colours(Term *t, CSI *csi)
}
}
}
+ END_TIMED_BLOCK();
}
static void
@@ -716,6 +722,9 @@ push_tab(Term *t, i32 n)
static i32
parse_csi(s8 *r, CSI *csi)
{
+ BEGIN_TIMED_BLOCK();
+ i32 result = 0;
+
if (peek(*r, 0) == '?') {
csi->priv = 1;
get_ascii(r);
@@ -735,16 +744,21 @@ parse_csi(s8 *r, CSI *csi)
if (cp != ';' || csi->argc == ESC_ARG_SIZ) {
if (cp == ';') csi->mode = get_ascii(r);
else csi->mode = cp;
- return 0;
+ goto end;
}
}
/* NOTE: if we fell out of the loop then we ran out of characters */
- return -1;
+ result = -1;
+end:
+ END_TIMED_BLOCK();
+
+ return result;
}
static void
handle_csi(Term *t, CSI *csi)
{
+ BEGIN_TIMED_BLOCK();
s8 raw = csi->raw;
i32 ret = parse_csi(&raw, csi);
ASSERT(ret != -1);
@@ -805,11 +819,16 @@ handle_csi(Term *t, CSI *csi)
os_write_err_msg(s8("unknown csi: "));
dump_csi(csi);
}
+ END_TIMED_BLOCK();
}
static i32
parse_osc(s8 *raw, OSC *osc)
{
+ BEGIN_TIMED_BLOCK();
+
+ i32 result = 0;
+
*osc = (OSC){0};
osc->raw.data = raw->data;
@@ -838,16 +857,20 @@ parse_osc(s8 *raw, OSC *osc)
cp = get_ascii(raw);
osc->raw.len++;
if (cp == '\a')
- return 0;
+ goto end;
if (cp == 0x1B && peek(*raw, 0) == '\\') {
get_ascii(raw);
osc->raw.len++;
- return 0;
+ goto end;
}
osc->arg.len++;
}
/* NOTE: if we fell out of the loop then we ran out of characters */
- return -1;
+ result = -1;
+end:
+ END_TIMED_BLOCK();
+
+ return result;
}
static void
@@ -880,6 +903,7 @@ dump_osc(OSC *osc)
static void
handle_osc(Term *t, s8 *raw, Arena a)
{
+ BEGIN_TIMED_BLOCK();
OSC osc;
i32 ret = parse_osc(raw, &osc);
ASSERT(ret != -1);
@@ -893,11 +917,13 @@ handle_osc(Term *t, s8 *raw, Arena a)
dump_osc(&osc);
break;
}
+ END_TIMED_BLOCK();
}
static void
handle_escape(Term *t, s8 *raw, Arena a)
{
+ BEGIN_TIMED_BLOCK();
u32 cp = get_ascii(raw);
switch (cp) {
case '[': reset_csi(&t->csi, raw); t->escape |= EM_CSI; break;
@@ -942,6 +968,7 @@ handle_escape(Term *t, s8 *raw, Arena a)
fprintf(stderr, "unknown escape sequence: ESC %c (0x%02x)\n", cp, cp);
break;
}
+ END_TIMED_BLOCK();
}
static void
@@ -1017,9 +1044,13 @@ check_if_csi_moves_cursor(Term *t, s8 *raw)
static enum escape_moves_cursor_result
check_if_escape_moves_cursor(Term *t, s8 *raw)
{
+ BEGIN_TIMED_BLOCK();
+
enum escape_moves_cursor_result result = EMC_NORMAL_RETURN;
- if (raw->len < 2)
- return EMC_NEEDS_MORE_BYTES;
+ if (raw->len < 2) {
+ result = EMC_NEEDS_MORE_BYTES;
+ goto end;
+ }
u32 cp = get_ascii(raw);
switch(cp) {
case '[':
@@ -1053,6 +1084,8 @@ check_if_escape_moves_cursor(Term *t, s8 *raw)
break;
default: break;
}
+end:
+ END_TIMED_BLOCK();
return result;
}
@@ -1162,6 +1195,8 @@ end:
static void
push_line(Term *t, Line *line, Arena a)
{
+ BEGIN_TIMED_BLOCK();
+
TermView *tv = t->views + t->view_idx;
s8 l = line_to_s8(line, &tv->log);
t->cursor.style = line->cursor_state;
@@ -1230,6 +1265,7 @@ push_line(Term *t, Line *line, Arena a)
if (is_selected(&t->selection, t->cursor.pos.x, t->cursor.pos.y))
selection_clear(&t->selection);
}
+ END_TIMED_BLOCK();
}
static size
diff --git a/vtgl.c b/vtgl.c
@@ -1,7 +1,5 @@
/* See LICENSE for copyright details */
#define GL_GLEXT_PROTOTYPES 1
-#include <GL/glcorearb.h>
-#include <GL/glext.h>
#include <GLFW/glfw3.h>
#include "util.h"
@@ -871,16 +869,16 @@ draw_debug_overlay(Term *t, RenderPushBuffer *rpb)
glUniform1i(t->gl.render.texslot, 1);
v2 ws = t->gl.window_size;
- s8 buf = s8alloc(&t->arena_for_frame, 128);
+ s8 buf = s8alloc(&t->arena_for_frame, 1024);
static GlyphCacheStats glyph_stats;
static Rect r;
static f32 max_text_width;
- r.pos.x = ws.w - 1.1 * max_text_width;
- r.size.x = 1.1 * max_text_width;
+ r.pos.x = ws.w - (max_text_width + 20);
+ r.size.x = max_text_width + 20;
Colour fg = {.rgba = 0x1e9e33ff};
- Colour bg = {.rgba = 0x222222ff};
+ Colour bg = {.rgba = 0x090909ff};
draw_rectangle(rpb, &t->gl, r, bg);
@@ -889,7 +887,7 @@ draw_debug_overlay(Term *t, RenderPushBuffer *rpb)
{
s8 txt = buf;
- txt.len = snprintf((char *)txt.data, buf.len, "Render Time: %0.02f ms/f", dt_for_frame * 1e3);
+ txt.len = snprintf((char *)txt.data, buf.len, "Render Time: %0.02f ms/f", dt_for_frame * 1e3);
v2 ts = debug_measure_text(t, &t->debug_font, txt, 1);
txt_pos.y = (u32)(txt_pos.y - ts.y - line_pad);
debug_draw_text(t, rpb, txt, txt_pos, fg, bg, 1);
@@ -903,18 +901,11 @@ draw_debug_overlay(Term *t, RenderPushBuffer *rpb)
DebugRecord *dr = debug_records + i;
- s8 txt = buf;
- txt.len = snprintf((char *)txt.data, buf.len, "%s: %u %s", dr->function_name,
- hits[i], hits[i] > 1? "hits" : "hit");
- v2 ts = debug_measure_text(t, &t->debug_font, txt, 1);
- txt_pos.y = (u32)(txt_pos.y - ts.y - line_pad);
- debug_draw_text(t, rpb, txt, txt_pos, fg, bg, 1);
-
- if (ts.w > max_text_width) max_text_width = ts.w;
-
- txt.len = snprintf((char *)txt.data, buf.len, " %0.02f cycs/hit",
+ s8 txt = buf;
+ txt.len = snprintf((char *)txt.data, buf.len, "%29s: %5u %4s %11.02f cycs/hit",
+ dr->function_name, hits[i], hits[i] > 1? "hits" : "hit",
(f32)cycs[i]/(f32)hits[i]);
- ts = debug_measure_text(t, &t->debug_font, txt, 1);
+ v2 ts = debug_measure_text(t, &t->debug_font, txt, 1);
txt_pos.y = (u32)(txt_pos.y - ts.y - line_pad);
debug_draw_text(t, rpb, txt, txt_pos, fg, bg, 1);