github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/examples/ruby/rideshare_rails/app/helpers/application_helper.rb (about) 1 require "pyroscope" 2 3 module ApplicationHelper 4 def mutex_lock(n) 5 i = 0 6 start_time = Time.new 7 while Time.new - start_time < n * 10 do 8 i += 1 9 end 10 end 11 12 def check_driver_availability(n) 13 i = 0 14 start_time = Time.new 15 while Time.new - start_time < n / 2 do 16 i += 1 17 end 18 19 # Every 4 minutes this will artificially create make requests in eu-north region slow 20 # this is just for demonstration purposes to show how performance impacts show up in the 21 # flamegraph 22 current_time = Time.now 23 current_minute = current_time.strftime('%M').to_i 24 force_mutex_lock = (current_minute * 4 % 8) == 0 25 26 mutex_lock(n) if ENV["REGION"] == "eu-north" and force_mutex_lock 27 end 28 29 def find_nearest_vehicle(n, vehicle) 30 Pyroscope.tag_wrapper({ "vehicle" => vehicle }) do 31 i = 0 32 start_time = Time.new 33 while Time.new - start_time < n do 34 i += 1 35 end 36 37 check_driver_availability(n) if vehicle == "car" 38 end 39 end 40 41 end