<article class="max-w-4xl mx-auto px-6 py-12">
<header class="mb-12">
<h1 class="text-4xl font-bold mb-4">Memory Profiling</h1>
<p class="text-xl text-muted">
Detect memory leaks and analyze allocation patterns.
</p>
</header>
<div class="space-y-12">
<section>
<h2 class="text-2xl font-semibold mb-4">Quick Leak Check</h2>
<p class="text-muted mb-4">Wrap any code block to detect potential memory leaks.</p>
<app-code-block [code]="quickCheckCode" language="rust" />
</section>
<section>
<h2 class="text-2xl font-semibold mb-4">Memory Snapshots</h2>
<p class="text-muted mb-4">Compare memory state before and after operations.</p>
<app-code-block [code]="snapshotCode" language="rust" />
</section>
<section>
<h2 class="text-2xl font-semibold mb-4">Allocation Tracking</h2>
<p class="text-muted mb-4">Track every allocation with detailed statistics.</p>
<app-code-block [code]="trackingCode" language="rust" />
</section>
<section>
<h2 class="text-2xl font-semibold mb-4">Full Memory Report</h2>
<app-code-block [code]="reportCode" language="rust" />
</section>
<section>
<h2 class="text-2xl font-semibold mb-4">CI Integration</h2>
<p class="text-muted mb-4">Automatically check for leaks in CI with Valgrind.</p>
<app-code-block [code]="ciCode" language="yaml" />
</section>
<section>
<h2 class="text-2xl font-semibold mb-4">Profiling Features</h2>
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead>
<tr class="border-b border-border">
<th class="text-left py-3 px-4">Feature</th>
<th class="text-left py-3 px-4">Module</th>
<th class="text-left py-3 px-4">Description</th>
</tr>
</thead>
<tbody class="divide-y divide-border">
<tr>
<td class="py-3 px-4">Allocation Tracking</td>
<td class="py-3 px-4 font-mono text-xs">allocation.rs</td>
<td class="py-3 px-4 text-muted">Track every alloc/dealloc with stats</td>
</tr>
<tr>
<td class="py-3 px-4">Memory Snapshots</td>
<td class="py-3 px-4 font-mono text-xs">snapshot.rs</td>
<td class="py-3 px-4 text-muted">Capture and diff memory state</td>
</tr>
<tr>
<td class="py-3 px-4">Leak Detection</td>
<td class="py-3 px-4 font-mono text-xs">leak_detector.rs</td>
<td class="py-3 px-4 text-muted">Identify potential memory leaks</td>
</tr>
<tr>
<td class="py-3 px-4">Heap Profiling</td>
<td class="py-3 px-4 font-mono text-xs">heap.rs</td>
<td class="py-3 px-4 text-muted">System-level heap analysis</td>
</tr>
<tr>
<td class="py-3 px-4">Size Histogram</td>
<td class="py-3 px-4 font-mono text-xs">allocation.rs</td>
<td class="py-3 px-4 text-muted">Distribution of allocation sizes</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h2 class="text-2xl font-semibold mb-4">Enable Profiling</h2>
<div class="p-4 rounded-lg bg-surface border border-border">
<p class="text-sm text-muted mb-2">Add the <code class="text-amber-400">profiling</code> feature flag:</p>
<pre class="text-sm font-mono bg-black/30 p-3 rounded">prax-query = {{ version = "0.3", features = ["profiling"] }}</pre>
</div>
</section>
<section>
<h2 class="text-2xl font-semibold mb-4">CI Workflows</h2>
<div class="grid gap-4">
<div class="p-4 rounded-lg bg-surface border border-border">
<h3 class="font-semibold mb-1">Leak Detection Tests</h3>
<p class="text-sm text-muted">Run profiling module tests on every PR</p>
</div>
<div class="p-4 rounded-lg bg-surface border border-border">
<h3 class="font-semibold mb-1">Valgrind Analysis</h3>
<p class="text-sm text-muted">Check for definite memory leaks (Linux)</p>
</div>
<div class="p-4 rounded-lg bg-surface border border-border">
<h3 class="font-semibold mb-1">AddressSanitizer</h3>
<p class="text-sm text-muted">Runtime memory error detection (nightly)</p>
</div>
<div class="p-4 rounded-lg bg-surface border border-border">
<h3 class="font-semibold mb-1">DHAT Profiling</h3>
<p class="text-sm text-muted">Heap allocation analysis</p>
</div>
</div>
</section>
<section>
<h2 class="text-2xl font-semibold mb-4">Benchmarks</h2>
<div class="p-4 rounded-lg bg-surface border border-border">
<p class="text-sm text-muted mb-2">Run memory profiling benchmarks:</p>
<pre class="text-sm font-mono bg-black/30 p-3 rounded">cargo bench --package prax-query --bench memory_profile_bench</pre>
</div>
</section>
</div>
</article>