From b7ad217cd3b50e5cbe74489ae737d1ef555644b1 Mon Sep 17 00:00:00 2001 From: Andrei Dziahel Date: Tue, 22 Jul 2025 19:38:07 +0200 Subject: [PATCH] fix: unbreaks postgrest-profiled-run * replaces v2-build -> v2-run (which should be v2-exec) with one-shot v2-run * fixes empty postgrest.prof file by sending SIGINT to the profiled postgrest process to trigger writing it explicitly --- nix/tools/cabalTools.nix | 5 ++--- nix/tools/withTools.nix | 9 +++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/nix/tools/cabalTools.nix b/nix/tools/cabalTools.nix index 175e10a03..9db63eb20 100644 --- a/nix/tools/cabalTools.nix +++ b/nix/tools/cabalTools.nix @@ -95,9 +95,8 @@ let export PGRST_DB_POOL_ACQUISITION_TIMEOUT export PGRST_JWT_SECRET - ${cabal-install}/bin/cabal --builddir="dist-prof" v2-build --enable-profiling --disable-shared exe:postgrest - ${cabal-install}/bin/cabal --builddir="dist-prof" v2-run -- \ - postgrest +RTS -p -h -RTS "''${_arg_leftovers[@]}" + exec ${cabal-install}/bin/cabal --builddir="dist-prof" v2-run --enable-profiling --disable-shared exe:postgrest -- \ + +RTS -p -h -RTS "''${_arg_leftovers[@]}" ''; repl = diff --git a/nix/tools/withTools.nix b/nix/tools/withTools.nix index 82de1e4d6..d4b2a1440 100644 --- a/nix/tools/withTools.nix +++ b/nix/tools/withTools.nix @@ -5,6 +5,7 @@ , lib , postgresqlVersions , postgrest +, procps , python3Packages , slocat , writeText @@ -373,6 +374,14 @@ let pid=$! # shellcheck disable=SC2317 cleanup() { + # Send INT to all postgrest processes. + # Workaround to trigger dumping postgrest.prof for postgrest-profiled-run + # Caveat: we cannot realistically limit this to the current process' tree, + # since pkill's --parent supports only direct children; therefore this + # would reap neighbor postgrest instances as well, because INT is asking + # the process to terminate too. + # TODO: consider cgroups to make this cleaner + ${procps}/bin/pkill --echo --signal=INT --exact postgrest kill "$pid" || true } trap cleanup EXIT