# How do I use the profiler libraries with GUI applications?

**URL:** <https://racket.discourse.group/t/how-do-i-use-the-profiler-libraries-with-gui-applications/2956>\
**Category:** Questions & Answers\
**Tags:** gui\
**Created:** [June 8, 2024, 3:57pm UTC](https://racket.discourse.group/t/how-do-i-use-the-profiler-libraries-with-gui-applications/2956 "2024-06-08T15:57:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![benknoble](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/benknoble/32/16_2.png) [@benknoble](https://racket.discourse.group/u/benknoble)\
**Post date:** [June 8, 2024, 3:57pm UTC](https://racket.discourse.group/t/how-do-i-use-the-profiler-libraries-with-gui-applications/2956/1 "2024-06-08T15:57:59Z")

</div>

Has anyone had luck using [profile-lib's profile-thunk](https://docs.racket-lang.org/profile/index.html#%28def._%28%28lib._profile%2Fmain..rkt%29._profile-thunk%29%29) (or [profile-flame-graph's profile-thunk](https://docs.racket-lang.org/profile-flame-graph/index.html#%28def._%28%28lib._profile-flame-graph%2Fmain..rkt%29._profile-thunk%29%29)) on GUI applications? [I tried a couple variants in Frosthaven Manager](https://github.com/benknoble/frosthaven-manager/commit/6ad14d97fe02c90a2173de94f9e06485b2bda014) and consistently got no output data from [profile-flame-graph's profile-thunk](https://docs.racket-lang.org/profile-flame-graph/index.html#%28def._%28%28lib._profile-flame-graph%2Fmain..rkt%29._profile-thunk%29%29) (even with `#:threads #t` ), so I suspect custodians/the GUI setup is part of the problem. It would be _really_ sweet to have profiling information available, though.

I have not tried [profile-lib's profile-thunk](https://docs.racket-lang.org/profile/index.html#%28def._%28%28lib._profile%2Fmain..rkt%29._profile-thunk%29%29) yet to see if it does better, though I won't expect it to. As I said, I suspect the custodians and eventspaces of being part of the problem (if there's a clean way to start the application so that these libraries work correctly, maybe I'm just missing it!). My application starts in the current eventspace so that Racket will block waiting for it, but also (between GUI Easy, the web server, and other bits) spins off other threads and several "child" eventspaces (most of which are short-lived, and each of which get their own child custodian of the current one).

I'd also be interested in other profiling or performance insight approaches for GUI applications.

---

<div class="post-metadata">

**Author:** ![alexh](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/alexh/32/315_2.png) [@alexh](https://racket.discourse.group/u/alexh)\
**Post date:** [June 9, 2024, 10:45pm UTC](https://racket.discourse.group/t/how-do-i-use-the-profiler-libraries-with-gui-applications/2956/2 "2024-06-09T22:45:32Z")

</div>

> [@benknoble](#):
>
> I'd also be interested in other profiling or performance insight approaches for GUI applications.

I wrote my own profiler library for improving the performance sensitive areas of AcivtiyLog2. While it is a package, I never released it separately:

> **[ActivityLog2/pkgs/al2-profiler at master · alex-hhh/ActivityLog2](https://github.com/alex-hhh/ActivityLog2/tree/master/pkgs/al2-profiler)**
>
> Analyze data from swim, bike and run activities. Contribute to alex-hhh/ActivityLog2 development by creating an account on GitHub.

It works by explicitly instrumenting functions that need to be profiled (e.g. replacing `define` with `define/profile`), and calling `profile-display` to show the data.

There are two implementations, the one in "old.rkt" I used most and it is most reliable, but it does not handle recursive calls. The one in "main.rkt" can handle recursive calls and should have smaller runtime impact on the instrumented code but hasn't seen much use.

There is no documentation for either profiler, but the source code is commented.

Alex.
