@@ -29,16 +29,19 @@ struct IO_Event_Profiler_Call {
2929};
3030
3131struct IO_Event_Profiler {
32+ // Configuration:
3233 float log_threshold ;
3334 int track_calls ;
3435
36+ // Whether or not the profiler is currently running:
3537 int running ;
3638
3739 // Whether or not to capture call data:
3840 int capture ;
3941
40- // From this point on, the state of any profile in progress:
42+ size_t stalls ;
4143
44+ // From this point on, the state of any profile in progress:
4245 struct timespec start_time ;
4346 struct timespec stop_time ;
4447
@@ -135,6 +138,7 @@ VALUE IO_Event_Profiler_allocate(VALUE klass) {
135138 // Initialize the profiler state:
136139 profiler -> running = 0 ;
137140 profiler -> capture = 0 ;
141+ profiler -> stalls = 0 ;
138142 profiler -> nesting = 0 ;
139143 profiler -> current = NULL ;
140144
@@ -380,6 +384,7 @@ void IO_Event_Profiler_fiber_switch(struct IO_Event_Profiler *profiler)
380384 IO_Event_Profiler_finish (profiler );
381385
382386 if (duration > profiler -> log_threshold ) {
387+ profiler -> stalls += 1 ;
383388 IO_Event_Profiler_print (profiler , stderr );
384389 }
385390 }
@@ -479,6 +484,12 @@ void IO_Event_Profiler_print(struct IO_Event_Profiler *profiler, FILE *restrict
479484 }
480485}
481486
487+ VALUE IO_Event_Profiler_stalls (VALUE self ) {
488+ struct IO_Event_Profiler * profiler = IO_Event_Profiler_get (self );
489+
490+ return SIZET2NUM (profiler -> stalls );
491+ }
492+
482493void Init_IO_Event_Profiler (VALUE IO_Event ) {
483494 IO_Event_Profiler = rb_define_class_under (IO_Event , "Profiler" , rb_cObject );
484495 rb_define_alloc_func (IO_Event_Profiler , IO_Event_Profiler_allocate );
@@ -489,4 +500,6 @@ void Init_IO_Event_Profiler(VALUE IO_Event) {
489500
490501 rb_define_method (IO_Event_Profiler , "start" , IO_Event_Profiler_start , 0 );
491502 rb_define_method (IO_Event_Profiler , "stop" , IO_Event_Profiler_stop , 0 );
503+
504+ rb_define_method (IO_Event_Profiler , "stalls" , IO_Event_Profiler_stalls , 0 );
492505}
0 commit comments