]> git.mdlowis.com Git - archive/tide-ocaml.git/commitdiff
Added some timestamps for event loop profiling
authorMichael D. Lowis <mike.lowis@gentex.com>
Mon, 16 Oct 2017 18:39:06 +0000 (14:39 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Mon, 16 Oct 2017 18:39:06 +0000 (14:39 -0400)
edit.ml
lib/x11_prims.c

diff --git a/edit.ml b/edit.ml
index 0e1159f8f7ec82d09568ca21b016fc802cb502e4..9ba8547c6222c28995e9f9e2ab7cb52b9e184e64 100644 (file)
--- a/edit.ml
+++ b/edit.ml
@@ -1,9 +1,10 @@
 open X11
 
-let font = font_load "Times New Roman:size=12"
 (*
+let font = font_load "Times New Roman:size=12"
 let font = font_load "Monaco:size=10::antialias=true:autohint=true"
 *)
+let font = font_load "Sans Serif:size=11:antialias=true:autohint=true"
 
 let tags_buf = ref Buf.create
 let edit_buf = ref Buf.create
@@ -22,7 +23,7 @@ let draw_gray_bkg  = draw_bkg Cfg.Color.palette.(3)
 
 let draw_text text pos =
   draw_string font Cfg.Color.palette.(5) text (pos.x + 2, pos.y + 2);
-  { pos with y = (pos.y + 2 + font.height) }
+  { pos with y = (pos.y + 4 + font.height) }
 
 let draw_hrule width pos =
   draw_gray_bkg width 1 pos;
@@ -70,21 +71,22 @@ let draw_buffer pos width height =
 
 let draw_edit pos width height =
   draw_dark_bkg (width - pos.x) (height - pos.y) pos;
-  draw_buffer { pos with x = pos.x + 2 } width height
+  draw_buffer { x = pos.x + 4; y = pos.y + 2} width height
+  (* { pos with x = pos.x + 2  and} width height *)
 
 (* Event functions
  ******************************************************************************)
 let onfocus focused =
-  print_endline "onfocus"
+  () (*print_endline "onfocus"*)
 
 let onkeypress mods rune =
-  print_endline "onkeypress"
+  () (*print_endline "onkeypress"*)
 
 let onmousebtn mods btn x y pressed =
-  print_endline "onmousebtn"
+  () (*print_endline "onmousebtn"*)
 
 let onmousemove mods x y =
-  print_endline "onmousemove"
+  () (*print_endline "onmousemove"*)
 
 let onupdate width height =
   let (pos : drawpos) = { x = 0; y = 0 } in
@@ -103,11 +105,11 @@ let onevent = function
   | MouseClick e     -> onmousebtn e.mods e.btn e.x e.y true
   | MouseRelease e   -> onmousebtn e.mods e.btn e.x e.y false
   | MouseMove e      -> onmousemove e.mods e.x e.y
-  | Paste e          -> print_endline "paste"
-  | Command e        -> print_endline "command"
-  | PipeClosed e     -> print_endline "pipeclosed"
-  | PipeWriteReady e -> print_endline "pipewriteready"
-  | PipeReadReady e  -> print_endline "pipereadready"
+  | Paste e          -> () (*print_endline "paste"*)
+  | Command e        -> () (*print_endline "command"*)
+  | PipeClosed e     -> () (*print_endline "pipeclosed"*)
+  | PipeWriteReady e -> () (*print_endline "pipewriteready"*)
+  | PipeReadReady e  -> () (*print_endline "pipereadready"*)
   | Update e         -> onupdate e.width e.height
   | Shutdown         -> onshutdown ()
 
index 7dd1881fbd663320e33b72e16e05bb889c6ffb4d..eb31afe20131abd957b59d3eb1c354433fa462bd 100644 (file)
@@ -109,43 +109,77 @@ CAMLprim value x11_draw_rect(value rect) {
     CAMLreturn(Val_unit);
 }
 
+#define _XOPEN_SOURCE 700
+#include <time.h>
+#include <sys/time.h>
+
+uint64_t getmillis(void) {
+    struct timespec time;
+    clock_gettime(CLOCK_MONOTONIC, &time);
+    uint64_t ms = ((uint64_t)time.tv_sec * (uint64_t)1000);
+    ms += ((uint64_t)time.tv_nsec / (uint64_t)1000000);
+    return ms;
+}
+
 CAMLprim value x11_event_loop(value ms, value cbfn) {
     CAMLparam2(ms, cbfn);
     CAMLlocal1( event );
     while (X.running) {
         XEvent e; XPeekEvent(X.display, &e);
         //bool pending = false; //pollfds(Int_val(ms), cbfn);
+        uint64_t t0_, t0, t1_, t1, t2_, t2, t3_, t3, t4_, t4, t5_, t5;
+
+        t0 = getmillis();
 
+        t1 = getmillis();
         int nevents  = XEventsQueued(X.display, QueuedAfterFlush);
+        t1_ = getmillis();
 
-        /* Update the mouse posistion and simulate a mosuemove event for it */
-        Window xw; int _, x, y; unsigned int mods;
-        XQueryPointer(X.display, X.self, &xw, &xw, &_, &_, &x, &y, &mods);
-        caml_callback(cbfn, mkvariant(TMouseMove, 3, mods, x, y));
+        t2 = getmillis();
+        ///* Update the mouse position and simulate a mosuemove event for it */
+        //Window xw; int _, x, y; unsigned int mods;
+        //XQueryPointer(X.display, X.self, &xw, &xw, &_, &_, &x, &y, &mods);
+        //caml_callback(cbfn, mkvariant(TMouseMove, 3, mods, x, y));
+        t2_ = getmillis();
 
         /* check if we have any pending xevents */
         if (nevents) {
+            t3 = getmillis();
             /* pare down irrelevant mouse drag events to just the latest */
-            XTimeCoord* coords = XGetMotionEvents(
-                X.display, X.self, CurrentTime, CurrentTime, &nevents);
-            if (coords) XFree(coords);
+            //XTimeCoord* coords = XGetMotionEvents(
+            //    X.display, X.self, CurrentTime, CurrentTime, &nevents);
+            //if (coords) XFree(coords);
+            t3_ = getmillis();
 
+            t4 = getmillis();
             /* now take the events, convert them, and call the callback */
             for (XEvent e; XPending(X.display);) {
+                uint64_t t = getmillis();
                 XNextEvent(X.display, &e);
-                if (XFilterEvent(&e, None)) continue;
-                if (!EventHandlers[e.type]) continue;
-                event = EventHandlers[e.type](&e);
-                if (event != Val_int(TNone))
-                    caml_callback(cbfn, event);
+                if (!XFilterEvent(&e, None) && EventHandlers[e.type]) {
+                    event = EventHandlers[e.type](&e);
+                    if (event != Val_int(TNone))
+                        caml_callback(cbfn, event);
+                }
+                //printf("%lu ", getmillis()-t);
             }
+            //puts("");
+            t4_ = getmillis();
         }
 
+        t5 = getmillis();
         /* generate an update event and flush any outgoing events */
         if (X.running)
             caml_callback(cbfn, mkvariant(TUpdate, 2, Val_int(X.width), Val_int(X.height)));
+        t5_ = getmillis();
+
         XFlush(X.display);
+        t0_ = getmillis();
+
+        printf("time (ms): %lu %lu %lu %lu %lu (%lu)\n",
+            t1_ - t1, t2_ - t2, t3_ - t3, t4_ - t4, t5_ - t5, t0_ - t0);
     }
+
     CAMLreturn(Val_unit);
 }
 
@@ -259,7 +293,7 @@ CAMLprim value x11_draw_glyph(value color, value glyph, value coord) {
     XftGlyphFontSpec spec = {
         .font  = font,
         .glyph = intfield(glyph,1),
-        .x     = intfield(coord,0), // - intfield(glyph,4),
+        .x     = intfield(coord,0),
         .y     = intfield(coord,1) + font->ascent
     };
 //    printf("c: '%c' w: %d x: %d y: %d xoff: %d yoff: %d\n",