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