From 128bdefa8f0960591c3c05fcd0cd097dac7a4a5a 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 v2] Measure Windows CPU usage during tests (poor man's vmstat)
 and also setup RAM disk Measure per-process I/O too

ci-os-only: windows
---
 .github/workflows/pg-ci.yml | 83 +++++++++++++++++++++++++++++++------
 1 file changed, 70 insertions(+), 13 deletions(-)

diff --git a/.github/workflows/pg-ci.yml b/.github/workflows/pg-ci.yml
index 5bc5292d2a5..fc083c90f58 100644
--- a/.github/workflows/pg-ci.yml
+++ b/.github/workflows/pg-ci.yml
@@ -420,12 +420,12 @@ jobs:
         with:
           name: logs-${{ github.job }}-${{ github.run_id }}-${{ github.run_attempt }}
           path: |
-              **/*.log
-              **/*.diffs
-              **/regress_log_*
-              **/crashlog-*.txt
-              build/meson-logs/**
-              **/config.log
+              R:/***/*.log
+              R:/***/*.diffs
+              R:/***/regress_log_*
+              R:/***/crashlog-*.txt
+              R:/*build/meson-logs/**
+              R:/**/config.log
           if-no-files-found: ignore
 
 
@@ -810,7 +810,7 @@ jobs:
             -Ddarwin_sysroot=none \
             ${MESON_COMMON_FEATURES} \
             ${MESON_FEATURES} \
-            build
+          R:/build
 
       - name: Build
         run: *ninja_build_cmd
@@ -877,10 +877,21 @@ jobs:
         shell: cmd
 
     steps:
+      - name: Setup RAM Disk
+        uses: chad-golden/setup-ramdisk@v1.0.1
+        with:
+          size-in-mb: 12000    # Optional: Default is 2048
+          drive-letter: 'R'   # Optional: Default is R
+          copy-workspace: true # Optional: Default is false
+
       - &windows_disable_defender_step
         name: Disable Windows Defender
         shell: pwsh
         run: |
+          mkdir R:\build
+          icacls "R:\build" /grant "${env:USERNAME}:(OI)(CI)F" /Q | Out-Null
+          Write-Host "Granted Full Control to $env:USERNAME on R:\build"
+
           Set-MpPreference -DisableRealtimeMonitoring $true -SubmitSamplesConsent NeverSend -MAPSReporting Disable
           # Verify Defender status
           $status = Get-MpComputerStatus -ErrorAction SilentlyContinue
@@ -1000,13 +1011,48 @@ jobs:
             --buildtype debug ^
             -Db_pch=true ^
             -DTAR=${{env.TAR}} ^
-            build
+            R:/build
 
       - name: Build
         run: |
           call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64
-          ninja -C build ${{env.MBUILD_TARGET}} || exit 1
-          ninja -C build -t missingdeps
+          echo %cd%
+          ninja -C R:/build ${{env.MBUILD_TARGET}} || exit 1
+          ninja -C R:/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"'
+            '"\PhysicalDisk(*)\Avg. Disk sec/Read"'
+            '"\PhysicalDisk(*)\Avg. Disk sec/Write"'
+            '"\PhysicalDisk(*)\Avg. Disk Queue Length"'
+            '"\Process(*)\IO Data Bytes/sec"'
+            '"\Process(*)\IO Data Operations/sec"'
+            '"\Process(*)\IO Other Bytes/sec"'
+            '"\Process(*)\IO Other Operations/sec"'
+            '"\Process(*)\IO Read Bytes/sec"'
+            '"\Process(*)\IO Read Operations/sec"'
+            '"\Process(*)\IO Write Bytes/sec"'
+            '"\Process(*)\IO Write Operations/sec"'
+            '-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:
@@ -1017,11 +1063,22 @@ jobs:
           MTEST_TARGET: --slice ${{ matrix.slice}}/${{ matrix.num_slices}} ${{env.MTEST_TARGET}}
           ADDITIONAL_SETUP: |
             call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64
+            R:
         run: *meson_test_world_cmd
 
-      # TODO: We need to collect crashlogs but for them to be generated, we'd
-      # have to configure the JIT Debugger to do so. cdb.exe is installed on
-      # the runner so that is possible.
+      - 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
+
       - *upload_logs_step
 
 
-- 
2.43.0

