From 97cd559265a22603b029893533524d8e44618f9a Mon Sep 17 00:00:00 2001 From: steve-chavez Date: Wed, 28 Feb 2024 13:28:20 -0500 Subject: [PATCH] nix: add postgrest-profiled-run Runs a profiled build of postgREST that can be used for optimization. --- default.nix | 2 +- nix/tools/memory.nix | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/default.nix b/default.nix index 48903f3fc0..32f9f992ba 100644 --- a/default.nix +++ b/default.nix @@ -134,7 +134,7 @@ rec { # Script for running memory tests. memory = - pkgs.callPackage nix/tools/memory.nix { inherit postgrestProfiled withTools; }; + pkgs.callPackage nix/tools/memory.nix { inherit postgrestProfiled postgrest withTools; }; # Utility for updating the pinned version of Nixpkgs. nixpkgsTools = diff --git a/nix/tools/memory.nix b/nix/tools/memory.nix index 15683275d3..1c00d04817 100644 --- a/nix/tools/memory.nix +++ b/nix/tools/memory.nix @@ -5,6 +5,7 @@ , checkedShellScript , curl , postgrestProfiled +, postgrest , withTools }: let @@ -20,9 +21,32 @@ let ${withTools.withPg} -f test/spec/fixtures/load.sql test/memory/memory-tests.sh ''; + runProfiled = + checkedShellScript + { + name = "postgrest-profiled-run"; + docs = "Run a profiled build of postgREST. This will generate a postgrest.prof file that can be used to do optimization."; + args = + [ + "ARG_USE_ENV([PGRST_DB_ANON_ROLE], [postgrest_test_anonymous], [PostgREST anonymous role])" + "ARG_USE_ENV([PGRST_DB_POOL], [1], [PostgREST pool size])" + "ARG_USE_ENV([PGRST_DB_POOL_ACQUISITION_TIMEOUT], [1], [PostgREST pool size])" + "ARG_LEFTOVERS([PostgREST arguments])" + ]; + workingDir = "/"; + withPath = [ postgrestProfiled ]; + withEnv = postgrest.env; + } + '' + export PGRST_DB_ANON_ROLE + export PGRST_DB_POOL + export PGRST_DB_POOL_ACQUISITION_TIMEOUT + + postgrest +RTS -p -h -RTS "''${_arg_leftovers[@]}" + ''; in buildToolbox { name = "postgrest-memory"; - tools = { inherit test; }; + tools = { inherit test runProfiled; }; }