Skip to content

Commit 57d33e3

Browse files
committed
feat(internals): Add documentation for profiler usage
1 parent fab17ed commit 57d33e3

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Profiler
2+
3+
Invenio App RDM includes a profiler for analyzing Python and SQL performance.
4+
5+
## Features
6+
7+
- Start/stop profiling sessions from a web UI
8+
- Collects and stores function-level profiling using [pyinstrument](https://github.com/joerick/pyinstrument)
9+
- Collects and stores SQL query profiling using [sqltap](https://github.com/vinsci/sqltap)
10+
- Profiling data is saved per-session as SQLite files in the configured storage directory.
11+
- Generated reports can be viewed (or downloaded) per request for both the Python (base) and SQL layers.
12+
13+
## Installation
14+
15+
The profiler's dependencies are included in the `profiler` extra of `invenio-app-rdm`:
16+
17+
```
18+
pip install invenio-app-rdm[profiler]
19+
```
20+
21+
Or, if you are using `setup.cfg`, ensure the following:
22+
23+
```ini
24+
[options.extras_require]
25+
profiler =
26+
pyinstrument>=5.0.0,<6
27+
sqltap>=0.3.11,<1.0.0
28+
```
29+
30+
## Enabling the profiler
31+
32+
By default, the profiler is **disabled** in production. To enable it, add the following in your `invenio.cfg` or environment:
33+
34+
```python
35+
APP_RDM_PROFILER_ENABLED = True
36+
# Optionally restrict profiler to administrators only
37+
# See: APP_RDM_PROFILER_PERMISSION in Customization below
38+
```
39+
40+
## Customization
41+
42+
You may customize profiler behavior by setting Flask config variables:
43+
44+
- `APP_RDM_PROFILER_ENABLED`: `True`/`False` - enable/disable profiler
45+
- `APP_RDM_PROFILER_STORAGE`: Path object or string, directory for profiler DBs (default: `$INSTANCE_PATH/profiler`)
46+
- `APP_RDM_PROFILER_ACTIVE_SESSION_LIFETIME`: `timedelta`, how long a session is valid for (default: 60 min)
47+
- `APP_RDM_PROFILER_ACTIVE_SESSION_REFRESH`: `timedelta`, session activity refresh window (default: 30 min)
48+
- `APP_RDM_PROFILER_IGNORED_ENDPOINTS`: List of endpoint regexes to ignore (default: `["static", r"profiler\..+"]`)
49+
- `APP_RDM_PROFILER_PERMISSION`: Callable returning True if current user can access the profiler (default: administrators only)
50+
51+
52+
## Usage
53+
54+
With the profiler enabled and required dependencies installed:
55+
56+
1. Visit: `/profiler/` (e.g. http://localhost:5000/profiler/)
57+
2. Start a profiling session by clicking "Start session", choosing:
58+
- an ID for the session,
59+
- whether to enable Python profiling,
60+
- whether to enable SQL profiling.
61+
3. Interact with your site as usual. The profiler will collect profile data for each request.
62+
4. Return to `/profiler/` to view and manage the collected profiling sessions and their reports.

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ nav:
192192
- Building services: maintenance/internals/service.md
193193
- Building serializers: maintenance/internals/serializers.md
194194
- Create a database migration: maintenance/internals/alembic.md
195+
- Profiler: maintenance/internals/profiler.md
195196
- Database transaction management: maintenance/internals/transactions.md
196197
- Grouping atomic operations: maintenance/internals/uow.md
197198
- Job system: maintenance/internals/jobs.md

0 commit comments

Comments
 (0)