commit 17e3e0397ffbe9ef5114df91a40395a67b5854de
parent 1486e5a9e0b47f28f845c042ef303ca440b9783c
Author: Daniel Barlow <dan@telent.net>
Date: Thu, 12 Jun 2025 20:53:22 +0100
add environment variable to enable profile stats collection
Diffstat:
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git 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)