Skip to content

Commit 3d52925

Browse files
committed
Fix test.
1 parent 358300a commit 3d52925

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

ext/io/event/profiler.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,19 @@ struct IO_Event_Profiler_Call {
2929
};
3030

3131
struct 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+
482493
void 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
}

test/io/event/profiler.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,21 @@
66
require "io/event"
77

88
describe IO::Event::Profiler do
9-
let(:profiler) {subject.new}
9+
let(:profiler) {subject.new(0.0001)}
1010

1111
it "should start profiling" do
1212
skip "Not implemented" unless subject.respond_to?(:new)
1313

1414
profiler.start
1515

1616
Fiber.new do
17-
sleep 1.0
18-
end
17+
sleep 0.0001
18+
end.resume
1919

2020
profiler.stop
21+
22+
expect(profiler).to have_attributes(
23+
stalls: be >= 1
24+
)
2125
end
2226
end

0 commit comments

Comments
 (0)