Skip to content

Commit a01ca65

Browse files
thomasdiluccioAnouckColsonchadcarlson
authored
Add PHP and Python continuous profiling documentation (#3895)
* Add PHP and Python continuous profiling documentation * Add CPU support for the node.js cont profiler * Doc review --------- Co-authored-by: Anouck Colson <[email protected]> Co-authored-by: chadcarlson <[email protected]>
1 parent 15fcf31 commit a01ca65

File tree

4 files changed

+123
-8
lines changed

4 files changed

+123
-8
lines changed

sites/upsun/src/increase-observability/application-metrics/go.md

+7-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ It is available directly from the Console under the `Profiling` tab of your envi
1313
The GO continuous profiling is currently made accross 6 dimensions:
1414
- **Allocations**: Number of objects allocated
1515
- **Allocated Memory**: Number of bytes allocated
16-
- **CPU**: Time spent running on the CPU
16+
- **CPU**: Time spent running on the CPU
1717
- **Goroutines**: Number of goroutines (both on-CPU and off-CPU)
18-
- **Heap Live Objects**: Number of objects allocated that are not yet garbage collected.
19-
- **Heap Live Size**: Number of bytes allocated that are not yet garbage collected.
18+
- **Heap Live Objects**: Number of objects allocated that are not yet garbage collected
19+
- **Heap Live Size**: Number of bytes allocated that are not yet garbage collected
20+
21+
The default sampling frequency is 100 Hz. This means the Go continuous profiler is
22+
collecting information 100 times per second.
2023

2124
## Prerequisites
2225

@@ -63,7 +66,7 @@ The `Start` function accepts the following options:
6366
- `WithCPUDuration`: specifies the length at which to collect CPU profiles.
6467
The default is 45 seconds. Can also be set via the environment variable `BLACKFIRE_CONPROF_CPU_DURATION`.
6568

66-
- `WithCPUProfileRate`: sets the CPU profiling rate to Hz samples per second.
69+
- `WithCPUProfileRate`: sets the CPU profiling rate in Hz (number of samples per second).
6770
The default is defined by the Go runtime as 100 Hz. Can also be set via the environment
6871
variable `BLACKFIRE_CONPROF_CPU_PROFILERATE`.
6972

sites/upsun/src/increase-observability/application-metrics/nodejs.md

+8-4
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@
22
title: Continuous profiling for Node.js
33
sidebarTitle: "Node.js continuous profiler"
44
description: Configure and use the NodeJS continuous profiler.
5-
weight: 40
5+
weight: 30
66
---
77

88
## Continuous profiling on {{% vendor/name %}}
99

1010
{{< vendor/name >}} Continuous Profiling is powered by [Blackfire](../../../increase-observability/application-metrics/blackfire.md).
1111
It is available directly from the Console under the `Profiling` tab of your environments.
1212

13-
The Node.js continuous profiling is currently made accross 2 dimensions:
14-
- **wall-time**: elapsed time per function call
15-
- **heap**: memory allocation and reserved space over time
13+
The Node.js continuous profiling is currently made accross 3 dimensions:
14+
- **CPU Time**: Time spent running on the CPU
15+
- **Wall-time**: Elapsed time per function call
16+
- **Heap**: Memory allocation and reserved space over time
17+
18+
The default sampling frequency is 100 Hz. This means the Node.js continuous profiler is
19+
collecting information 100 times per second.
1620

1721
## Prerequisites
1822

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
title: Continuous profiling for PHP
3+
sidebarTitle: "PHP continuous profiler"
4+
description: Configure and use the PHP continuous profiler.
5+
weight: 30
6+
---
7+
8+
{{< vendor/name >}} [Continuous Profiler](./cont-prof.md) is powered by [Blackfire](../../../increase-observability/application-metrics/blackfire.md).
9+
It is available directly the [Console](/administration/web/_index.md), under the **Profiling** tab of your environments.
10+
11+
The PHP continuous profiling is currently made accross 4 dimensions:
12+
- **CPU Time**: Time spent running on the CPU
13+
- **Wall-time**: Elapsed time per function call
14+
- **Allocated Memory**: Number of bytes allocated in memory
15+
- **Allocations**: Time spent running on the CPU
16+
17+
The default sampling frequency is 100 Hz. This means the PHP continuous profiler is
18+
collecting information 100 times per second.
19+
20+
## Prerequisites
21+
22+
{{< vendor/name >}} Continuous Profiler requires [`PHP >=8.2`](/languages/php/_index.md).
23+
24+
## Installation
25+
26+
The Blackfire Continuous Profiler PHP library is included by default in all
27+
PHP images matching its requirements. There is no installation required.
28+
29+
## Configuration
30+
31+
The PHP continuous profiler is enabled by default without configuration.
32+
33+
Optionally, you can override the following environment variables:
34+
35+
- `DD_PROFILING_ENABLED=true`: forces the PHP continuous profiler activation/deactivation
36+
- `DD_PROFILING_LOG_LEVEL=off`: controls the PHP continuous profiler log level
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
title: Continuous profiling for Python
3+
sidebarTitle: "Python continuous profiler"
4+
description: Configure and use the Python continuous profiler.
5+
weight: 30
6+
---
7+
8+
{{< vendor/name >}} [Continuous Profiler](./cont-prof.md) is powered by [Blackfire](../../../increase-observability/application-metrics/blackfire.md).
9+
It is available directly from the [Console](/administration/web/_index.md), under the **Profiling** tab of your environments.
10+
11+
The PHP continuous profiling is currently made accross 4 dimensions:
12+
- **CPU Time**: Time spent running on the CPU
13+
- **Wall-time**: Elapsed time per function call
14+
- **Heap Live Size**: Number of bytes allocated that are not yet garbage collected
15+
- **Allocated Memory**: Number of bytes allocated in memory
16+
- **Allocations**: Time spent running on the CPU
17+
18+
The default sampling frequency is 100 Hz. This means the Python continuous profiler is
19+
collecting information 100 times per second.
20+
21+
## Prerequisites
22+
23+
{{< vendor/name >}} Continuous Profiler requires [`Python >=3.7.0`](/languages/python/_index.md).
24+
25+
## Installation
26+
27+
The [Blackfire Continuous Profiler Python library](https://github.com/blackfireio/python-continuous-profiling) is included by default in all
28+
Python images matching its requirements. There is no installation required.
29+
30+
## Python continuous profiler API
31+
32+
The Python profiler API (`profiler`) can be initiated with the following options:
33+
34+
- `application_name`: the application name.
35+
- `period`: specifies the length at which to collect CPU profiles. The default is 45 seconds.
36+
- `upload_timeout`: observability data upload timeout. The default is 10 seconds.
37+
- `labels`: a dict containing the custom labels specific to the profile payload that is sent.
38+
39+
The Python continuous profiler API has two functions:
40+
41+
``` python
42+
def start():
43+
def stop():
44+
```
45+
46+
| Function | Description |
47+
| ---------------------- | ----------- |
48+
| `def start():` | The `start` function starts the continuous profiler probe. </br>It collects profiling information in the background and periodically uploads it to the Blackfire Agent until the ``stop`` function is called. |
49+
| `def stop():` |Stops the continuous profiling probe. |
50+
51+
## Example
52+
53+
Here is an example of how you can initiate the Python `profiler` on a basic app:
54+
55+
1. Create `example.py` with the following code:
56+
57+
``` python
58+
def foo():
59+
import time
60+
time.sleep(1.0)
61+
62+
profiler = Profiler(application_name="my-python-app", labels={'my-extra-label': 'data'})
63+
profiler.start()
64+
foo()
65+
profiler.stop()
66+
```
67+
68+
2. Run the app:
69+
70+
``` bash
71+
python example.py
72+
```

0 commit comments

Comments
 (0)