Skip to content

Gabicle/pg-query-profiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Query Profiler

A real-time query profiler for .NET applications using PostgreSQL. Hooks into Entity Framework Core's interceptor pipeline to capture, fingerprint, and aggregate query performance metrics.

Built as a companion tool for fga-dotnet , a Zanzibar-inspired fine-grained authorization system that works with any EF Core + PostgreSQL application.

What it does

  • Intercepts every query EF Core sends to PostgreSQL

  • Normalizes SQL into fingerprints so identical query patterns are grouped together

  • Computes p50 / p95 / p99 latency percentiles per query pattern

  • Exposes aggregated stats via a /metrics/snapshot endpoint

  • Designed as a drop-in plugin i.e one line to add to any existing app

How to plug it in

1. Reference the project

dotnet add reference ../query-profiler/QueryProfiler.Core/QueryProfiler.Core.csproj

2. Register the services

builder.Services.AddQueryProfiler();

3. Hook the interceptor into your DbContext

services.AddDbContext<YourDbContext>((sp, options) =>

{

    options.UseNpgsql(connectionString);

    options.AddInterceptors(sp.GetRequiredService<QueryProfilingInterceptor>());

});

4. Expose the endpoint

app.MapGet("/metrics/snapshot", (IQueryMetricsStore store) =>

    Results.Ok(store.GetSnapshot()));

Target system

This profiler is demonstrated against fga-dotnet — a PostgreSQL-backed authorization system where permission checks run on every API call, making query performance critical.

Roadmap

  • Prometheus /metrics endpoint

  • Slow query EXPLAIN ANALYZE capture

  • Grafana dashboard

About

Real-time query profiler for EF Core + PostgreSQL. Intercepts, fingerprints, and tracks p50/p95/p99 latency per query pattern.

Topics

Resources

Stars

Watchers

Forks

Contributors

Languages