storage
storage
¶
SQLite + JSONL storage for profiler time-series data.
Provides MonitorStorage which writes system snapshots and process
events to a SQLite database and optionally appends NDJSON lines for
streaming consumers. All SQLite I/O uses aiosqlite to avoid
blocking the event loop.
Read methods reconstruct Pydantic models from the stored rows,
and a cleanup() method enforces the configured retention policy.
Classes¶
MonitorStorage
¶
Async SQLite + JSONL storage for profiler time-series data.
Uses aiosqlite for non-blocking database access and WAL mode
for safe concurrent reads (mzt top) while the daemon writes.
Parameters¶
db_path: Path to the SQLite database file. Parent directories are created automatically. jsonl_path: Optional path for the NDJSON streaming log. When provided, each snapshot is also appended as a single JSON line. jsonl_max_bytes: Maximum JSONL file size before rotation (default 50 MB).
Source code in src/marianne/daemon/profiler/storage.py
Methods:¶
close
async
¶
initialize
async
¶
Create tables and indexes if they don't exist.
Source code in src/marianne/daemon/profiler/storage.py
write_snapshot
async
¶
Insert a snapshot and its process metrics into the database.
Returns the snapshot row ID for cross-referencing.
Source code in src/marianne/daemon/profiler/storage.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | |
write_event
async
¶
Insert a process lifecycle event.
Source code in src/marianne/daemon/profiler/storage.py
read_snapshots
async
¶
Read snapshots since the given unix timestamp.
Returns snapshots in chronological order, most recent last. Process metrics are reconstructed for each snapshot.
Source code in src/marianne/daemon/profiler/storage.py
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 | |
read_events
async
¶
Read process events since the given unix timestamp.
Source code in src/marianne/daemon/profiler/storage.py
read_process_history
async
¶
Read historical metrics for a specific process.
Source code in src/marianne/daemon/profiler/storage.py
read_job_resource_profile
async
¶
Aggregate resource profile for a specific job.
Returns a dict with peak memory, total CPU-time, process spawn
count, and syscall hotspots — useful for scheduling hints and
mzt diagnose --resources.
Source code in src/marianne/daemon/profiler/storage.py
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 | |
cleanup
async
¶
Apply retention policy by deleting old data.
- Snapshots + process_metrics older than full_resolution_hours
- Process events older than events_days
Source code in src/marianne/daemon/profiler/storage.py
append_jsonl
¶
Append one NDJSON line for the given snapshot.
Synchronous I/O — callers should wrap in run_in_executor
if strict non-blocking is required. In practice the writes are
small and fast enough for the daemon's collection loop.
Performs size-based rotation: when the file exceeds
jsonl_max_bytes, renames it with a .1 suffix (keeping
at most 2 rotated files) and starts a new file.
Source code in src/marianne/daemon/profiler/storage.py
Functions:¶
generate_resource_report
async
¶
Generate comprehensive resource report for a job.
Produces a text report designed for AI consumption (mzt diagnose
--resources). Aggregates peak memory per sheet, total CPU-time,
process spawn count, signal/kill events, zombie/OOM events, syscall
hotspots, and anomaly history.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_id
|
str
|
The job ID to generate the report for. |
required |
storage
|
MonitorStorage
|
An initialized |
required |
Returns:
| Type | Description |
|---|---|
str
|
Multi-line text report. Returns a short "no data" message if the |
str
|
job has no profiler data. |
Source code in src/marianne/daemon/profiler/storage.py
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 | |