diff --git a/examples/dotnet/3.1/fast-slow/Dockerfile b/examples/dotnet/3.1/fast-slow/Dockerfile deleted file mode 100644 index ca5609828d..0000000000 --- a/examples/dotnet/3.1/fast-slow/Dockerfile +++ /dev/null @@ -1,13 +0,0 @@ -FROM mcr.microsoft.com/dotnet/sdk:3.1 - -WORKDIR /dotnet - -COPY --from=pyroscope/pyroscope:latest /usr/bin/pyroscope /usr/bin/pyroscope -ADD example . - -RUN dotnet publish -o . -r $(dotnet --info | grep RID | cut -b 6- | tr -d ' ') - -ENV PYROSCOPE_APPLICATION_NAME=fast-slow.dotnet.app -ENV PYROSCOPE_SERVER_ADDRESS=http://pyroscope:4040/ -ENV PYROSCOPE_LOG_LEVEL=debug -CMD ["pyroscope", "exec", "-spy-name", "dotnetspy", "/dotnet/example"] diff --git a/examples/dotnet/3.1/fast-slow/example/Example.csproj b/examples/dotnet/3.1/fast-slow/example/Example.csproj deleted file mode 100644 index 105382b929..0000000000 --- a/examples/dotnet/3.1/fast-slow/example/Example.csproj +++ /dev/null @@ -1,8 +0,0 @@ - - - netcoreapp3.1 - example - Exe - example - - \ No newline at end of file diff --git a/examples/dotnet/3.1/web/Dockerfile b/examples/dotnet/3.1/web/Dockerfile deleted file mode 100644 index c2bcad955a..0000000000 --- a/examples/dotnet/3.1/web/Dockerfile +++ /dev/null @@ -1,13 +0,0 @@ -FROM mcr.microsoft.com/dotnet/sdk:3.1 - -WORKDIR /dotnet - -COPY --from=pyroscope/pyroscope:latest /usr/bin/pyroscope /usr/bin/pyroscope -ADD example . - -RUN dotnet publish -o . -r $(dotnet --info | grep RID | cut -b 6- | tr -d ' ') - -ENV PYROSCOPE_APPLICATION_NAME=web.dotnet.app -ENV PYROSCOPE_SERVER_ADDRESS=http://pyroscope:4040/ -ENV PYROSCOPE_LOG_LEVEL=debug -CMD ["pyroscope", "exec", "dotnet", "/dotnet/example.dll"] diff --git a/examples/dotnet/3.1/web/example/Example.csproj b/examples/dotnet/3.1/web/example/Example.csproj deleted file mode 100644 index 105382b929..0000000000 --- a/examples/dotnet/3.1/web/example/Example.csproj +++ /dev/null @@ -1,8 +0,0 @@ - - - netcoreapp3.1 - example - Exe - example - - \ No newline at end of file diff --git a/examples/dotnet/5.0/fast-slow/docker-compose.yml b/examples/dotnet/5.0/fast-slow/docker-compose.yml deleted file mode 100644 index 34a71db77e..0000000000 --- a/examples/dotnet/5.0/fast-slow/docker-compose.yml +++ /dev/null @@ -1,13 +0,0 @@ ---- -version: "3.9" -services: - pyroscope: - image: "pyroscope/pyroscope:latest" - ports: - - "4040:4040" - command: - - "server" - app: - build: "" - cap_add: - - SYS_PTRACE diff --git a/examples/dotnet/5.0/fast-slow/example/Program.cs b/examples/dotnet/5.0/fast-slow/example/Program.cs deleted file mode 100644 index e29276c601..0000000000 --- a/examples/dotnet/5.0/fast-slow/example/Program.cs +++ /dev/null @@ -1,38 +0,0 @@ -namespace Example -{ - public class Program - { - public static void Main(string[] args) - { - while (true) - { - _ = new Fast.Work(); - _ = new Slow.Work(); - } - } - } -} - -namespace Slow -{ - public class Work - { - public Work() - { - var j = 0; - for (var i = 0; i < 8000; i++) j++; - } - } -} - -namespace Fast -{ - public class Work - { - public Work() - { - var j = 0; - for (var i = 0; i < 2000; i++) j++; - } - } -} diff --git a/examples/dotnet/5.0/web/docker-compose.yml b/examples/dotnet/5.0/web/docker-compose.yml deleted file mode 100644 index 6baaddeffb..0000000000 --- a/examples/dotnet/5.0/web/docker-compose.yml +++ /dev/null @@ -1,17 +0,0 @@ ---- -version: "3.9" -services: - pyroscope: - image: "pyroscope/pyroscope:latest" - ports: - - "4040:4040" - command: - - "server" - app: - environment: - ASPNETCORE_URLS: http://*:5000 - ports: - - "5000:5000" - build: "" - cap_add: - - SYS_PTRACE diff --git a/examples/dotnet/5.0/web/example/Program.cs b/examples/dotnet/5.0/web/example/Program.cs deleted file mode 100644 index e9746636be..0000000000 --- a/examples/dotnet/5.0/web/example/Program.cs +++ /dev/null @@ -1,27 +0,0 @@ -using Microsoft.AspNetCore; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Http; - -public static class Program -{ - public static void Main() - { - WebHost.CreateDefaultBuilder() - .Configure(app => - { - app.UseRouting(); - app.UseEndpoints(endpoints => - { - endpoints.MapGet("/", async context => - { - var j = 0; - for (var i = 0; i < 100000000; i++) j++; - await context.Response.WriteAsync("Hello!"); - }); - }); - }) - .Build() - .Run(); - } -} \ No newline at end of file diff --git a/examples/dotnet/README.md b/examples/dotnet/README.md new file mode 100644 index 0000000000..b8dd47be5b --- /dev/null +++ b/examples/dotnet/README.md @@ -0,0 +1,39 @@ +# .NET Examples + +The directory contains examples of how to run Pyroscop to profile .NET applications in Docker containers. + +### Fast-slow + +The example is a simple single-thread application similar to examples for other spies. + +The code is pretty self-explanatory: `Slow.Work` should take 80% of CPU time and remaining 20% to be consumed by +`Fast.Work`. You may ask why `Fast` and `Slow` classes are defined in separate namespaces. The fact is that Pyroscope +colors frames depending on the namespaces (for .NET traces), so they are defined in this way just for sake of demo ;) + +In this example, the program is built as an executable (`/dotnet/example`), therefore `-spy-name dotnetspy` argument is +required to tell Pyroscope how to deal with the process: +> CMD ["pyroscope", "exec", "-spy-name", "dotnetspy", "/dotnet/example"] + +To run the example execute the following commands: + +```shell +# cd examples/dotnet/fast-slow +# docker-compose up +``` + +### Web + +The example is a simple ASP.NET Core web app that enables you to observe how consumed CPU time is changed by making +HTTP requests to [http://localhost:5000](http://localhost:5000). + +In contrast to the previous example, the application is built as a dynamic library (`/dotnet/example.dll`) and +runs with dotnet. This allows Pyroscope to automatically detect which kind of spy to use, making `-spy-name` option +unnecessary: +> CMD ["pyroscope", "exec", "dotnet", "/dotnet/example.dll"] + +To run the example execute the following commands: + +```shell +# cd examples/dotnet/web +# docker-compose up +``` diff --git a/examples/dotnet/5.0/fast-slow/Dockerfile b/examples/dotnet/fast-slow/Dockerfile similarity index 100% rename from examples/dotnet/5.0/fast-slow/Dockerfile rename to examples/dotnet/fast-slow/Dockerfile diff --git a/examples/dotnet/3.1/fast-slow/docker-compose.yml b/examples/dotnet/fast-slow/docker-compose.yml similarity index 100% rename from examples/dotnet/3.1/fast-slow/docker-compose.yml rename to examples/dotnet/fast-slow/docker-compose.yml diff --git a/examples/dotnet/5.0/fast-slow/example/Example.csproj b/examples/dotnet/fast-slow/example/Example.csproj similarity index 100% rename from examples/dotnet/5.0/fast-slow/example/Example.csproj rename to examples/dotnet/fast-slow/example/Example.csproj diff --git a/examples/dotnet/3.1/fast-slow/example/Program.cs b/examples/dotnet/fast-slow/example/Program.cs similarity index 100% rename from examples/dotnet/3.1/fast-slow/example/Program.cs rename to examples/dotnet/fast-slow/example/Program.cs diff --git a/examples/dotnet/5.0/web/Dockerfile b/examples/dotnet/web/Dockerfile similarity index 100% rename from examples/dotnet/5.0/web/Dockerfile rename to examples/dotnet/web/Dockerfile diff --git a/examples/dotnet/3.1/web/docker-compose.yml b/examples/dotnet/web/docker-compose.yml similarity index 100% rename from examples/dotnet/3.1/web/docker-compose.yml rename to examples/dotnet/web/docker-compose.yml diff --git a/examples/dotnet/5.0/web/example/Example.csproj b/examples/dotnet/web/example/Example.csproj similarity index 100% rename from examples/dotnet/5.0/web/example/Example.csproj rename to examples/dotnet/web/example/Example.csproj diff --git a/examples/dotnet/3.1/web/example/Program.cs b/examples/dotnet/web/example/Program.cs similarity index 100% rename from examples/dotnet/3.1/web/example/Program.cs rename to examples/dotnet/web/example/Program.cs