Pyroscope
vela port-forward addon-pyroscope -n vela-system
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: pyroscope-app
namespace: fourier
spec:
components:
- name: pyroscope-comp-01
type: webservice
properties:
image: nginx:latest
ports:
- expose: true
port: 80
protocol: TCP
imagePullPolicy: IfNotPresent
traits:
- type: pyroscope
properties:
server: "http://pyroscope-server:9084"
logger: "pyroscope.StandardLogger"
appName: "pyroscope-test"
- type: scaler
properties:
replicas: 1
- To start profiling a Go application, you need to include our go module in your app
# make sure you also upgrade pyroscope server to version 0.3.1 or higher
go get github.com/pyroscope-io/client/pyroscope
- Then add the following code to your application:
package main
import "github.com/pyroscope-io/client/pyroscope"
func main() {
pyroscope.Start(pyroscope.Config{
ApplicationName: "simple.golang.app",
// replace this with the address of pyroscope server
ServerAddress: "http://pyroscope-server:4040",
// you can disable logging by setting this to nil
// AuthToken: os.Getenv("PYROSCOPE_AUTH_TOKEN"),
// by default all profilers are enabled, but you can select the ones you want to use:
ProfileTypes: []pyroscope.ProfileType{
pyroscope.ProfileCPU,
pyroscope.ProfileAllocObjects,
pyroscope.ProfileAllocSpace,
pyroscope.ProfileInuseObjects,
pyroscope.ProfileInuseSpace,
},
})
// your code goes here
}
- Check out the examples directory in our repository to learn more
Pyroscope for Java applications
- Java integration is distributed as a single jar file: pyroscope.jar. It contains native async-profiler libraries
- To start profiling a Java application, run your application with pyroscope.jar javaagent:
- Check out the examples folder in our repository to learn more
- To start profiling a .NET application inside a container, you may wrap your application with pyroscope exec as an entrypoint of your image. The tricky part is that you need to copy pyroscope binary to your docker container. To do that, use COPY —from command in your Dockerfile. The following example Dockerfile shows how to build the image:
FROM mcr.microsoft.com/dotnet/sdk:5.0
WORKDIR /dotnet
COPY --from=pyroscope/pyroscope:latest /usr/bin/pyroscope /usr/bin/pyroscope
ADD my-app .
RUN dotnet publish -o . -r $(dotnet --info | grep RID | cut -b 6- | tr -d ' ')
# optionally you may set the pyroscope server address as well as the app name and other configuration options.
ENV PYROSCOPE_SERVER_ADDRESS=http://pyroscope-server:4040
ENV PYROSCOPE_APPLICATION_NAME=my.dotnet.app
ENV PYROSCOPE_LOG_LEVEL=debug
CMD ["pyroscope", "exec", "dotnet", "/dotnet/my-app.dll"]
- If you are using Docker Compose, you can run both pyroscope server and agent with this configuration:
---
version: "3.9"
services:
pyroscope-server:
image: "pyroscope/pyroscope:latest"
ports:
- "4040:4040"
command:
- "server"
app:
image: "my-app:latest"
environment:
PYROSCOPE_APPLICATION_NAME: my.dotnet.app
ASPNETCORE_URLS: http://*:5000
ports:
- "5000:5000"
cap_add:
- SYS_PTRACE
- Check out the examples folder in our repository to learn more
Pyroscope for Python applications
- First, install pyroscope-io pip package:
pip install pyroscope-io
- Add the following code to your application. This code will initialize pyroscope profiler and start profiling:
import pyroscope
pyroscope.configure(
app_name = "my.python.app", # replace this with some name for your application
server_address = "http://my-pyroscope-server:4040", # replace this with the address of your pyroscope server
# auth_token = "{YOUR_API_KEY}", # optionally, if authentication is enabled, specify the API key
)
- To start profiling a PHP application in a container, you may wrap your application with pyroscope exec as an entrypoint of your image. The tricky part is that you need to copy pyroscope binary to your docker container. To do that, use COPY —from command in your Dockerfile. The following example Dockerfile shows how to build the image:
- If you are using Docker Compose, you can run both pyroscope server and agent with this configuration:
---
services:
pyroscope-server:
image: "pyroscope/pyroscope:latest"
ports:
- "4040:4040"
command:
- "server"
app:
image: "my-app:latest"
env:
PYROSCOPE_SERVER_ADDRESS: http://pyroscope-server:4040
PYROSCOPE_APPLICATION_NAME: my.php.app
cap_add:
- SYS_PTRACE
- Check out the examples folder in our repository to learn more
Pyroscope for NodeJS applications
- To start profiling a NodeJS application, you need to include the npm module in your app:
npm install @pyroscope/nodejs
# or
yarn add @pyroscope/nodejs
- Then add the following code to your application:
const Pyroscope = require('@pyroscope/nodejs');
Pyroscope.init({
serverAddress: 'http://pyroscope:4040',
appName: 'myNodeService'
});
Pyroscope.start()
- Check out the examples directory in our repository to learn more