From a8fadbffc46f15ff771bf39945ab8a26b51902db Mon Sep 17 00:00:00 2001
From: Jakub Wartak <jakub.wartak@enterprisedb.com>
Date: Wed, 10 Jun 2026 09:38:34 +0200
Subject: [PATCH v1] Measure Windows CPU usage during tests (poor man's vmstat)

ci-os-only: windows
---
 .github/workflows/postgresql-ci.yml | 36 +++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/.github/workflows/postgresql-ci.yml b/.github/workflows/postgresql-ci.yml
index e2795ca0ffb..de55f4dfd44 100644
--- a/.github/workflows/postgresql-ci.yml
+++ b/.github/workflows/postgresql-ci.yml
@@ -800,12 +800,48 @@ jobs:
           ninja -C build ${{env.MBUILD_TARGET}}
           ninja -C build -t missingdeps
 
+      - name: Start CPU Monitoring
+        shell: pwsh
+        run: |
+          $TypeperfArgs = @(
+            # CPU Metrics
+            '"\Processor(_Total)\% Processor Time"'
+            '"\Processor(_Total)\% Privileged Time"'
+            '"\System\Processor Queue Length"'
+            # Memory Metrics
+            '"\Memory\Available MBytes"'
+            '"\Memory\% Committed Bytes In Use"'
+            '"\Memory\Pages/sec"'
+            # Disk I/O Metrics
+            '"\PhysicalDisk(_Total)\Avg. Disk sec/Read"'
+            '"\PhysicalDisk(_Total)\Avg. Disk sec/Write"'
+            '"\PhysicalDisk(_Total)\Avg. Disk Queue Length"'
+            '-si', '2'
+            '-f', 'CSV',
+            '-o', 'D:\system_perf.csv'
+          )
+          Start-Process typeperf -ArgumentList $TypeperfArgs -WindowStyle Hidden
+          Write-Host "Performance monitoring started."
+
       - name: Test world
         env:
           ADDITIONAL_SETUP: |
             call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64
         run: *meson_test_world_cmd
 
+      - name: Stop CPU Monitoring
+        shell: pwsh
+        if: always()
+        run: |
+          Stop-Process -Name typeperf -Force -ErrorAction SilentlyContinue
+          Write-Host "Performance monitoring stopped."
+
+      - name: Upload CPU Log Artifact
+        uses: actions/upload-artifact@v4
+        if: always()
+        with:
+          path: D:\system_perf.csv
+
       # FIX: We need to collect crashlogs but they are not collected. cdb.exe
       # is installed on the runner so it needs to be configured.
       - *upload_logs_step
-- 
2.43.0

