Skip to content

Commit

Permalink
ArgumentError on interval <1 or >1m
Browse files Browse the repository at this point in the history
  • Loading branch information
benbuckman committed Nov 11, 2019
1 parent 55d2a87 commit 8743eec
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ext/stackprof/stackprof.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <pthread.h>

#define BUF_SIZE 2048
#define MICROSECONDS_IN_SECOND 1000000

typedef struct {
size_t total_samples;
Expand Down Expand Up @@ -92,6 +93,10 @@ stackprof_start(int argc, VALUE *argv, VALUE self)
}
if (!RTEST(mode)) mode = sym_wall;

if (!NIL_P(interval) && (NUM2INT(interval) < 1 || NUM2INT(interval) >= MICROSECONDS_IN_SECOND)) {
rb_raise(rb_eArgError, "interval is a number of microseconds between 1 and 1 million");
}

if (!_stackprof.frames) {
_stackprof.frames = st_init_numtable();
_stackprof.overall_signals = 0;
Expand Down
9 changes: 9 additions & 0 deletions test/test_stackprof.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,15 @@ def test_pathname_out
refute_empty profile[:frames]
end

def test_min_max_interval
[-1, 0, 1_000_000, 1_000_001].each do |invalid_interval|
err = assert_raises(ArgumentError, "invalid interval #{invalid_interval}") do
StackProf.run(interval: invalid_interval, debug: true) {}
end
assert_match(/microseconds/, err.message)
end
end

def math
250_000.times do
2 ** 10
Expand Down

0 comments on commit 8743eec

Please sign in to comment.