Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions IntegrationTest/BikeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ public BikeService(OrderService orderService)
_orderService = orderService;
}

public void Order(int searchRadius)
{
public void Order(int searchRadius) =>
_orderService.FindNearestVehicle(searchRadius, "bike");
}
}
}
6 changes: 2 additions & 4 deletions IntegrationTest/CarService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ public CarService(OrderService orderService)
_orderService = orderService;
}

public void Order(int searchRadius)
{
public void Order(int searchRadius) =>
_orderService.FindNearestVehicle(searchRadius, "car");
}
}
}
3 changes: 1 addition & 2 deletions IntegrationTest/Dockerfile.load-generator
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.9
FROM python:3.12

RUN pip3 install requests

Expand All @@ -7,4 +7,3 @@ COPY load-generator.py ./load-generator.py
ENV PYTHONUNBUFFERED=1

CMD [ "python", "load-generator.py" ]

40 changes: 22 additions & 18 deletions IntegrationTest/OrderService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using Pyroscope;

namespace Example;

Expand All @@ -8,50 +8,54 @@ public void FindNearestVehicle(long searchRadius, string vehicle)
{
lock (_lock)
{
var labels = Pyroscope.LabelSet.Empty.BuildUpon()
var labels = LabelSet.Empty.BuildUpon()
.Add("vehicle", vehicle)
.Build();
Pyroscope.LabelsWrapper.Do(labels, () =>

LabelsWrapper.Do(labels, static (state) =>
{
for (long i = 0; i < searchRadius * 1000000000; i++)
for (long i = 0; i < state.searchRadius * 1_000_000_000; i++)
{
}

if (vehicle.Equals("car"))
if (string.Equals("car", state.vehicle))
{
CheckDriverAvailability(labels, searchRadius);
CheckDriverAvailability(state.labels, state.searchRadius);
}
});
},
(labels, searchRadius, vehicle));
}
}

private readonly object _lock = new();

private static void CheckDriverAvailability(Pyroscope.LabelSet ctx, long searchRadius)
private static void CheckDriverAvailability(LabelSet labels, long searchRadius)
{
var region = System.Environment.GetEnvironmentVariable("REGION") ?? "unknown_region";
ctx = ctx.BuildUpon()
var region = Environment.GetEnvironmentVariable("REGION") ?? "unknown_region";
labels = labels.BuildUpon()
.Add("driver_region", region)
.Build();
Pyroscope.LabelsWrapper.Do(ctx, () =>

LabelsWrapper.Do(labels, static (state) =>
{
for (long i = 0; i < searchRadius * 1000000000; i++)
for (long i = 0; i < state.searchRadius * 1_000_000_000; i++)
{
}

var now = DateTime.Now.Minute % 2 == 0;
var forceMutexLock = DateTime.Now.Minute % 2 == 0;
if ("eu-north".Equals(region) && forceMutexLock)

if (string.Equals("eu-north", state.region) && forceMutexLock)
{
MutexLock(searchRadius);
MutexLock(state.searchRadius);
}
});
},
(region, searchRadius));
}

private static void MutexLock(long searchRadius)
{
for (long i = 0; i < 30 * searchRadius * 1000000000; i++)
for (long i = 0; i < 30 * searchRadius * 1_000_000_000; i++)
{
}
}
}
}
61 changes: 23 additions & 38 deletions IntegrationTest/Program.cs
Original file line number Diff line number Diff line change
@@ -1,45 +1,30 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Collections;
using Example;

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
var builder = WebApplication.CreateBuilder(args);

namespace Example;
builder.Services.AddSingleton<BikeService>();
builder.Services.AddSingleton<CarService>();
builder.Services.AddSingleton<OrderService>();
builder.Services.AddSingleton<ScooterService>();

public static class Program
{
private static readonly List<FileStream> Files = new();
public static void Main(string[] args)
{
var orderService = new OrderService();
var bikeService = new BikeService(orderService);
var scooterService = new ScooterService(orderService);
var carService = new CarService(orderService);
var app = builder.Build();

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/bike", (BikeService service) =>
{
service.Order(1);
return "Bike ordered";
});

app.MapGet("/bike", () =>
{
bikeService.Order(1);
return "Bike ordered";
});
app.MapGet("/scooter", () =>
{
scooterService.Order(2);
return "Scooter ordered";
});
app.MapGet("/scooter", (ScooterService service) =>
{
service.Order(2);
return "Scooter ordered";
});

app.MapGet("/car", () =>
{
carService.Order(3);
return "Car ordered";
});
app.MapGet("/car", (CarService service) =>
{
service.Order(3);
return "Car ordered";
});

app.Run();
}
}
app.Run();
12 changes: 12 additions & 0 deletions IntegrationTest/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"profiles": {
"Rideshare": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:56129;http://localhost:56130"
}
}
}
6 changes: 5 additions & 1 deletion IntegrationTest/Rideshare.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFrameworks>net8.0;net6.0</TargetFrameworks>
<AssemblyName>rideshare</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>rideshare</PackageId>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<!-- Disable NETSDK1138 -->
<CheckEolTargetFramework>false</CheckEolTargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../Pyroscope/Pyroscope/Pyroscope.csproj" />
Expand Down
9 changes: 4 additions & 5 deletions IntegrationTest/ScooterService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Diagnostics;

namespace Example;

internal class ScooterService
Expand All @@ -13,9 +11,10 @@ public ScooterService(OrderService orderService)

public void Order(int searchRadius)
{
for (long i = 0; i < 2000000000; i++)
for (long i = 0; i < 2_000_000_000; i++)
{
}

OrderInternal(searchRadius);
DoSomeOtherWork();
}
Expand All @@ -25,9 +24,9 @@ private void OrderInternal(int searchRadius)
_orderService.FindNearestVehicle(searchRadius, "scooter");
}

private void DoSomeOtherWork()
private static void DoSomeOtherWork()
{
for (long i = 0; i < 1000000000; i++)
for (long i = 0; i < 1_000_000_000; i++)
{
}
}
Expand Down
4 changes: 2 additions & 2 deletions Pyroscope/Pyroscope.OpenTracing/PyroscopeSpanBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class PyroscopeSpanBuilder : ISpanBuilder
private const string ProfileIdSpanTagKey = "pyroscope.profile.id";

private readonly ISpanBuilder _delegate;
private ISpanContext? _parent;
private readonly ISpanContext? _parent;

internal PyroscopeSpanBuilder(ISpanBuilder spanBuilder, ISpanContext? parent)
{
Expand Down Expand Up @@ -135,7 +135,7 @@ public ISpanBuilder IgnoreActiveSpan()
return this;
}

class PyroscopeScope : IScope
private sealed class PyroscopeScope : IScope
{
private readonly IScope _delegate;
private readonly ISpanContext? _parent;
Expand Down
27 changes: 27 additions & 0 deletions Pyroscope/Pyroscope.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36429.23 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pyroscope", "Pyroscope\Pyroscope.csproj", "{7DA9EFD3-9B8D-4DF4-A1D1-108D43B53BBD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pyroscope.OpenTelemetry", "Pyroscope.OpenTelemetry\Pyroscope.OpenTelemetry.csproj", "{AEB842E5-386E-275E-3A1B-00CD047918A4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pyroscope.OpenTracing", "Pyroscope.OpenTracing\Pyroscope.OpenTracing.csproj", "{AE3C5FD4-119D-3AAD-DC9E-C903F2D8EFDF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rideshare", "..\IntegrationTest\Rideshare.csproj", "{230842A8-C534-4ECF-249E-0AD71F4126E2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -12,5 +21,23 @@ Global
{7DA9EFD3-9B8D-4DF4-A1D1-108D43B53BBD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7DA9EFD3-9B8D-4DF4-A1D1-108D43B53BBD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7DA9EFD3-9B8D-4DF4-A1D1-108D43B53BBD}.Release|Any CPU.Build.0 = Release|Any CPU
{AEB842E5-386E-275E-3A1B-00CD047918A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AEB842E5-386E-275E-3A1B-00CD047918A4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AEB842E5-386E-275E-3A1B-00CD047918A4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AEB842E5-386E-275E-3A1B-00CD047918A4}.Release|Any CPU.Build.0 = Release|Any CPU
{AE3C5FD4-119D-3AAD-DC9E-C903F2D8EFDF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AE3C5FD4-119D-3AAD-DC9E-C903F2D8EFDF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AE3C5FD4-119D-3AAD-DC9E-C903F2D8EFDF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AE3C5FD4-119D-3AAD-DC9E-C903F2D8EFDF}.Release|Any CPU.Build.0 = Release|Any CPU
{230842A8-C534-4ECF-249E-0AD71F4126E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{230842A8-C534-4ECF-249E-0AD71F4126E2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{230842A8-C534-4ECF-249E-0AD71F4126E2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{230842A8-C534-4ECF-249E-0AD71F4126E2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F1C82690-DF18-45C2-AFA5-BC1083ABCD77}
EndGlobalSection
EndGlobal
34 changes: 26 additions & 8 deletions Pyroscope/Pyroscope/LabelsWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,32 @@ public static void Do(LabelSet labels, Action a)
}
finally
{
if (labels.Previous == null)
{
Profiler.Instance.ClearDynamicTags();
}
else
{
labels.Previous.Activate();
}
ResetLabels(labels);
}
}

public static void Do<T>(LabelSet labels, Action<T> a, T state)
{
try
{
labels.Activate();
a.Invoke(state);
}
finally
{
ResetLabels(labels);
}
}

private static void ResetLabels(LabelSet labels)
{
if (labels.Previous == null)
{
Profiler.Instance.ClearDynamicTags();
}
else
{
labels.Previous.Activate();
}
}
}
2 changes: 1 addition & 1 deletion itest.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ COPY Pyroscope/package-logo.png ./Pyroscope/package-logo.png
COPY Pyroscope/Pyroscope ./Pyroscope/Pyroscope

# Set the target framework to SDK_VERSION
RUN sed -i -E 's|<TargetFramework>.*</TargetFramework>|<TargetFramework>net'$SDK_VERSION'</TargetFramework>|' ./app/Rideshare.csproj
RUN sed -i -E 's|<TargetFrameworks>.*</TargetFrameworks>|<TargetFramework>net'$SDK_VERSION'</TargetFramework>|' ./app/Rideshare.csproj

WORKDIR /dotnet/app

Expand Down
Loading