github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/examples/dotnet/rideshare/example/OrderService.cs (about) 1 using System; 2 3 namespace Example; 4 5 internal class OrderService 6 { 7 public void FindNearestVehicle(long searchRadius, string vehicle) 8 { 9 lock (_lock) 10 { 11 var labels = Pyroscope.LabelSet.Empty.BuildUpon() 12 .Add("vehicle", vehicle) 13 .Build(); 14 Pyroscope.LabelsWrapper.Do(labels, () => 15 { 16 for (long i = 0; i < searchRadius * 1000000000; i++) 17 { 18 } 19 20 if (vehicle.Equals("car")) 21 { 22 CheckDriverAvailability(labels, searchRadius); 23 } 24 }); 25 } 26 } 27 28 private readonly object _lock = new(); 29 30 private static void CheckDriverAvailability(Pyroscope.LabelSet ctx, long searchRadius) 31 { 32 var region = System.Environment.GetEnvironmentVariable("REGION") ?? "unknown_region"; 33 ctx = ctx.BuildUpon() 34 .Add("driver_region", region) 35 .Build(); 36 Pyroscope.LabelsWrapper.Do(ctx, () => 37 { 38 for (long i = 0; i < searchRadius * 1000000000; i++) 39 { 40 } 41 42 var now = DateTime.Now.Minute % 2 == 0; 43 var forceMutexLock = DateTime.Now.Minute % 2 == 0; 44 if ("eu-north".Equals(region) && forceMutexLock) 45 { 46 MutexLock(searchRadius); 47 } 48 }); 49 } 50 51 private static void MutexLock(long searchRadius) 52 { 53 for (long i = 0; i < 30 * searchRadius * 1000000000; i++) 54 { 55 } 56 } 57 }