Skip to content

Commit 4b60b76

Browse files
authored
Merge pull request #126 from benbuckman/benbuckman-max-interval
ArgumentError on interval <1 or >1m
2 parents b820a02 + ac1efb5 commit 4b60b76

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

ext/stackprof/stackprof.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <pthread.h>
1717

1818
#define BUF_SIZE 2048
19+
#define MICROSECONDS_IN_SECOND 1000000
1920

2021
#define FAKE_FRAME_GC INT2FIX(0)
2122
#define FAKE_FRAME_MARK INT2FIX(1)
@@ -120,6 +121,10 @@ stackprof_start(int argc, VALUE *argv, VALUE self)
120121
}
121122
if (!RTEST(mode)) mode = sym_wall;
122123

124+
if (!NIL_P(interval) && (NUM2INT(interval) < 1 || NUM2INT(interval) >= MICROSECONDS_IN_SECOND)) {
125+
rb_raise(rb_eArgError, "interval is a number of microseconds between 1 and 1 million");
126+
}
127+
123128
if (!_stackprof.frames) {
124129
_stackprof.frames = st_init_numtable();
125130
_stackprof.overall_signals = 0;

test/test_stackprof.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,15 @@ def test_pathname_out
232232
refute_empty profile[:frames]
233233
end
234234

235+
def test_min_max_interval
236+
[-1, 0, 1_000_000, 1_000_001].each do |invalid_interval|
237+
err = assert_raises(ArgumentError, "invalid interval #{invalid_interval}") do
238+
StackProf.run(interval: invalid_interval, debug: true) {}
239+
end
240+
assert_match(/microseconds/, err.message)
241+
end
242+
end
243+
235244
def math
236245
250_000.times do
237246
2 ** 10

0 commit comments

Comments
 (0)