github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/examples/adhoc/adhoc-push.rb (about) 1 #!/usr/bin/env ruby 2 require "pyroscope" 3 4 def is_prime(n) 5 i = 2 6 while i < n do 7 return true if i * i > n 8 return false if n % i == 0 9 i += 1 10 end 11 false 12 end 13 14 def slow(n) 15 (1..n).reduce(:+) 16 end 17 18 def fast(n) 19 root = Math::sqrt(n).to_i 20 (1..n).step(root).map{|a| 21 b = [a + root - 1, n].min 22 (b - a + 1) * (a + b) / 2 23 }.reduce(:+) 24 end 25 26 def run 27 base = rand(1..10**6) 28 (0..2*10**6).each do |i| 29 is_prime(base + i) ? slow(rand(1..10**4)) : fast(rand(1..10**4)) 30 end 31 end 32 33 Pyroscope.configure do |config| 34 # No need to modify existing settings, 35 # pyroscope will override the server address 36 config.app_name = "adhoc.push.ruby" 37 config.server_address = "http://pyroscope:4040" 38 end 39 run