Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ dist-newstyle/
*.hp
*.prof
*.hspp
*.aux
*.ps
build.log
postgres-data/
grafana-data/
Expand Down
12 changes: 6 additions & 6 deletions config/dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ setup:

peer_manager:
# Cooldown period after a peer failure before retrying (in seconds)
peer_failure_cooldown_seconds: 300
max_collector_lifetime_seconds: 3000 # 50 minutes
max_concurrent_collectors: 150
peer_failure_cooldown_seconds: 60
max_collector_lifetime_seconds: 1200 # 20 minutes
max_concurrent_collectors: 400

sentry:
duplicate_blocks:
Expand Down Expand Up @@ -106,12 +106,12 @@ quota:
cleanup_interval: 3600 # 1 hour

orphan_detection:
aging_batch_size: 1000
aging_batch_size: 5000

block_eviction:
eviction_interval_seconds: 3600 # 1 hour
eviction_interval_seconds: 300 # 5 minutes

# Cardano node integration configuration
cardano_node_integration:
ssh_server_alive_interval_seconds: 60
immutable_tip_refresh_seconds: 20
immutable_tip_refresh_seconds: 5
101 changes: 101 additions & 0 deletions docs/profiling.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Profiling Guide

Quick guide for profiling hoard using GHC's built-in profiling tools.

## Quick Start

### 1. Run with Profiling

```bash
# Run hoard with profiling enabled
nix run .#profiling -- +RTS -p -hc -T -RTS your-args-here
```

This creates:
- `hoard-exe.prof` - Time and allocation profile
- `hoard-exe.hp` - Heap profile data

### 2. Visualize Heap Profile

```bash
# Convert heap profile to PDF and open it
nix run .#visualize-heap
```

Opens a PDF showing heap usage over time by cost centre.

## Common Profiling Workflows

### Heap Profiling by Module

For cleaner heap profiles grouped by module instead of cost centre:

```bash
nix run .#profile-heap-module
nix run .#visualize-heap
```

### Time/Allocation Profiling Only

For lightweight profiling without heap data:

```bash
nix run .#profile-time
cat hoard-exe.prof
```

### Custom RTS Flags

Run profiling build directly with your own flags:

```bash
# Heap profile by type
nix run .#profiling -- +RTS -hy -p -T -RTS

# Heap profile by closure description
nix run .#profiling -- +RTS -hd -p -T -RTS

# See all RTS options
nix run .#profiling -- +RTS --help -RTS
```

## Available Profiling Apps

| Command | Description |
|---------|-------------|
| `nix run .#profiling` | Profiling-enabled executable (pass custom RTS flags) |
| `nix run .#profile-heap` | Heap profiling by cost centre (detailed but cluttered) |
| `nix run .#profile-heap-module` | Heap profiling by module (cleaner) |
| `nix run .#profile-time` | Time and allocation profiling only |
| `nix run .#visualize-heap` | Convert .hp file to PDF |

## Understanding the Output

### Time Profile (`hoard-exe.prof`)

Shows which functions consume the most time and allocations:

```
COST CENTRE %time %alloc
fetchBlocks 45.2 38.1
processBlock 28.3 42.5
```

### Heap Profile (`hoard-exe.pdf`)

Visual graph showing heap usage over time. Look for:
- **Steady growth** = possible memory leak
- **Spikes** = temporary allocations (usually fine)
- **Flat plateaus** = stable memory usage

## Tips

- Use `-hm` (module) for cleaner graphs than `-hc` (cost centre)
- Add `-L100` for more detailed heap sampling
- For concurrency analysis, use `nix run .#profile-eventlog` instead
- Profile with realistic workloads - toy data won't show real issues

## Further Reading

- [GHC Profiling Guide](https://downloads.haskell.org/ghc/latest/docs/users_guide/profiling.html)
- [Real World Haskell: Profiling](http://book.realworldhaskell.org/read/profiling-and-optimization.html)
15 changes: 13 additions & 2 deletions nix/outputs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ let
secretsApps = import ./secrets.nix { inherit pkgs; };
cardanoNode = import ./cardano-node.nix { inherit pkgs inputs system; };
monitoringApps = import ./monitoring.nix { inherit pkgs lib; };
profiling = import ./profiling.nix { inherit inputs pkgs; };
in
{
# Expose packages built by haskell.nix
Expand All @@ -84,7 +85,9 @@ in
default = projectFlake.packages."hoard:exe:hoard-exe";
}
# Merge in cardano-node packages (mithril-client-cli, etc.)
// cardanoNode.packages;
// cardanoNode.packages
# Merge in profiling package
// profiling.packages;

# Development shell
devShells.default = import ./shell.nix {
Expand All @@ -98,6 +101,12 @@ in

# Custom apps
apps = {
# Default app: run hoard executable
default = {
type = "app";
program = "${projectFlake.packages."hoard:exe:hoard-exe"}/bin/hoard-exe";
};

# ghcid with multi-repl for all packages and tests
ghcid-multi = {
type = "app";
Expand Down Expand Up @@ -143,7 +152,9 @@ in
# Import cardano-node and Mithril apps from separate module
// cardanoNode.apps
# Import monitoring apps (Prometheus, Grafana, node_exporter)
// monitoringApps.apps;
// monitoringApps.apps
# Import profiling apps (hoard-profiling, profile-heap, etc.)
// profiling.apps;

# Checks
checks = projectFlake.checks // {
Expand Down
Loading
Loading