1
0
mirror of https://github.com/rricharz/Tek4010.git synced 2026-05-08 08:23:49 +00:00

Improved measuremt of slow graphics response

This commit is contained in:
Rene Richarz
2026-05-04 05:48:19 +02:00
parent af87f00e14
commit e83f654de3
2 changed files with 43 additions and 45 deletions

View File

@@ -63,6 +63,8 @@
#define SLOW_THRESHOLD 100 // ms: acceptable redraw latency
#define WINDOW_MSEC 10000 // ms: time window for detecting slow behavior
static long lastQueueDrawTime = 0;
extern FILE *putKeys;
char *windowName;
@@ -86,48 +88,50 @@ extern int tube_doClearPersistent;
static void do_drawing(cairo_t *, GtkWidget *);
void check_timer_interval(void)
long now_msec(void)
{
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec * 1000L + tv.tv_usec / 1000L;
}
void check_graphics_response(long lag)
{
static long last = 0;
static int slowCount = 0;
static long firstSlowTime = 0;
static int fastSwitched = 0;
struct timeval tv;
long now;
long diff;
gettimeofday(&tv, NULL);
now = tv.tv_sec * 1000L + tv.tv_usec / 1000L;
if (fastSwitched || argFast)
return;
if (last != 0) {
diff = now - last;
if (lag <= SLOW_THRESHOLD)
return;
if (!fastSwitched && diff > SLOW_THRESHOLD) {
if (slowCount == 0) {
firstSlowTime = now;
slowCount = 1;
}
else if ((now - firstSlowTime) <= WINDOW_MSEC) {
slowCount++;
}
else {
// restart detection window
firstSlowTime = now;
slowCount = 1;
}
now = tube_mSeconds();
if (slowCount >= 3) {
argFast = 1;
fastSwitched = 1;
printf("Slow graphics response -> switched to fast mode\n");
fflush(stdout);
}
}
if (slowCount == 0) {
firstSlowTime = now;
slowCount = 1;
}
else if ((now - firstSlowTime) <= WINDOW_MSEC) {
slowCount++;
}
else {
// restart detection window
firstSlowTime = now;
slowCount = 1;
}
last = now;
if (slowCount >= 3) {
argFast = 1;
fastSwitched = 1;
printf("Slow graphics response -> switched to fast mode\n");
fflush(stdout);
}
}
static gboolean on_draw_event(GtkWidget *widget, cairo_t *cr,
@@ -139,19 +143,12 @@ static gboolean on_draw_event(GtkWidget *widget, cairo_t *cr,
static gboolean on_timer_event(GtkWidget *widget)
{
/* static int count = 0;
count++;
if (count >= 100) {
printf("timer heartbeat\n");
fflush(stdout);
count = 0;
if (tube_on_timer_event()) {
lastQueueDrawTime = now_msec();
gtk_widget_queue_draw(widget);
}
*/
check_timer_interval();
if (tube_on_timer_event())
gtk_widget_queue_draw(widget);
return TRUE;
return TRUE;
}
static gboolean clicked(GtkWidget *widget, GdkEventButton *event, gpointer user_data)
@@ -174,6 +171,8 @@ static void do_drawing(cairo_t *cr, GtkWidget *widget)
// g_source_remove(global_timeout_ref); // stop timer, in case do_drawing takes too long
check_graphics_response(now_msec() - lastQueueDrawTime);
if (global_firstcall) {
// force aspect ratio by making black stripes at left and right, or top and bottom
gtk_window_get_size(GTK_WINDOW(window), &windowWidth, &windowHeight);
@@ -321,7 +320,8 @@ static void on_key_press(GtkWidget *widget, GdkEventKey *event, gpointer user_da
}
}
else {
if (ch == '\r')
/* if (ch == '\r')
printf("KEY <CR>\n");
else if (ch == '\n')
printf("KEY <LF>\n");
@@ -330,6 +330,7 @@ static void on_key_press(GtkWidget *widget, GdkEventKey *event, gpointer user_da
else
printf("KEY <%02X>\n", ch & 0xFF);
fflush(stdout);
*/
putc(ch, putKeys);
fflush(putKeys);

View File

@@ -344,9 +344,6 @@ void tek4010_draw(cairo_t *cr, cairo_t *cr2, int first)
{
int ch, tag;
printf(".");
fflush(stdout);
refreshCount++;