Metadata-Version: 2.4
Name: fastpluggy-memory-analyzer
Version: 0.0.16
Summary: Memory Analyzer plugin for Fastpluggy
Author: FastPluggy Team
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: FastPluggy>=0.4.21
Requires-Dist: psutil
Requires-Dist: pympler
Provides-Extra: e2e
Requires-Dist: fastpluggy-cli; extra == "e2e"
Provides-Extra: tests
Requires-Dist: pytest>=7.0; extra == "tests"
Requires-Dist: pytest-cov>=4.0; extra == "tests"
Requires-Dist: pytest-asyncio>=0.23; extra == "tests"

# Memory Analyzer

![Memory Analyzer](https://img.shields.io/badge/FastPluggy-Memory%20Analyzer-blue)
[![Release](https://gitlab.ggcorp.fr/open/fastpluggy/plugins/memory_analyzer/-/badges/release.svg)](https://gitlab.ggcorp.fr/open/fastpluggy/plugins/memory_analyzer/-/releases)
[![Pipeline Status](https://gitlab.ggcorp.fr/open/fastpluggy/plugins/memory_analyzer/badges/main/pipeline.svg?key_text=CI)](https://gitlab.ggcorp.fr/open/fastpluggy/plugins/memory_analyzer/-/pipelines?ignore_skipped=true)
[![Coverage](https://gitlab.ggcorp.fr/open/fastpluggy/plugins/memory_analyzer/badges/main/coverage.svg)](https://gitlab.ggcorp.fr/open/fastpluggy/plugins/memory_analyzer/-/pipelines)

A FastPluggy plugin for profiling per-request memory usage and monitoring system resources.

## Features

- **PSUtil system dashboard** — process list, thread detail, current heap analysis
- **Endpoint memory tracking** — per-request Pympler snapshots with delta/duration stats
- **Configurable watchlist** — select specific endpoints to profile via CRUD API, with auto-suggest from registered routes
- **Metrics export** — exposes profiling stats to the metrics aggregator for endpoints flagged with `export_to_metrics`
- **TTL eviction** — samples older than a configurable threshold are automatically discarded
- **Pure ASGI middleware** — lightweight middleware (`__call__`) without BaseHTTPMiddleware overhead

## Configuration

Settings persist via `BaseDatabaseSettings` (env prefix: `FP_MEMORY_`):

| Setting | Default | Description |
|---------|---------|-------------|
| `sampling_rate` | `0.15` | Fraction of requests to sample when watchlist is empty |
| `debug_header` | `X-Debug-Mem` | Header name to force a snapshot (`1` or `true`) |
| `stats_ttl_hours` | `24` | Discard samples older than this (hours) |

## Installation

```bash
pip install -e ".[dev]"
```

## Development

```bash
pytest tests/
```

## Documentation

See [`docs/endpoint-watchlist.md`](docs/endpoint-watchlist.md) for watchlist API, metrics export, and configuration details.

