Skip to content

Commit d753cdb

Browse files
committed
add db population
1 parent 40ef4b6 commit d753cdb

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

script/bench.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,13 @@ def port_available? port
7676
puts `bundle exec rake db:create`
7777
`bundle exec rake db:migrate`
7878

79-
puts "Loading Rails"
79+
puts "Timing loading Rails"
8080
measure("load_rails") do
8181
`bundle exec rake middleware`
8282
end
8383

84+
puts "Populating Profile DB"
85+
run("bundle exec ruby script/profile_db_generator.rb")
8486

8587
begin
8688
pid = spawn("bundle exec thin start -p #{port}")

script/profile_db_generator.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# can be used to generate a mock db for profiling purposes
22

3+
# we want our script to generate a consistent output, to do so
4+
# we monkey patch array sample so it always uses the same rng
5+
class Array
6+
RNG = Random.new(1098109928029800)
7+
8+
def sample
9+
self[RNG.rand(size)]
10+
end
11+
end
12+
13+
314
# based on https://gist.github.com/zaius/2643079
415
def unbundled_require(gem)
516
if defined?(::Bundler)
@@ -21,8 +32,9 @@ def unbundled_require(gem)
2132
begin
2233
unbundled_require 'gabbler'
2334
rescue LoadError
24-
puts "please run: gem install gabller"
25-
exit
35+
puts "installing gabbler gem"
36+
puts `gem install gabbler`
37+
unbundled_require 'gabbler'
2638
end
2739

2840
user_id = nil

0 commit comments

Comments
 (0)