Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print scheduler details (ExecutionContext) #18

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

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"
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.

action = LibC::Sigaction.new
action.sa_flags = LibC::SA_RESTART
action.sa_sigaction = LibC::SigactionHandlerT.new do |_, _, _|
print_runtime_status(details)
Copy link
Contributor Author

@ysbaddaden ysbaddaden Jun 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line doesn't compile: we can't pass a variable (here details) to a C closure and we can't pass custom data to the sigaction handler either. We need a global variable (meh) or keep a Hash(Int32, Bool) as a class property (sounds better).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we only need to cover two cases, maybe we could create two different procs?

if details 
  LibC::SigactionHandlerT.new do |_, _, _|
    print_runtime_status(true)
  end
else
  LibC::SigactionHandlerT.new do |_, _, _|
    print_runtime_status(false)
  end
end

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.

None yet

2 participants