github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/examples/python/rideshare/flask/lib/utility/utility.py (about)

     1  import time
     2  import pyroscope
     3  import os
     4  from datetime import datetime
     5  
     6  
     7  def mutex_lock(n):
     8      i = 0
     9      start_time = time.time()
    10      while time.time() - start_time < n * 10:
    11          i += 1
    12  
    13  def check_driver_availability(n):
    14      i = 0
    15      start_time = time.time()
    16      while time.time() - start_time < n / 2:
    17          i += 1
    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  
    23      force_mutex_lock = datetime.today().minute * 4 % 8 == 0
    24      if os.getenv("REGION") == "eu-north" and force_mutex_lock:
    25          mutex_lock(n)
    26  
    27  
    28  def find_nearest_vehicle(n, vehicle):
    29      with pyroscope.tag_wrapper({ "vehicle": vehicle}):
    30          i = 0
    31          start_time = time.time()
    32          while time.time() - start_time < n:
    33              i += 1
    34          if vehicle == "car":
    35              check_driver_availability(n)