diff --git a/pkgs/maps/main.fnl b/pkgs/maps/main.fnl index 4b4b0f2..b2cc36f 100644 --- a/pkgs/maps/main.fnl +++ b/pkgs/maps/main.fnl @@ -8,6 +8,10 @@ (import-macros { : define-tests : expect : expect= } :assert) +(local profile + (and (os.getenv "IN_NIX_SHELL") + (require :libluaperf))) + (macro with-timing [label & body] `(let [before# (ptime.clock_gettime ptime.CLOCK_PROCESS_CPUTIME_ID) ret# (table.pack (do ,body))] @@ -58,13 +62,17 @@ label.readout { ) (style_provider:load_from_data CSS))) +(fn main-quit [] + (when profile (profile:stop)) + (Gtk.main_quit)) + (local window (Gtk.Window { :title "Map" :name "toplevel" :default_width viewport-width :default_height viewport-height - :on_destroy Gtk.main_quit + :on_destroy main-quit })) (local state-widgets { }) @@ -453,6 +461,15 @@ label.readout { true) nil nil) +(fn collect-profile [] + (GLib.timeout_add + GLib.PRIORITY_DEFAULT + (* 60 1000) main-quit + nil nil) + (print "profiling for 60 seconds") + (profile.start 0)) + + (window:add (doto (Gtk.Overlay {}) (: :add (osm-widget)) @@ -463,4 +480,5 @@ label.readout { (window:show_all) (styles) +(when (os.getenv "MAP_PROFILE") (collect-profile)) (Gtk:main)