Skip to content

Print scheduler details (ExecutionContext)#18

Merged
ysbaddaden merged 7 commits intomainfrom
feature/execution-context-scheduler-trace
May 19, 2025
Merged

Print scheduler details (ExecutionContext)#18
ysbaddaden merged 7 commits intomainfrom
feature/execution-context-scheduler-trace

Conversation

@ysbaddaden
Copy link
Contributor

@ysbaddaden ysbaddaden commented Jun 18, 2024

Prints runtime information about a program, either at regular interval, programmatically or on demand (through a signal), with or without the list of fibers (that can be huge). Stops the world to be able to print an accurate map of all execution contexts,

For example (idle program with a couple additional execution contexts):

sched.details time=571371878
ExecutionContext::SingleThreaded name=DEFAULT global_queue.size=0
  Scheduler name=DEFAULT thread=0x7f22d27a9740 local_queue.size=0 status=event-loop
ExecutionContext::SingleThreaded name=ST1 global_queue.size=0
  Scheduler name=ST1 thread=0x7f22cd750700 local_queue.size=0 status=parked
ExecutionContext::SingleThreaded name=ST2 global_queue.size=0
  Scheduler name=ST2 thread=0x7f22ccf4f700 local_queue.size=0 status=parked

Requirements:

Usage:

require "perf-tools/scheduler_trace"
require "execution_context"

# print on demand (UNIX only):
PerfTools::SchedulerTrace.on(Signal::USR1, details: true)

# print at regular intervals:
PerfTools::SchedulerTrace.every(5.seconds, details: false)

# print manually:
PerfTools::SchedulerTrace.print_runtime_status(details: true)

Specify details: true to also print the list of fibers in each execution context.

straight-shoota pushed a commit to crystal-lang/crystal that referenced this pull request Aug 7, 2024
Add `GC.stop_world` and `GC.start_world` methods to be able to stop and restart the world at will from within Crystal.

- gc/boehm: delegates to `GC_stop_world_external` and `GC_start_world_external`;
- gc/none: implements its own mechanism (tested on UNIX & Windows).

My use case is a [perf-tools](https://github.com/crystal-lang/perf-tools) feature for [RFC 2](crystal-lang/rfcs#2) that must stop the world to print out runtime information of each ExecutionContext with their schedulers and fibers. See crystal-lang/perf-tools#18
@ysbaddaden ysbaddaden marked this pull request as ready for review May 5, 2025 10:20
@ysbaddaden
Copy link
Contributor Author

Tested against Crystal 1.16.2 and polished with a few last details. Ready for review.

@ysbaddaden ysbaddaden merged commit 70e016a into main May 19, 2025
@ysbaddaden ysbaddaden deleted the feature/execution-context-scheduler-trace branch May 19, 2025 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants