summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-08-24 19:50:44 -0300
committerWerner Almesberger <werner@almesberger.net>2016-08-24 19:50:44 -0300
commit51e5f3fd52b7b338a153857b1d7dd01d632097bb (patch)
treecc0b7e2d2066d6b17fb97076a0850c43b3f903b5
parent891cec01ba4dace8feba7636c0f9aa293324cf09 (diff)
downloadeeshow-51e5f3fd52b7b338a153857b1d7dd01d632097bb.tar.gz
eeshow-51e5f3fd52b7b338a153857b1d7dd01d632097bb.tar.bz2
eeshow-51e5f3fd52b7b338a153857b1d7dd01d632097bb.zip
GUI performance timer, toggle with "T"
Shows milliseconds between last event and completion of screen update.
-rw-r--r--Makefile2
-rw-r--r--README1
-rw-r--r--gui/input.c11
-rw-r--r--gui/render.c3
-rw-r--r--gui/sheet.c6
-rw-r--r--gui/timer.c78
-rw-r--r--gui/timer.h23
-rw-r--r--help.html3
-rw-r--r--help.txt1
9 files changed, 127 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index b02907e..687ab2f 100644
--- a/Makefile
+++ b/Makefile
@@ -19,7 +19,7 @@ OBJS = main.o version.o \
kicad/pl-parse.o kicad/pl-render.o kicad/ext.o kicad/pro.o \
gui/gui.o gui/over.o gui/style.o gui/aoi.o gui/fmt-pango.o gui/input.o \
gui/progress.o gui/glabel.o gui/sheet.o gui/history.o gui/render.o \
- gui/help.o gui/icons.o gui/index.o \
+ gui/help.o gui/icons.o gui/index.o gui/timer.o \
file/file.o file/git-util.o file/git-file.o file/git-hist.o \
gfx/style.o gfx/fig.o gfx/record.o gfx/cro.o gfx/diff.o gfx/gfx.o \
gfx/text.o gfx/misc.o gfx/pdftoc.o \
diff --git a/README b/README
index 2466805..573d00e 100644
--- a/README
+++ b/README
@@ -201,6 +201,7 @@ Esc cancel current action (exit history, close pop-up,
de-highlight glabel, close help)
E show/hide extra information (pin types)
H show/hide help window
+T toggle performance timer
D when comparing revisions, show difference (default)
N show newer sheet
O show older sheet
diff --git a/gui/input.c b/gui/input.c
index f005527..49e310c 100644
--- a/gui/input.c
+++ b/gui/input.c
@@ -19,6 +19,7 @@
#include "misc/util.h"
#include "misc/diag.h"
+#include "gui/timer.h"
#include "gui/input.h"
@@ -183,6 +184,8 @@ static gboolean motion_notify_event(GtkWidget *widget, GdkEventMotion *event,
progress(3, "motion %s", state());
+ timer_start();
+
switch (sp->state) {
case input_idle:
hover_consider(event->x, event->y);
@@ -224,6 +227,8 @@ static gboolean button_press_event(GtkWidget *widget, GdkEventButton *event,
progress(3, "press %s", state());
+ timer_start();
+
buttons |= 1 << event->button;
switch (sp->state) {
@@ -261,6 +266,8 @@ static gboolean button_release_event(GtkWidget *widget, GdkEventButton *event,
progress(3, "release %s", state());
+ timer_start();
+
buttons &= ~(1 << event->button);
if (buttons)
return TRUE;
@@ -307,6 +314,8 @@ static gboolean button_release_event(GtkWidget *widget, GdkEventButton *event,
static gboolean scroll_event(GtkWidget *widget, GdkEventScroll *event,
gpointer data)
{
+ timer_start();
+
if (!sp || !sp->ops->scroll)
return TRUE;
switch (event->direction) {
@@ -329,6 +338,8 @@ static gboolean scroll_event(GtkWidget *widget, GdkEventScroll *event,
static gboolean key_press_event(GtkWidget *widget, GdkEventKey *event,
gpointer data)
{
+ timer_start();
+
if (sp && sp->ops->key)
sp->ops->key(sp->user, curr_x, curr_y, event->keyval);
return TRUE;
diff --git a/gui/render.c b/gui/render.c
index 2411fd6..214b7b2 100644
--- a/gui/render.c
+++ b/gui/render.c
@@ -29,6 +29,7 @@
#include "gfx/diff.h"
#include "gui/aoi.h"
#include "gui/over.h"
+#include "gui/timer.h"
#include "gui/common.h"
@@ -241,6 +242,8 @@ static gboolean on_draw_event(GtkWidget *widget, cairo_t *cr,
if (ctx->mode == showing_index)
index_draw_event(ctx, cr);
+ timer_show(cr);
+
return FALSE;
}
diff --git a/gui/sheet.c b/gui/sheet.c
index 3e65f28..f500078 100644
--- a/gui/sheet.c
+++ b/gui/sheet.c
@@ -26,6 +26,7 @@
#include "gui/input.h"
#include "gui/help.h"
#include "gui/icons.h"
+#include "gui/timer.h"
#include "gui/common.h"
@@ -577,6 +578,11 @@ static void sheet_key(void *user, int x, int y, int keyval)
help();
break;
+ case GDK_KEY_t:
+ timer_toggle();
+ redraw(ctx);
+ break;
+
case GDK_KEY_q:
gtk_main_quit();
}
diff --git a/gui/timer.c b/gui/timer.c
new file mode 100644
index 0000000..6d6cdd6
--- /dev/null
+++ b/gui/timer.c
@@ -0,0 +1,78 @@
+/*
+ * gui/timer.c - Performance timer
+ *
+ * Written 2016 by Werner Almesberger
+ * Copyright 2016 by Werner Almesberger
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#define _GNU_SOURCE /* for asprintf */
+#include <stdbool.h>
+#include <stdio.h>
+#include <sys/time.h>
+
+#include <cairo/cairo.h>
+
+#include "gui/timer.h"
+
+
+static bool timer_enabled = 0;
+static struct timeval then;
+
+
+void timer_start(void)
+{
+ if (timer_enabled)
+ gettimeofday(&then, NULL);
+}
+
+
+static void timer_show_cairo(cairo_t *cr, const char *s)
+{
+ double x1, y1, x2, y2;
+ cairo_text_extents_t ext;
+
+ cairo_reset_clip(cr);
+ cairo_clip_extents(cr, &x1, &y1, &x2, &y2);
+ cairo_select_font_face(cr, "Mono Sans",
+ CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
+ cairo_set_font_size(cr, 20);
+ cairo_text_extents(cr, s, &ext);
+ cairo_move_to(cr, x2 - ext.width - 4, y2 - 4);
+ cairo_set_source_rgb(cr, 0, 0, 0.7);
+ cairo_show_text(cr, s);
+}
+
+
+void timer_show(cairo_t *cr)
+{
+ struct timeval now;
+ char *s;
+
+ if (!timer_enabled)
+ return;
+
+ gettimeofday(&now, NULL);
+ now.tv_sec -= then.tv_sec;
+ now.tv_usec -= then.tv_usec;
+ if (now.tv_usec < 0) {
+ now.tv_sec--;
+ now.tv_usec += 1000000;
+ }
+
+
+ if (asprintf(&s , "%u.%03d",
+ (unsigned) now.tv_sec, (int) now.tv_usec / 1000)) {}
+ timer_show_cairo(cr, s);
+}
+
+
+void timer_toggle(void)
+{
+ timer_enabled = !timer_enabled;
+ timer_start();
+}
diff --git a/gui/timer.h b/gui/timer.h
new file mode 100644
index 0000000..cdda945
--- /dev/null
+++ b/gui/timer.h
@@ -0,0 +1,23 @@
+/*
+ * gui/timer.h - Performance timer
+ *
+ * Written 2016 by Werner Almesberger
+ * Copyright 2016 by Werner Almesberger
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#ifndef GUI_TIMER_H
+#define GUI_TIMER_H
+
+#include <cairo/cairo.h>
+
+
+void timer_start(void);
+void timer_show(cairo_t *cr);
+void timer_toggle(void);
+
+#endif /* !GUI_TIMER_H */
diff --git a/help.html b/help.html
index 7b4c1f8..af76d74 100644
--- a/help.html
+++ b/help.html
@@ -39,6 +39,9 @@
<TD>H
<TD>open/close help window
<TR>
+ <TD>T
+ <TD>toggle performance timer
+ <TR>
<TD>D
<TD>when comparing revisions, show difference
<TR>
diff --git a/help.txt b/help.txt
index 5f18ab7..0545d7b 100644
--- a/help.txt
+++ b/help.txt
@@ -13,6 +13,7 @@ Esc cancel current action (exit history, close
pop-up, de-highlight glabel, close help)
E show/hide extra information (pin types)
H show/hide help window
+T toggle performance timer
D when comparing revisions, show difference
N show newer sheet
O show older sheet