Skip to content

Commit

Permalink
Merge pull request #126 from benbuckman/benbuckman-max-interval
Browse files Browse the repository at this point in the history
ArgumentError on interval <1 or >1m
  • Loading branch information
tmm1 authored Jul 5, 2020
2 parents b820a02 + ac1efb5 commit 4b60b76
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

#define FAKE_FRAME_GC INT2FIX(0)
#define FAKE_FRAME_MARK INT2FIX(1)
Expand Down Expand Up @@ -120,6 +121,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 @@ -232,6 +232,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 4b60b76

Please sign in to comment.